Sfoglia il codice sorgente

修改会员语言和国家

kevin 1 anno fa
parent
commit
8e4d56b270

+ 5 - 0
backendApi/modules/v1/controllers/UserController.php

@@ -63,6 +63,7 @@ use common\models\forms\UserSystemForm;
 use common\models\forms\UserTeamworkForm;
 use common\models\forms\UserTransferPropForm;
 use common\models\Instalment;
+use common\models\Language;
 use common\models\Period;
 use common\models\ReconsumeAudit;
 use common\models\ReconsumePool;
@@ -1154,6 +1155,8 @@ class UserController extends BaseController
         $data['allNation'] = \Yii::$app->params['nation'];
         $data['allOpenBank'] = OpenBank::findAllAsArray('STATUS=1 AND COUNTRY_ID=:COUNTRY_ID', [':COUNTRY_ID' => $userInfo['COUNTRY_ID']]);
         $data['region'] = Region::getByCountryId($userInfo['COUNTRY_ID']);
+        $data['language'] = Language::getFromCache();
+        $data['country'] = Countries::getFromCache();
 
         $data['userInfo'] = [
             'userId' => $userInfo['ID'],
@@ -1164,6 +1167,8 @@ class UserController extends BaseController
             'openBank' => $userInfo['OPEN_BANK'],
             'bankAddress' => $userInfo['BANK_ADDRESS'],
             'bankNo' => $userInfo['BANK_NO'],
+            'language' => $userInfo['LANGUAGE_ID'],
+            'country' => $userInfo['COUNTRY_ID'],
         ];
 
         return static::notice($data);

+ 70 - 3
common/models/forms/UserBasicForm.php

@@ -3,9 +3,18 @@
 namespace common\models\forms;
 
 use common\components\Model;
+use common\helpers\Cache;
 use common\helpers\Date;
+use common\helpers\Form;
+use common\helpers\Tool;
 use common\libs\logging\operate\AdminOperate;
+use common\models\CurrencyConversions;
+use common\models\Instalment;
+use common\models\Period;
 use common\models\User;
+use common\models\UserImmigrant;
+use common\models\UserWallet;
+use Yii;
 use yii\base\Exception;
 
 /**
@@ -24,6 +33,8 @@ class UserBasicForm extends Model {
     public $openBank;
     public $bankAddress;
     public $bankNo;
+    public $country;
+    public $language;
 
     public $status;
 
@@ -42,7 +53,7 @@ class UserBasicForm extends Model {
             [['userId', 'password', 'passwordType','realName', 'mobile','openBank','bankAddress','bankNo','status'], 'trim'],
             [['userId'], 'required'],
             [[/*'idCard', */'allData'], 'required', 'on'=>['addWithUserName']],
-            [['nation','realName', 'mobile', /*'idCard', */'openBank', 'bankAddress', 'bankNo'], 'required', 'on'=>'modifyProfile'],
+            [['nation','realName', 'mobile', /*'idCard', */'openBank', 'bankAddress', 'bankNo', 'country', 'language'], 'required', 'on'=>'modifyProfile'],
             [['mobile'], 'mobile'],
         ];
     }
@@ -55,7 +66,7 @@ class UserBasicForm extends Model {
         $parentScenarios = parent::scenarios();
         $customScenarios = [
             'modifyPassword' => ['userId', 'password', 'passwordType'],
-            'modifyProfile' => ['userId','realName',/*'idCard',*/'mobile','openBank','bankAddress','bankNo'],
+            'modifyProfile' => ['userId','realName',/*'idCard',*/'mobile','openBank','bankAddress','bankNo', 'country', 'language'],
             'modifyStatus' => ['userId','status'],
             'isModifyPasswordStatus' => ['userId','status'],
         ];
@@ -75,6 +86,8 @@ class UserBasicForm extends Model {
             'bankAddress' => '开户支行',
             'bankNo' => '银行账号',
             'status' => '状态',
+            'country' => '国家',
+            'language' => '语言',
         ];
     }
 
@@ -119,15 +132,42 @@ class UserBasicForm extends Model {
      * 修改个人资料
      * @return User|null
      * @throws \yii\db\Exception
+     * @throws Exception
      */
     public function modifyProfile(){
         if(!$this->validate()){
             return null;
         }
+
+        // 会员信息
+        $userModel = User::findOne(['ID' => $this->userId]);
+        // 原国家
+        $beforeCountry = $userModel->COUNTRY_ID;
+        // 移民前汇率
+        $beforeCurrency = CurrencyConversions::getToUSDRate($beforeCountry);
+        // 移民后汇率
+        $afterCurrency = CurrencyConversions::getToUSDRate($this->country);
+        if (!$afterCurrency) {
+            throw new Exception(Yii::t('app', 'currencyDoesNotExist'));
+        }
+        // 如果移民,则需要进行移民条件检查
+        if ($this->country != $beforeCountry) {
+            // 1.是否有进行中的分期订单
+            $instalmentOrder = Instalment::findOne(['USER_ID' => $this->userId]);
+            // 订单分期总期数配置
+            if ($instalmentOrder) {
+                // 分期的总期数
+                $instalment = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
+                // 分期商品的期数不能大于总分期数限制
+                if (intval($instalmentOrder['STAGE']) < $instalment) {
+                    throw new Exception(Yii::t('app', 'instalmentOrderInProcess'));
+                }
+            }
+        }
+
         $db = \Yii::$app->db;
         $transaction = $db->beginTransaction();
         try {
-            $userModel = User::findOne(['ID' => $this->userId]);
             $this->adminOperateLogger->beforeUpdate($userModel);
 //            $userModel->NATION = $this->nation;
             $userModel->REAL_NAME = $this->realName;
@@ -136,10 +176,35 @@ class UserBasicForm extends Model {
             $userModel->OPEN_BANK = $this->openBank;
             $userModel->BANK_NO = $this->bankNo;
             $userModel->BANK_ADDRESS = $this->bankAddress;
+            $userModel->LANGUAGE_ID = $this->language;
+            $userModel->COUNTRY_ID = $this->country;
             if( !$userModel->save(false) ) {
                 throw new Exception($userModel->getErrors());
             }
+
+            // 现金钱包余额转换
+            $userWallet = UserWallet::findOne(['USER_ID' => $this->userId]);
+            if ($userWallet && $userWallet->CASH > 0) {
+                $userWallet->CASH = Tool::convertAmount($userWallet->CASH, $beforeCurrency, $afterCurrency);
+                if (!$userWallet->save()) {
+                    $transaction->rollBack();
+                    throw new Exception($userModel->getErrors());
+                }
+            }
+
+            // 移民记录
+            $model = new UserImmigrant();
+            $model->user_id = $this->userId;
+            $model->before_country_id = $beforeCountry;
+            $model->after_country_id = $this->country;
+            $model->period_num = Period::instance()->getNowPeriodNum();
+            $model->created_by = \Yii::$app->user->id;
+            if (!$model->save()) {
+                throw new Exception(Form::formatErrorsForApi($model->getErrors()));
+            }
+
             $transaction->commit();
+
             $this->adminOperateLogger->afterUpdate($userModel)->clean()->save([
                 'optType' => 'Modification of Member information', // 修改会员资料
                 'userId' => $this->userId,
@@ -151,6 +216,8 @@ class UserBasicForm extends Model {
                 'openBank' => $this->openBank,
                 'bankNo' => $this->bankNo,
                 'bankAddress' => $this->bankAddress,
+                'language' => $this->language,
+                'country' => $this->country,
             ]);
         }catch (Exception $e) {
             $transaction->rollBack();