|
|
|
@ -7,12 +7,12 @@ class MarketService
|
|
|
|
|
{
|
|
|
|
|
public function shift($marketShift)
|
|
|
|
|
{
|
|
|
|
|
$formId = $marketShift['form_id'];
|
|
|
|
|
$fromId = $marketShift['from_id'];
|
|
|
|
|
$promoteId = $marketShift['promote_id'];
|
|
|
|
|
$toId = $marketShift['to_id'];
|
|
|
|
|
$time = $marketShift['split_time'] == 0 ? null : $marketShift['split_time'];
|
|
|
|
|
|
|
|
|
|
$promote = M('promote', 'tab_')->field(['chain', 'id', 'level', 'admin_id'])->where(['id' => $promoteId, 'admin_id' => $formId])->find();
|
|
|
|
|
$promote = M('promote', 'tab_')->field(['chain', 'id', 'level', 'admin_id'])->where(['id' => $promoteId, 'admin_id' => $fromId])->find();
|
|
|
|
|
|
|
|
|
|
if (!$promote) {
|
|
|
|
|
throw new \Exception('会长不存在');
|
|
|
|
@ -20,27 +20,34 @@ class MarketService
|
|
|
|
|
if ($promote['level'] != 1) {
|
|
|
|
|
throw new \Exception('该账号非会长');
|
|
|
|
|
}
|
|
|
|
|
if ($fromId == $toId) {
|
|
|
|
|
throw new \Exception('原市场专员与新市场专员相同,不可转换。');
|
|
|
|
|
}
|
|
|
|
|
if ($promote['admin_id'] == $toId) {
|
|
|
|
|
throw new \Exception('新市场专员与现市场专员相同,不可转换。');
|
|
|
|
|
}
|
|
|
|
|
$promotes = (new PromoteService)->getAllChildren($promote, 0, ['id']);
|
|
|
|
|
$promoteIds = [$promote['id']];
|
|
|
|
|
$promoteIds = array_merge(array_column($promotes, 'id'), $promoteIds);
|
|
|
|
|
|
|
|
|
|
$this->shiftPromote($formId, $toId);
|
|
|
|
|
$this->shiftSpend($promoteIds, $formId, $toId, $time);
|
|
|
|
|
$this->shiftDeposit($promoteIds, $formId, $toId, $time);
|
|
|
|
|
$this->shiftPromote($promoteId, $fromId, $toId);
|
|
|
|
|
$this->shiftSpend($promoteIds, $fromId, $toId, $time);
|
|
|
|
|
$this->shiftDeposit($promoteIds, $fromId, $toId, $time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function shiftPromote($promoteId, $formId, $toId, $time = null)
|
|
|
|
|
public function shiftPromote($promoteId, $fromId, $toId, $time = null)
|
|
|
|
|
{
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['id'] = $promoteId;
|
|
|
|
|
$map['admin_id'] = $fromId;
|
|
|
|
|
M('promote', 'tab_')->where($map)->save(['admin_id' => $toId]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function shiftSpend($promoteIds, $formId, $toId, $time = null)
|
|
|
|
|
public function shiftSpend($promoteIds, $fromId, $toId, $time = null)
|
|
|
|
|
{
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['promote_id'] = ['in', $promoteIds];
|
|
|
|
|
$map['market_admin_id'] = $formId;
|
|
|
|
|
$map['market_admin_id'] = $fromId;
|
|
|
|
|
if ($time) {
|
|
|
|
|
$map['pay_time'] = ['egt', $time];
|
|
|
|
|
}
|
|
|
|
@ -54,11 +61,11 @@ class MarketService
|
|
|
|
|
M('spend', 'tab_')->where($map)->save(['market_admin_id' => $toId]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function shiftDeposit($promoteIds, $formId, $toId, $time = null)
|
|
|
|
|
public function shiftDeposit($promoteIds, $fromId, $toId, $time = null)
|
|
|
|
|
{
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['promote_id'] = ['in', $promoteIds];
|
|
|
|
|
$map['market_admin_id'] = $formId;
|
|
|
|
|
$map['market_admin_id'] = $fromId;
|
|
|
|
|
if ($time) {
|
|
|
|
|
$map['create_time'] = ['egt', $time];
|
|
|
|
|
}
|
|
|
|
|