From a153fb9a0e59749fd761a27ef35d1f11dd6f4b60 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 23 Jun 2020 16:52:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ConsoleController.class.php | 42 ++ .../Controller/MarketController.class.php | 189 +++++++++ .../Controller/MemberController.class.php | 22 +- .../Controller/SpendController.class.php | 19 + .../Admin/Controller/UserController.class.php | 20 + Application/Admin/View/Market/rebind.html | 365 ++++++++++++++++++ .../Admin/View/Market/rebindRecords.html | 241 ++++++++++++ Application/Admin/View/Member/user_info.html | 14 +- Application/Admin/View/Spend/lists.html | 16 +- Application/Admin/View/User/rolelist.html | 14 +- .../Base/Repository/SpendRepository.class.php | 171 ++++++++ .../Base/Service/MarketService.class.php | 74 ++++ .../Base/Service/PaymentService.class.php | 8 + Application/Base/Task/BaseTask.class.php | 21 + .../Base/Task/MarketShiftTask.class.php | 31 ++ Application/Base/Task/Task.class.php | 83 ++++ Application/Base/Tool/ServiceClient.class.php | 63 +++ 17 files changed, 1387 insertions(+), 6 deletions(-) create mode 100644 Application/Admin/Controller/MarketController.class.php create mode 100644 Application/Admin/View/Market/rebind.html create mode 100644 Application/Admin/View/Market/rebindRecords.html create mode 100644 Application/Base/Service/MarketService.class.php create mode 100644 Application/Base/Service/PaymentService.class.php create mode 100644 Application/Base/Task/BaseTask.class.php create mode 100644 Application/Base/Task/MarketShiftTask.class.php create mode 100644 Application/Base/Task/Task.class.php create mode 100644 Application/Base/Tool/ServiceClient.class.php diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php index 7fd9fc095..c035089c1 100644 --- a/Application/Admin/Controller/ConsoleController.class.php +++ b/Application/Admin/Controller/ConsoleController.class.php @@ -10,6 +10,7 @@ use Base\Tool\TaskClient; use Base\Service\PromoteService; use GuzzleHttp\Client; use think\Db; +use Base\Task\Task; class ConsoleController extends Think { @@ -92,6 +93,47 @@ class ConsoleController extends Think { } } + public function runTask($type = null, $count = 1) + { + Printer::export($type); + Printer::export($count); + try { + $task = new Task($type); + $task->run($count); + Printer::export('运行完成'); + } catch (\Exception $e) { + Printer::export($e->getMessage()); + } + } + + public function addTask() + { + $id = M('market_shift', 'tab_')->add([ + 'from_id' => 1, + 'to_id' => 2, + 'split_time' => 0, + 'created_time' => time() + ]); + $params = [ + 'market_shift_id' => $id + ]; + Task::add('market-shift', $params); + } + + public function initMarketAdmin() + { + $marketService = new MarketService(); + $promoteService = new PromoteService(); + $promotes = M('promote', 'tab_')->where(['level' => ['gt', 1], 'admin_id' => ['gt', 0], 'company_belong' => ['in', [1, 2]]])->select(); + foreach ($promotes as $promote) { + $subPromotes = $promoteService->getAllChildren($promote, 0, ['id']); + $promoteIds = [$promote['id']]; + $promoteIds = array_merge(array_column($subPromotes, 'id'), $promoteIds); + $marketService->shiftSpend($promoteIds, 0, $promote['admin_id']); + $marketService->shiftDeposit($promoteIds, 0, $promote['admin_id']); + } + } + public function modifyLoginRepair() { $this->modifyLogin(1569686400); diff --git a/Application/Admin/Controller/MarketController.class.php b/Application/Admin/Controller/MarketController.class.php new file mode 100644 index 000000000..e8dc2b908 --- /dev/null +++ b/Application/Admin/Controller/MarketController.class.php @@ -0,0 +1,189 @@ +field(['id'])->where(['company_id' => $companyId, 'level' => 1])->getField('id', true); + if (count($companyPromoteIds) > 0) { + $promoteIds = count($promoteIds) ? array_intersect($companyPromoteIds, $promoteIds) : $companyPromoteIds; + $promoteIds[] = 0; + } else { + $promoteIds = [0]; + } + } + if (count($promoteIds)) { + $conditions['promote_id'] = ['in', $promoteIds]; + } + $query = M('market_shift', 'tab_')->where($conditions); + + $countQuery = clone $query; + $items = $query->order('id desc')->page($page, $row)->select(); + $count = $countQuery->count(); + + $recordPromotes = []; + $recordCompanys = []; + if (count($items) > 0) { + $recordPromotes = M('promote', 'tab_')->field(['id', 'account', 'company_id'])->where(['id' => ['in', array_column($items, 'promote_id')]])->select(); + $recordCompanyIds = array_column($recordPromotes, 'company_id'); + if (count($recordCompanyIds) > 0) { + $recordCompanys = M('promote_company', 'tab_')->field(['id', 'company_name', 'company_belong'])->where(['id' => ['in', $recordCompanyIds]])->select(); + } + $adminIds = array_merge(array_column($items, 'from_id'), array_column($items, 'to_id')); + $recordAdmins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', $adminIds]])->select(); + $recordPromotes = index_by_column('id', $recordPromotes); + $recordCompanys = index_by_column('id', $recordCompanys); + $recordAdmins = index_by_column('id', $recordAdmins); + } + + $companyTypes = [ + 0 => '内团', + 1 => '外团', + 2 => '外团-分发联盟', + 3 => '无' + ]; + + $statusList = [ + 0 => '待处理', + 1 => '处理成功', + 2 => '处理失败', + ]; + + $records = []; + foreach ($items as $item) { + $records[] = [ + 'id' => $item['id'], + 'promote_account' => $recordPromotes[$item['promote_id']]['account'], + 'company_name' => $recordCompanys[$recordPromotes[$item['promote_id']]['company_id']]['company_name'], + 'company_belong' => $companyTypes[$recordCompanys[$recordPromotes[$item['promote_id']]['company_id']]['company_belong']], + 'remark' => $item['remark'], + 'from_username' => $recordAdmins[$item['from_id']]['username'], + 'to_username' => $recordAdmins[$item['to_id']]['username'], + 'split_time' => date('Y-m-d H:i:s', $item['split_time']), + 'created_time' => date('Y-m-d H:i:s', $item['created_time']), + 'status_text' => $statusList[$item['status']], + 'status' => $item['status'] + ]; + } + $companys = M('promote_company', 'tab_')->field(['id', 'company_name'])->where(['company_belong' => ['in', [1, 2]]])->select(); + + $page = set_pagination($count, $row); + if($page) { + $this->assign('_page', $page); + } + $this->assign('records', $records); + $this->assign('companys', $companys); + $this->display(); + } + + public function rebind() + { + $this->meta_title = '新增换绑'; + $id = I('id', 0); + $companys = M('promote_company', 'tab_')->field(['id', 'company_name'])->where(['company_belong' => ['in', [1, 2]]])->select(); + $marketAdmins = getMarketAdmins(); + $this->assign('companys', $companys); + $this->assign('marketAdmins', $marketAdmins); + $this->display('rebind'); + } + + public function save() + { + $records = I('records', []); + if (count($records) == 0) { + $this->ajaxReturn([ + 'status' => 0, + 'message' => '未提交换绑数据' + ]); + } + + $userAuth = session('user_auth'); + foreach ($records as $record) { + $item = [ + 'promote_id' => $record['promote_id'], + 'from_id' => $record['from_id'], + 'to_id' => $record['to_id'], + 'split_time' => $record['split_time'], + 'remark' => $record['remark'], + 'creator_id' => $userAuth['uid'], + 'created_time' => time() + ]; + $id = M('market_shift', 'tab_')->add($item); + if ($id) { + Task::add('market-shift', ['market_shift_id' => $id]); + } + } + + $this->ajaxReturn([ + 'status' => 1, + 'message' => '提交成功,等待后台处理' + ]); + } + + public function delete() + { + $id = I('id', 0); + M('market_shift', 'tab_')->where(['id' => $id])->delete(); + + addOperationLog([ + 'op_type' => 2, + 'key' => $id, + 'op_name' => '删除市场换绑记录', + 'url' => U('Market/delete', ['id' => $id]), + 'menu' => '推广员-推广员管理-市场换绑-删除市场换绑记录' + ]); + + $this->ajaxReturn([ + 'status' => 1, + 'message' => '删除成功' + ]); + } + + public function getPromotesByCompany() + { + $companyId = I('company_id', 0); + $promotes = M('promote', 'tab_')->field(['id', 'account', 'admin_id']) + ->where(['level' => 1, 'company_id' => $companyId, 'admin_id' => ['gt', 0]]) + ->select(); + + $marketAdmins = index_by_column('id', getMarketAdmins()); + + $records = []; + foreach ($promotes as $promote) { + $admin = isset($marketAdmins[$promote['admin_id']]) ? $marketAdmins[$promote['admin_id']] : null; + $records[] = [ + 'id' => $promote['id'], + 'account' => $promote['account'], + 'admin_id' => $promote['admin_id'], + 'admin_username' => $admin ? $admin['username'] : '', + ]; + } + + $this->ajaxReturn([ + 'status' => 1, + 'message' => '获取成功', + 'data' => [ + 'promotes' => $records + ] + ]); + } +} diff --git a/Application/Admin/Controller/MemberController.class.php b/Application/Admin/Controller/MemberController.class.php index 73a47deae..6e06bb156 100644 --- a/Application/Admin/Controller/MemberController.class.php +++ b/Application/Admin/Controller/MemberController.class.php @@ -79,6 +79,16 @@ class MemberController extends ThinkController $is_repeat = true; } + $marketAdminId = I('market_admin_id', 0); + if ($marketAdminId) { + $map['tab_user.market_admin_id'] = $marketAdminId; + } + + $isMarketAdmin = isMarketAdmin(); + if ($isMarketAdmin) { + $userAuth = session('user_auth'); + $map['tab_user.market_admin_id'] = $userAuth['uid']; + } if (isset($_REQUEST['status'])) { $map['lock_status'] = $_REQUEST['status']; @@ -135,7 +145,7 @@ class MemberController extends ThinkController //计算用户列表 $data = M("user","tab_") ->field("tab_user.id,`device_number`,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,lock_remark, - `register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(ss.pay_amount,0) AS recharge_total,tab_user.is_repeat") + `register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(ss.pay_amount,0) AS recharge_total,tab_user.is_repeat,tab_user.market_admin_id") ->where($map) ->group("tab_user.id") ->order($order); @@ -217,7 +227,13 @@ class MemberController extends ThinkController )); data2csv($data,"玩家_玩家列表",$field); } - + + $adminUsernameList = getAdminUsernameList(array_column($data, 'market_admin_id')); + foreach ($data as $key=>&$value ) { + ($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):''; + $value['market_admin_username'] = $adminUsernameList[$value['market_admin_id']] ?? '无'; + } + //计算总人数 if($is_repeat){ $field ="count(*) user_count,IFNULL(sum(ss.pay_amount), 0) recharge_total"; @@ -258,6 +274,8 @@ class MemberController extends ThinkController $no_repeat_count = $userDbRes['no_repeat_count']; } + $this->assign('isMarketAdmin', $isMarketAdmin); + $this->assign('marketAdmins', getMarketAdmins()); $this->assign('repeat_count',$repeat_count); $this->assign('no_repeat_count',$no_repeat_count); diff --git a/Application/Admin/Controller/SpendController.class.php b/Application/Admin/Controller/SpendController.class.php index 8c008686e..b2fe67251 100644 --- a/Application/Admin/Controller/SpendController.class.php +++ b/Application/Admin/Controller/SpendController.class.php @@ -72,6 +72,17 @@ class SpendController extends ThinkController unset($_REQUEST['pay_game_status']); } + $marketAdminId = I('market_admin_id', 0); + if ($marketAdminId) { + $map['market_admin_id'] = $marketAdminId; + } + + $isMarketAdmin = isMarketAdmin(); + if ($isMarketAdmin) { + $userAuth = session('user_auth'); + $map['market_admin_id'] = $userAuth['uid']; + } + // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // @@ -125,6 +136,14 @@ class SpendController extends ThinkController $data = D(self::model_name)->lists($_GET["p"], $map, $order); + $adminUsernameList = getAdminUsernameList(array_column($data, 'market_admin_id')); + foreach ($data['data'] as $key=>&$value ) { + ($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):''; + $value['market_admin_username'] = $adminUsernameList[$value['market_admin_id']] ?? '无'; + } + + $this->assign('isMarketAdmin', $isMarketAdmin); + $this->assign('marketAdmins', getMarketAdmins()); $this->assign('startDate', $startDate); $this->assign('endDate', $endDate); $this->assign('list_data', $data['data']); diff --git a/Application/Admin/Controller/UserController.class.php b/Application/Admin/Controller/UserController.class.php index 64cc6a33e..45dc6352e 100644 --- a/Application/Admin/Controller/UserController.class.php +++ b/Application/Admin/Controller/UserController.class.php @@ -666,6 +666,17 @@ class UserController extends AdminController unset($_REQUEST['role_id']); } + $marketAdminId = I('market_admin_id', 0); + if ($marketAdminId) { + $map['market_admin_id'] = $marketAdminId; + } + + $isMarketAdmin = isMarketAdmin(); + if ($isMarketAdmin) { + $userAuth = session('user_auth'); + $map['market_admin_id'] = $userAuth['uid']; + } + // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // @@ -704,10 +715,19 @@ class UserController extends AdminController empty(I('user_account')) || $map['user_account'] = ['like', "%" . I('user_account') . "%"]; $this->checkListOrCountAuthRestMap($map,["role_id", "role_name", "user_account"]); $list = $this->lists(M('user_play_info', 'tab_'), $map, 'play_time desc'); + + $adminUsernameList = getAdminUsernameList(array_column($list, 'market_admin_id')); + foreach ($list as $key=>&$value ) { + ($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):''; + $value['market_admin_username'] = $adminUsernameList[$value['market_admin_id']] ?? '无'; + } + $this->assign('list', $list); $this->meta_title = '角色数据'; $this->m_title = '角色查询'; + $this->assign('isMarketAdmin', $isMarketAdmin); + $this->assign('marketAdmins', getMarketAdmins()); $this->assign('commonset', M('Kuaijieicon')->where(['url' => 'User/rolelist', 'status' => 1])->find()); $this->assign("is_admin",is_administrator()); $show_data_power = (is_administrator()|| session('user_auth')['show_data']); diff --git a/Application/Admin/View/Market/rebind.html b/Application/Admin/View/Market/rebind.html new file mode 100644 index 000000000..0acbe4a10 --- /dev/null +++ b/Application/Admin/View/Market/rebind.html @@ -0,0 +1,365 @@ + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
*推广公司: + +
*会长: + +
*原市场专员: + -- +
*新市场专员: + +
订单切分时间: + +
备注: + +
+
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + +
推广公司会长账号内外团原市场专员新市场专员订单切分时间备注操作
+
+
+
+ 全部提交 +
+
+
+ + + +
+ + + + if(C('COLOR_STYLE')=='blue_color') echo ''; + + + + + \ No newline at end of file diff --git a/Application/Admin/View/Market/rebindRecords.html b/Application/Admin/View/Market/rebindRecords.html new file mode 100644 index 000000000..2af097e02 --- /dev/null +++ b/Application/Admin/View/Market/rebindRecords.html @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ +
+
+ 搜索 + 添加 + +
+ +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
推广公司会长账号内外团原市场专员新市场专员备注订单切分时间状态换绑操作时间操作
aOh! 暂时还没有内容!
{$data.company_name}{$data.promote_account}{$data.company_belong}{$data.from_username}{$data.to_username}{$data.remark}{$data.split_time}{$data.status_text}{$data.created_time} +
+ 删除 +
+
+
+
+
+ + + + {$_page|default=''} +
+ + +
+ + + + + + + + \ No newline at end of file diff --git a/Application/Admin/View/Member/user_info.html b/Application/Admin/View/Member/user_info.html index dbac7fc44..f0a3f0d0c 100644 --- a/Application/Admin/View/Member/user_info.html +++ b/Application/Admin/View/Member/user_info.html @@ -160,6 +160,16 @@ + +
+ +
+
 
@@ -202,6 +212,7 @@ 玩家账号 所属推广员 + 所属市场专员 @@ -244,7 +255,7 @@ - aOh! 暂时还没有内容! + aOh! 暂时还没有内容! @@ -284,6 +295,7 @@ + {$data.market_admin_username} {$data.balance} {$data.recharge_total} {$data.gold_coin|default='0.00'} diff --git a/Application/Admin/View/Spend/lists.html b/Application/Admin/View/Spend/lists.html index f7c6790c8..cb5bab994 100644 --- a/Application/Admin/View/Spend/lists.html +++ b/Application/Admin/View/Spend/lists.html @@ -122,6 +122,16 @@ + +
+ +
+
@@ -151,6 +161,7 @@ 玩家账号 游戏名称 所属推广员 + 所属市场专员 充值ip 区服ID 游戏区服 @@ -170,7 +181,7 @@ - aOh! 暂时还没有内容! + aOh! 暂时还没有内容! @@ -215,6 +226,7 @@ + {$data.market_admin_username} {$data.spend_ip} — — @@ -272,7 +284,7 @@ 汇总 - + 当页充值:{:null_to_0(array_sum(array_column(array_status2value('pay_status','',$list_data),'pay_amount')))} diff --git a/Application/Admin/View/User/rolelist.html b/Application/Admin/View/User/rolelist.html index 77bf16481..678214c33 100644 --- a/Application/Admin/View/User/rolelist.html +++ b/Application/Admin/View/User/rolelist.html @@ -108,6 +108,16 @@
+ +
+ +
+
@@ -127,6 +137,7 @@ 角色名 游戏等级 所属推广员 + 所属市场专员 最后登录时间 最后登录IP @@ -161,13 +172,14 @@ {$data.promote_account|encryptStr} + {$data.market_admin_username} {$data.play_ip} - aOh! 暂时还没有内容! + aOh! 暂时还没有内容! diff --git a/Application/Base/Repository/SpendRepository.class.php b/Application/Base/Repository/SpendRepository.class.php index b9b483087..f6fe4b649 100644 --- a/Application/Base/Repository/SpendRepository.class.php +++ b/Application/Base/Repository/SpendRepository.class.php @@ -374,4 +374,175 @@ class SpendRepository { // return M('spend', 'tab_')->field($columns)->where($map); } + + public function achievement() + { + $time = I('time', date('Y-m-d')); + if (!empty($time)) { + $defaultTime = $time; + } else { + $defaultTime = date('Y-m-d', time()); + } + $sdkVersion = I('sdk_version', 0); + $relationGameId = I('relation_game_id', 0); + $serverId = I('server_id', 0); + $parentId = I('parent_id', 0); + $promoteId = I('promote_id', 0); + $status = I('status', 0); + $searchLevel = 0; + $searchLevelName = ''; + $currentDisplay = ''; + $prevParentId = 0; + + $promoteService = new PromoteService(); + $loginPromote = $this->getLoginPromote(); + + $parent = null; + if ($parentId > 0) { + $parent = M('promote', 'tab_')->where(['id' => $parentId])->find(); + $currentDisplay = $promoteService->getLevelName($parent['level']) . '推广'; + $prevParentId = $parent['parent_id'] == $loginPromote['parent_id'] ? 0 : $parent['parent_id']; + } else { + $parent = $loginPromote; + $currentDisplay = '自己'; + } + $searchLevel = $parent['level'] + 1; + $searchLevelName = $promoteService->getLevelName($searchLevel); + + $games = get_promote_serach_game(); + + $subPromotes = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'group_remark'])->where(['parent_id' => $parent['id']])->select(); + + $map = ['parent_id' => $parent['id']]; + if ($promoteId > 0) { + $map['id'] = $promoteId; + } + + $query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map); + list($promotes, $pagination, $count) = $this->paginate($query); + + $ids = array_column($promotes, 'id'); + + $rows = []; + if (count($ids) > 0) { + $rows = M('promote', 'tab_') + ->field(['id', 'chain']) + ->where(['chain' => ['like', [$parent['chain'] . $parent['id'] . '/%']], 'level' => ['gt', $parent['level'] + 1]]) + ->select(); + } + + $basicPromotes = []; + foreach ($ids as $id) { + foreach ($rows as $row) { + $needChain = $parent['chain'] . $parent['id'] . '/' . $id . '/'; + if (strpos($row['chain'], $needChain) !== false) { + $basicPromotes[$row['id']] = $id; + } + } + } + $params = [ + 'isContainSubs' => true, + 'basicPromotes' => $basicPromotes, + ]; + if ($relationGameId != 0 || $sdkVersion != 0) { + $gameIds = gameSearch($relationGameId, $sdkVersion); + $params['game_id'] = ['in', $gameIds]; + } + if ($serverId > 0) { + $params['server_id'] = $serverId; + } + if ($status > 0) { + $params['lock_status'] = $status; + } + list($beginTime, $endTime) = $this->getBetweenTime($time); + $params['begin_time'] = $beginTime; + $params['end_time'] = $endTime; + + $timeout = 0; + $records = []; + if (intval($endTime - $beginTime) / (24 * 3600) <= 7) { + $promoteRepository = new PromoteRepository(); + $createRoleCountList = $promoteRepository->getCreateRoleCountByIds($ids, $params); + $createRoleUserCountList = $promoteRepository->getCreateRoleUserCountByIds($ids, $params); + $newCreateRoleUserCountList = $promoteRepository->getNewCreateRoleUserCountByIds($ids, $params); + // $newCreateRoleDeviceCountList = $promoteRepository->getNewCreateRoleDeviceCountByIds($ids, $params); + $newCreateRoleIpCountList = $promoteRepository->getNewCreateRoleIpCountByIds($ids, $params); + $loginUserCountList = $promoteRepository->getLoginUserCountByIds($ids, $params); + + $rechargeCountList = []; + $rechargeUserCountList = []; + $rechargeAmountList = []; + if ($this->canViewUserRecharge) { + $rechargeCountList = $promoteRepository->getRechargeCountByIds($ids, $params); + $rechargeUserCountList = $promoteRepository->getRechargeUserCountByIds($ids, $params); + $rechargeAmountList = $promoteRepository->getRechargeAmountByIds($ids, $params); + } + + $promoteService = new PromoteService(); + + if (I('p', 1) == 1) { + $selfParams = $params; + $selfParams['isContainSubs'] = false; + $selfCreateRoleCountList = $promoteRepository->getCreateRoleCountByIds([$parent['id']], $selfParams); + $selfCreateRoleUserCountList = $promoteRepository->getCreateRoleUserCountByIds([$parent['id']], $selfParams); + $selfNewCreateRoleUserCountList = $promoteRepository->getNewCreateRoleUserCountByIds([$parent['id']], $selfParams); + // $selfNewCreateRoleDeviceCountList = $promoteRepository->getNewCreateRoleDeviceCountByIds([$parent['id']], $selfParams); + $selfNewCreateRoleIpCountList = $promoteRepository->getNewCreateRoleIpCountByIds([$parent['id']], $selfParams); + $selfLoginUserCountList = $promoteRepository->getLoginUserCountByIds([$parent['id']], $selfParams); + $record = [ + 'id' => $parent['id'], + 'account' => $parent['account'], + 'promote_group' => $promoteService->getGroupNameByChain($parent['chain'], $parent['id']), + 'real_name' => hideRealName($parent['real_name']), + 'level' => $parent['level'], + 'create_role_count' => $selfCreateRoleCountList[$parent['id']], + 'create_role_user_count' => $selfCreateRoleUserCountList[$parent['id']], + 'new_create_role_user_count' => $selfNewCreateRoleUserCountList[$parent['id']], + // 'new_create_role_device_count' => $selfNewCreateRoleDeviceCountList[$parent['id']], + 'new_create_role_ip_count' => $selfNewCreateRoleIpCountList[$parent['id']], + 'login_user_count' => $selfLoginUserCountList[$parent['id']], + 'current_display' => $currentDisplay, + ]; + if ($this->canViewUserRecharge) { + $selfRechargeCountList = $promoteRepository->getRechargeCountByIds([$parent['id']], $selfParams); + $selfRechargeUserCountList = $promoteRepository->getRechargeUserCountByIds([$parent['id']], $selfParams); + $selfRechargeAmountList = $promoteRepository->getRechargeAmountByIds([$parent['id']], $selfParams); + $record['recharge_count'] = $selfRechargeCountList[$parent['id']]; + $record['recharge_user_count'] = $selfRechargeUserCountList[$parent['id']]; + $record['recharge_amount'] = $selfRechargeAmountList[$parent['id']]['ban_coin'] + $selfRechargeAmountList[$parent['id']]['coin'] + $selfRechargeAmountList[$parent['id']]['cash']; + $record['recharge_by_ban_coin'] = $selfRechargeAmountList[$parent['id']]['ban_coin']; + $record['recharge_by_coin'] = $selfRechargeAmountList[$parent['id']]['coin']; + $record['recharge_by_cash'] = $selfRechargeAmountList[$parent['id']]['cash']; + } + $records[] = $record; + } + foreach ($promotes as $promote) { + $id = $promote['id']; + $record = [ + 'id' => $id, + 'account' => $promote['account'], + 'promote_group' => $promoteService->getGroupNameByChain($promote['chain'], $promote['id']), + 'real_name' => hideRealName($promote['real_name']), + 'level' => $promote['level'], + 'create_role_count' => $createRoleCountList[$id], + 'create_role_user_count' => $createRoleUserCountList[$id], + 'new_create_role_user_count' => $newCreateRoleUserCountList[$id], + // 'new_create_role_device_count' => $newCreateRoleDeviceCountList[$id], + 'new_create_role_ip_count' => $newCreateRoleIpCountList[$id], + 'login_user_count' => $loginUserCountList[$id], + 'current_display' => '', + ]; + if ($this->canViewUserRecharge) { + $record['recharge_count'] = $rechargeCountList[$id]; + $record['recharge_user_count'] = $rechargeUserCountList[$id]; + $record['recharge_amount'] = $rechargeAmountList[$id]['ban_coin'] + $rechargeAmountList[$id]['coin'] + $rechargeAmountList[$id]['cash']; + $record['recharge_by_ban_coin'] = $rechargeAmountList[$id]['ban_coin']; + $record['recharge_by_coin'] = $rechargeAmountList[$id]['coin']; + $record['recharge_by_cash'] = $rechargeAmountList[$id]['cash']; + } + $records[] = $record; + } + } else { + $timeout = 1; + } } \ No newline at end of file diff --git a/Application/Base/Service/MarketService.class.php b/Application/Base/Service/MarketService.class.php new file mode 100644 index 000000000..caeb9b26a --- /dev/null +++ b/Application/Base/Service/MarketService.class.php @@ -0,0 +1,74 @@ +field(['chain', 'id', 'level', 'admin_id'])->where(['id' => $promoteId, 'admin_id' => $formId])->find(); + + if (!$promote) { + throw new \Exception('会长不存在'); + } + if ($promote['level'] != 1) { + throw new \Exception('该账号非会长'); + } + $promotes = (new PromoteService)->getAllChildren($promote, 0, ['id']); + $promoteIds = [$promote['id']]; + $promoteIds = array_merge(array_column($promotes, 'id'), $promoteIds); + + $this->shiftPromote($formId, $toId); + $this->shiftSpend($promoteIds, $formId, $toId, $time); + $this->shiftDeposit($promoteIds, $formId, $toId, $time); + } + + private function shiftPromote($promoteId, $formId, $toId, $time = null) + { + $map = []; + $map['id'] = $promoteId; + M('promote', 'tab_')->where($map)->save(['admin_id' => $toId]); + } + + private function shiftSpend($promoteIds, $formId, $toId, $time = null) + { + $map = []; + $map['promote_id'] = ['in', $promoteIds]; + $map['market_admin_id'] = $formId; + if ($time) { + $map['pay_time'] = ['egt', $time]; + } + + $count = M('spend', 'tab_')->where($map)->count(); + $limit = 50; + $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]); + } + + private function shiftDeposit($promoteIds, $formId, $toId, $time = null) + { + $map = []; + $map['promote_id'] = ['in', $promoteIds]; + $map['market_admin_id'] = $formId; + if ($time) { + $map['create_time'] = ['egt', $time]; + } + + $count = M('deposit', 'tab_')->where($map)->count(); + $limit = 50; + $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]); + } +} \ No newline at end of file diff --git a/Application/Base/Service/PaymentService.class.php b/Application/Base/Service/PaymentService.class.php new file mode 100644 index 000000000..1cf22bf5a --- /dev/null +++ b/Application/Base/Service/PaymentService.class.php @@ -0,0 +1,8 @@ + + */ +class BaseTask +{ + public $params; + + public function __construct($params = []) + { + $this->params = $params; + } + + public function run() + { + + } +} \ No newline at end of file diff --git a/Application/Base/Task/MarketShiftTask.class.php b/Application/Base/Task/MarketShiftTask.class.php new file mode 100644 index 000000000..7c1a36d7b --- /dev/null +++ b/Application/Base/Task/MarketShiftTask.class.php @@ -0,0 +1,31 @@ + + */ +class MarketShiftTask extends BaseTask +{ + public function run() + { + $id = $this->params['market_shift_id']; + $record = M('market_shift', 'tab_')->where(['id' => $id])->find(); + if (!$record) { + throw new \Exception('换绑记录不存在'); + } + if ($record['status'] != 0) { + throw new \Exception('换绑记录状态错误'); + } + try { + $marketService = new MarketService(); + $marketService->shift($record); + M('market_shift', 'tab_')->where(['id' => $id])->save(['status' => 1]); + } catch (\Exception $e) { + M('market_shift', 'tab_')->where(['id' => $id])->save(['status' => 2]); + throw new \Exception($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/Application/Base/Task/Task.class.php b/Application/Base/Task/Task.class.php new file mode 100644 index 000000000..6e1db5765 --- /dev/null +++ b/Application/Base/Task/Task.class.php @@ -0,0 +1,83 @@ + + */ +class Task +{ + public static $types = [ + 'market-shift' => '\Base\Task\MarketShiftTask', + ]; + + public $type; + public $tasks; + + public function __construct($type = null) + { + $this->type = $type; + } + + public function run($count = 1) + { + $map = ['status' => 0]; + if ($this->type !== null) { + $map['type'] = $this->type; + } + $this->tasks = M('tasks', 'tab_')->where($map)->limit($count)->select(); + if (count($this->tasks) == 0) { + throw new \Exception('暂无任务'); + } + + $this->updateTasks(['status' => 1, 'start_time' => time()]); + + foreach ($this->tasks as $task) { + $class = $this->getTypeClass($task); + if (is_null($class) || !class_exists($class)) { + $this->updateTask($task, ['status' => 3, 'end_time' => time(), 'result' => '任务处理类不存在']); + continue; + } + try { + $params = json_decode($task['params'], true); + $obj = new $class($params); + $obj->run(); + $this->updateTask($task, ['status' => 2, 'end_time' => time(), 'result' => '处理成功']); + } catch (\Exception $e) { + $this->updateTask($task, ['status' => 3, 'end_time' => time(), 'result' => $e->getMessage()]); + } + } + } + + public function getTypeClass($task) + { + if (!isset(self::$types[$task['type']])) { + return null; + } + return self::$types[$task['type']]; + } + + private function updateTask($task, $data) + { + M('tasks', 'tab_')->where(['id' => $task['id']])->save($data); + } + + private function updateTasks($data) + { + $ids = array_column($this->tasks, 'id'); + M('tasks', 'tab_')->where(['id' => ['in', $ids]])->save($data); + } + + public static function add($type, $params = []) + { + if (!isset(self::$types[$type])) { + return false; + } + $record = [ + 'type' => $type, + 'params' => json_encode($params), + 'created_time' => time() + ]; + return M('tasks', 'tab_')->add($record); + } +} \ No newline at end of file diff --git a/Application/Base/Tool/ServiceClient.class.php b/Application/Base/Tool/ServiceClient.class.php new file mode 100644 index 000000000..8bf2c1a21 --- /dev/null +++ b/Application/Base/Tool/ServiceClient.class.php @@ -0,0 +1,63 @@ +client = new Client([ + 'base_uri' => C('SERVICE_URL'), + 'timeout' => 10.0, + ]); + } + + protected function post($uri, $data) + { + $response = $this->client->post($uri, [ + 'verify' => false, + 'form_params' => $data + ]); + $result = (string)$response->getBody(); + return json_decode($result, true); + } + + public function sendSmsCode(string $mobile, string $clientIp) + { + $options = ['type' => 'code', 'client_ip' => $clientIp]; + return $this->sendSms($mobile, $options); + } + + public function sendSmsContent(string $mobile, string $content) + { + $options = ['type' => 'content', 'content' => $content]; + return $this->sendSms($mobile, $options); + } + + public function sendSmsBatch(array $mobiles, string $content) + { + $options = ['type' => 'batch', 'content' => $content]; + return $this->sendSms($mobiles, $options); + } + + private function sendSms($mobile, array $options) + { + return $this->post('/message/sms-send', ['mobile' => $mobile, 'options' => $options]); + } + + public function checkSms($mobile, $code) + { + return $this->post('/message/sms-check', ['mobile' => $mobile, 'code' => $code]); + } + + public function registerEvent($userId, $source) + { + return $this->post('/game-event/register', ['user_id' => $userId, 'source' => $source]); + } +} \ No newline at end of file