max 1 год назад
Родитель
Сommit
9a8bf92ae9

+ 41 - 0
common/models/forms/RechargeForm.php

@@ -36,6 +36,8 @@ class RechargeForm extends Model {
 
     private $_userId;
 
+    public $id;
+
     /**
      * @inheritdoc
      */
@@ -49,6 +51,7 @@ class RechargeForm extends Model {
             [['applyAmount'], 'isApplyAmount'],
             [['applyAmount'], 'number', 'max' => 10000000000, 'min' => 1],
             [['selectedIds'], 'isSelected'],
+            [['id'], 'number'],
             //[['sn'], 'isSn'],
         ];
     }
@@ -222,6 +225,44 @@ class RechargeForm extends Model {
         return $rechargeModel;
     }
 
+    /**
+     * 更新充值申请
+     * @return null|string
+     * @throws \yii\db\Exception
+     */
+    public function update() {
+        if (!$this->validate()) {
+            return false;
+        }
+        if(!$this->id){
+            return false;
+        }
+        $db = \Yii::$app->db;
+        $transaction = $db->beginTransaction();
+        try {
+            $nowTime = Date::nowTime();
+            $period = Recharge::getPeriod($nowTime);
+            //增加记录
+            $userInfo = Info::baseInfo($this->_userId);
+
+            $rechargeModel = Recharge::where(['id'=>$this->id])->one();
+            $rechargeModel->AMOUNT = $this->applyAmount;
+            $rechargeModel->OPEN_BANK = $this->openBank;
+            $rechargeModel->BANK_ADDRESS = $this->bankAddress;
+            $rechargeModel->BANK_NO = $this->bankNo;
+            $rechargeModel->UPDATED_AT = $nowTime;
+            if (!$rechargeModel->save()) {
+                throw new Exception(Form::formatErrorsForApi($rechargeModel->getErrors()));
+            }
+            $transaction->commit();
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            $this->addError('update', $e->getMessage());
+            return false;
+        }
+        return $rechargeModel;
+    }
+
     /**
      * 生成流水号
      * @return string

+ 23 - 0
frontendApi/modules/v1/controllers/FinanceController.php

@@ -564,6 +564,29 @@ class FinanceController extends BaseController {
         return static::notice(['allOpenBank' => $allOpenBank]);
     }
 
+    /**
+     * 提交充值申请
+     * @return mixed
+     * @throws \yii\db\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionRechargeUpdate() {
+        if (\Yii::$app->request->isPost) {
+            $formModel = new RechargeForm();
+            $formModel->scenario = 'updateByUser';
+            if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->update()) {
+                return static::notice(Yii::t('app', 'rechargeApplicationHasBeenSubmitted'));
+            } else {
+                return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
+            }
+        }
+
+        $countryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
+        // 所有开户行
+        $allOpenBank = OpenBank::findAllAsArray('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId]);
+        return static::notice(['allOpenBank' => $allOpenBank]);
+    }
+
     /**
      * 上传充值凭证
      * @return mixed