Просмотр исходного кода

1. fix bug: xhGoodsCategory 表已经没有 delStatus 字段
2. 初步把权限校验函数统一到 util 类中

shizhongqi 10 месяцев назад
Родитель
Сommit
67aca8c3c6
2 измененных файлов с 15 добавлено и 3 удалено
  1. 2 2
      app-hd/controllers/CategoryController.php
  2. 13 1
      common/components/util.php

+ 2 - 2
app-hd/controllers/CategoryController.php

@@ -89,7 +89,7 @@ class CategoryController extends BaseController
         $get = Yii::$app->request->get();
         $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
         $category = CategoryClass::getById($categoryId);
-        CategoryService::valid($category, $this->mainId);
+        util::validMainId($category, $this->mainId);
 
         if ($category['goodsNum'] > 0) {
             $goodsCateObjs = GoodsCategoryClass::getAllByCondition(['mainId' => $this->mainId, 'cId' => $categoryId]);
@@ -108,7 +108,7 @@ class CategoryController extends BaseController
             $defaultCategoryId = $defaultCategory['id'];
             foreach ($goodsCateObjs as $gcObj) {
                 // 先判断商品是否也在其它分类下
-                $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId' => $this->mainId, 'gId' => $gcObj['gId'], 'delStatus' => 0]);
+                $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId' => $this->mainId, 'gId' => $gcObj['gId']]);
                 if ($goodsOtherCateCount == 1) {
                     // 如果商品仅在此分类下,则归到默认分类
                     GoodsCategoryClass::updateById($gcObj['id'], ['cId' => $defaultCategoryId, 'delStatus' => 0]);

+ 13 - 1
common/components/util.php

@@ -408,9 +408,21 @@ class util
         $cacheKey = "checkRepeatCommit_" . $ctl . "_" . $action . "_" . $adminId;
         $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
         if (!empty($has)) {
-            util::fail('请稍等几秒再提交');
+            self::fail('请稍等几秒再提交');
         }
         Yii::$app->redis->executeCommand('SETEX', [$cacheKey, $second, 'has']);
     }
 
+    /**
+     * 用 mainId 验证操作权限
+     * @param array $arr 模型数据数组
+     * @param int $mainId
+     * @throws \Exception
+     */
+    public static function validMainId($arr, $mainId)
+    {
+        if (isset($arr['mainId']) == false || $arr['mainId'] != $mainId) {
+            self::fail('您无法操作');
+        }
+    }
 }