Kaynağa Gözat

批量修改product价格

林琦海 5 yıl önce
ebeveyn
işleme
5c4bf7c4be
1 değiştirilmiş dosya ile 29 ekleme ve 0 silme
  1. 29 0
      app-hd/controllers/ProductController.php

+ 29 - 0
app-hd/controllers/ProductController.php

@@ -179,4 +179,33 @@ class ProductController extends BaseController
         ProductClass::updateProduct($post);
         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['sjId'] = $this->sjId;
+            if (empty($val)) {
+                util::fail("参数错误1");
+            }
+            $data = [
+                $type => $val
+            ];
+            ProductClass::updateByCondition($where, $data);
+            ProductClass::autoPriceById($id);
+        }
+        util::complete();
+    }
 }