|
@@ -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'));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|