|
|
@@ -837,6 +837,7 @@ class OrderForm extends Model
|
|
|
$totalAmount = 0;
|
|
|
$totalPv = 0;
|
|
|
$goodsType = ShopGoods::GOODS_TYPE;
|
|
|
+ $hasInstalment = 0;
|
|
|
foreach ($this->goodsNum as $k => $v) {
|
|
|
if ($v) {
|
|
|
$goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
|
|
|
@@ -871,11 +872,17 @@ class OrderForm extends Model
|
|
|
if($v>1){ // 不可以购买多个
|
|
|
throw new Exception(Yii::t('app', 'allowOnlyOne'));
|
|
|
}
|
|
|
- $loginUserId = \Yii::$app->user->id;
|
|
|
- $userStage = Instalment::getStage($loginUserId);
|
|
|
- if ($userStage==0 || $userStage == 3){
|
|
|
+ $userId = Info::getUserIdByUserName($this->userName);
|
|
|
+ $userStage = Instalment::getStage($userId);
|
|
|
+ $userInstalmentInfo = Instalment::getInfo($userId);
|
|
|
+ if ($userStage == 3){
|
|
|
|
|
|
}else{
|
|
|
+ if($userInstalmentInfo){
|
|
|
+ if($userInstalmentInfo['STAGE']>0 && $userInstalmentInfo['ORDER_TYPE']!='FX'){
|
|
|
+ throw new Exception(Yii::t('app', 'canNotBuy'));
|
|
|
+ }
|
|
|
+ }
|
|
|
if($userStage + 1 != $goods['INSTALMENT']){ // 若用户分期阶段+1不等于商品的分期阶段,则报异常
|
|
|
throw new Exception(Yii::t('app', 'canNotBuy'));
|
|
|
}
|
|
|
@@ -949,6 +956,18 @@ class OrderForm extends Model
|
|
|
if (!$orderResult = $this->addUserOrder()) {
|
|
|
throw new Exception(Form::formatErrorsForApi($orderResult->getErrors()));
|
|
|
}
|
|
|
+ if ($hasInstalment){ // 如果有分期付款的商品,写入信息至分期付款表
|
|
|
+ $instalmentModel = Instalment::findOne(['USER_ID'=>$userId]);
|
|
|
+ if(!$instalmentModel) {
|
|
|
+ $instalmentModel = new Instalment();
|
|
|
+ }
|
|
|
+ $instalmentModel->USER_ID = $userId;
|
|
|
+ $instalmentModel->STAGE = $hasInstalment;
|
|
|
+ $instalmentModel->ORDER_TYPE = 'FX';
|
|
|
+ $instalmentModel->UPDATE_TIME = time();
|
|
|
+ $instalmentModel->save();
|
|
|
+ }
|
|
|
+
|
|
|
$transaction->commit();
|
|
|
}catch (\Exception $e){
|
|
|
$transaction->rollBack();
|