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.

263 lines
12 KiB
PHP

<?php
/**
* 定时自动完成
*/
namespace Admin\Controller;
use Admin\Model\SpendModel;
use Think\Think;
use Base\Tool\Printer;
use Base\Service\PromoteService;
class ConsoleController extends Think {
protected function _initialize()
{
C(api('Config/lists'));
}
public function modifyPromote()
{
$promotes = M('promote', 'tab_')->where(['parent_id' => 0])->select();
foreach ($promotes as $promote) {
$promote['chain'] = '/';
$promote['level'] = 1;
M('promote', 'tab_')->where(['id' => $promote['id']])->save(['chain' => '/', 'level' => 1]);
$subPromote = $promote;
unset($subPromote['id']);
$subPromote['parent_id'] = $promote['id'];
$subPromote['parent_name'] = $promote['account'];
$subPromote['chain'] = $promote['chain'] . $promote['id'] . '/';
$subPromote['level'] = $promote['level'] + 1;
$subPromote['account'] = 'second_' . $promote['account'];
$subPromote['nickname'] = '二级_' . $promote['nickname'];
$subPromote['mobile_phone'] = '';
$subPromote['email'] = '';
$subPromote['real_name'] = '';
$subPromote['money'] = 0;
$subPromote['total_money'] = 0;
$subPromote['balance_coin'] = 0;
$subPromote['create_time'] = time();
$subPromote['last_login_time'] = 0;
$subPromote['idcard'] = '';
M('promote', 'tab_')->add($subPromote);
$subId = M()->getLastInsID();
$subChain = $subPromote['chain'] . $subId . '/';
M('promote', 'tab_')->where(['parent_id' => $promote['id'], 'id' => ['neq', $subId]])->save([
'parent_id' => $subId,
'parent_name' => $subPromote['account'],
'chain' => $subChain,
'level' => 3,
]);
// echo M()->getLastSql() . "\n";
M('promote', 'tab_')->where(['grand_id' => $promote['id']])->save([
'chain' => ['exp', 'concat("' . $subChain. '",parent_id,"/")'],
'level' => 4,
]);
// echo M()->getLastSql() . "\n";
}
}
public function runShiftTask()
{
$promoteService = new PromoteService();
$tasks = M('shift_task', 'sys_')->where(['status' => 0, 'order_time' => ['elt', time()]])->select();
if (count($tasks) == 0) {
Printer::export('无可执行任务', true);
}
foreach ($tasks as $task) {
if ($task['type'] == 1) {
$message = '推广员迁移[' . $task['id'] . ']';
$result = $promoteService->shiftPromote($task);
if ($result['status']) {
$message = 'SUCCESS ----- ' . $message . $result['msg'];
} else {
$message = 'ERROR ----- ' . $message . $result['msg'];
}
Printer::export($message);
} elseif ($task['type'] == 2) {
$message = '玩家迁移[' . $task['id'] . ']';
$result = $promoteService->shiftPlayer($task);
if ($result['status']) {
$message = 'SUCCESS ----- ' . $message . $result['msg'];
} else {
$message = 'ERROR ----- ' . $message . $result['msg'];
}
Printer::export($message);
}
}
}
/**
* 登录校验
*/
public function modifyLogin()
{
$start_time = $current_time = strtotime(date("Y-m-d"));
for ($i=$start_time; $i<=$current_time; $i+=86400) {
$end_time = $i+86400;
$result = M()->query("SELECT
game_id,
FROM_UNIXTIME(login_time, '%Y-%m-%d') create_time,
user_id,
promote_id
FROM
tab_user_login_record
WHERE
login_time >= {$i} and login_time < {$end_time}
GROUP BY
create_time,
game_id,
user_id");
if ($result) {
foreach ($result as $index => $item) {
$item['create_time'] = strtotime($item['create_time']);
if ($item['create_time']) {
$res = M("login_daily_record", "tab_")->add($item);
echo "写入{$item['create_time']} $res \n";
} else {
echo "写入{$item['create_time']} error \n";
}
unset($result[$index]);
}
} else {
echo "写入{$item['create_time']}\n";
}
}
}
public function deleteRepeatUserPlayInfo()
{
/* INSERT INTO `tab_server`(`game_id`, `game_name`, `server_name`, `server_num`, `recommend_status`, `show_status`, `stop_status`, `server_status`, `icon`, `start_time`, `desride`, `prompt`, `parent_id`, `create_time`, `server_version`, `developers`, `server_id`) VALUES
(148, '王者纷争(安卓版)', 'O3-潜龙于渊', 3294, 1, 1, 0, 0, NULL, 1571399818, NULL, NULL, NULL, 1571399818, 1, 0, '3294'),
(148, '王者纷争(安卓版)', 'O4-攻心为上', 3301, 1, 1, 0, 0, NULL, 1571399818, NULL, NULL, NULL, 1571399818, 1, 0, '3301'),
(148, '王者纷争(安卓版)', 'O5-知人善用', 3311, 1, 1, 0, 0, NULL, 1571399818, NULL, NULL, NULL, 1571399818, 1, 0, '3311'),
(148, '王者纷争(安卓版)', 'O8-剑拔弩张', 3332, 1, 1, 0, 0, NULL, 1571399818, NULL, NULL, NULL, 1571399818, 1, 0, '3332'),
(148, '王者纷争(安卓版)', 'O12-七擒七纵', 3336, 1, 1, 0, 0, NULL, 1571399818, NULL, NULL, NULL, 1571399818, 1, 0, '3336'),
(148, '王者纷争(安卓版)', 'O15-遮空蔽日', 3375, 1, 1, 0, 0, NULL, 1571399818, NULL, NULL, NULL, 1571399818, 1, 0, '3375'); */
// $gameId = 157;
// $gameId = 155;
// $gameId = 153;
// $gameId = 150;
// $gameId = 151;
// 需要先执行上面sql插入区服才能清理干净
// $gameId = 148;
// $gameId = 175;
// $gameId = 142;
// $gameId = 143;
// $gameId = 172;
// $gameId = 173;
// $gameId = 155;
// $gameId = 154;
$gameId = 153;
$sql = 'select id from tab_user_play_info a left join (
select role_id, server_id, game_id, count(1) from tab_user_play_info where server_id="' . $serverId . '" and game_id = ' . $gameId . ' GROUP BY role_id, server_id, game_id, server_name having count(1) > 1
) b on a.role_id=b.role_id where a.server_id=b.server_id and a.game_id=b.game_id and a.server_id="' . $serverId . '" and a.game_id = ' . $gameId . ' order by a.role_id, a.server_id, a.game_id';
$model = new \Think\Model();
$servers = M('server', 'tab_')->field('server_id')->where(['game_id' => $gameId])->group('server_id')->select();
foreach ($servers as $server) {
$serverId = $server['server_id'];
$sql = 'select a.id, a.role_id, a.server_id, a.game_id, a.role_level from tab_user_play_info a left join (
select role_id, server_id, game_id, count(1) from tab_user_play_info where server_id="' . $serverId . '" and game_id = ' . $gameId . ' GROUP BY role_id, server_id, game_id, server_name having count(1) > 1
) b on a.role_id=b.role_id where a.server_id=b.server_id and a.game_id=b.game_id and a.server_id="' . $serverId . '" and a.game_id = ' . $gameId . ' order by a.role_id, a.server_id, a.game_id';
// var_dump($sql);
$result = $model->query($sql);
$uniqueRole = null;
$items = [];
foreach ($result as $item) {
$items[$item['role_id']][] = $item;
}
$maxRoleIds = [];
$repeatIds = [];
foreach ($items as $roles) {
$maxRole = null;
foreach ($roles as $role) {
if ($maxRole == null) {
$maxRole = $role;
} elseif ($role['role_level'] > $maxRole['role_level']) {
$repeatIds[] = $maxRole['id'];
$maxRole = $role;
} else {
$repeatIds[] = $role['id'];
}
}
$maxRoleIds[] = $maxRole['id'];
}
if (count($repeatIds) > 0) {
M('user_play_info', 'tab_')->where(['id' => ['in', $repeatIds], 'game_id' => $gameId, 'server_id' => $serverId])->delete();
echo M()->getLastSql();
echo PHP_EOL;
}
}
}
public function deleteRepeatUserPlayInfo2()
{
// $gameId = 157;
// $gameId = 148;
// $gameId = 150;
// $gameId = 151;
// $gameId = 158;
// $gameId = 175;
// $gameId = 142;
// $gameId = 143;
// $gameId = 172;
// $gameId = 173;
// $gameId = 154;
// $gameId = 155;
// $gameId = 176;
// $gameId = 165;
// $gameId = 164;
// $gameId = 179;
// $gameId = 156;
$gameId = 153;
$sql = 'select id from tab_user_play_info a left join (
select role_id, server_id, game_id, count(1) from tab_user_play_info where server_id="' . $serverId . '" and game_id = ' . $gameId . ' GROUP BY role_id, server_id, game_id, server_name having count(1) > 1
) b on a.role_id=b.role_id where a.server_id=b.server_id and a.game_id=b.game_id and a.server_id="' . $serverId . '" and a.game_id = ' . $gameId . ' order by a.role_id, a.server_id, a.game_id';
$model = new \Think\Model();
$servers = M('server', 'tab_')->field('server_id')->where(['game_id' => $gameId])->group('server_id')->select();
foreach ($servers as $server) {
$serverId = $server['server_id'];
$sql = 'select a.id, a.role_id, a.server_id, a.game_id, a.role_level from tab_user_play_info a left join (
select role_id, server_id, game_id, count(1) from tab_user_play_info where server_id="' . $serverId . '" and game_id = ' . $gameId . ' GROUP BY role_id, server_id, game_id having count(1) > 1
) b on a.role_id=b.role_id where a.server_id=b.server_id and a.game_id=b.game_id and a.server_id="' . $serverId . '" and a.game_id = ' . $gameId . ' order by a.role_id, a.server_id, a.game_id';
// var_dump($sql);
$result = $model->query($sql);
$uniqueRole = null;
$items = [];
foreach ($result as $item) {
$items[$item['role_id']][] = $item;
}
$maxRoleIds = [];
$repeatIds = [];
foreach ($items as $roles) {
$maxRole = null;
foreach ($roles as $role) {
if ($maxRole == null) {
$maxRole = $role;
} elseif ($role['role_level'] >= $maxRole['role_level']) {
$repeatIds[] = $maxRole['id'];
$maxRole = $role;
} else {
$repeatIds[] = $role['id'];
}
}
$maxRoleIds[] = $maxRole['id'];
}
if (count($repeatIds) > 0) {
M('user_play_info', 'tab_')->where(['id' => ['in', $repeatIds], 'game_id' => $gameId, 'server_id' => $serverId])->delete();
echo M()->getLastSql();
echo PHP_EOL;
}
}
}
}