ソースを参照

水机分期调整

kevin 1 年間 前
コミット
22e7294c1b

+ 1 - 0
.gitignore

@@ -118,3 +118,4 @@ vendor/yiisoft/yii2/di/Container.php
 vendor/yiisoft/yii2/di/Instance.php
 vendor/yiisoft/yii2/di/NotInstantiableException.php
 vendor/yiisoft/yii2/di/ServiceLocator.php
+frontendApi/runtime/logs/

+ 30 - 0
common/models/forms/ApproachDeclarationUpgradeForm.php

@@ -200,6 +200,15 @@ class ApproachDeclarationUpgradeForm extends Model
                             }
                             $userStage = Instalment::getStage($userId);
                             $userInstalmentInfo = Instalment::getInfo($userId);
+
+                            if (!$userInstalmentInfo){
+                                // 写入分期记录
+                                $this->insertInstalment($userId, 0);
+
+                                $userStage = Instalment::getStage($userId);
+                                $userInstalmentInfo = Instalment::getInfo($userId);
+                            }
+
                             if (!$userInstalmentInfo){ // 如果没有分期付款记录
                                 throw new Exception(Yii::t('app', 'canNotBuy'));
                             } else if ($userInstalmentInfo['ORDER_TYPE']!='BD' || (($userStage == $instalment) && ($goods['INSTALMENT'] != 1))) { // 如果分期付款记录中,不是报单,或已是最后一期
@@ -491,4 +500,25 @@ class ApproachDeclarationUpgradeForm extends Model
         
         return true;
     }
+
+    /**
+     * 添加会员分期付款记录
+     * @param $userId
+     * @param int $stage
+     * @return Instalment
+     * @throws Exception
+     */
+    public function insertInstalment($userId, int $stage = 1){
+        // 增加会员分期付款记录
+        $instalment = new Instalment();
+        $instalment->USER_ID = $userId;
+        $instalment->STAGE = $stage;
+        $instalment->ORDER_TYPE = 'BD';
+        $instalment->UPDATE_TIME = time();
+
+        if (!$instalment->save()) {
+            throw new Exception(Form::formatErrorsForApi($instalment->getErrors()));
+        }
+        return $instalment;
+    }
 }

+ 29 - 0
common/models/forms/DeclarationUpgradeForm.php

@@ -200,6 +200,15 @@ class DeclarationUpgradeForm extends Model
                             
                             $userStage = Instalment::getStage($userId);
                             $userInstalmentInfo = Instalment::getInfo($userId);
+
+                            if (!$userInstalmentInfo){
+                                // 写入分期记录
+                                $this->insertInstalment($userId, 0);
+
+                                $userStage = Instalment::getStage($userId);
+                                $userInstalmentInfo = Instalment::getInfo($userId);
+                            }
+
                             if (!$userInstalmentInfo){ // 如果没有分期付款记录
                                 throw new Exception(Yii::t('app', 'canNotBuy'));
                             } else if ($userInstalmentInfo['ORDER_TYPE']!='BD' || (($userStage == $instalment) && ($goods['INSTALMENT'] != 1))) { // 如果分期付款记录中,不是报单,或已是最后一期
@@ -516,6 +525,26 @@ class DeclarationUpgradeForm extends Model
         return true;
     }
 
+    /**
+     * 添加会员分期付款记录
+     * @param $userId
+     * @param int $stage
+     * @return Instalment
+     * @throws Exception
+     */
+    public function insertInstalment($userId, int $stage = 1){
+        // 增加会员分期付款记录
+        $instalment = new Instalment();
+        $instalment->USER_ID = $userId;
+        $instalment->STAGE = $stage;
+        $instalment->ORDER_TYPE = 'BD';
+        $instalment->UPDATE_TIME = time();
+
+        if (!$instalment->save()) {
+            throw new Exception(Form::formatErrorsForApi($instalment->getErrors()));
+        }
+        return $instalment;
+    }
 
     // /**
     //  * 删单