林琦海 5 лет назад
Родитель
Сommit
e521490599
2 измененных файлов с 127 добавлено и 0 удалено
  1. 36 0
      app-ghs/controllers/ProductController.php
  2. 91 0
      biz-ghs/product/classes/ProductClass.php

+ 36 - 0
app-ghs/controllers/ProductController.php

@@ -180,4 +180,40 @@ class ProductController extends BaseController
         ProductClass::changeAddPrice($productId,$addPrice);
         util::complete();
     }
+
+    //批量修改product 排序,成本价,加价
+    public function actionBatchUpdate()
+    {
+        $data = Yii::$app->request->post('data',''); //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
+        $type = Yii::$app->request->post('type','');
+        if(empty($data) || empty($type)){
+            util::fail("参数错误");
+        }
+        if(in_array($type,['inTurn','addPrice','cost','weight','ratio']))
+        $data = json_decode($data,true);
+        foreach ($data as $v){
+            $id = $v['id'];
+            $val = $v[$type]??'';
+            $where = [];
+            $where['id'] = $id;
+            $where['shopId'] = $this->shopId;
+            $where['merchantId'] = $this->sjId;
+            if(empty($val)){
+                util::fail("参数错误1");
+            }
+            $data =[
+                $type=>$val
+            ];
+            ProductClass::updateByCondition($where,$data);
+        }
+        util::complete();
+    }
+
+    public function actionUpdate()
+    {
+        $post = Yii::$app->request->post();
+        ProductClass::updateProduct($post);
+        util::complete();
+
+    }
 }

+ 91 - 0
biz-ghs/product/classes/ProductClass.php

@@ -512,4 +512,95 @@ class ProductClass extends BaseClass
         $mergeNum = self::mergeItemNum($bigNum,$smallNum,$ratio);
         return bcmul($mergeNum,$weight,2);
     }
+
+    //修改product
+    public static function updateProduct($data)
+    {
+        $id = $data['id'] ?? 0;
+
+        $model = self::getById($id);
+        if (!$model) {
+            util::fail("该花材不存在");
+        }
+        $upData = [];
+        if (isset($data['name'])) {
+            if (empty($data['name'])) {
+                util::fail("请输入花材名称");
+            }
+            $upData['name'] = $data['name'];
+        }
+        if (isset($data['py'])) {
+            if (empty($data['py'])) {
+                util::fail("请输入花材拼音");
+            }
+            $upData['py'] = $data['py'];
+        }
+
+        if (isset($data['cover'])) {
+            if (empty($data['cover'])) {
+                util::fail("请输入花材图片");
+            }
+            $upData['cover'] = $data['cover'];
+        }
+//        if (isset($data['alias'])) {
+//            if (empty($data['alias'])) {
+//                util::fail("请输入花材别名");
+//            }
+//            $upData['alias'] = $data['alias'];
+//        }
+        if (isset($data['cost'])) {
+            if (empty($data['cost'])) {
+                util::fail("请输入花材成本价");
+            }
+            $upData['cost'] = $data['cost'];
+        }
+        if (isset($data['ratio'])) {
+            if (empty($data['ratio'])) {
+                util::fail("请输入花材比例");
+            }
+            $upData['ratio'] = $data['ratio'];
+        }
+        if (isset($data['weight'])) {
+            if (empty($data['weight'])) {
+                util::fail("请输入花材重量");
+            }
+            $upData['weight'] = $data['weight'];
+        }
+        if (isset($data['addPrice'])) {
+            if (empty($data['addPrice'])) {
+                util::fail("请输入花材价加");
+            }
+            $upData['addPrice'] = $data['addPrice'];
+        }
+
+
+        if (isset($data['stockWarning'])) {
+            if (empty($data['stockWarning'])) {
+                util::fail("请输入花材库存预警");
+            }
+            $upData['stockWarning'] = $data['stockWarning'];
+        }
+        if (isset($data['bigUnit'])) {
+            if (empty($data['bigUnit'])) {
+                util::fail("请输入花材大单位");
+            }
+            $upData['bigUnit'] = $data['bigUnit'];
+        }
+        if (isset($data['smallUnit'])) {
+            if (empty($data['smallUnit'])) {
+                util::fail("请输入花材小单位");
+            }
+            $upData['smallUnit'] = $data['smallUnit'];
+        }
+        if (isset($data['inTurn'])) {
+            $upData['inTurn'] = $data['inTurn'];
+        }
+
+
+        unset($data['id']);
+        if (empty($upData)) {
+            util::fail("参数错误");
+        }
+        self::updateById($id, $upData);
+    }
 }