Browse Source

代理被删除,旗下用户归属代理的代理,代理修改占比旗下代理清零

master
wanghongjun 2 years ago
parent
commit
01f75aa77e
  1. 2
      app/controller/AdminAgentTeam.php
  2. 37
      app/model/AgentInfo.php

2
app/controller/AdminAgentTeam.php

@ -240,6 +240,8 @@ class AdminAgentTeam extends BaseController
$resInfo = AgentInfo::destroy($agent_info_id);
if (!$resInfo) throw new ValidateException('删除失败');
AgentInfo::syncUpdateAid($param['aid']);
$connection->commit();
return $this->renderSuccess('已删除');
} catch (ValidateException $validateException) {

37
app/model/AgentInfo.php

@ -71,5 +71,42 @@ class AgentInfo extends Model
$AgentInfoRes->rebate_ratio = $rebate_ratio / 100;
$AgentInfoRes->update_time = date("Y-m-d H:i:s",time());
$AgentInfoRes->save();
self::syncUpdateRebateRatio($aid);
}
/**
* 代理修改占比,旗下代理全部清零
* @param $aid
* @return false|void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected static function syncUpdateRebateRatio($aid)
{
$UserRes = User::where(['aid' => $aid,'identity' => 2])->field('id')->select()->toArray();
if (empty($UserRes)) return false;
foreach ($UserRes as $UserRow) {
# 修改为0
self::updateRebateRatio($UserRow['id'],0);
}
}
/**
* 代理被删除,旗下用户变为代理上级代理
* @param $oldAid // 被删除的aid
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function syncUpdateAid($oldAid)
{
// 被删除aid的上级id
$newAid = User::withTrashed()->where('id',$oldAid)->value('aid');
$newAid = $newAid ?: 0;
$UserRes = User::where(['aid' => $oldAid, 'identity' => 2])->field('id')->select()->toArray();
$userIdArr = [];
foreach ($UserRes as $UserRow) $userIdArr[] = $UserRow['id'];
User::update(['aid' => $newAid],['id' => $userIdArr],['aid']);
}
}

Loading…
Cancel
Save