|
|
@@ -16,6 +16,7 @@ use common\models\DeclarationPackage;
|
|
|
use common\models\DecLevelLog;
|
|
|
use common\models\DecOrder;
|
|
|
use common\models\EmployLevel;
|
|
|
+use common\models\Instalment;
|
|
|
use common\models\Order;
|
|
|
use common\models\OrderGoods;
|
|
|
use common\models\Period;
|
|
|
@@ -113,6 +114,7 @@ class ApproachDeclarationUpgradeForm extends Model
|
|
|
if(!$this->validate()){
|
|
|
return null;
|
|
|
}
|
|
|
+ $hasInstalment = 0;
|
|
|
// 首购单
|
|
|
if($this->type == self::TYPE_ZC){
|
|
|
//报单商品及PV判断
|
|
|
@@ -185,10 +187,35 @@ class ApproachDeclarationUpgradeForm extends Model
|
|
|
'TAX_RATE' => $goods['TAX_RATE'],
|
|
|
];
|
|
|
}
|
|
|
+ if($goods['INSTALMENT']>0){ // 如果有分期付款商品,检查用户的分期付款状态
|
|
|
+ if($v>1){ // 不可以购买多个
|
|
|
+ throw new Exception(Yii::t('app', 'allowOnlyOne'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分期的总期数
|
|
|
+ $instalment = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
|
|
|
+ $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) { // 如果分期付款记录中,不是报单,或已是最后一期
|
|
|
+ throw new Exception(Yii::t('app', 'canNotBuy'));
|
|
|
+ }
|
|
|
+ if($userStage + 1 != $goods['INSTALMENT']){ // 若用户分期阶段+1不等于商品的分期阶段,则报异常
|
|
|
+ throw new Exception(Yii::t('app', 'canNotBuy'));
|
|
|
+ }
|
|
|
+ if ($userStage + 1 > $instalment){ // 若用户分期阶段+1大于总分期阶段,则报异常
|
|
|
+ throw new Exception(Yii::t('app', 'canNotBuy'));
|
|
|
+ }
|
|
|
+ $hasInstalment = $goods['INSTALMENT'];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
// 这里特殊是用户原报单PV之和+用户购买的商品总PV
|
|
|
$checkPv = $totalPv + $diffPerf;
|
|
|
+ if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
|
|
|
+ $allData['hasInstalment'] = 1;
|
|
|
+ }
|
|
|
if($checkPv < $decLevel['PERF']) {
|
|
|
throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
|
|
|
}
|
|
|
@@ -214,6 +241,19 @@ class ApproachDeclarationUpgradeForm extends Model
|
|
|
if (!$decResult) {
|
|
|
throw new Exception(Yii::t('app', 'failed'), 400);
|
|
|
}
|
|
|
+
|
|
|
+ if ($hasInstalment){ // 如果有分期付款的商品,写入信息至分期付款表
|
|
|
+ $instalmentModel = Instalment::findOne(['USER_ID'=>$userId]);
|
|
|
+ if(!$instalmentModel) {
|
|
|
+ $instalmentModel = new Instalment();
|
|
|
+ }
|
|
|
+ $instalmentModel->USER_ID = $userId;
|
|
|
+ $instalmentModel->STAGE = $hasInstalment;
|
|
|
+ $instalmentModel->ORDER_TYPE = 'BD';
|
|
|
+ $instalmentModel->UPDATE_TIME = time();
|
|
|
+ $instalmentModel->save();
|
|
|
+ }
|
|
|
+
|
|
|
return $decResult;
|
|
|
}
|
|
|
return true;
|