diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index e78bd275c..f8dca8f93 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -2469,5 +2469,94 @@ function getAvailableBalance($promote_id=0,$game_id=0,$server_id='') { } +function getMarketGroupIds() +{ + return ['11', '12']; +} + +function getMarketAdmins() +{ + $ids = getMarketGroupIds(); + $adminIds = M('auth_group_access', 'sys_')->where(['group_id' => ['in', $ids]])->getField('uid', true); + return M('ucenter_member', 'sys_')->where(['id' => ['in', $adminIds]])->select(); +} + +function getMarketAdminsByPromoteIds($promoteIds) +{ + $promotes = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => ['in', $promoteIds]])->select(); + $resultMap = []; + foreach ($promotes as $promote) { + if ($promote['chain'] == '/') { + $resultMap[$promote['id']] = ['top_id' => $promote['id']]; + } else { + $item = explode('/', trim($promote['chain'], '/')); + $resultMap[$promote['id']] = ['top_id' => $item[0]]; + } + } + if (count($promotes) == 0) { + return []; + } + $topPromotes = M('promote', 'tab_')->field(['id', 'admin_id'])->where(['id' => ['in', array_column($resultMap, 'top_id')]])->select(); + $topAdminMap = []; + foreach ($topPromotes as $topPromote) { + $topAdminMap[$topPromote['id']] = $topPromote['admin_id']; + } + $admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', array_column($topPromotes, 'admin_id')]])->select(); + $admins = index_by_column('id', $admins); + foreach ($resultMap as &$row) { + $adminId = $topAdminMap[$row['top_id']] ?? 0; + $admin = $admins[$adminId] ?? null; + $row['admin'] = $admin; + } + return $resultMap; +} + +function getAdminUsernameList(array $ids) +{ + if (count($ids) == 0) { + return []; + } + $admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', $ids]])->select(); + $items = []; + foreach ($admins as $admin) { + $items[$admin['id']] = $admin['username']; + } + return $items; +} -?> +function isMarketAdmin() +{ + $ids = getMarketGroupIds(); + $userAuth = session('user_auth'); + $adminIds = M('auth_group_access', 'sys_')->where(['group_id' => ['in', $ids]])->getField('uid', true); + return in_array($userAuth['uid'], $adminIds); +} + +function getPromoteIdsByTopIds($ids) +{ + if (count($ids) == 0) { + return []; + } + $idsExp = implode(',', $ids); + $map = array(); + $where['SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,"/",2),"/",-1)'] = array('exp',"IN({$idsExp})"); + $where['id'] = array('in', $ids);//会长本身 + $where['_logic'] = 'or'; + $map['_complex'] = $where; + $result = M('promote', 'tab_')->field('id')->where($map)->getField('id', true); + return $result; +} + +function getCompanyDevelopTypes() +{ + return [ + 1 => '自主开发', + 2 => '自主开发及维护', + 3 => '只维护' + ]; +} + +function getCompanyDevelopTypeText($type) +{ + return getCompanyDevelopTypes()[$type] ?? '无'; +} \ No newline at end of file diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php index c035089c1..1d970e99c 100644 --- a/Application/Admin/Controller/ConsoleController.class.php +++ b/Application/Admin/Controller/ConsoleController.class.php @@ -11,6 +11,7 @@ use Base\Service\PromoteService; use GuzzleHttp\Client; use think\Db; use Base\Task\Task; +use Base\Service\MarketService; class ConsoleController extends Think { @@ -124,8 +125,11 @@ class ConsoleController extends Think { { $marketService = new MarketService(); $promoteService = new PromoteService(); - $promotes = M('promote', 'tab_')->where(['level' => ['gt', 1], 'admin_id' => ['gt', 0], 'company_belong' => ['in', [1, 2]]])->select(); + $promotes = M('promote', 'tab_')->field(['id', 'admin_id', 'account', 'chain', 'level']) + ->where(['level' => 1, 'admin_id' => ['gt', 0], 'company_belong' => ['in', [1, 2]]]) + ->select(); foreach ($promotes as $promote) { + Printer::export('处理会长: ' . $promote['account']); $subPromotes = $promoteService->getAllChildren($promote, 0, ['id']); $promoteIds = [$promote['id']]; $promoteIds = array_merge(array_column($subPromotes, 'id'), $promoteIds); diff --git a/Application/Admin/Controller/FinancePromoteController.class.php b/Application/Admin/Controller/FinancePromoteController.class.php index 24fbd3190..15b84a551 100644 --- a/Application/Admin/Controller/FinancePromoteController.class.php +++ b/Application/Admin/Controller/FinancePromoteController.class.php @@ -76,6 +76,21 @@ class FinancePromoteController extends AdminController $nwtflag = false; } } + if(isset($_REQUEST['admin_id'])){ + if($_REQUEST['admin_id']!=0){ + $nwtflag = false; + } + } + if(isset($_REQUEST['admin_id'])){ + if($_REQUEST['admin_id']!=0){ + $nwtflag = false; + } + } + if(isset($_REQUEST['develop_type'])){ + if($_REQUEST['develop_type']!=0){ + $nwtflag = false; + } + } if (isset($_REQUEST['promote_id'])) { if($_REQUEST['promote_id'] == 0){ $gfidlag = true; @@ -110,7 +125,14 @@ class FinancePromoteController extends AdminController "bind_coin_count"=>0, "inside_cash_count"=>0, ); + $promotes = []; + if (count($senddata) > 0) { + $promotes = M('promote', 'tab_')->field(['id', 'account', 'admin_id'])->where(['id' => ['in', array_column($senddata, 'p_id')]])->select(); + } + $promotes = index_by_column('id', $promotes); + $adminUsernames = getAdminUsernameList(array_column($promotes, 'admin_id')); foreach($senddata as $k=>$v){ + $promote = $promotes[$v['p_id']] ?? null; $v['company_belong'] = $v['company_belong'] ?:0; $v['company_belong'] = getCompanyBlong($v['company_belong']); if(empty($v['company_name'])) $v['company_name']= $this->COMPANY_NAME; @@ -119,8 +141,10 @@ class FinancePromoteController extends AdminController if(!array_key_exists('balance_coin_count',$v)) $v['balance_coin_count']=0; if(!array_key_exists('bind_coin_count',$v)) $v['bind_coin_count']=0; if(!array_key_exists('inside_cash_count',$v)) $v['inside_cash_count']=0; - $v['promote_account'] = get_promote_name($v['p_id']); - + $v['promote_account'] = $v['p_id'] == 0 ? '官方渠道' : ($promote ? $promote['account'] : ''); + $v['admin_username'] = $adminUsernames[$promote['admin_id']] ?? '无'; + $v['develop_type_text'] = getCompanyDevelopTypeText($v['develop_type']); + $v['inside_cash_count'] = number_format($v['inside_cash_count'],2,'.',''); $v['allcount'] = number_format($v['cash_count']-0+$v['balance_coin_count']+$v['bind_coin_count'],2,'.',''); $count['cash_count'] += $v['cash_count']; @@ -208,6 +232,13 @@ class FinancePromoteController extends AdminController $map['promote.company_belong'] = $_REQUEST['company_belong']; } + + if (!empty(I('develop_type'))) { + $map['company.develop_type'] = I('develop_type'); + } + if (!empty(I('admin_id'))) { + $map['promote.admin_id'] = I('admin_id'); + } if($type == "spend"){ @@ -222,7 +253,7 @@ class FinancePromoteController extends AdminController SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count, SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as bind_coin_count, IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id, - IFNULL(company_id,0) company_id,company_name,IFNULL(promote.company_belong,0) company_belong"; + IFNULL(company_id,0) company_id,company_name,develop_type,IFNULL(promote.company_belong,0) company_belong"; return M() ->table("tab_spend s use index(promote_time)") ->field($field) @@ -319,8 +350,18 @@ class FinancePromoteController extends AdminController "bind_coin_count"=>0, "inside_cash_count"=>0, ); - foreach($senddata as $k=>$v){ + $promotes = []; + if (count($senddata) > 0) { + $promotes = M('promote', 'tab_')->field(['id', 'account', 'admin_id'])->where(['id' => ['in', array_column($senddata, 'promote_id')]])->select(); + } + $promotes = index_by_column('id', $promotes); + $adminUsernames = getAdminUsernameList(array_column($promotes, 'admin_id')); + + foreach($senddata as $k=>$v){ + $promote = $promotes[$v['promote_id']] ?? null; + $v['admin_username'] = $adminUsernames[$promote['admin_id']] ?? '无'; + $v['develop_type_text'] = getCompanyDevelopTypeText($v['develop_type']); $v['company_belong'] = getCompanyBlong($v['company_belong']); if(empty($v['company_name'])) $v['company_name']= $this->COMPANY_NAME; if(empty($v['promote_account'])) $v['promote_account']= "官方渠道"; @@ -391,7 +432,7 @@ class FinancePromoteController extends AdminController $field= "SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count, SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count, SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as bind_coin_count, - IFNULL(company_id,0) company_id,company_name,promote_id,promote.account promote_account,IFNULL(promote.company_belong,0) company_belong"; + IFNULL(company_id,0) company_id,company_name,promote_id,promote.account promote_account,develop_type,IFNULL(promote.company_belong,0) company_belong"; return M() ->table("tab_spend s use index(promote_time)") ->field($field) @@ -439,6 +480,12 @@ class FinancePromoteController extends AdminController } elseif (isset($_REQUEST['time_end'])) { $map['s.pay_time'] = ['LT', strtotime($_REQUEST['time_end']) + 86399]; } + if (!empty(I('develop_type'))) { + $map['develop_type'] = I('develop_type'); + } + if (!empty(I('admin_id'))) { + $map['admin_id'] = I('admin_id'); + } //获取推广员 $title = ''; @@ -454,13 +501,24 @@ class FinancePromoteController extends AdminController }else { $data =self::gameStatisticsData($map, $row, $p); } + $promotes = []; + if (count($data) > 0) { + $promotes = M('promote', 'tab_')->field(['id', 'account', 'admin_id'])->where(['id' => ['in', array_column($data, 'p_id')]])->select(); + } + $promotes = index_by_column('id', $promotes); + $adminUsernames = getAdminUsernameList(array_column($promotes, 'admin_id')); + foreach ($data as $key => &$value) { + $promote = $promotes[$value['p_id']] ?? null; $value['cash_count']?:0; $value['balance_coin_count']?:0; $value['inside_cash_count']?:0; $value['all_cash_count'] = number_format($value['cash_count'] + $value['balance_coin_count'] + $value['inside_cash_count'],2,'.',''); $value['company_belong'] =getCompanyBlong($value['company_belong']); + $value['admin_username'] = $adminUsernames[$promote['admin_id']] ?? '无'; + $value['develop_type_text'] = getCompanyDevelopTypeText($value['develop_type']); + $value['game_name'] =clearGameNameType($value['game_name']); $value['sdk_version'] =getGameTypeName($value['sdk_version']); @@ -538,6 +596,14 @@ class FinancePromoteController extends AdminController $map['pay_order_number'] = $_REQUEST['pay_order_number']; } + /* if (!empty(I('develop_type'))) { + $map['company.develop_type'] = I('develop_type'); + } + + if (!empty(I('admin_id'))) { + $map['market_admin_id'] = I('admin_id'); + } */ + if (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type']) || isset($_REQUEST['partner_id'])) { $map["game_id"] = array("in",implode(',', array_column(getGameidByPartnerNameType($_REQUEST['partner_id'],$_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) ); } @@ -650,7 +716,7 @@ class FinancePromoteController extends AdminController SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count, SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as inside_cash_count, IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id, - IFNULL(company_name,'{$this->COMPANY_NAME}') company_name,IFNULL(promote.company_belong,0) company_belong") + IFNULL(company_name,'{$this->COMPANY_NAME}') company_name,develop_type,IFNULL(promote.company_belong,0) company_belong") ->join('LEFT JOIN tab_game as g ON s.game_id=g.id') ->join("tab_promote promote ON s.promote_id = promote.id","left") ->join("tab_promote_company company ON promote.company_id = company.id","left") @@ -678,7 +744,9 @@ class FinancePromoteController extends AdminController SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as inside_cash_count"); if ($join) { $query = $query->join('LEFT JOIN tab_game as g ON s.game_id=g.id') - ->join('LEFT JOIN tab_partner as p ON g.partner_id=p.id'); + ->join('LEFT JOIN tab_partner as p ON g.partner_id=p.id') + ->join("tab_promote promote ON s.promote_id = promote.id","left") + ->join("tab_promote_company company ON promote.company_id = company.id","left"); } $data = $query->where(['s.pay_status' => 1]) ->where($map) @@ -987,6 +1055,20 @@ class FinancePromoteController extends AdminController } $title .= (getCompanyBlong($_REQUEST['company_belong'])."-"); } + + if (!empty(I('develop_type'))) { + $map['company.develop_type'] = I('develop_type'); + if(I('develop_type') != 0){ + $gfflg = false; + } + } + if (!empty(I('admin_id'))) { + $map['promote.admin_id'] = I('admin_id'); + if(I('admin_id') != 0){ + $gfflg = false; + } + } + if (isset($_REQUEST['promote_id'])) { if($ptype){ $pmap = false;//取消非特异推广员检索 diff --git a/Application/Admin/Controller/MemberController.class.php b/Application/Admin/Controller/MemberController.class.php index 6e06bb156..febe047cf 100644 --- a/Application/Admin/Controller/MemberController.class.php +++ b/Application/Admin/Controller/MemberController.class.php @@ -81,13 +81,13 @@ class MemberController extends ThinkController $marketAdminId = I('market_admin_id', 0); if ($marketAdminId) { - $map['tab_user.market_admin_id'] = $marketAdminId; + $map['promote.admin_id'] = $marketAdminId; } $isMarketAdmin = isMarketAdmin(); if ($isMarketAdmin) { $userAuth = session('user_auth'); - $map['tab_user.market_admin_id'] = $userAuth['uid']; + $map['promote.admin_id'] = $userAuth['uid']; } if (isset($_REQUEST['status'])) { @@ -144,8 +144,8 @@ class MemberController extends ThinkController $this->checkListOrCountAuthRestMap($map,["tab_user.id","tab_user.account","tab_user.device_number"]); //计算用户列表 $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,tab_user.market_admin_id") + ->field("tab_user.id,`device_number`,`age_status`,tab_user.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,promote.admin_id") ->where($map) ->group("tab_user.id") ->order($order); @@ -164,6 +164,7 @@ class MemberController extends ThinkController "); } $data->join("tab_user_data AS ss ON ss.user_id = tab_user.id","left"); + $data->join("tab_promote AS promote ON promote.id = tab_user.promote_id", "left"); if(!isset($_REQUEST['export'])){ $data ->page($page, $row); @@ -228,10 +229,10 @@ class MemberController extends ThinkController data2csv($data,"玩家_玩家列表",$field); } - $adminUsernameList = getAdminUsernameList(array_column($data, 'market_admin_id')); + $adminUsernameList = getAdminUsernameList(array_column($data, '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']] ?? '无'; + $value['market_admin_username'] = $adminUsernameList[$value['admin_id']] ?? '无'; } //计算总人数 @@ -258,6 +259,7 @@ class MemberController extends ThinkController "); } $user_count->join("tab_user_data AS ss ON ss.user_id = tab_user.id","left"); + $user_count->join("tab_promote AS promote ON promote.id = tab_user.promote_id", "left"); $userDbRes = $user_count->find(); if($is_repeat){ $user_count =$userDbRes['user_count']; diff --git a/Application/Admin/Controller/SpendController.class.php b/Application/Admin/Controller/SpendController.class.php index b2fe67251..cc1c4a612 100644 --- a/Application/Admin/Controller/SpendController.class.php +++ b/Application/Admin/Controller/SpendController.class.php @@ -136,7 +136,7 @@ class SpendController extends ThinkController $data = D(self::model_name)->lists($_GET["p"], $map, $order); - $adminUsernameList = getAdminUsernameList(array_column($data, 'market_admin_id')); + $adminUsernameList = getAdminUsernameList(array_column($data['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']] ?? '无'; diff --git a/Application/Admin/Controller/UserController.class.php b/Application/Admin/Controller/UserController.class.php index 45dc6352e..d803f2324 100644 --- a/Application/Admin/Controller/UserController.class.php +++ b/Application/Admin/Controller/UserController.class.php @@ -666,25 +666,35 @@ class UserController extends AdminController unset($_REQUEST['role_id']); } - $marketAdminId = I('market_admin_id', 0); - if ($marketAdminId) { - $map['market_admin_id'] = $marketAdminId; - } - + $adminId = 0; $isMarketAdmin = isMarketAdmin(); if ($isMarketAdmin) { $userAuth = session('user_auth'); - $map['market_admin_id'] = $userAuth['uid']; + $adminId = $userAuth['uid']; } -// $promoteRoot = getPowerPromoteIds(); -// $data_empower_type = session('user_auth')['data_empower_type']; -// -// if ($promoteRoot) { + $marketAdminId = I('market_admin_id', 0); + if ($adminId == 0) { + $adminId = $marketAdminId > 0 ? $marketAdminId : 0; + } + + if ($adminId) { + $topPromoteIds = M('promote', 'tab_')->where(['admin_id' => $adminId, 'level' => 1])->getField('id', true); + $promoteIds = getPromoteIdsByTopIds($topPromoteIds); + if (count($promoteIds) == 0) { + $promoteIds = [-1]; + } + $map['promote_id'] = ['in', $promoteIds]; + } + + // $promoteRoot = getPowerPromoteIds(); + // $data_empower_type = session('user_auth')['data_empower_type']; + // + // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ -// $map['id'] = array('lt',1); -// } + // $map['id'] = array('lt',1); + // } setPowerPromoteIds($map,'promote_id'); if (isset($_REQUEST['promote_id'])) { @@ -716,10 +726,10 @@ class UserController extends AdminController $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')); + $adminList = getMarketAdminsByPromoteIds(array_column($list, 'promote_id')); foreach ($list as $key=>&$value ) { ($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):''; - $value['market_admin_username'] = $adminUsernameList[$value['market_admin_id']] ?? '无'; + $value['market_admin_username'] = isset($adminList[$value['promote_id']]) && $adminList[$value['promote_id']]['admin'] ? $adminList[$value['promote_id']]['admin']['username'] : '无'; } $this->assign('list', $list); diff --git a/Application/Admin/View/FinancePromote/gameStatistics.html b/Application/Admin/View/FinancePromote/gameStatistics.html index 553f6b7bc..3e142e708 100644 --- a/Application/Admin/View/FinancePromote/gameStatistics.html +++ b/Application/Admin/View/FinancePromote/gameStatistics.html @@ -128,6 +128,23 @@ +