diff --git a/Application/Admin/Controller/FinancePromoteController.class.php b/Application/Admin/Controller/FinancePromoteController.class.php index 24a0b62f3..cefe9beec 100644 --- a/Application/Admin/Controller/FinancePromoteController.class.php +++ b/Application/Admin/Controller/FinancePromoteController.class.php @@ -59,7 +59,6 @@ class FinancePromoteController extends AdminController $senddata[$v['p_id']] = $v; }; } - //官方渠道单算 //判断公司 $gfidlag = true; @@ -81,11 +80,6 @@ class FinancePromoteController extends AdminController $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; @@ -241,11 +235,12 @@ class FinancePromoteController extends AdminController if (!empty(I('develop_type'))) { $map['company.develop_type'] = I('develop_type'); } + + $havingPids = []; if (!empty(I('admin_id'))) { - $map['promote.admin_id'] = I('admin_id'); + $havingPids = M('promote', 'tab_')->where(['admin_id' => I('admin_id')])->getField('id', true); + $havingPids = count($havingPids) > 0 ? $havingPids : [0]; } - - if($type == "spend"){ if (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type'])) { $map["s.game_id"] = array("in",implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) ); @@ -259,30 +254,41 @@ class FinancePromoteController extends AdminController 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,develop_type,IFNULL(promote.company_belong,0) company_belong"; - return M() + $query = M() ->table("tab_spend s use index(promote_time)") ->field($field) ->where($map) ->join("tab_promote promote ON s.promote_id = promote.id","left") ->join("tab_promote_company company ON promote.company_id = company.id","left") - ->group('p_id') - ->select(); + ->group('p_id'); + if (count($havingPids) > 0) { + $query->having('p_id in (' . implode(',', $havingPids) . ')'); + } + return $query->select(); }else{ if($istimeselect){ $map['s.create_time']=$istimeselect; } + $havingPids = []; + if (!empty(I('admin_id'))) { + $havingPids = M('promote', 'tab_')->where(['admin_id' => I('admin_id')])->getField('id', true); + $havingPids = count($havingPids) > 0 ? $havingPids : [0]; + } $map['s.status']=1; $map['s.source_id']=0; $field= "SUM(CASE WHEN s.type = 1 THEN num ELSE 0 END) as pay_amount,SUM(CASE WHEN s.type = 2 THEN num ELSE 0 END) as back_amount,IFNULL(if(substring_index(substring_index(`chain`,'/',2),'/',-1)='', s.promote_id,substring_index(substring_index(`chain`,'/',2),'/',-1)),0) p_id, IFNULL(company_id,0) company_id,company_name,IFNULL(promote.company_belong,0) company_belong"; - return M("promote_coin s","tab_") + $query = M("promote_coin s","tab_") ->field($field) ->where($map) ->join("tab_promote promote ON s.promote_id = promote.id","left") ->join("tab_promote_company company ON promote.company_id = company.id","left") - ->group('p_id') - ->select(); + ->group('p_id'); + if (count($havingPids) > 0) { + $query->having('p_id in (' . implode(',', $havingPids) . ')'); + } + return $query->select(); } } @@ -356,19 +362,17 @@ class FinancePromoteController extends AdminController "inside_cash_count"=>0, ); - $promotes = []; + $marketAdmins = []; if (count($senddata) > 0) { $promoteIds = array_column($senddata, 'promote_id'); if (count($promoteIds)) { - $promotes = M('promote', 'tab_')->field(['id', 'account', 'admin_id'])->where(['id' => ['in', $promoteIds]])->select(); + $marketAdmins = getMarketAdminsByPromoteIds($promoteIds); } } - $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['admin_username'] = isset($marketAdmins[$v['promote_id']]) && $marketAdmins[$v['promote_id']]['admin'] ? $marketAdmins[$v['promote_id']]['admin']['username'] : '无'; $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; @@ -443,14 +447,22 @@ 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(company_id,0) company_id,company_name,promote_id,promote.account promote_account,develop_type,IFNULL(promote.company_belong,0) company_belong"; - return M() + $query = M() ->table("tab_spend s use index(promote_time)") ->field($field) ->where($map) ->join("tab_promote promote ON s.promote_id = promote.id", "left") ->join("tab_promote_company company ON promote.company_id = company.id", "left") - ->group('promote_id') - ->select(); + ->group('promote_id'); + + $havingPids = []; + if (!empty(I('admin_id'))) { + $topIds = M('promote', 'tab_')->where(['admin_id' => I('admin_id')])->getField('id', true); + $havingPids = getPromoteIdsByTopIds($topIds); + $havingPids = count($havingPids) > 0 ? $havingPids : [0]; + $query->having('promote_id in (' . implode(',', $havingPids) . ')'); + } + return $query->select(); }else{ if($istimeselect){ $map['s.create_time']=$istimeselect; @@ -459,13 +471,21 @@ class FinancePromoteController extends AdminController $map['s.source_id']=0; $field= "SUM(CASE WHEN s.type = 1 THEN num ELSE 0 END) as pay_amount,SUM(CASE WHEN s.type = 2 THEN num ELSE 0 END) as back_amount, IFNULL(company_id,0) company_id,company_name,promote_id,promote.account promote_account,IFNULL(promote.company_belong,0) company_belong"; - return M("promote_coin s","tab_") + $query = M("promote_coin s","tab_") ->field($field) ->where($map) ->join("tab_promote promote ON s.promote_id = promote.id","left") ->join("tab_promote_company company ON promote.company_id = company.id", "left") - ->group('promote_id') - ->select(); + ->group('promote_id'); + + $havingPids = []; + if (!empty(I('admin_id'))) { + $topIds = M('promote', 'tab_')->where(['admin_id' => I('admin_id')])->getField('id', true); + $havingPids = getPromoteIdsByTopIds($topIds); + $havingPids = count($havingPids) > 0 ? $havingPids : [0]; + $query->having('promote_id in (' . implode(',', $havingPids) . ')'); + } + return $query->select(); } } /** @@ -493,9 +513,6 @@ class FinancePromoteController extends AdminController if (!empty(I('develop_type'))) { $map['develop_type'] = I('develop_type'); } - if (!empty(I('admin_id'))) { - $map['admin_id'] = I('admin_id'); - } //获取推广员 $title = ''; @@ -742,6 +759,12 @@ class FinancePromoteController extends AdminController if ($row != 0) { $query = $query->page($page,$row); } + $havingPids = []; + if (!empty(I('admin_id'))) { + $havingPids = M('promote', 'tab_')->where(['admin_id' => I('admin_id')])->getField('id', true); + $havingPids = count($havingPids) > 0 ? $havingPids : [0]; + $query->having('p_id in (' . implode(',', $havingPids) . ')'); + } $data = $query->select(false); $data = M() ->table("(".$data.") a") @@ -1078,7 +1101,6 @@ class FinancePromoteController extends AdminController } } if (!empty(I('admin_id'))) { - $map['promote.admin_id'] = I('admin_id'); if(I('admin_id') != 0){ $gfflg = false; } diff --git a/Application/Admin/Controller/PromoteCompanyController.class.php b/Application/Admin/Controller/PromoteCompanyController.class.php index 9f434f15b..2080579f4 100644 --- a/Application/Admin/Controller/PromoteCompanyController.class.php +++ b/Application/Admin/Controller/PromoteCompanyController.class.php @@ -340,6 +340,19 @@ class PromoteCompanyController extends ThinkController $savedata = array( "company_belong"=>$save['company_belong'] ); + + // 权限跟随 + $authGroup = M('sys_auth_group')->where(['title'=>'市场总监'])->find(); + $subPromoteIds = M('promote', 'tab_')->where(['level' => 1, 'company_id' => $company_id])->getField('id', true); + $dataPresident = explode(',', $authGroup['data_president']); + M('sys_auth_group')->where(['title'=>'市场总监'])->save(['data_president'=>$info['data_president'].",".$id]); + if ($save['company_belong'] == 0) { + $dataPresident = array_diff($dataPresident, $subPromoteIds); + } elseif ($save['company_belong'] == 1 || $save['company_belong'] == 2) { + $dataPresident = array_unique(array_merge($dataPresident, $subPromoteIds)); + } + M('sys_auth_group')->where(['title'=>'市场总监'])->save(['data_president'=>implode(',', $dataPresident)]); + M("Promote","tab_")->where("company_id = '{$company_id}'")->save($savedata); } addOperationLog(['op_type'=>1,'key'=>$_POST['company_name'],'op_name'=>'编辑推广公司','url'=>U('PromoteCompany/lists'),'menu'=>'推广员-推广员管理-推广公司管理-编辑推广公司']);