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

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