Browse Source

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

kevinElken 9 months ago
parent
commit
bdd82a6796

+ 4 - 5
backendApi/config/menu.php

@@ -275,11 +275,10 @@ return [
             ['name'=>'编辑会员级别', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'dec-level-edit', 'routePath'=>'config/dec-level-edit', 'show'=>0,],
             ['name'=>'编辑会员级别', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'dec-level-edit', 'routePath'=>'config/dec-level-edit', 'show'=>0,],
             ['name'=>'报单中心级别配置', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'dec-role', 'routePath'=>'config/dec-role', 'show'=>1, 'wiki' => 'decRoleConfig'],
             ['name'=>'报单中心级别配置', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'dec-role', 'routePath'=>'config/dec-role', 'show'=>1, 'wiki' => 'decRoleConfig'],
             ['name'=>'编辑报单中心级别', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'dec-role-edit', 'routePath'=>'config/dec-role-edit', 'show'=>0,],
             ['name'=>'编辑报单中心级别', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'dec-role-edit', 'routePath'=>'config/dec-role-edit', 'show'=>0,],
-            ['name'=>'汇率列表', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'currencies-conversions', 'routePath'=>'currency/currencies-conversions', 'show'=>1,  'wiki' => 'exchangeRateConfig'],
-            ['name'=>'汇率配置', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'set-currencies-conversions', 'routePath'=>'currency/set-currencies-conversions', 'show'=>0],
-            ['name'=>'汇率', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'currencies', 'routePath'=>'currency/currencies', 'show'=>0],
-            ['name'=>'运费模板列表', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'transportation', 'routePath'=>'transportation/transportation', 'show'=>1,  'wiki' => 'transportationConfig'],
-            ['name'=>'运费模板设置', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'set-transportation', 'routePath'=>'transportation/set-transportation', 'show'=>0],
+            ['name'=>'汇率列表', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'currencies-conversions', 'config'=>'currency/currencies-conversions', 'show'=>1,  'wiki' => 'exchangeRateConfig'],
+            ['name'=>'汇率配置', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'set-currencies-conversions', 'config'=>'currency/set-currencies-conversions', 'show'=>0],
+            ['name'=>'运费模板列表', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'transportation', 'routePath'=>'config/transportation', 'show'=>1,  'wiki' => 'transportationConfig'],
+            ['name'=>'运费模板设置', 'class'=>'', 'icon'=>'', 'controller'=>'config', 'action'=>'set-transportation', 'routePath'=>'config/set-transportation', 'show'=>0],
         ],
         ],
     ],
     ],
 ];
 ];

+ 7 - 0
backendApi/config/urlManagerRules.php

@@ -322,6 +322,11 @@ return [
             'POST,GET sms' => 'sms',
             'POST,GET sms' => 'sms',
             'POST,GET transfer' => 'transfer',
             'POST,GET transfer' => 'transfer',
             'POST,GET score' => 'score',
             'POST,GET score' => 'score',
+            'GET currencies' => 'currencies',
+            'GET currencies-conversions' => 'currencies-conversions',
+            'POST set-currencies-conversions' => 'set-currencies-conversions',
+            'GET transportation' => 'transportation',
+            'POST set-transportation' => 'set-transportation',
         ],
         ],
     ],
     ],
     [
     [
@@ -601,6 +606,8 @@ return [
             'GET currencies' => 'currencies',
             'GET currencies' => 'currencies',
             'GET currencies-conversions' => 'currencies-conversions',
             'GET currencies-conversions' => 'currencies-conversions',
             'POST set-currencies-conversions' => 'set-currencies-conversions',
             'POST set-currencies-conversions' => 'set-currencies-conversions',
+            'GET transportation' => 'transportation',
+            'POST set-transportation' => 'set-transportation',
         ],
         ],
     ],
     ],
     [
     [

+ 120 - 0
backendApi/modules/v1/controllers/ConfigController.php

@@ -9,14 +9,21 @@
 namespace backendApi\modules\v1\controllers;
 namespace backendApi\modules\v1\controllers;
 
 
 use backendApi\modules\v1\models\Admin;
 use backendApi\modules\v1\models\Admin;
+use backendApi\modules\v1\models\AdminCountry;
+use backendApi\modules\v1\models\AdminRole;
 use common\helpers\Cache;
 use common\helpers\Cache;
 use common\helpers\Date;
 use common\helpers\Date;
 use common\helpers\Form;
 use common\helpers\Form;
+use common\models\Countries;
+use common\models\Currency;
+use common\models\CurrencyConversions;
 use common\models\DecRole;
 use common\models\DecRole;
 use common\models\forms\ConfigForm;
 use common\models\forms\ConfigForm;
 use common\models\forms\ConfigPeriodForm;
 use common\models\forms\ConfigPeriodForm;
+use common\models\forms\CurrenciesConversionsForm;
 use common\models\forms\DecLevelForm;
 use common\models\forms\DecLevelForm;
 use common\models\forms\DecRoleForm;
 use common\models\forms\DecRoleForm;
+use common\models\forms\FreeTemplateForm;
 use common\models\forms\RegTypeForm;
 use common\models\forms\RegTypeForm;
 use common\models\forms\DeclarationLevelForm;
 use common\models\forms\DeclarationLevelForm;
 use common\models\forms\EmployLevelForm;
 use common\models\forms\EmployLevelForm;
@@ -24,6 +31,7 @@ use common\models\forms\OcrApiForm;
 use common\models\forms\SmsApiForm;
 use common\models\forms\SmsApiForm;
 use common\models\forms\SmsTemplateForm;
 use common\models\forms\SmsTemplateForm;
 use common\models\forms\WithdrawLevelForm;
 use common\models\forms\WithdrawLevelForm;
+use common\models\FreeTemplate;
 use common\models\OcrApi;
 use common\models\OcrApi;
 use common\models\RegType;
 use common\models\RegType;
 use common\models\DeclarationLevel;
 use common\models\DeclarationLevel;
@@ -35,10 +43,18 @@ use Yii;
 use common\models\Config;
 use common\models\Config;
 use yii\base\Exception;
 use yii\base\Exception;
 use yii\helpers\Json;
 use yii\helpers\Json;
+use yii\web\HttpException;
 
 
 class ConfigController extends BaseController {
 class ConfigController extends BaseController {
     public $modelClass = Config::class;
     public $modelClass = Config::class;
 
 
+    public $currencyModelClass = Currency::class;
+
+    public $currencyConversionsModelClass = CurrencyConversions::class;
+
+    public $freeTemplateModelClass = FreeTemplate::class;
+    public $countiesModelClass = Countries::class;
+
     public function behaviors() {
     public function behaviors() {
         return parent::behaviors();
         return parent::behaviors();
     }
     }
@@ -798,4 +814,108 @@ class ConfigController extends BaseController {
         file_put_contents($path, $content, LOCK_EX);
         file_put_contents($path, $content, LOCK_EX);
         return static::notice(Yii::t('ctx', 'successfully'));
         return static::notice(Yii::t('ctx', 'successfully'));
     }
     }
+
+    public function actionCurrencies()
+    {
+        $data = $this->currencyModelClass::getFromCache();
+        return static::notice(['data' => $data]);
+    }
+
+    public function actionCurrenciesConversions()
+    {
+        // 国家
+        $countries = Cache::getCountries();
+        // 货币
+        $currencies = $this->currencyModelClass::getFromCache();
+        // 汇率配置
+        $currencyConversion = $this->currencyConversionsModelClass::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');
+
+            $currencies = array_filter($currencies, fn($currency) => in_array($currency['ID'], $countriesId));
+            $currencies = array_values($currencies);
+            $currenciesId = array_column($currencies, 'ID');
+
+            $currencyConversion = array_filter($currencyConversion, fn($conversion) => in_array($conversion['TO_CURRENCY_ID'], $currenciesId));
+            $currencyConversion = array_values($currencyConversion);
+        }
+
+        $currencyConversion = array_column($currencyConversion, NULL, 'TO_CURRENCY_ID');
+
+        foreach ($currencies as &$currency) {
+            $currency['PRODUCT_RATE'] = $currencyConversion[$currency['ID']]['PRODUCT_RATE'] ?? 0;
+            $currency['BONUSES_RATE'] = $currencyConversion[$currency['ID']]['BONUSES_RATE'] ?? 0;
+        }
+
+        return static::notice(['data' => $currencies]);
+    }
+
+    /**
+     * @throws \yii\db\Exception
+     * @throws HttpException
+     */
+    public function actionSetCurrenciesConversions()
+    {
+        if (\Yii::$app->request->isPost) {
+            $formModel = new CurrenciesConversionsForm();
+            $formModel->scenario = 'setCurrenciesConversions';
+            if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->setCurrenciesConversions()) {
+                // 更新缓存
+                $this->currencyConversionsModelClass::updateToCache();
+
+                return static::notice(\Yii::t('ctx', 'successfully'));
+            } else {
+                return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
+
+            }
+        }
+
+        return static::notice(\Yii::t('ctx', 'illegalRequest'));
+    }
+
+    public function actionTransportation()
+    {
+        // 国家列表
+        $countries = $this->countiesModelClass::getFromCache();
+        // 运费列表
+        $transportation = $this->freeTemplateModelClass::getFromCache();
+        $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;
+            $country['free_shipping'] = $transportation[$country['ID']]['free_shipping'] ?? 0;
+            $country['currency'] = $this->currencyModelClass::getById($country['LOCAL_CURRENCY_ID']);
+        }
+
+        return static::notice(['data' => $countries]);
+    }
+
+    public function actionSetTransportation()
+    {
+        if (\Yii::$app->request->isPost) {
+            $formModel = new FreeTemplateForm();
+            $formModel->scenario = 'setTransportation';
+            if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->setTransportation()) {
+                // 更新缓存
+                $this->modelClass::updateToCache();
+
+                return static::notice(\Yii::t('ctx', 'successfully'));
+            } else {
+                return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
+
+            }
+        }
+
+        return static::notice(\Yii::t('ctx', 'illegalRequest'));
+    }
 }
 }