shish 5 lat temu
rodzic
commit
7a10daeae0

+ 60 - 43
app/shop/controllers/OrderController.php

@@ -6,6 +6,7 @@ use biz\merchant\services\MerchantAssetService;
 use biz\merchant\services\MerchantExtendService;
 use biz\merchant\services\MerchantService;
 use biz\merchant\services\ShopService;
+use biz\order\classes\OrderClass;
 use biz\order\classes\OrderSendClass;
 use biz\order\services\OrderService;
 use biz\saas\services\RegionService;
@@ -35,22 +36,56 @@ class OrderController extends BaseController
     public function actionCreateOrder()
     {
         $post = Yii::$app->request->post();
-        $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
-        $goodsStyleId = isset($post['goodsStyleId']) ? $post['goodsStyleId'] : 0;
-        $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
         $needSend = isset($post['needSend']) && is_numeric($post['needSend']) ? $post['needSend'] : 1;
-        if (empty($goodsId)) {
+
+        $goodsInfo = $post['goodsInfo'] ?? '';
+        $goodsInfoArr = json_decode($goodsInfo, true);
+        if (empty($goodsInfoArr)) {
             util::fail('请选择商品');
         }
-        $goodsInfo = GoodsService::getGoodsInfo($goodsId);
-        if (empty($goodsInfo)) {
-            util::fail('没有找到商品');
-        }
-        if (isset($goodsInfo['stock']) == false || $goodsInfo['stock'] == 0) {
-            util::fail('已经卖完了');
+        //总的商品金额
+        $totalGoodsPrice = 0;
+        $orderGoods = [];
+        foreach ($goodsInfoArr as $key => $currentGoods) {
+            $currentGoodsId = $currentGoods['goodsId'];
+            $currentGoodsInfo = GoodsService::getGoodsInfo($currentGoodsId);
+            if (empty($currentGoodsInfo)) {
+                util::fail('没有找到商品');
+            }
+            $goodsStyleId = $currentGoods['goodsStyleId'];
+            $goodsNum = $currentGoods['goodsNum'];
+            //计算总金额
+            $unitPrice = $currentGoodsInfo['price'];
+            $goodsStyleList = isset($currentGoodsInfo['goodsStyleList']) ? $currentGoodsInfo['goodsStyleList'] : [];
+            if (!empty($goodsStyleId)) {
+                if (empty($goodsStyleList)) {
+                    util::fail('商品款式没有找到');
+                }
+                $styleIdList = array_keys($goodsStyleList);
+                if (in_array($goodsStyleId, $styleIdList) == false) {
+                    util::fail('商品款式没有找到!');
+                }
+                $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
+            }
+            $goodsPrice = $unitPrice * $goodsNum;
+            $totalGoodsPrice = stringUtil::calcAdd($totalGoodsPrice, $goodsPrice);
+
+            $orderGoods[] = [
+                'goodsId' => $currentGoodsId,
+                'userId' => $this->adminId,
+                'merchantId' => $this->sjId,
+                'title' => $currentGoodsInfo['goodsName'],
+                'cover' => isset($goodsInfo['shortImgList']) && !empty($currentGoodsInfo['shortImgList']) ? current($currentGoodsInfo['shortImgList']) : '',
+                'unitPrice' => $unitPrice,
+                'num' => $goodsNum,
+                'goodsStyleName' => isset($currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
+                'goodsStyleId' => $goodsStyleId,
+                'createTime' => date("Y-m-d H:i:s"),
+            ];
+
         }
-        //运费计算方式
-        $freightType = isset($goodsInfo['freightType']) ? $goodsInfo['freightType'] : 0;
+
+
         $customId = $post['customId'] ?? 0;
         if (!empty($customId)) {
             $customId = $this->customId;
@@ -70,6 +105,8 @@ class OrderController extends BaseController
         $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
         $sendCost = 0;
         //按距离计算运费并且客户要求送的
+        //运费计算方式
+        $freightType = 0;
         if ($freightType == 0 && $needSend == 1) {
             $lat = $post['latitude'];//收货人纬度
             $lng = $post['longitude'];//收货人经度
@@ -80,21 +117,8 @@ class OrderController extends BaseController
         $post['merchantId'] = $this->sjId;
         $post['shopId'] = $defaultShopId;
 
-        //计算总金额
-        $unitPrice = $goodsInfo['price'];
-        $goodsStyleList = isset($goodsInfo['goodsStyleList']) ? $goodsInfo['goodsStyleList'] : [];
-        if (!empty($goodsStyleId)) {
-            if (empty($goodsStyleList)) {
-                util::fail('商品款式没有找到');
-            }
-            $styleIdList = array_keys($goodsStyleList);
-            if (in_array($goodsStyleId, $styleIdList) == false) {
-                util::fail('商品款式没有找到!');
-            }
-            $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
-        }
-        $goodsPrice = $unitPrice * $goodsNum;
-        $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
+        $prePrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
+
         //非门店订单
         $store = 0;
         $post['store'] = $store;
@@ -115,24 +139,17 @@ class OrderController extends BaseController
         $post['fromType'] = 1;//商城
         $post['prePrice'] = $prePrice;
         $post['actPrice'] = $actPrice;
-        $order = OrderService::addOrder($post);
+        $order = OrderClass::addOrder($post);
         $orderId = $order['id'];
         $orderSn = $order['orderSn'];
-        $data = [
-            'orderId' => $orderId,
-            'goodsId' => $goodsId,
-            'userId' => $this->adminId,
-            'merchantId' => $this->sjId,
-            'title' => $goodsInfo['goodsName'],
-            'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
-            'unitPrice' => $unitPrice,
-            'num' => $goodsNum,
-            'goodsStyleName' => isset($goodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $goodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
-            'goodsStyleId' => $goodsStyleId,
-            'createTime' => date("Y-m-d H:i:s"),
-        ];
-        OrderGoodsService::add($data);//创建订单商品列表
-        util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId]);
+
+        foreach ($orderGoods as $key => $val) {
+            $val['orderId'] = $orderId;
+            $val['orderSn'] = $orderSn;
+            OrderGoodsService::add($val);//创建订单商品列表
+        }
+
+        util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
     }
 
     //下单要用到的相关信息 shish 2019.12.6

+ 2 - 1
biz/order/classes/OrderClass.php

@@ -11,6 +11,7 @@ use biz\stat\classes\StatOrderCountClass;
 use biz\stat\classes\StatOrderMonthClass;
 use biz\user\classes\UserClass;
 use common\components\miniUtil;
+use common\components\orderSn;
 use common\components\stringUtil;
 use common\services\xhOrderDayNumService;
 use common\services\xhOrderMonthNumService;
@@ -66,7 +67,7 @@ class OrderClass extends BaseClass
     {
         $date = date("Y-m-d H:i:s");
         $merchantId = $data['merchantId'];
-        $data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
+        $data['orderSn'] = orderSn::getOrderSn();
         $data['payStatus'] = 0;
         $data['createTime'] = $date;
         $data['addTime'] = time();

+ 2 - 1
sql.sql

@@ -1139,4 +1139,5 @@ ALTER TABLE xhItemClass ADD `group` TINYINT NOT NULL DEFAULT 0 COMMENT ' 所属
 ALTER TABLE xhItem ADD classId INT NOT NULL DEFAULT 0 COMMENT '平台分类id' AFTER `cover`;
 ALTER TABLE `xhItem`
 MODIFY COLUMN `addTime`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
-MODIFY COLUMN `updateTime`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间';
+MODIFY COLUMN `updateTime`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间';
+ALTER TABLE xhOrderGoods ADD orderSn CHAR(20) NOT NULL DEFAULT '' COMMENT '' AFTER `orderId`;