shish 1 год назад
Родитель
Сommit
2107ab87af

+ 113 - 4
app-ghs/controllers/OrderController.php

@@ -1148,7 +1148,8 @@ class OrderController extends BaseController
             $hasTime = dict::getDict('order_pay_has_time');
             $totalTime = bcadd($time, $hasTime);
             $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
-            $return = OrderService::createFinishOrder($post, $custom, $hasPay);
+            //多处有用到此方法,需要同步修改,搜索关键词create_new_order
+            $return = OrderService::createNewOrder($post, $custom, $hasPay);
             $transaction->commit();
 
             $saleId = $return->id ?? 0;
@@ -2607,13 +2608,25 @@ class OrderController extends BaseController
     //导入开单 ssh 20241126
     public function actionImportCreate()
     {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
         $get = Yii::$app->request->get();
-        $id = $get['id'] ?? '';
+        $customId = $get['id'] ?? '';
+        $customRes = CustomClass::getById($customId, true);
+        if (empty($customRes)) {
+            util::fail('没有找到客户');
+        }
+        if ($customRes->ownMainId != $this->mainId) {
+            util::fail('不是你的客户');
+        }
+
         $file = $_FILES['file'];
         if (!is_uploaded_file($file['tmp_name'])) {
             util::fail('please upload img');
         }
-        $mainId = $this->sjId;
+        $mainId = $this->mainId;
+        $sjId = $this->sjId;
         $shopId = $this->shopId;
         $month = date("Ym");
         $date = date("d");
@@ -2645,7 +2658,103 @@ class OrderController extends BaseController
                 $arr[] = $rowData;
             }
             array_shift($arr);
-            print_r($arr);
+            $productIds = [];
+            foreach ($arr as $k => $v) {
+                $productId = $v[0] ?? 0;
+                $productId = trim($productId);
+                if (is_numeric($productId) && $productId > 0) {
+                    $productIds[] = $productId;
+                }
+            }
+
+            $productInfo = ProductClass::getByIds($productIds, null, 'id');
+
+            print_r($productInfo);
+
+            $mat = [];
+            foreach ($arr as $k => $v) {
+                $productId = $v[0] ?? 0;
+                $productId = trim($productId);
+                $itemName = $v[1] ?? '';
+                $itemName = trim($itemName);
+                $num = $v[2] ?? 0;
+                $num = trim($num);
+                $unitPrice = $v[3] ?? 0;
+                $unitPrice = trim($unitPrice);
+                $remark = $v['5'] ?? '';
+                $remark = trim($remark);
+                if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
+                    $product = $productInfo[$productId] ?? [];
+                    $ptItemId = $product['itemId'] ?? 0;
+                    echo $ptItemId;die;
+                    $mat[] = [
+                        'productId' => $productId,
+                        'bigNum' => $num,
+                        'itemId' => $ptItemId,
+                        'smallNum' => 0,
+                        'price' => $unitPrice,
+                        'remark' => $remark,
+                    ];
+                }
+            }
+
+            $modifyPrice = 0;
+            foreach ($mat as $ma) {
+                $cNum = $ma['bigNum'] ?? 0;
+                $cPrice = $ma['price'] ?? 0;
+                $cTotal = bcmul($cNum, $cPrice, 2);
+                $modifyPrice = bcadd($modifyPrice, $cTotal, 2);
+            }
+
+            $customName = $customRes->name ?? '';
+            $customMobile = $customRes->mobile ?? '';
+            $customPy = $customRes->py ?? '';
+            $ghsId = $customRes->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'] = $mainId;
+            $post['fromType'] = 1;
+            $post['expressId'] = 0;
+            $post['sjId'] = $sjId;
+
+            $staff = $this->shopAdmin;
+            $staffId = $staff->id ?? 0;
+            $staffName = $staff->name ?? '';
+            $post['shopAdminId'] = $staffId;
+            $post['shopAdminName'] = $staffName;
+            $post['getStaffId'] = $staffId;
+            $post['getStaffName'] = $staffName;
+
+            $post['customMobile'] = $customMobile;
+            $post['customNamePy'] = $customPy;
+            $post['customAvatar'] = '';
+
+            $post['newVersion'] = 1;
+            $post['book'] = 0;
+            $post['wlName'] = '';
+            $post['dealPrice'] = 1;
+            $post['ghsId'] = $ghsId;
+
+            //多处有用到此方法,需要同步修改,搜索关键词create_new_order
+            OrderService::createNewOrder($post, $custom, $hasPay);
+
         } else {
             util::fail('上传失败');
         }

+ 1 - 1
biz-ghs/order/services/OrderService.php

@@ -154,7 +154,7 @@ class OrderService extends BaseService
     }
 
     //添加订单
-    public static function createFinishOrder($data, $custom, $hasPay = 1)
+    public static function createNewOrder($data, $custom, $hasPay = 1)
     {
         //有unitType数据,说明是收银台传过来的数据,转换成和手机端结构一致
         $hasUnitType = array_column($data['product'], 'unitType');

+ 2 - 2
console/controllers/LiveOrderController.php

@@ -153,8 +153,8 @@ class LiveOrderController extends Controller
                     $post['ghsId'] = $ghsId;
 
                     $post['historyDate'] = $historyDate;
-
-                    $order = OrderService::createFinishOrder($post, $custom, $hasPay);
+                    //多处有用到此方法,需要同步修改,搜索关键词create_new_order
+                    $order = OrderService::createNewOrder($post, $custom, $hasPay);
 
                     //清掉一天多单的汇总
                     $sameDate = date("Y_m_d");