Przeglądaj źródła

feat: EK-856: 管理员增加“Country”属性.

kevinElken 9 miesięcy temu
rodzic
commit
9476626ba2

+ 13 - 0
backendApi/modules/v1/controllers/ShopController.php

@@ -140,11 +140,24 @@ class ShopController extends BaseController {
                 return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
             }
         }
+
+        $countries = Cache::getCountries();
+
+        $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
+        if (!$isSuper) {
+            $adminId = Yii::$app->getUser()->getUserInfo()['id'];
+            $adminCountry = AdminCountry::getCountry($adminId);
+
+            $countries = array_filter($countries, fn($country) => in_array($country['ID'], $adminCountry));
+            $countries = array_values($countries);
+        }
+
         return static::notice([
             'sellType' => ShopGoods::getSaleType(),
             'goodsType' => ShopGoods::getGoodType(),
             'giftType' => ShopGoods::getGiftType(),
             'categoryType' => ShopGoods::getCategoryType(),
+            'countries' => $countries,
         ]);
     }