Răsfoiți Sursa

价格修改

shish 5 ani în urmă
părinte
comite
517019f71a

+ 23 - 1
app-ghs/controllers/ProductController.php

@@ -227,8 +227,10 @@ class ProductController extends BaseController
         if (empty($data) || empty($type)) {
             util::fail("参数错误");
         }
-        if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio', 'delStatus', 'ratio'])) {
+        if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio', 'delStatus', 'ratio','price'])) {
             $data = json_decode($data, true);
+        } else {
+            util::fail('不允许的类型');
         }
         foreach ($data as $v) {
             if ($type == 'delStatus') {
@@ -242,12 +244,32 @@ class ProductController extends BaseController
             $id = $v['id'];
             $val = $v[$type] ?? '';
 
+            //shish 20210703
             if ($type == 'ratio') {
                 if (preg_match("/^[1-9][0-9]*$/", $val) == false || $val <= 0) {
                     util::fail('单位比请填写整数,并且要大于0');
                 }
             }
 
+            //修改售价 shish 20210703
+            if ($type == 'price') {
+                $product = ProductClass::getLockById($id);
+                if (empty($product)) {
+                    continue;
+                }
+                //留空恢复自动调价
+                if (empty($val)) {
+                    $product->priceLabel = ProductClass::PRICE_LABEL_AUTO;
+                    $product->price = bcadd($product->cost, $product->addPrice, 2);
+                    $product->save();
+                } else {
+                    $product->priceLabel = ProductClass::PRICE_LABEL_CHANGE;
+                    $product->price = $val;
+                    $product->save();
+                }
+                continue;
+            }
+
             $where = [];
             $where['id'] = $id;
             $where['shopId'] = $this->shopId;

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

@@ -110,6 +110,8 @@ class ProductClass extends BaseClass
                 $smallPrice = bcdiv($v['price'], $ratio, 2);
             }
             $list[$k]['smallPrice'] = $smallPrice;
+            //原价 shish 20210703
+            $list[$k]['prePrice'] = bcadd($v['cost'], $v['addPrice'], 2);
         }
         return $list;
     }