shish 1 éve
szülő
commit
42fd67d5a1
1 módosított fájl, 102 hozzáadás és 35 törlés
  1. 102 35
      console/controllers/LiveOrderController.php

+ 102 - 35
console/controllers/LiveOrderController.php

@@ -5,6 +5,7 @@ namespace console\controllers;
 use biz\shop\classes\ShopClass;
 use bizGhs\live\classes\LiveOrderClass;
 use bizGhs\live\classes\LiveOrderCustomClass;
+use bizGhs\live\classes\LiveSeatClass;
 use common\components\noticeUtil;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\order\services\OrderService;
@@ -19,76 +20,142 @@ class LiveOrderController extends Controller
     {
         ini_set('memory_limit', '2045M');
         set_time_limit(0);
-        $shopList = ShopClass::getAllByCondition(['ptStyle'=>2],null,'*',null,true);
-        if(empty($shopList)){
+        $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
+        if (empty($shopList)) {
             return false;
         }
-        foreach($shopList as $shop){
+        foreach ($shopList as $shop) {
             $mainId = $shop->mainId;
-            $shopName = $shop->shopName??'';
-            $sjName = $shop->merchantName??'';
-            $name = $sjName.' '.$shopName;
+            $shopName = $shop->shopName ?? '';
+            $sjName = $shop->merchantName ?? '';
+            $shopId = $shop->id ?? 0;
+            $sjId = $shop->sjId ?? 0;
+            $name = $sjName . ' ' . $shopName;
             $cacheKey = 'live_order_' . $mainId;
             $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
-            if(empty($has)){
+            if (empty($has)) {
                 continue;
             }
-            echo $cacheKey.' ';
             $connection = Yii::$app->db;
             $transaction = $connection->beginTransaction();
             try {
 
-                $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId,'switchOrder'=>0], null, '*');
-                if(empty($list)){
+                $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId, 'switchOrder' => 0], null, '*');
+                if (empty($list)) {
                     continue;
                 }
-                $customInfo = CustomClass::getAllByCondition(['ownMainId'=>$mainId],null,'*','id');
+                $customInfo = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
                 $total = [];
                 $format = [];
+                $staffId = 0;
+                $staffName = '';
+                $historyDate = date("Y-m-d");
                 foreach ($list as $key => $live) {
                     $addTime = $live['addTime'];
+                    $historyDate = date("Y-m-d", strtotime($addTime));
                     $orderSn = $live['orderSn'];
                     $itemId = $live['itemId'];
                     $ptItemId = $live['ptItemId'];
+                    $staffId = $live['staffId'] ?? 0;
+                    $staffName = $live['staffName'] ?? '';
                     $date = date("Y-m-d", strtotime($addTime));
-                    $customList = LiveOrderCustomClass::getAllByCondition(['orderSn'=>$orderSn],null,'*');
-                    if(empty($customList)){
+                    $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
+                    if (empty($customList)) {
                         continue;
                     }
                     $total[$date] = 1;
-                    foreach($customList as $k => $v){
-                        $customId = $v['customId']??0;
-                        $num = $v['num']??0;
-                        $unitPrice = $v['unitPrice']??0;
-                        $currentCustom = $customInfo[$customId]??[];
-                        if(empty($currentCustom)){
+                    foreach ($customList as $k => $v) {
+                        $customId = $v['customId'] ?? 0;
+                        $num = $v['num'] ?? 0;
+                        $unitPrice = $v['unitPrice'] ?? 0;
+                        $currentCustom = $customInfo[$customId] ?? [];
+                        if (empty($currentCustom)) {
                             throw new \Exception("出现不存在的客户 customId:{$customId}");
                         }
-                        $format[$customId][] =[
-                            'productId'=>$itemId,
-                            'bigNum'=>$num,
-                            'itemId'=>$ptItemId,
-                            'smallNum'=>0,
-                            'price'=>$unitPrice,
+                        $format[$customId][] = [
+                            'productId' => $itemId,
+                            'bigNum' => $num,
+                            'itemId' => $ptItemId,
+                            'smallNum' => 0,
+                            'price' => $unitPrice,
                         ];
                     }
                 }
                 if (count($total) > 1) {
-                    noticeUtil::push($name." mainId:{$mainId} live order 有记录不是同一天的", '15280215347');
+                    noticeUtil::push($name . " mainId:{$mainId} live order 有记录不是同一天的", '15280215347');
                     continue;
                 }
+                if (empty($format)) {
+                    noticeUtil::push($name . " mainId:{$mainId} live order 没有找到客户预订", '15280215347');
+                    continue;
+                }
+
+                foreach ($format as $customId => $mat) {
+
+                    $modifyPrice = 0;
+                    foreach ($mat as $ma) {
+                        $cNum = $ma['bigNum'] ?? 0;
+                        $cPrice = $ma['price'] ?? 0;
+                        $cTotal = bcmul($cNum, $cPrice, 2);
+                        $modifyPrice = bcadd($modifyPrice, $cTotal, 2);
+                    }
+
+                    $currentCustom = $customInfo[$customId] ?? [];
+                    if (empty($currentCustom)) {
+                        throw new \Exception("出现不存在的客户哦 customId:{$customId}");
+                    }
+                    $customName = $currentCustom['name'] ?? '';
+                    $customMobile = $currentCustom['mobile'] ?? '';
+                    $customPy = $currentCustom['py'] ?? '';
+                    $ghsId = $currentCustom['ghsId'] ?? 0;
+
+                    $hasPay = 2;
+                    $custom = CustomClass::getCustom($customId);
+                    $post = [];
+                    $post['modifyPrice'] = $modifyPrice;
+                    $post['shopId'] = $shopId;
+                    $post['sendType'] = 0;
+                    $post['transType'] = 0;
+                    $post['sendSide'] = 0;
+                    $post['sendCost'] = 0;
+                    $post['packCost'] = 0;
+                    $post['customId'] = $customId;
+                    $post['customName'] = $customName;
+                    $post['payWay'] = 0;
+                    $post['needPrint'] = 2;
+                    $post['hasPay'] = 2;
+                    $post['product'] = $mat;
+                    $post['deadline'] = date("Y-m-d H:i:s", time() + 86400);
+                    $post['debt'] = 1;
+                    $post['mainId'] = 0;
+                    $post['fromType'] = 1;
+                    $post['expressId'] = 0;
+                    $post['sjId'] = $sjId;
+
+                    $post['shopAdminId'] = $staffId;
+                    $post['shopAdminName'] = $staffName;
+                    $post['getStaffId'] = $staffId;
+                    $post['getStaffName'] = $staffName;
 
-                print_r($format);die;
+                    $post['customMobile'] = $customMobile;
+                    $post['customNamePy'] = $customPy;
+                    $post['customAvatar'] = '';
 
+                    $post['newVersion'] = 1;
+                    $post['book'] = 0;
+                    $post['wlName'] = '';
+                    $post['dealPrice'] = 1;
+                    $post['ghsId'] = $ghsId;
 
-                $hasPay = 2;
-                $customId = 0;
-                $custom = CustomClass::getCustom($customId);
-                $post = [];
-                $post['shopId'] =0;
-                OrderService::createFinishOrder($post, $custom, $hasPay);
+                    $post['historyDate'] = $historyDate;
+
+                    OrderService::createFinishOrder($post, $custom, $hasPay);
+
+                }
 
-                //转换完了之后要清货位号!!!!!!!!!
+                //清空货位
+                CustomClass::updateByCondition(['ownMainId' => $mainId], ['seatSn' => '']);
+                LiveSeatClass::updateByCondition(['mainId' => $mainId], ['customId' => 0, 'customName' => '']);
 
                 $transaction->commit();
                 Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
@@ -96,7 +163,7 @@ class LiveOrderController extends Controller
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 $msg = $e->getMessage();
-                noticeUtil::push($name." mainId:{$mainId} live order 报错了:".$msg, '15280215347');
+                noticeUtil::push($name . " mainId:{$mainId} live order 报错了:" . $msg, '15280215347');
             }
         }
     }