From b0ef81e0f56c336f24417084b5356e93f46c78b6 Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Tue, 12 Oct 2021 10:25:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=89=E5=AE=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ConsoleController.class.php | 41 ++- .../Base/Business/ShiftPlayer.class.php | 293 +++++++++++++++++ .../Base/Service/PromoteService.class.php | 303 +++++++----------- 3 files changed, 432 insertions(+), 205 deletions(-) create mode 100644 Application/Base/Business/ShiftPlayer.class.php diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php index c36acb21f..073ddee18 100644 --- a/Application/Admin/Controller/ConsoleController.class.php +++ b/Application/Admin/Controller/ConsoleController.class.php @@ -71,30 +71,37 @@ class ConsoleController extends Think { 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); + + $replenishTasks = M('shift_task', 'sys_') + ->where(['status' => 1, 'order_time' => ['elt', time()], 'handle_time' => ['egt', time() - 3600], 'is_replenished' => 0, 'type' => 2]) + ->select(); + foreach ($replenishTasks as $replenishTask) { + $message = '玩家补充迁移[' . $replenishTask['id'] . ']'; + $result = $promoteService->replenishShift($replenishTask); + if ($result['status']) { + $message = 'SUCCESS ----- ' . $message . $result['msg']; + } else { + $message = 'ERROR ----- ' . $message . $result['msg']; + } + Printer::export($message); } + + $tasks = M('shift_task', 'sys_')->where(['status' => 0, 'order_time' => ['elt', time()]])->select(); 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); + } else { + $message = '未知类型迁移[' . $task['id'] . ']'; + } + $result = $promoteService->shift($task); + if ($result['status']) { + $message = 'SUCCESS ----- ' . $message . $result['msg']; + } else { + $message = 'ERROR ----- ' . $message . $result['msg']; } + Printer::export($message); } } diff --git a/Application/Base/Business/ShiftPlayer.class.php b/Application/Base/Business/ShiftPlayer.class.php new file mode 100644 index 000000000..04686bf21 --- /dev/null +++ b/Application/Base/Business/ShiftPlayer.class.php @@ -0,0 +1,293 @@ +task = $task; + $this->orderTime = $task['order_time']; + $this->userIds = json_decode($task['shift_ids'], true) ?? []; + $this->getPromotes(); + $this->getShiftUsers(); + $this->statShiftPayAmount(); + + } + + public function handle() + { + if ($this->fromPromote['id'] == 0 && count($this->userIds) == 0) { + throw new Exception('官方渠道玩家不能全部迁移'); + } + + $this->getNoticeCommonWords(); + + $model = new Model(); + $model->startTrans(); + + $hasError = false; + foreach ($this->users as $user) { + $amount = $this->payAmountItems[$user['id']] ?? 0; + $status = $this->updateMend($user['id'], $amount); + if (!$status) { + $hasError = true; + break; + } + $this->generateNotice($user, $amount); + } + + if ($hasError) { + $model->rollback(); + throw new Exception('系统异常,修改补链记录失败'); + } + + $this->saveNotices(); + + $status = $this->shiftUser(); + if (!$status) { + $model->rollback(); + throw new Exception('系统异常,修改用户推广员失败'); + } + + try { + $this->shiftPlayer(); + $this->shiftSpend(); + $this->shiftDeposit(); + $this->shiftBindSpend(); + $this->shiftUserDataCount(); + $model->commit(); + } catch (\Exception $e) { + $model->rollback(); + throw new \Exception('系统异常: ' . $e->getMessage()); + } + } + + public function handleReplenish() + { + $model = new Model(); + $model->startTrans(); + + $hasError = false; + foreach ($this->payAmountItems as $userId => $amount) { + $status = $this->updateMend($userId, $amount); + if (!$status) { + $hasError = true; + break; + } + } + + if ($hasError) { + $model->rollback(); + throw new Exception('系统异常,修改补链记录失败'); + } + + try { + $this->shiftSpend(); + $this->shiftDeposit(); + $this->shiftBindSpend(); + $model->commit(); + } catch (\Exception $e) { + $model->rollback(); + throw new \Exception('系统异常: ' . $e->getMessage()); + } + } + + private function getPromotes() + { + $toPromoteId = $this->task['to_promote_id']; + $fromPromoteId = $this->task['from_promote_id']; + + $toPromote = M('promote', 'tab_')->where(['id' => $toPromoteId])->find(); + $fromPromote = M('promote', 'tab_')->where(['id' => $fromPromoteId])->find(); + + $this->toPromote = $toPromote ?? ['id' => 0, 'account' => C('OFFICIEL_CHANNEL'), 'company_id' => 0]; + $this->fromPromote = $fromPromote ?? ['id' => 0, 'account' => C('OFFICIEL_CHANNEL'), 'company_id' => 0]; + } + + private function getNoticeCommonWords() + { + $belongs = PromoteCompanyService::$belongs; + + $formConpany = M('promote_company', 'tab_')->field(['company_name', 'company_belong'])->where(['id' => $this->fromPromote['company_id']])->find(); + $toConpany = M('promote_company', 'tab_')->field(['company_name', 'company_belong'])->where(['id' => $this->toPromote['company_id']])->find(); + + $this->fromWord = $this->fromPromote['account'] . ($formConpany ? '(' . $belongs[$formConpany['company_belong']] . '-' . $formConpany['company_name'] . ')' : ''); + $this->toWord = $this->toPromote['account'] . ($toConpany ? '(' . $belongs[$toConpany['company_belong']] . '-' . $toConpany['company_name'] . ')' : ''); + } + + private function getShiftUsers() + { + $map = $this->getShiftCommonMap(true); + $this->users = M('user', 'tab_')->field(['id', 'account', 'nickname'])->where($map)->select(); + } + + private function getSpendMap() + { + $map = $this->getShiftCommonMap(); + $map['pay_time'] = ['egt', $this->orderTime]; + // $map['is_check'] = ['in','1,2']; + $map['settle_check'] = 0; + $map['selle_status'] = 0; + $map['pay_status'] = 1; + return $map; + } + + private function statShiftPayAmount() + { + $spendMap = $this->getSpendMap(); + $payAmountRows = M('spend', 'tab_') + ->field(['user_id', 'sum(pay_amount) pay_amount']) + ->where($spendMap) + ->group('user_id') + ->select(); + foreach ($payAmountRows as $row) { + $this->payAmountItems[$row['user_id']] = round(floatval($row['pay_amount']), 2); + } + } + + private function updateMend($userId, $amount) + { + return M('mend', 'tab_') + ->where(['task_id' => $this->task['id'], 'user_id' => $userId]) + ->save(['status' => 1, 'pay_amount' => ['exp', 'pay_amount+' . $amount], 'update_time' => time()]); + } + + private function generateNotice($user, $amount) + { + if ($amount > 500) { + $userWord = '玩家账号' . $user['account']; + $content = $userWord . ', 从' . $this->fromWord . '换绑到' . $this->toWord . ',换绑金额超过500,达到' . $amount . '元'; + $this->notices[] = [ + 'type' => 'shift-player', + 'title' => '换绑额度超500', + 'content' => $content, + 'admin_ids' => '31', + 'create_time' => time(), + 'target' => $user['account'], + 'start_time' => time(), + 'end_time' => time() + 7*24*3600, + ]; + } + } + + private function saveNotices() + { + if (count($this->notices) > 0) { + M('admin_notice', 'tab_')->addAll($this->notices); + } + } + + private function shiftUser() + { + $map = $this->getShiftCommonMap(true); + return M('user', 'tab_')->where($map)->save([ + 'promote_id' => $this->toPromote['id'], + 'promote_account' => $this->toPromote['account'] + ]); + } + + private function shiftPlayer() + { + $map = $this->getShiftCommonMap(); + $updateData = [ + 'promote_id' => $this->toPromote['id'], + 'promote_account' => $this->toPromote['account'] + ]; + M('user_play', 'tab_')->where($map)->save($updateData); + M('user_play_info', 'tab_')->where($map)->save($updateData); + } + + private function shiftSpend() + { + $toPromote = $this->toPromote; + $spendMap = $this->getSpendMap(); + [$hasGameIds, $hasNotGameIds] = $this->getPromoteGameIds($toPromote); + + unset($spendMap['pay_status']); + + $updateData = [ + 'promote_id' => $toPromote['id'], + 'promote_account' => $toPromote['account'], + 'market_admin_id' => $toPromote['admin_id'], + ]; + + if (count($hasGameIds) > 0) { + $spendMap['game_id'] = ['in', $hasGameIds]; + M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, ['is_check' => 1])); + } + + if (count($hasNotGameIds) > 0) { + $spendMap['game_id'] = ['in', $hasNotGameIds]; + M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, ['is_check' => 2])); + } + } + + private function getPromoteGameIds($promote) + { + $service = new PromoteService(); + $toTopPromote = $service->getTopPromote($promote); + $hasGameIds = $toTopPromote['game_ids'] == '' ? [] : explode(',', $toTopPromote['game_ids']); + $hasNotGameIds = M('game', 'tab_')->where(['game_id' => ['not in', $hasGameIds]])->getField('id', true); + $hasNotGameIds = $hasNotGameIds ?? []; + return [$hasGameIds, $hasNotGameIds]; + } + + private function getShiftCommonMap($isUserTable = false) + { + $map = ['promote_id' => $this->fromPromote['id']]; + if (count($this->userIds) > 0) { + $userColumn = $isUserTable ? 'id' : 'user_id'; + $map[$userColumn] = ['in', $this->userIds]; + } + return $map; + } + + private function shiftDeposit() + { + $map = $this->getShiftCommonMap(); + $map['create_time'] = ['egt', $this->orderTime]; + + $toPromote = $this->toPromote; + M('deposit', 'tab_')->where($map)->save([ + 'promote_id' => $toPromote['id'], + 'promote_account' => $toPromote['account'], + 'market_admin_id' => $toPromote['admin_id'], + ]); + } + + private function shiftBindSpend() + { + $map = $this->getShiftCommonMap(); + $map['pay_time'] = ['egt', $this->orderTime]; + + $toPromote = $this->toPromote; + M('bind_spend', 'tab_')->where($map)->save([ + 'promote_id' => $toPromote['id'], + 'promote_account' => $toPromote['account'] + ]); + } + + private function shiftUserDataCount() + { + $map = $this->getShiftCommonMap(); + $map['create_time'] = ['egt', $this->orderTime]; + M('user_play_data_count', 'tab_')->where($map)->save(['promote_id' => $this->toPromote['id']]); + } +} \ No newline at end of file diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index bb7413388..b8cee2eee 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -1,15 +1,12 @@ field(['id'])->where(['type' => $type, 'status' => 0, 'from_promote_id' => $fromPromoteId])->find(); + /* $shiftTask = M('shift_task', 'sys_')->field(['id'])->where(['type' => $type, 'status' => 0, 'from_promote_id' => $fromPromoteId])->find(); if ($shiftTask) { return [ 'status' => false, 'msg' => '含有类似未执行迁移任务,请稍后再试' ]; - } - - $isFuture = false; - if (strtotime($orderTime) > strtotime(date('Y-m-d 23:59:59'))) { - $isFuture = true; - } + } */ $data = [ 'from_promote_id' => $fromPromoteId, @@ -154,6 +146,10 @@ class PromoteService { ]; if (M('shift_task', 'sys_')->add($data)) { + if ($type == 2) { + $data['id'] = M()->getLastInsID(); + $this->addMendsByTask($data); + } return [ 'status' => true, 'msg'=>'迁移任务创建成功' @@ -166,15 +162,55 @@ class PromoteService { } } + public function addMendsByTask($task) + { + $userIds = json_decode($task['shift_ids'], true); + $users = M('user', 'tab_')->field(['id', 'account', 'nickname'])->where(['id' => ['in', $userIds]])->select(); + $users = index_by_column('id', $users); + $toPromote = M('promote','tab_')->field(['id', 'account'])->where(['id' => $task['to_promote_id']])->find(); + $fromPromote = M('promote','tab_')->field(['id', 'account'])->where(['id' => $task['from_promote_id']])->find(); + + $creator = null; + $opAccount = ''; + if ($task['creator_type'] == 1) { + $creator = M('promote', 'tab_')->where(['id' => $task['creator_id']])->find(); + $opAccount = $creator ? $creator['account'] : ''; + } else { + $creator = M('ucenter_member', 'sys_')->where(['id' => $task['creator_id']])->find(); + $opAccount = $creator ? $creator['username'] : ''; + } + + $mends = []; + foreach ($userIds as $userId) { + $user = $users[$userId]; + $mends[] = [ + 'task_id' => $task['id'], + 'user_id' => $userId, + 'user_account' => $user['account'], + 'user_nickname' => $user['nickname'], + 'promote_id' => $fromPromote ? $fromPromote['id'] : 0, + 'promote_account' => $fromPromote ? $fromPromote['account'] : C('OFFICIEL_CHANNEL'), + 'promote_id_to' => $toPromote ? $toPromote['id'] : 0, + 'promote_account_to' => $toPromote ? $toPromote['account'] : C('OFFICIEL_CHANNEL'), + 'remark' => $task['remark'] == '' ? ($task['creator_type'] == 0 ? '后台补链' : '玩家迁移') : $task['remark'], + 'order_time' => $task['order_time'], + 'create_time' => time(), + 'pay_amount' => 0, + 'op_id' => $task['creator_id'], + 'op_account' => $opAccount, + 'op_type' => $task['creator_type'], + 'bind_type' => 1, + ]; + } + M('mend', 'tab_')->addAll($mends); + } + public function shiftPromote($task) { $model = new Model(); $model->startTrans(); - - $coinRecordService = new PromoteCoinRecordService(); - $promoteCoinService = new PromoteCoinService(); - $shiftIds = json_decode($task['shift_ids'], true) ?? []; + $shiftIds = $task['shift_ids'] ? (json_decode($task['shift_ids'], true) ?? []) : []; $toPromote = M('promote', 'tab_')->where(['id' => $task['to_promote_id']])->find(); $fromPromote = M('promote', 'tab_')->where(['id' => $task['from_promote_id']])->find(); @@ -196,33 +232,34 @@ class PromoteService { return ['status' => false, 'msg' => '系统异常, 处理推广员平台币失败']; } */ + $levelColumn = 'level' . $toPromote['level'] . '_id'; + $subLevelColumn = 'level' . ($toPromote['level'] + 1) . '_id'; $firstMap = ['parent_id' => $fromPromote['id']]; $secondMap = ['chain' => ['like', $fromPromote['chain'] . $fromPromote['id'] . '/%']]; if (count($shiftIds) > 0) { $firstMap['id'] = ['in', $shiftIds]; - $secondMap['parent_id'] = ['in', $shiftIds]; + $secondMap[$subLevelColumn] = ['in', $shiftIds]; } - M('promote', 'tab_')->where($firstMap)->save([ - 'parent_id' => $toPromote['id'], - 'parent_name' => $toPromote['account'], - 'chain' => $toPromote['chain'] . $toPromote['id'] . '/', - 'level' . $toPromote['level'] => $toPromote['id'] - ]); + try { + M('promote', 'tab_')->where($firstMap)->save([ + 'parent_id' => $toPromote['id'], + 'parent_name' => $toPromote['account'], + 'chain' => $toPromote['chain'] . $toPromote['id'] . '/', + $levelColumn => $toPromote['id'] + ]); - M('promote', 'tab_')->where($secondMap)->save([ - 'chain' => ['exp', 'REPLACE(chain, "/' . $fromPromote['id'] . '/","/' . $toPromote['id'] . '/")'], - 'level' . $toPromote['level'] => $toPromote['id'] - ]); + M('promote', 'tab_')->where($secondMap)->save([ + 'chain' => ['exp', 'REPLACE(chain, "/' . $fromPromote['id'] . '/","/' . $toPromote['id'] . '/")'], + $levelColumn => $toPromote['id'] + ]); - $status = M('ShiftTask')->where('id=' . $task['id'])->save(['status' => 1, 'handle_time' => time()]); - if (!$status) { + $model->commit(); + return ['status' => true, 'msg' => '推广帐号迁移成功']; + } catch (\Exception $e) { $model->rollback(); - return ['status' => false, 'msg' => '系统异常,修改迁移任务状态失败']; + return ['status' => true, 'msg' => '推广帐号迁移失败: ' . $e->getMessage()]; } - - $model->commit(); - return ['status' => true, 'msg' => '推广帐号迁移成功']; } public function shiftRemoveCoin($promote, $task) @@ -234,7 +271,7 @@ class PromoteService { $topBalanceCoin = $this->getBalanceCoin($topPromote['id'], 0); $topBalancePlus = 0; - $map = ['chain' => $promote['chain'] . $chain['id'] . '/%']; + $map = ['chain' => $promote['chain'] . $promote['id'] . '/%']; if (count($shiftIds) > 0) { $map['id'] = ['in', $shiftIds]; } @@ -306,168 +343,53 @@ class PromoteService { public function shiftPlayer($task) { - $toPromoteId = $task['to_promote_id']; - $fromPromoteId = $task['from_promote_id']; - $orderTime = $task['order_time']; - $shiftIds = json_decode($task['shift_ids'], true) ?? []; - $remark = $task['remark'] ?? ''; - - $creator = null; - $opAccount = ''; - if ($task['creator_type'] == 1) { - $creator = M('promote', 'tab_')->where(['id' => $task['creator_id']])->find(); - $opAccount = $creator ? $creator['account'] : ''; - } else { - $creator = M('ucenter_member', 'sys_')->where(['id' => $task['creator_id']])->find(); - $opAccount = $creator ? $creator['username'] : ''; - } - - $toPromote = M('promote', 'tab_')->where(['id' => $toPromoteId])->find(); - $fromPromote = M('promote', 'tab_')->where(['id' => $fromPromoteId])->find(); - - $toPromote = $toPromote ?? ['id' => 0, 'account' => C('OFFICIEL_CHANNEL'), 'company_id' => 0]; - $fromPromote = $fromPromote ?? ['id' => 0, 'account' => C('OFFICIEL_CHANNEL'), 'company_id' => 0]; - - if ($fromPromote['id'] == 0 && count($shiftIds) == 0) { - return ['status' => false, 'msg' => '官方渠道玩家不能全部迁移']; - } - - $map = []; - $map['promote_id'] = $fromPromote['id']; - $spendMap = $map; - if (count($shiftIds) > 0) { - $spendMap['user_id'] = $map['id'] = ['in', $shiftIds]; - } - - $users = M('user', 'tab_')->field(['id', 'account', 'nickname'])->where($map)->select(); - - $spendMap['pay_time'] = ['egt', $orderTime]; - // $spendMap['is_check'] = ['in','1,2']; - $spendMap['settle_check'] = 0; - $spendMap['selle_status'] = 0; - $spendMap['pay_status'] = 1; - - $payAmountRows = M('spend', 'tab_') - ->field(['user_id', 'sum(pay_amount) pay_amount']) - ->where($spendMap) - ->group('user_id') - ->select(); - $payAmountRows = index_by_column('user_id', $payAmountRows); - $users = index_by_column('id', $users); - $notices = []; - $formConpany = M('promote_company', 'tab_')->field(['company_name', 'company_belong'])->where(['id' => $fromPromote['company_id']])->find(); - $toConpany = M('promote_company', 'tab_')->field(['company_name', 'company_belong'])->where(['id' => $toPromote['company_id']])->find(); - $belongs = PromoteCompanyService::$belongs; - - $mends = []; - foreach ($users as $item) { - $amount = isset($payAmountRows[$item['id']]) ? round(floatval($payAmountRows[$item['id']]['pay_amount']), 2) : 0; - $mends[] = [ - 'user_id' => $item['id'], - 'user_account' => $item['account'], - 'user_nickname' => $item['nickname'], - 'promote_id' => $fromPromote['id'], - 'promote_account' => $fromPromote['account'], - 'promote_id_to' => $toPromote['id'], - 'promote_account_to' => $toPromote['account'], - 'remark' => $remark == '' ? ($task['creator_type'] == 0 ? '后台补链' : '玩家迁移') : $remark, - 'order_time' => $orderTime, - 'create_time' => time(), - 'pay_amount' => $amount, - 'op_id' => $creator ? $creator['id'] : 0, - 'op_account' => $opAccount, - 'op_type' => $task['creator_type'], - 'bind_type' => 1, - ]; - if ($amount > 500) { - $userWord = '玩家账号' . $item['account']; - $fromWord = $fromPromote['account'] . ($formConpany ? '(' . $belongs[$formConpany['company_belong']] . '-' . $formConpany['company_name'] : ''); - $toWord = $toPromote['account'] . ($toConpany ? '(' . $belongs[$toConpany['company_belong']] . '-' . $toConpany['company_name'] : ''); - $content = $userWord . ', 从' . $fromWord . '换绑到' . $toWord . ',换绑金额超过500,达到' . $amount . '元'; - $notices[] = [ - 'type' => 'shift-player', - 'title' => '换绑额度超500', - 'content' => $content, - 'admin_ids' => '31', - 'create_time' => time(), - 'target' => $item['account'], - 'start_time' => time(), - 'end_time' => time() + 7*24*3600, - ]; - } - } - - $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->startTrans(); - - $status = M('mend', 'tab_')->addAll($mends); - if (!$status) { - $model->rollback(); - return ['status' => false, 'msg' => '系统异常,添加变更记录失败']; - } - - if (count($notices) > 0) { - M('admin_notice', 'tab_')->addAll($notices); - } - - $updateData = [ - 'promote_id' => $toPromote['id'], - 'promote_account' => $toPromote['account'] - ]; - $updateMarket = [ - 'market_admin_id' => $toPromote['admin_id'], - ]; - - $map = $otherMap = ['promote_id' => $fromPromote['id']]; - if (count($shiftIds) > 0) { - $map['id'] = ['in', $shiftIds]; - $otherMap['user_id'] = ['in', $shiftIds]; - } - - $status = M('user', 'tab_')->where($map)->save($updateData); - if (!$status) { - $model->rollback(); - return ['status' => false, 'msg' => '系统异常,修改用户推广员失败']; + try { + $shiftPlayer = new ShiftPlayer($task); + $shiftPlayer->handle(); + return ['status' => true, 'msg' => '玩家迁移成功']; + } catch (\Exception $e) { + return ['status' => false, 'msg' => $e->getMessage()]; } + } - M('user_play', 'tab_')->where($otherMap)->save($updateData); - M('user_play_info', 'tab_')->where($otherMap)->save($updateData); - - unset($spendMap['pay_status']); - - $updateCheck = []; - if (count($hasGameIds) > 0) { - $spendMap['game_id'] = ['in', $hasGameIds]; - M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket, ['is_check' => 1])); + public function afterShift($task, $result) + { + $data = []; + if ($result['status']) { + $data = ['status' => 1, 'result' => $result['msg'], 'handle_time' => time()]; + } else { + $data = ['status' => 2, 'result' => $result['msg'], 'handle_time' => time()]; } + M('shift_task', 'sys_')->where('id=' . $task['id'])->save($data); + } - if (count($hasNotGameIds) > 0) { - $spendMap['game_id'] = ['in', $hasNotGameIds]; - M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket, ['is_check' => 2])); + /** + * 玩家补充迁移(处理在迁移过程中玩家正在充值的订单无法迁移的问题) + */ + public function replenishShift($task) + { + try { + $shiftPlayer = new ShiftPlayer($task); + $shiftPlayer->handleReplenish(); + M('shift_task', 'sys_')->where('id=' . $task['id'])->save(['is_replenished' => 1]); + return ['status' => true, 'msg' => '玩家补充迁移完成']; + } catch (\Exception $e) { + return ['status' => false, 'msg' => $e->getMessage()]; } + } - $bindMap = $otherMap; - $bindMap['pay_time'] = ['egt', $orderTime]; - M('bind_spend', 'tab_')->where($bindMap)->save($updateData); - - $orderMap = $otherMap; - $orderMap['create_time'] = ['egt', $orderTime]; - M('deposit', 'tab_')->where($orderMap)->save(array_merge($updateData, $updateMarket)); - M('user_play_data_count', 'tab_')->where($orderMap)->save(['promote_id' => $toPromote['id']]); - - $status = M('shift_task', 'sys_')->where('id=' . $task['id'])->save(['status' => 1, 'handle_time' => time()]); - if (!$status) { - $model->rollback(); - return ['status' => false, 'msg' => '系统异常,修改迁移任务失败']; + public function shift($task) + { + $result = null; + if ($task['type'] == 1) { + $result = $this->shiftPromote($task); + } elseif ($task['type'] == 2) { + $result = $this->shiftPlayer($task); + } else { + $result = ['status' => false, 'msg' => '类型错误']; } - - $model->commit(); - return ['status' => true, 'msg' => '玩家迁移成功']; + $this->afterShift($task, $result); + return $result; } public function cancelShift($params) @@ -944,6 +866,11 @@ class PromoteService { return M('promote', 'tab_')->field(['id'])->where($conditions)->select(false); } + public function subInCompanySql($companyId, $withSelf = true) + { + return M('promote', 'tab_')->field(['id'])->where(['company_id' => $companyId])->select(false); + } + public function getLevelName($level) { return self::$levels[$level] ?? '未知';