Merge pull request '推广员添加每级id' (#106) from feature/add_promote_level_id into release

Reviewed-on: http://8.136.139.249:3000/wmtx/platform/pulls/106
master
廖金灵 4 years ago
commit 3609845743

@ -14,6 +14,8 @@ use Base\Task\Task;
use Base\Service\MarketService; use Base\Service\MarketService;
use Base\Tool\AggregateClient; use Base\Tool\AggregateClient;
use Base\Repository\GameRepository; use Base\Repository\GameRepository;
use Base\Tool\Redis;
use Think\Model;
class ConsoleController extends Think { class ConsoleController extends Think {
@ -666,4 +668,84 @@ class ConsoleController extends Think {
} }
echo '<table>' . PHP_EOL . $trs . '</table>'; echo '<table>' . PHP_EOL . $trs . '</table>';
} }
public function generateHistoryGame()
{
$items = M('spend', 'tab_')
->field(['tab_promote.level1_id', 'group_concat(distinct tab_spend.game_id) game_ids'])
->join('left join tab_promote on tab_spend.promote_id=tab_promote.id')
->where('tab_spend.is_check=1 and tab_spend.pay_status=1')
->group('tab_promote.level1_id')
->select();
foreach ($items as $item) {
if ($item['level1_id']) {
$key = Redis::getKey('promote_history_games', ['promote_id' => $item['level1_id']]);
Redis::set($key, $item['game_ids']);
}
}
}
public function updateHistoryGame()
{
$items = M('spend', 'tab_')
->field(['tab_promote.level1_id', 'group_concat(distinct tab_spend.game_id) game_ids'])
->join('left join tab_promote on tab_spend.promote_id=tab_promote.id')
->where('tab_spend.is_check=1 and tab_spend.pay_status=1 and tab_spend.pay_time>' . strtotime(date('Y-m-d 00:00:00')))
->group('tab_promote.level1_id')
->select();
foreach ($items as $item) {
if ($item['level1_id']) {
$key = Redis::getKey('promote_history_games', ['promote_id' => $item['level1_id']]);
$value = Redis::get($key);
$gameIds = $value ? explode(',', $value) : [];
$nowGameIds = explode(',', $item['game_ids']);
$gameIds = array_unique(array_merge($gameIds, $nowGameIds));
Redis::set($key, implode(',', $gameIds));
}
}
}
public function generatePromotesLevelId()
{
$promotes = M('promote', 'tab_')->field(['chain', 'id'])->select();
foreach ($promotes as $promote) {
$fullChain = explode('/', $promote['chain'] . $promote['id']);
M('promote', 'tab_')->where(['id' => $promote['id']])->save([
'level1_id' => $fullChain[1] ?? 0,
'level2_id' => $fullChain[2] ?? 0,
'level3_id' => $fullChain[3] ?? 0,
'level4_id' => $fullChain[4] ?? 0,
]);
}
}
public function setUserFirstPayTime()
{
$hasNext = true;
$limit = 500;
$lastId = 0;
do {
$items = M('spend', 'tab_')
->field(['user_id', 'min(pay_time) first_pay_time'])
->where(['pay_status' => 1, 'user_id' => ['gt', $lastId]])
->group('user_id')
->order('user_id asc')
->limit($limit)
->select();
$model = new Model();
$model->startTrans();
foreach ($items as $item) {
M('user', 'tab_')->where(['id' => $item['user_id']])->save([
'first_pay_time' => $item['first_pay_time']
]);
$lastId = $item['user_id'];
}
$model->commit();
if (count($items) < $limit) {
$hasNext = false;
}
} while($hasNext);
}
} }

@ -7,6 +7,7 @@ use Base\Model\UserPlayModel;
use Base\Model\UserModel; use Base\Model\UserModel;
use Base\Tool\IdCard; use Base\Tool\IdCard;
use Base\Tool\Registry; use Base\Tool\Registry;
use Base\Tool\Redis;
use Think\Model; use Think\Model;
use Base\Repository\SpendRepository; use Base\Repository\SpendRepository;
@ -205,11 +206,13 @@ class PromoteService {
M('promote', 'tab_')->where($firstMap)->save([ M('promote', 'tab_')->where($firstMap)->save([
'parent_id' => $toPromote['id'], 'parent_id' => $toPromote['id'],
'parent_name' => $toPromote['account'], 'parent_name' => $toPromote['account'],
'chain' => $toPromote['chain'] . $toPromote['id'] . '/' 'chain' => $toPromote['chain'] . $toPromote['id'] . '/',
'level' . $toPromote['level'] => $toPromote['id']
]); ]);
M('promote', 'tab_')->where($secondMap)->save([ M('promote', 'tab_')->where($secondMap)->save([
'chain' => ['exp', 'REPLACE(chain, "/' . $fromPromote['id'] . '/","/' . $toPromote['id'] . '/")'], 'chain' => ['exp', 'REPLACE(chain, "/' . $fromPromote['id'] . '/","/' . $toPromote['id'] . '/")'],
'level' . $toPromote['level'] => $toPromote['id']
]); ]);
$status = M('ShiftTask')->where('id=' . $task['id'])->save(['status' => 1, 'handle_time' => time()]); $status = M('ShiftTask')->where('id=' . $task['id'])->save(['status' => 1, 'handle_time' => time()]);
@ -394,6 +397,11 @@ class PromoteService {
} }
} }
$toTopPromote = $this->getTopPromote($toPromote);
$hasGameIds = $toTopPromote['game_ids'] == '' ? [] : explode(',', $toTopPromote['game_ids']);
$hasNotGameIds = M('game', 'tab_')->where(['game_id' => ['not in', $hasGameIds]])->getField('id', true);
$hasNotGameIds = $hasNotGameIds ?? [];
$model = new Model(); $model = new Model();
$model->startTrans(); $model->startTrans();
@ -431,7 +439,17 @@ class PromoteService {
M('user_play_info', 'tab_')->where($otherMap)->save($updateData); M('user_play_info', 'tab_')->where($otherMap)->save($updateData);
unset($spendMap['pay_status']); unset($spendMap['pay_status']);
M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket)); // 只改未对账的数据
$updateCheck = [];
if (count($hasGameIds) > 0) {
$spendMap['game_id'] = ['in', $hasGameIds];
M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket, ['is_check' => 1]));
}
if (count($hasNotGameIds) > 0) {
$spendMap['game_id'] = ['in', $hasNotGameIds];
M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket, ['is_check' => 0]));
}
$bindMap = $otherMap; $bindMap = $otherMap;
$bindMap['pay_time'] = ['egt', $orderTime]; $bindMap['pay_time'] = ['egt', $orderTime];
@ -1069,6 +1087,16 @@ class PromoteService {
resetUserAuth(); resetUserAuth();
} }
$fullChain = $data['chain'] . $insert;
$fullChainList = explode('/', trim($fullChain, '/'));
M('promote', 'tab_')->where(['id' => $insert])->update([
'level1_id' => $fullChainList[0] ?? 0,
'level2_id' => $fullChainList[1] ?? 0,
'level3_id' => $fullChainList[2] ?? 0,
'level4_id' => $fullChainList[3] ?? 0,
]);
return $insert; return $insert;
} }
@ -1241,17 +1269,9 @@ class PromoteService {
public function getHistoryGameIds($promote) public function getHistoryGameIds($promote)
{ {
$topPromote = $this->getTopPromote($promote); $topPromote = $this->getTopPromote($promote);
$key = Redis::getKey('promote_history_games', ['promote_id' => $item['level1_id']]);
$spendRepository = new SpendRepository(); $value = Redis::get($key);
$historyGameIds = $value ? explode(',', $value) : [];
$map = [];
$map['_string'] = ' promote_id in(' . $this->subInSql($topPromote) . ')';
$map = $spendRepository->withIsCheck($map);
$historyGames = M('spend', 'tab_')->field(['distinct game_id'])->where($map)->select();
$historyGameIds = [];
if ($historyGames) {
$historyGameIds = array_column($historyGames, 'game_id');
}
$nowGameIds = $topPromote['game_ids'] == '' ? [] : explode(',', $topPromote['game_ids']); $nowGameIds = $topPromote['game_ids'] == '' ? [] : explode(',', $topPromote['game_ids']);
return array_unique(array_merge($historyGameIds, $nowGameIds)); return array_unique(array_merge($historyGameIds, $nowGameIds));
} }

@ -8,6 +8,22 @@ class Redis
{ {
private static $handler; private static $handler;
public static $allKeys = [
'promote_history_games' => 'promote_history_games:{promote_id}', // 会长历史游戏
];
public static function getKey($name, $params = [])
{
$realKey = self::$allKeys[$name] ?? null;
if (is_null($realKey)) {
throw new \Exception('KEY不存在');
}
foreach ($params as $key => $value) {
$realKey = str_replace('{' . $key . '}', $value, $realKey);
}
return $realKey;
}
public static function getHandler() public static function getHandler()
{ {
if(self::$handler == null) { if(self::$handler == null) {

@ -801,7 +801,7 @@ class QueryController extends BaseController
$newPayUserCountList = $spendRepository->getNewPayUserCountGroupByDay($params); $newPayUserCountList = $spendRepository->getNewPayUserCountGroupByDay($params);
$payAmountList = $spendRepository->getPayAmountGroupByDay($params); $payAmountList = $spendRepository->getPayAmountGroupByDay($params);
$newPayAmountList = $spendRepository->getNewPayAmountGroupByDay($params); $newPayAmountList = $spendRepository->getNewPayAmountGroupByDay($params);
$historyPayCountList = $spendRepository->getHistoryPayCountGroupByDay($params); // $historyPayCountList = $spendRepository->getHistoryPayCountGroupByDay($params);
$loginCountList = $userRepository->getLoginCountGroupByDay($params); $loginCountList = $userRepository->getLoginCountGroupByDay($params);
$registerCountList = $userRepository->getRegisterCountGroupByDay($params); $registerCountList = $userRepository->getRegisterCountGroupByDay($params);
@ -813,7 +813,7 @@ class QueryController extends BaseController
'newPayUserCount' => $newPayUserCountList[$day], 'newPayUserCount' => $newPayUserCountList[$day],
'payAmount' => number_format($payAmountList[$day], 2), 'payAmount' => number_format($payAmountList[$day], 2),
'newPayAmount' => number_format($newPayAmountList[$day], 2), 'newPayAmount' => number_format($newPayAmountList[$day], 2),
'historyPayCount' => $historyPayCountList[$day], // 'historyPayCount' => $historyPayCountList[$day],
'loginCount' => $loginCountList[$day], 'loginCount' => $loginCountList[$day],
'registerCount' => $registerCountList[$day], 'registerCount' => $registerCountList[$day],
'payRate' => $loginCountList[$day] == 0 ? '--' : round($payUserCountList[$day] / $loginCountList[$day] * 100, 2) . '%', 'payRate' => $loginCountList[$day] == 0 ? '--' : round($payUserCountList[$day] / $loginCountList[$day] * 100, 2) . '%',

@ -2791,4 +2791,4 @@ ADD COLUMN `apply_leave_time` int(11) NOT NULL DEFAULT 0 COMMENT '申请离职
ADD COLUMN `leave_time` int(11) NOT NULL DEFAULT 0 COMMENT '离职时间' AFTER `apply_leave_time`; ADD COLUMN `leave_time` int(11) NOT NULL DEFAULT 0 COMMENT '离职时间' AFTER `apply_leave_time`;
ALTER TABLE `tab_company_statement_info` ALTER TABLE `tab_company_statement_info`
ADD COLUMN `is_reward_fine_split` tinyint(255) NULL DEFAULT 0 COMMENT '是否是奖罚分离生成 0 否 1 是' AFTER `pay_check_time`; ADD COLUMN `is_reward_fine_split` tinyint(255) NULL DEFAULT 0 COMMENT '是否是奖罚分离生成 0 否 1 是' AFTER `pay_check_time`;

Loading…
Cancel
Save