shish 5 лет назад
Родитель
Сommit
00e92dd9be
1 измененных файлов с 54 добавлено и 0 удалено
  1. 54 0
      app-ghs/controllers/ProductController.php

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

@@ -232,6 +232,60 @@ class ProductController extends BaseController
 
 
     }
     }
 
 
+    //改价
+    public function actionChangePrice()
+    {
+        //花材价格只能在首店修改,并同步到分店
+        $shop = $this->shop;
+        $default = $shop->default ?? 0;
+        if ($default != 1) {
+            util::fail('请在首店修改');
+        }
+
+        $shopAdmin = $this->shopAdmin;
+        $roleId = $shopAdmin['roleId'] ?? 0;
+        $role = AdminRoleClass::getById($roleId);
+        $roleName = $role['roleName'] ?? '';
+        if ($roleName == '员工') {
+            util::fail('没有权限操作哦');
+        }
+
+        $productId = Yii::$app->request->post('productId', 0);
+        $price = Yii::$app->request->post('price', '');
+        if (is_numeric($price) && $price > 0) {
+            //判断是否有效
+            $productData = ProductClass::getProductData($productId, $this->shopId);
+            if (!$productData) {
+                util::fail("花材不存在");
+            }
+            ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_CHANGE);
+        } else {
+            //自动调价
+            $productData = ProductClass::getById($productId);
+            if (!$productData) {
+                util::fail("花材不存在");
+            }
+            $price = bcadd($productData['cost'], $productData['addPrice'], 2);
+            ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
+        }
+        util::success(['price' => $price]);
+    }
+
+    //恢复自动调价
+    public function actionAutoPrice()
+    {
+        $productId = Yii::$app->request->post('productId', 0);
+        $productData = ProductClass::getById($productId);
+        if (!$productData) {
+            util::fail("花材不存在");
+        }
+        //2021.04.06改为用product中的成本价+加价
+        $price = bcadd($productData['cost'], $productData['addPrice'], 2);
+        ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
+        util::complete("操作成功");
+    }
+
+
     //修改加价
     //修改加价
     public function actionChangeAddPrice()
     public function actionChangeAddPrice()
     {
     {