shish 5 éve
szülő
commit
8308705553
1 módosított fájl, 21 hozzáadás és 29 törlés
  1. 21 29
      app-ghs/controllers/ProductController.php

+ 21 - 29
app-ghs/controllers/ProductController.php

@@ -158,6 +158,12 @@ class ProductController extends BaseController
     //批量改价
     public function actionBatchChangePrice()
     {
+
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+            util::fail('超管才能修改');
+        }
+
         //花材价格只能在首店修改,并同步到分店
         $shop = $this->shop;
         $default = $shop->default ?? 0;
@@ -165,14 +171,6 @@ class ProductController extends BaseController
             util::fail('请在首店修改');
         }
 
-        $shopAdmin = $this->shopAdmin;
-        $roleId = $shopAdmin['roleId'] ?? 0;
-        $role = AdminRoleClass::getById($roleId);
-        $roleName = $role['roleName'] ?? '';
-        if ($roleName == '员工') {
-            util::fail('没有权限操作哦');
-        }
-
         $data = Yii::$app->request->post('data', '');
         if (empty($data)) {
             util::fail('没有修改');
@@ -235,6 +233,11 @@ class ProductController extends BaseController
     //改价
     public function actionChangePrice()
     {
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+            util::fail('超管才能修改');
+        }
+
         //花材价格只能在首店修改,并同步到分店
         $shop = $this->shop;
         $default = $shop->default ?? 0;
@@ -242,31 +245,20 @@ class ProductController extends BaseController
             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);
+        $productInfo = ProductClass::getById($productId, true);
+        if (empty($productInfo)) {
+            util::fail("花材不存在");
+        }
+        if ($productInfo->shopId != $this->shopId) {
+            util::fail('没有权限');
+        }
         $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);
+            ProductClass::changePrice($productId, $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);
+            $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
+            ProductClass::changePrice($productId, $price, ProductClass::PRICE_LABEL_AUTO);
         }
         util::success(['price' => $price]);
     }