|
|
@@ -61,6 +61,9 @@ class DeclarationUpgradeForm extends Model
|
|
|
private $_standardAmount;
|
|
|
private $_decAmountStandard;
|
|
|
public $period;
|
|
|
+ public $instalment;
|
|
|
+ public $isMax;
|
|
|
+ public $maxLv;
|
|
|
|
|
|
const TYPE_ZC = 'ZC';
|
|
|
private $_userForm = null;
|
|
|
@@ -74,7 +77,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
{
|
|
|
return [
|
|
|
[['remark','type','decLv','decWay','packageId','goodsId', 'goodsNum', 'insertUserName','consignee','acceptMobile','province',/*'city','county',*/'lgaName','cityName','address','nowPerf','nextPerf'], 'trim'],
|
|
|
- [['type','decLv','decWay','insertUserName','nowPerf','province',/*'city','county',*/'address','acceptMobile'], 'required'],
|
|
|
+ [['type','decLv','decWay','insertUserName','nowPerf','province',/*'city','county',*/'address','acceptMobile', 'isMax'], 'required'],
|
|
|
[['decUserName'], 'issetDec'], // 必须是报单中心
|
|
|
[['decWay'], 'hasProduct'],// 必须选择商品
|
|
|
[['decLv'], 'alreadyMaxDec'], //判断要升级用户是否已经是最高级
|
|
|
@@ -117,19 +120,9 @@ class DeclarationUpgradeForm extends Model
|
|
|
$hasInstalment = 0;
|
|
|
// 首购单
|
|
|
if($this->type == self::TYPE_ZC){
|
|
|
- //报单商品及PV判断
|
|
|
- $decLevelConfig = Cache::getDecLevelConfig();
|
|
|
- $decLevel = $decLevelConfig[$this->decLv];
|
|
|
- $toDecLevel = $this->decLv;
|
|
|
- if(!$this->decLv){
|
|
|
- throw new Exception(Yii::t('app', 'pleaseSelectUpgradeLevel'));
|
|
|
- }
|
|
|
$baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
|
|
|
$userId = $baseInfo['ID'];
|
|
|
- $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
|
|
|
- if ($userDecPvSum != $this->nowPerf) {
|
|
|
- throw new Exception(Yii::t('app', 'checkPerformanceOfUpgradedMember'));
|
|
|
- }
|
|
|
+
|
|
|
// 获取用户是否是观察期
|
|
|
$observe = Config::getConfigByType('observe'); // 获取观察期配置信息
|
|
|
$observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
|
|
|
@@ -138,22 +131,25 @@ class DeclarationUpgradeForm extends Model
|
|
|
if ($this->decWay != 2) {
|
|
|
throw new Exception(Yii::t('app', 'upgradeMethodIncorrect'));
|
|
|
}
|
|
|
- if($this->decWay==1) {
|
|
|
- // 先不加套餐升级方式
|
|
|
- // $decPackage = DeclarationPackage::findOneAsArray('ID=:ID', [':ID'=>$this->packageId]);
|
|
|
- // $this->_decAmount = $decPackage['AMOUNT'];
|
|
|
- // $this->_decPv = $decPackage['PV'];
|
|
|
- // $this->_orderGoods[] = [
|
|
|
- // 'GOODS_ID' => $this->packageId,
|
|
|
- // 'PRICE' => $this->_decAmount,
|
|
|
- // 'REAL_PRICE' => $this->_decAmount,
|
|
|
- // 'PV' => $this->_decPv,
|
|
|
- // 'REAL_PV' => $this->_decPv,
|
|
|
- // 'BUY_NUMS' => 1,
|
|
|
- // 'SKU_CODE' => $decPackage['PACKAGE_NO'],
|
|
|
- // 'GOODS_TITLE' => $decPackage['PACKAGE_NAME']
|
|
|
- // ];
|
|
|
- } else {
|
|
|
+
|
|
|
+ $decLevel = [];
|
|
|
+ $toDecLevel = $this->isMax ? $this->maxLv : '';
|
|
|
+ if (!$this->isMax) {
|
|
|
+ //报单商品及PV判断
|
|
|
+ $decLevelConfig = Cache::getDecLevelConfig();
|
|
|
+ $decLevel = $decLevelConfig[$this->decLv];
|
|
|
+ $toDecLevel = $this->decLv;
|
|
|
+ if(!$this->decLv){
|
|
|
+ throw new Exception(Yii::t('app', 'pleaseSelectUpgradeLevel'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
|
|
|
+ if ($userDecPvSum != $this->nowPerf) {
|
|
|
+ throw new Exception(Yii::t('app', 'checkPerformanceOfUpgradedMember'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
$ids = $this->goodsId;
|
|
|
$totalAmount = 0;
|
|
|
$totalAmountStandard = 0;
|
|
|
@@ -218,19 +214,20 @@ class DeclarationUpgradeForm extends Model
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 这里特殊是用户原报单PV之和+用户购买的商品总PV
|
|
|
- $checkPv = $totalPv + $diffPerf;
|
|
|
- if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
|
|
|
- $allData['hasInstalment'] = 1;
|
|
|
- }else if($checkPv < $decLevel['PERF']) {
|
|
|
- throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
|
|
|
- }
|
|
|
+ if (!$this->isMax) {
|
|
|
+ // 这里特殊是用户原报单PV之和+用户购买的商品总PV
|
|
|
+ $checkPv = $totalPv + $diffPerf;
|
|
|
+ if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
|
|
|
+ $allData['hasInstalment'] = 1;
|
|
|
+ }else if($checkPv < $decLevel['PERF']) {
|
|
|
+ throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
|
|
|
+ }
|
|
|
|
|
|
- // 会员已有PV+本次订单PV 不能多于 下一个级别所需PV
|
|
|
- $nextDecLv = DeclarationLevel::getNextDecLv($toDecLevel);
|
|
|
- LoggerTool::debug(['Ats', $nextDecLv, $checkPv]);
|
|
|
- if ($nextDecLv && ($checkPv >= $nextDecLv['PERF'])) {
|
|
|
- throw new Exception(Yii::t('app', 'totalPvExceedPv'), 400);
|
|
|
+ // 会员已有PV+本次订单PV 不能多于 下一个级别所需PV
|
|
|
+ $nextDecLv = DeclarationLevel::getNextDecLv($toDecLevel);
|
|
|
+ if ($nextDecLv && ($checkPv >= $nextDecLv['PERF'])) {
|
|
|
+ throw new Exception(Yii::t('app', 'totalPvExceedPv'), 400);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$this->_decAmount = $totalAmount;
|
|
|
@@ -238,6 +235,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
$this->_decAmountStandard = $totalAmountStandard;
|
|
|
$this->_standardAmount = $this->_decAmountStandard;
|
|
|
}
|
|
|
+
|
|
|
//看现金余额是否充足
|
|
|
if (Cash::getAvailableBalance($loginUserId) < $this->_decAmount){
|
|
|
throw new Exception(Yii::t('app', 'applicantCashShort'), 400);
|
|
|
@@ -470,6 +468,7 @@ class DeclarationUpgradeForm extends Model
|
|
|
return false;
|
|
|
}
|
|
|
if ($this->decWay!=1 && empty($this->goodsId)) {
|
|
|
+ $this->instalment = ShopGoods::findAllAsArray('INSTALMENT > 0 AND ID IN(' . implode(',', $this->goodsId) . ')');
|
|
|
$this->addError($attribute, 'Purchase product upgrade, please select product');//购买商品升级,请选择商品'
|
|
|
return false;
|
|
|
}
|
|
|
@@ -479,13 +478,17 @@ class DeclarationUpgradeForm extends Model
|
|
|
|
|
|
// 判断要升级的会员,是否已是最高级别
|
|
|
public function alreadyMaxDec($attribute) {
|
|
|
- $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
|
|
|
- $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
|
|
|
- $maxPerfInfo = DeclarationLevel::getMaxDecPref();
|
|
|
- $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
|
|
|
- if ($maxDecId == $userDecId) {
|
|
|
- $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
|
|
|
- return false;
|
|
|
+ // 如果商品是分期商品,则不判断是否已经顶级
|
|
|
+ if (!$this->instalment || !$this->isMax) {
|
|
|
+ $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
|
|
|
+ $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
|
|
|
+ $maxPerfInfo = DeclarationLevel::getMaxDecPref();
|
|
|
+ $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
|
|
|
+ $this->maxLv = $maxPerfInfo['ID'];
|
|
|
+ if ($maxDecId == $userDecId) {
|
|
|
+ $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return true;
|