|
|
@@ -300,8 +300,8 @@ class ApproachOrderForm extends Model
|
|
|
throw new Exception(Form::formatErrorsForApi('支付金额与订单金额不符'));
|
|
|
}
|
|
|
|
|
|
- // 是否给BA升级的单子
|
|
|
- $isBrandAmbassadorUpgrade = $this->note['customer'][2]['value'] ?? false;
|
|
|
+ // 订单类型:userOrder(会员订单)、userUpgrade(会员升级)、userDec(会员报单)
|
|
|
+ $orderType = $customFields[1]['value'] ?? false;
|
|
|
|
|
|
$db = \Yii::$app->db;
|
|
|
$transaction = $db->beginTransaction();
|
|
|
@@ -325,44 +325,60 @@ class ApproachOrderForm extends Model
|
|
|
$approachOrderGood['EMAIL'] = $this->email;
|
|
|
}
|
|
|
OrderGoods::batchInsert($approachOrderGoods);
|
|
|
- // 同步报单
|
|
|
- $approachDecOrder = ApproachDecOrder::findOneAsArray('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
|
|
|
- if ($approachDecOrder) {
|
|
|
- unset($approachDecOrder['STATUS']);
|
|
|
+
|
|
|
+ // 会员报单、BA升级
|
|
|
+ if (in_array($orderType, ['userDec', 'baUpgrade', 'userUpgrade'])) {
|
|
|
// 同步报单
|
|
|
- DecOrder::insertOne($approachDecOrder);
|
|
|
-
|
|
|
- // 会员升级 报单类型:2会员升级单
|
|
|
- if ($approachDecOrder['DETAIL_TYPE'] == 2) {
|
|
|
- // 为被升级人进行升级操作
|
|
|
- $decLevelLog = new DecLevelLog();
|
|
|
- $decLog = [
|
|
|
- 'userId' => $approachDecOrder['TO_USER_ID'],//会员ID
|
|
|
- 'fromId' => $approachDecOrder['ORI_LV'], // 变动前的级别
|
|
|
- 'levelId' => $approachDecOrder['UPGRADE_LV'],// 变动后的级别
|
|
|
- 'actionId' => $approachDecOrder['USER_ID'],
|
|
|
- 'remark' => $approachDecOrder['REMARK'],
|
|
|
- 'lvPv' => $this->_model->PV,
|
|
|
- ];
|
|
|
- $modifyDecLv = $decLevelLog->frontendChange($decLog);
|
|
|
- if (empty($modifyDecLv)) {
|
|
|
- $transaction->rollBack();
|
|
|
- throw new Exception("Failed to upgrade for member");//为会员升级失败
|
|
|
+ $approachDecOrder = ApproachDecOrder::findOneAsArray('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
|
|
|
+ if ($approachDecOrder) {
|
|
|
+ unset($approachDecOrder['STATUS']);
|
|
|
+
|
|
|
+ // 同步报单
|
|
|
+ DecOrder::insertOne($approachDecOrder);
|
|
|
+ // 修改会员锁定状态
|
|
|
+ if (!User::updateAll(['STATUS' => 1], 'ID=:USER_ID', [':USER_ID' => $approachDecOrder['TO_USER_ID']])) {
|
|
|
+ throw new Exception(Form::formatErrorsForApi('change user status error'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改BA会员升级状态
|
|
|
+ if ($orderType === 'baUpgrade') {
|
|
|
+ // 查询BA会员名
|
|
|
+ $userInfo = User::findOneAsArray('ID=:USER_ID', [':USER_ID' => $approachDecOrder['TO_USER_ID']]);
|
|
|
+ if (!BaUser::updateAll(['WHETHER_UPGRADE' => 1, 'BA_UPGRADE_AT' => time()], 'USER_NAME=:USER_NAME', [':USER_NAME' => $userInfo['USER_NAME']])) {
|
|
|
+ throw new Exception(Form::formatErrorsForApi('Brand Ambassador upgrade error!'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 正式会员-升级单
|
|
|
+ if ($orderType === 'userUpgrade') {
|
|
|
+ // 会员升级 报单类型:2会员升级单
|
|
|
+ if ($approachDecOrder['DETAIL_TYPE'] == 2) {
|
|
|
+ // 为被升级人进行升级操作
|
|
|
+ $decLevelLog = new DecLevelLog();
|
|
|
+ $decLog = [
|
|
|
+ 'userId' => $approachDecOrder['TO_USER_ID'],//会员ID
|
|
|
+ 'fromId' => $approachDecOrder['ORI_LV'], // 变动前的级别
|
|
|
+ 'levelId' => $approachDecOrder['UPGRADE_LV'],// 变动后的级别
|
|
|
+ 'actionId' => $approachDecOrder['USER_ID'],
|
|
|
+ 'remark' => $approachDecOrder['REMARK'],
|
|
|
+ 'lvPv' => $this->_model->PV,
|
|
|
+ ];
|
|
|
+ $modifyDecLv = $decLevelLog->frontendChange($decLog);
|
|
|
+ if (empty($modifyDecLv)) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ throw new Exception("Failed to upgrade for member");//为会员升级失败
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 删除中间表
|
|
|
+ ApproachDecOrder::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 删除中间表
|
|
|
ApproachOrder::deleteAll('SN = :SN', [':SN' => $this->sn]);
|
|
|
ApproachOrderGoods::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
|
|
|
- ApproachDecOrder::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
|
|
|
-
|
|
|
- if ($isBrandAmbassadorUpgrade) {
|
|
|
- // 修改BA会员升级状态
|
|
|
- if (!BaUser::updateAll(['WHETHER_UPGRADE' => 1, 'BA_UPGRADE_AT' => time()], 'USER_NAME=:USER_NAME', [':USER_NAME' => $isBrandAmbassadorUpgrade])) {
|
|
|
- throw new Exception(Form::formatErrorsForApi('BA升级状态错误'));
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
$transaction->commit();
|
|
|
} catch (Exception $e) {
|