|
|
@@ -22,6 +22,7 @@ use common\models\ShopGoods;
|
|
|
use common\models\User;
|
|
|
use common\models\UserInfo;
|
|
|
use common\models\UserNetwork;
|
|
|
+use common\models\Instalment;
|
|
|
use Yii;
|
|
|
use yii\base\Exception;
|
|
|
|
|
|
@@ -58,7 +59,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
private $_orderGoods;
|
|
|
private $_standardAmount;
|
|
|
private $_decAmountStandard;
|
|
|
-
|
|
|
+
|
|
|
const TYPE_ZC = 'ZC';
|
|
|
private $_userForm = null;
|
|
|
// 全部的安置网上级
|
|
|
@@ -154,6 +155,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
$totalAmount = 0;
|
|
|
$totalAmountStandard = 0;
|
|
|
$totalPv = 0;
|
|
|
+ $hasInstalment = 0;
|
|
|
$exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
|
|
|
foreach ($this->goodsNum as $k => $v) {
|
|
|
if ($v) {
|
|
|
@@ -183,11 +185,30 @@ class DeclarationUpgradeForm extends Model
|
|
|
'TAX_RATE' => $goods['TAX_RATE'],
|
|
|
];
|
|
|
}
|
|
|
+ if($goods['INSTALMENT']>0){ // 如果有分期付款商品,检查用户的分期付款状态
|
|
|
+ if($v>1){ // 不可以购买多个
|
|
|
+ throw new Exception(Yii::t('app', 'allowOnlyOne'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $userStage = Instalment::getStage($userId);
|
|
|
+ $userInstalmentInfo = Instalment::getInfo($userId);
|
|
|
+ if (!$userInstalmentInfo){ // 如果没有分期付款记录
|
|
|
+ throw new Exception(Yii::t('app', 'canNotBuy'));
|
|
|
+ } else if ($userInstalmentInfo['ORDER_TYPE']!='BD' || $userStage == 3) { // 如果分期付款记录中,不是报单,或已是3
|
|
|
+ throw new Exception(Yii::t('app', 'canNotBuy'));
|
|
|
+ }
|
|
|
+ if($userStage + 1 != $goods['INSTALMENT']){ // 若用户分期阶段+1不等于商品的分期阶段,则报异常
|
|
|
+ throw new Exception(Yii::t('app', 'canNotBuy'));
|
|
|
+ }
|
|
|
+ $hasInstalment = $goods['INSTALMENT'];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
// 这里特殊是用户原报单PV之和+用户购买的商品总PV
|
|
|
$checkPv = $totalPv + $diffPerf;
|
|
|
- if($checkPv < $decLevel['PERF']) {
|
|
|
+ if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
|
|
|
+ $allData['hasInstalment'] = 1;
|
|
|
+ }else if($checkPv < $decLevel['PERF']) {
|
|
|
throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
|
|
|
}
|
|
|
foreach ($decLevelConfig as $key=>$val){
|
|
|
@@ -214,6 +235,17 @@ class DeclarationUpgradeForm extends Model
|
|
|
if(!($decResult = $this->addDecOrder($insertConId,$insertRecId, $baseInfo['DEC_LV'],$isObserve,$this->remark))) {
|
|
|
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 true;
|
|
|
}
|
|
|
@@ -300,7 +332,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
$transaction->rollBack();
|
|
|
throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 2022-05-10
|
|
|
* York
|
|
|
@@ -377,7 +409,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
} catch(Exception $e) {
|
|
|
$transaction->rollBack();
|
|
|
throw new Exception($e->getMessage());
|
|
|
-
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -431,7 +463,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
public function alreadyMaxDec($attribute) {
|
|
|
$baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
|
|
|
$userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
|
|
|
- $maxPerfInfo = DeclarationLevel::getMaxDecPref();
|
|
|
+ $maxPerfInfo = DeclarationLevel::getMaxDecPref();
|
|
|
$maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
|
|
|
if ($maxDecId == $userDecId) {
|
|
|
$this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
|
|
|
@@ -467,7 +499,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
}
|
|
|
}
|
|
|
unset($allParentUserIds);
|
|
|
-
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -501,4 +533,4 @@ class DeclarationUpgradeForm extends Model
|
|
|
// return true;
|
|
|
// }
|
|
|
|
|
|
-}
|
|
|
+}
|