You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.3 KiB
PHTML

4 years ago
<?php
namespace Base\Service;
use Base\Facade\Request;
class MarketService
{
public function shift($marketShift)
{
4 years ago
$fromId = $marketShift['from_id'];
4 years ago
$promoteId = $marketShift['promote_id'];
$toId = $marketShift['to_id'];
$time = $marketShift['split_time'] == 0 ? null : $marketShift['split_time'];
4 years ago
$promote = M('promote', 'tab_')->field(['chain', 'id', 'level', 'admin_id'])->where(['id' => $promoteId, 'admin_id' => $fromId])->find();
4 years ago
if (!$promote) {
throw new \Exception('会长不存在');
}
if ($promote['level'] != 1) {
throw new \Exception('该账号非会长');
}
4 years ago
if ($fromId == $toId) {
throw new \Exception('原市场专员与新市场专员相同,不可转换。');
}
if ($promote['admin_id'] == $toId) {
throw new \Exception('新市场专员与现市场专员相同,不可转换。');
}
4 years ago
$promotes = (new PromoteService)->getAllChildren($promote, 0, ['id']);
$promoteIds = [$promote['id']];
$promoteIds = array_merge(array_column($promotes, 'id'), $promoteIds);
4 years ago
$this->shiftPromote($promote, $fromId, $toId);
4 years ago
$this->shiftSpend($promoteIds, $fromId, $toId, $time);
$this->shiftDeposit($promoteIds, $fromId, $toId, $time);
4 years ago
}
4 years ago
public function shiftPromote($promote, $fromId, $toId, $time = null)
4 years ago
{
$map = [];
4 years ago
$map['id'] = $promote['id'];
4 years ago
$map['admin_id'] = $fromId;
4 years ago
M('promote', 'tab_')->where($map)->save(['admin_id' => $toId]);
4 years ago
M('promote', 'tab_')->where(['chain' => ['like', $promote['chain'] . $promote['id'] . '/%']])->save(['admin_id' => $toId]);
4 years ago
4 years ago
$authGroup = M('auth_group', 'sys_')->where(['title'=>'市场总监'])->find();
4 years ago
$dataPresident = explode(',', $authGroup['data_president']);
if (!in_array($promote['id'], $dataPresident)) {
4 years ago
M('auth_group', 'sys_')->where(['title'=>'市场总监'])->save(['data_president' => $authGroup['data_president'] . ',' . $promote['id']]);
4 years ago
}
4 years ago
}
4 years ago
public function shiftSpend($promoteIds, $fromId, $toId, $time = null)
4 years ago
{
$map = [];
$map['promote_id'] = ['in', $promoteIds];
4 years ago
$map['market_admin_id'] = $fromId;
4 years ago
if ($time) {
$map['pay_time'] = ['egt', $time];
}
$count = M('spend', 'tab_')->where($map)->count();
4 years ago
$limit = 500;
4 years ago
$pageCount = ceil($count/$limit);
for ($page = 0; $page <= $pageCount; $page ++) {
M('spend', 'tab_')->where($map)->limit($limit)->save(['market_admin_id' => $toId]);
}
M('spend', 'tab_')->where($map)->save(['market_admin_id' => $toId]);
}
4 years ago
public function shiftDeposit($promoteIds, $fromId, $toId, $time = null)
4 years ago
{
$map = [];
$map['promote_id'] = ['in', $promoteIds];
4 years ago
$map['market_admin_id'] = $fromId;
4 years ago
if ($time) {
$map['create_time'] = ['egt', $time];
}
$count = M('deposit', 'tab_')->where($map)->count();
4 years ago
$limit = 500;
4 years ago
$pageCount = ceil($count/$limit);
for ($page = 0; $page <= $pageCount; $page ++) {
M('deposit', 'tab_')->where($map)->limit($limit)->save(['market_admin_id' => $toId]);
}
M('deposit', 'tab_')->where($map)->save(['market_admin_id' => $toId]);
}
}