Kaynağa Gözat

feat: EK-879: 【AE】管理员增加“Country”属性,根据所选国家限制登录后所显示的奖金、余额等数据(二期).

kevinElken 9 ay önce
ebeveyn
işleme
96e97f2d1d

+ 14 - 3
backendApi/modules/v1/controllers/ConfigController.php

@@ -886,10 +886,21 @@ class ConfigController extends BaseController {
         $countries = $this->countiesModelClass::getFromCache();
         // 运费列表
         $transportation = $this->freeTemplateModelClass::getFromCache();
+
+        $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);
+            $countriesId = array_column($countries, 'ID');
+
+            $transportation = array_filter($transportation, fn($item) => in_array($item['country_id'], $countriesId));
+            $transportation = array_values($transportation);
+        }
+
         $transportation = array_column($transportation, NULL, 'country_id');
-        // 货币列表
-        $currencies = $this->currencyModelClass::getFromCache();
-        $currencies = array_column($currencies, NULL, 'ID');
 
         foreach ($countries as &$country) {
             $country['freight'] = $transportation[$country['ID']]['freight'] ?? 0;