修复:购买商品赠送权重值 - 由于数据结构变更导致计算后修改用户持有权重值失败

This commit is contained in:
wuhui_zzw 2023-10-24 11:10:50 +08:00
parent 39dac89841
commit d4cab66f3b
2 changed files with 12 additions and 7 deletions

View File

@ -130,9 +130,11 @@ class IndexController extends BaseController{
public function test(){
// (new WeightValue())->upgradeGiveInit(1,1);
// (new WeightValue())->giveInit(Order::find(128));
// (new WeightValue())->giveInit(Order::find(134));
debug("调试中...");
}

View File

@ -37,20 +37,24 @@ class WeightValue extends BaseModel{
$goodsList = $this->getGoodsList($model->id);
// 获取当前用户及上级信息
$agents = $this->getParent($model->uid);
$agentAllList = [];
foreach(array_merge($agents['current_user'],$agents['parents'],$agents['agents']) as $agentSingleInfo){
$agentAllList[(string)$agentSingleInfo['uid']] = $agentSingleInfo;
}
// 循环处理每个商品
$changeRecord = [];// 变更记录
foreach($goodsList as $goodsInfo){
$useAgentList = [];
$mergeAgentList = array_merge($agents['parents'],$agents['agents']);// 默认上级信息
// 判断:是否开启自购
if((int)$goodsInfo['is_self_purchase'] == 1) $mergeAgentList = array_merge($agents['current_user'],$agents['parents'],$agents['agents']);
if((int)$goodsInfo['is_self_purchase'] == 1) $mergeAgentList = $agentAllList;
foreach($mergeAgentList as $useAgentItem){
$useAgentList[$useAgentItem['uid']] = $useAgentItem;
}
// 循环上级信息 处理每一个用户、每一个商品的赠送情况
foreach($useAgentList as $agentKey => $agentInfo){
// 用户当前的权重值
$currentAgentHasWeightValue = (float)$agents[$agentKey]['weight_value']['quantity'] ?? 0;
$currentAgentHasWeightValue = (float)$agentAllList[$agentInfo['uid']]['weight_value']['quantity'] ?? 0;
// 符合条件 获取当前用户应得的权重值
$totalWeightValue = $this->getWeightValue($goodsInfo,$agentInfo);// 应得权重值
// 应得权重值大于0 记录改变信息并且修改持有权重值
@ -70,20 +74,19 @@ class WeightValue extends BaseModel{
'remark' => "订单{$model->order_sn}赠送",// 备注
'created_at' => time(),// 变更时间
];
$agents[$agentKey]['weight_value']['quantity'] = $changeAfter;
$agentAllList[$agentInfo['uid']]['weight_value']['quantity'] = $changeAfter;
}
}
}
// 修改用户权重值变更信息 | 处理权重值变更记录
if($changeRecord){
$updateWeightValueList = array_column($agents,'weight_value');
$updateWeightValueList = array_column($agentAllList,'weight_value');
self::updateInfo($updateWeightValueList);
WeightValueLog::insert($changeRecord);
}
DB::commit();
}catch(\Exception $e){
\Log::debug('------购买商品赠送权重值 - 错误抛出------',$e->getMessage());
DB::rollBack();
}
@ -305,7 +308,7 @@ class WeightValue extends BaseModel{
foreach($parents as $agentKey => $agentInfo){
// 判断:当前用户是否已经领取 已领取不可重复领取
if(in_array($agentInfo['uid'],$getRecord)) {
\Log::debug('------经销商升级赠送权重值 - 错误 - 当前用户是否已经领取 ------',$agentInfo['uid']);
\Log::debug('------经销商升级赠送权重值 - 错误 - 当前用户已经领取 ------',$agentInfo['uid']);
continue;
}
// 用户当前持有的权重值