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