Przeglądaj źródła

批发与零售跑腿计算规则分开设置与保存

shizhongqi 8 miesięcy temu
rodzic
commit
0ef43a8cc4
1 zmienionych plików z 62 dodań i 15 usunięć
  1. 62 15
      app-ghs/controllers/ShopExtController.php

+ 62 - 15
app-ghs/controllers/ShopExtController.php

@@ -4,7 +4,6 @@ namespace ghs\controllers;
 
 use biz\product\classes\XjClass;
 use biz\shop\classes\ShopExtClass;
-use bizGhs\order\classes\PurchaseOrderClass;
 use bizGhs\product\classes\ProductClass;
 use common\components\printUtil;
 use common\components\util;
@@ -19,16 +18,24 @@ class ShopExtController extends BaseController
     public function actionModifyExt()
     {
         $post = Yii::$app->request->post();
-        $arr = [];
+
+        $hdArr = [];
+        $ghsArr = [];
+
         if (isset($post['orderFlow'])) {
-            $arr['orderFlow'] = $post['orderFlow'];
+            $hdArr['orderFlow'] = $post['orderFlow'];
+            $ghsArr['orderFlow'] = $post['orderFlow'];
         }
         if (isset($post['thirdSend'])) {
-            $arr['thirdSend'] = $post['thirdSend'];
+            $hdArr['thirdSend'] = $post['thirdSend'];
+            $ghsArr['thirdSend'] = $post['thirdSend'];
         }
         if (isset($post['thirdSendFee'])) {
-            $arr['thirdSendFee'] = $post['thirdSendFee'];
+            $hdArr['thirdSendFee'] = $post['thirdSendFee'];
+            $ghsArr['thirdSendFee'] = $post['thirdSendFee'];
         }
+
+        // 组建零售数据
         if (!empty($post['hcMap'])) {
             $str = $post['hcMap'];
             $map = json_decode($str, true);
@@ -40,27 +47,56 @@ class ShopExtController extends BaseController
                         }
                     }
                 }
-                $arr['hcMap'] = json_encode($map);
+                $hdArr['hcMap'] = json_encode($map);
             }
         }
         if(isset($post['hsFreeKm'])){
-            $arr['hsFreeKm'] = $post['hsFreeKm'];
+            $hdArr['hsFreeKm'] = $post['hsFreeKm'];
         }
         if(isset($post['hsAddFee'])){
-            $arr['hsAddFee'] = $post['hsAddFee'];
+            $hdArr['hsAddFee'] = $post['hsAddFee'];
         }
         if(isset($post['hcFreeKm'])){
-            $arr['hcFreeKm'] = $post['hcFreeKm'];
+            $hdArr['hcFreeKm'] = $post['hcFreeKm'];
         }
-        if (empty($arr)) {
+
+        // 组建批发数据
+        if (!empty($post['pfHcMap'])) {
+            $str = $post['pfHcMap'];
+            $map = json_decode($str, true);
+            if (!empty($map)) {
+                foreach ($map as $v) {
+                    foreach ($v as $v1) {
+                        if(!is_numeric($v1)){
+                            util::fail('请填写完整');
+                        }
+                    }
+                }
+                $ghsArr['hcMap'] = json_encode($map);
+            }
+        }
+        if(isset($post['pfHsFreeKm'])){
+            $ghsArr['hsFreeKm'] = $post['pfHsFreeKm'];
+        }
+        if(isset($post['pfHsAddFee'])){
+            $ghsArr['hsAddFee'] = $post['pfHsAddFee'];
+        }
+        if(isset($post['pfHcFreeKm'])){
+            $ghsArr['hcFreeKm'] = $post['pfHcFreeKm'];
+        }
+
+        if (empty($hdArr) && empty($ghsArr)) {
             util::fail('没有需要修改');
         }
+
+        //批发端更新
         $shopId = $this->shopId;
-        ShopExtClass::updateByCondition(['shopId' => $shopId], $arr);
-        //零售端暂时同步更新
+        ShopExtClass::updateByCondition(['shopId' => $shopId], $ghsArr);
+
+        //零售端更新
         $shop = $this->shop;
         $lsShopId = $shop->lsShopId;
-        ShopExtClass::updateByCondition(['shopId' => $lsShopId], $arr);
+        ShopExtClass::updateByCondition(['shopId' => $lsShopId], $hdArr);
         util::complete('修改成功');
     }
 
@@ -115,10 +151,21 @@ class ShopExtController extends BaseController
         $zjGatheringItemId = $ext->zjGatheringItem ?? 0;
         $zjGatheringItem = ProductClass::getById($zjGatheringItemId, true);
         $zjGatheringItemName = $zjGatheringItem->name ?? '';
-        $arr = $ext->attributes ?? [];
+
+        //零售 shopExt
+        $shop = $this->shop;
+        $lsShopId = $shop->lsShopId;
+        $shopObj = ShopExtClass::getByCondition(['shopId' => $lsShopId], true, 'id,hcMap,hcFreeKm,hsFreeKm,hsAddFee');
+        $arr = $shopObj->attributes;
+
+        //批发 shopExt
+        $arr['pfHcMap'] = $ext['hcMap'];
+        $arr['pfHcFreeKm'] = $ext['hcFreeKm'];
+        $arr['pfHsFreeKm'] = $ext['hsFreeKm'];
+        $arr['pfHsAddFee'] = $ext['hsAddFee'];
+
         $arr['losingItemName'] = $losingItemName;
         $arr['zjGatheringItemName'] = $zjGatheringItemName;
-
         $arr['main'] = $this->main;
 
         util::success($arr);