diff --git a/Application/Admin/Controller/CompanyGameRatioController.class.php b/Application/Admin/Controller/CompanyGameRatioController.class.php index f5690e000..b34a95943 100644 --- a/Application/Admin/Controller/CompanyGameRatioController.class.php +++ b/Application/Admin/Controller/CompanyGameRatioController.class.php @@ -54,9 +54,9 @@ class CompanyGameRatioController extends AdminController $where['m.relation_game_id'] = $params['relation_game_id']; } $pwhere = false; - if(isset($params['company_belong'])){ - $pwhere = " and p.company_belong = {$params['company_belong']}"; - } +// if(isset($params['company_belong'])){ +// $pwhere = " and p.company_belong = {$params['company_belong']}"; +// } if(isset($params['company_id'])){ $where['m.company_id'] = $params['company_id']; @@ -107,18 +107,29 @@ class CompanyGameRatioController extends AdminController } $gameres = M("game","tab_")->field("tab_game.relation_game_id,tab_game.relation_game_name,IF(tab_game.original_package_name='','未配置',tab_game.original_package_name) original_package_name,tab_game_type.type_name game_type_name")->where($gamewhere)->join("tab_game_type on tab_game.game_type_id = tab_game_type.id")->group("tab_game.relation_game_id")->select(false); + $dbres = M("company_game_ratio","tab_") ->alias('m') - ->field("m.*,g.*,p.company_name,(CASE WHEN p.company_belong is not null THEN p.company_belong ELSE m.company_belong END) company_belong,IFNULL(r.settlement_type,-1) settlement_type,group_concat(turnover_type ORDER BY begin_time ASC SEPARATOR '|') turnover_type,group_concat(ratio ORDER BY begin_time ASC SEPARATOR '|') ratio,group_concat(begin_time ORDER BY begin_time ASC SEPARATOR '|') begin_time,group_concat(end_time ORDER BY begin_time ASC SEPARATOR '|') end_time,group_concat(m.turnover_ratio ORDER BY begin_time ASC SEPARATOR '|') turnover_ratio,group_concat(m.id ORDER BY begin_time ASC SEPARATOR '|') operate_id") + ->field("g.game_type_name,g.original_package_name,g.relation_game_name,m.company_id,p.company_name,(CASE WHEN p.company_belong is not null THEN p.company_belong ELSE m.company_belong END) company_belong,IFNULL(r.settlement_type,-1) settlement_type,group_concat(turnover_type ORDER BY begin_time ASC SEPARATOR '|') turnover_type,group_concat(ratio ORDER BY begin_time ASC SEPARATOR '|') ratio,group_concat(begin_time ORDER BY begin_time ASC SEPARATOR '|') begin_time,group_concat(end_time ORDER BY begin_time ASC SEPARATOR '|') end_time,group_concat(m.turnover_ratio ORDER BY begin_time ASC SEPARATOR '|') turnover_ratio,group_concat(m.id ORDER BY begin_time ASC SEPARATOR '|') operate_id") ->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id") ->join("left JOIN tab_promote_company p ON ( m.company_id = p.id".$pwhere.")") - ->join("left JOIN tab_company_relation r ON (r.first_company_type =2 AND r.first_company_id = m.company_id) OR (r.second_company_type =2 AND r.second_company_id = m.company_id)"); + ->join("left JOIN tab_company_relation r ON (r.first_company_type =2 AND r.first_company_id = m.company_id) OR (r.second_company_type =2 AND r.second_company_id = m.company_id)") + ->where($where)->group("company_id,m.relation_game_id,p.company_belong") + ->select(false); + + if(isset($params['company_belong'])){ + $secwhere['company_belong'] = $params['company_belong']; + } + + $dbres = M()->table("({$dbres})a") + ->where("company_id = '0' or company_name is not null") + ->where($secwhere); if(isset($params['export'])){ - $dbres = $dbres->where($where)->group("company_id,m.relation_game_id,m.company_belong")->select(); + $dbres = $dbres->select(); }else{ - $dbres = $dbres->where($where)->page($page, $row)->group("company_id,m.relation_game_id,m.company_belong")->select(); + $dbres = $dbres->page($page, $row)->select(); } - +// dump($dbres);die(); foreach($dbres as $k=>&$v){ $begin_time = explode('|',$v['begin_time']); @@ -182,13 +193,20 @@ class CompanyGameRatioController extends AdminController exit(); } - $count = M("company_game_ratio","tab_")->alias('m')->field("m.id") + $count = M("company_game_ratio","tab_")->alias('m')->field("m.company_id,p.company_name,m.id,p.company_belong,m.relation_game_id") ->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id") - ->join("JOIN tab_promote_company p ON ( m.company_id = p.id".$pwhere.")") + ->join("left JOIN tab_promote_company p ON ( m.company_id = p.id".$pwhere.")") ->where($where) ->group("company_id,m.relation_game_id,m.company_belong") ->select(false); + $count = M()->table("({$count})a") + ->where("company_id = '0' or company_name is not null") + ->where($secwhere) + ->group("company_id,relation_game_id,company_belong") + ->select(false); +// dump($count);die(); + $count = M()->table("({$count})a")->count(); $page = set_pagination($count, $row,$params); @@ -221,10 +239,10 @@ class CompanyGameRatioController extends AdminController $where['m.status'] = $params['status']; } - $pwhere = false; - if(isset($params['company_belong'])){ - $pwhere = " and p.company_belong = {$params['company_belong']}"; - } +// $pwhere = false; +// if(isset($params['company_belong'])){ +// $pwhere = " and p.company_belong = {$params['company_belong']}"; +// } if(isset($params['company_id'])){ $where['m.company_id'] = $params['company_id']; @@ -250,7 +268,7 @@ class CompanyGameRatioController extends AdminController if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { $time_start = strtotime($_REQUEST['time_start']); $time_end = strtotime($_REQUEST['time_end'])+ 86399; - $where["_string"] = "(begin_time BETWEEN {$time_start} AND {$time_end}) OR (end_time BETWEEN {$time_start} AND {$time_end}) OR (begin_time <= {$time_end} AND end_time >= {$time_end}) OR (begin_time >0 AND end_time = 0)"; + $where["_string"] = "(begin_time BETWEEN {$time_start} AND {$time_end}) OR (end_time BETWEEN {$time_start} AND {$time_end}) OR (begin_time <= {$time_end} AND end_time >= {$time_end}) OR (begin_time <{$time_start} AND (end_time >{$time_end} or end_time = 0))"; } elseif (isset($_REQUEST['time_start'])) { $time_start = strtotime($_REQUEST['time_start']); $where["_string"] = "end_time >= {$time_start} OR end_time = 0"; @@ -264,12 +282,22 @@ class CompanyGameRatioController extends AdminController $gameres = M("game","tab_")->field("tab_game.relation_game_id,tab_game.relation_game_name,IF(tab_game.original_package_name='','未配置',tab_game.original_package_name) original_package_name,tab_game_type.type_name game_type_name")->where($gamewhere)->join("tab_game_type on tab_game.game_type_id = tab_game_type.id")->group("tab_game.relation_game_id")->select(false); $dbres = M("company_game_ratio_log","tab_") ->alias('m') - ->field("m.*,g.*,p.company_name,(CASE WHEN p.company_belong is not null THEN p.company_belong ELSE m.company_belong END) company_belong,IFNULL(r.settlement_type,0) settlement_type") + ->field("m.id,m.status,g.game_type_name,g.original_package_name,g.relation_game_name,m.company_id,p.company_name,m.turnover_type,begin_time,end_time,m.turnover_ratio,last_ratio,last_turnover_ratio,m.ratio,verify_log,(CASE WHEN p.company_belong is not null THEN p.company_belong ELSE m.company_belong END) company_belong,IFNULL(r.settlement_type,0) settlement_type") ->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id") - ->join("left JOIN tab_promote_company p ON ( m.company_id = p.id".$pwhere.")") + ->join("left JOIN tab_promote_company p ON ( m.company_id = p.id)") ->join("left JOIN tab_company_relation r ON (r.first_company_type =2 AND r.first_company_id = m.company_id) OR (r.second_company_type =2 AND r.second_company_id = m.company_id)") ->where($where) - ->order("FIELD(m.status,0,1,-1,-2,2),id desc"); + ->order("FIELD(m.status,0,1,-1,-2,2),m.id desc") + ->select(false); + + if(isset($params['company_belong'])){ + $secwhere['company_belong'] = $params['company_belong']; + } + + $dbres = M()->table("({$dbres})a") + ->where("company_id = '0' or company_name is not null") + ->where($secwhere); + if(isset($params['export'])){ $dbres = $dbres->select(); }else{ @@ -378,10 +406,32 @@ class CompanyGameRatioController extends AdminController )); } - $count =M("company_game_ratio_log","tab_")->alias('m')->field("count(m.id) count") - ->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id") - ->join("JOIN tab_promote_company p ON ( m.company_id = p.id".$pwhere.")") - ->where($where)->find()['count']; +// $count =M("company_game_ratio_log","tab_")->alias('m')->field("m.id,p.company_belong,m.company_id,p.company_name") +// ->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id") +// ->join("left JOIN tab_promote_company p ON ( m.company_id = p.id)") +// ->where($where) +// ->select(false); + + $count = M("company_game_ratio_log","tab_") + ->alias('m') + ->field("m.id,m.company_id,p.company_name,m.turnover_type,(CASE WHEN p.company_belong is not null THEN p.company_belong ELSE m.company_belong END) company_belong") + ->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id") + ->join("left JOIN tab_promote_company p ON ( m.company_id = p.id)") + ->join("left JOIN tab_company_relation r ON (r.first_company_type =2 AND r.first_company_id = m.company_id) OR (r.second_company_type =2 AND r.second_company_id = m.company_id)") + ->where($where) + ->order("FIELD(m.status,0,1,-1,-2,2),m.id desc") + ->select(false); + + if(isset($params['company_belong'])){ + $secwhere['company_belong'] = $params['company_belong']; + } +// die($count); + $count = M()->table("({$count})a") + ->field("count(id) count") + ->where("company_id = '0' or company_name is not null") + ->where($secwhere) + ->find()['count']; + $this->assign('data', $dbres); $page = set_pagination($count, $row,$params); if($page) { @@ -621,7 +671,11 @@ class CompanyGameRatioController extends AdminController if (!isset($params['ratio']) || $params['ratio'] === '') { $this->error('默认分成比例不能为空'); } - $save['company_belong'] = $params['company_belong'] ?? 0; + + if(!$params['company_id']) { + $save['company_belong'] = $params['company_belong'] ?? 0; + } + $save['turnover_ratio'] = $this->setTurnoverRatio($params); $save['ratio'] = $params['ratio'] ?? 0; $save['relation_game_id'] = $params['relation_game_id'] ?? 0; diff --git a/Application/Admin/Controller/PromoteCompanyController.class.php b/Application/Admin/Controller/PromoteCompanyController.class.php index 8b5c05f69..bba334868 100644 --- a/Application/Admin/Controller/PromoteCompanyController.class.php +++ b/Application/Admin/Controller/PromoteCompanyController.class.php @@ -1369,7 +1369,7 @@ class PromoteCompanyController extends ThinkController foreach ($cgr_res as $k => $v) { $t_gid = $v['relation_game_id']; unset($game_arr[$t_gid]); - $senddata[$t_gid]['ratio_data'][$v['begin_time']] = ["turnover_ratio"=>$v['turnover_ratio'],"ratio"=>!$is_inside?$v['ratio']:0,"relation_game_id"=>$v['relation_game_id'],'time'=>($k == 0&&($v['begin_time']strtotime($_REQUEST['endtime']))?date("Y.m.d",$v['end_time']):date("Y.m.d",strtotime($_REQUEST['endtime'])))]; + $senddata[$t_gid]['ratio_data'][$v['begin_time']] = ["turnover_ratio"=>$v['turnover_ratio'],"ratio"=>!$is_inside?$v['ratio']:0,"relation_game_id"=>$v['relation_game_id'],'time'=>(($v['begin_time']strtotime($_REQUEST['endtime']))?date("Y.m.d",$v['end_time']):date("Y.m.d",strtotime($_REQUEST['endtime'])))]; $senddata[$t_gid] += $game[$t_gid]; $this->setPromoteRadio($senddata[$t_gid]['ratio_data'][$v['begin_time']],$is_inside); @@ -1419,7 +1419,7 @@ class PromoteCompanyController extends ThinkController $t_gid = $v['relation_game_id']; unset($game_arr[$t_gid]); - $senddata[$t_gid]['ratio_data'][$v['begin_time']] = ["turnover_ratio"=>$v['turnover_ratio'],"ratio"=>!$is_inside?$v['ratio']:0,"relation_game_id"=>$v['relation_game_id'],'time'=>($k == 0&&($v['begin_time']strtotime($_REQUEST['endtime']))?date("Y.m.d",$v['end_time']):date("Y.m.d",strtotime($_REQUEST['endtime'])))]; + $senddata[$t_gid]['ratio_data'][$v['begin_time']] = ["turnover_ratio"=>$v['turnover_ratio'],"ratio"=>!$is_inside?$v['ratio']:0,"relation_game_id"=>$v['relation_game_id'],'time'=>(($v['begin_time']strtotime($_REQUEST['endtime']))?date("Y.m.d",$v['end_time']):date("Y.m.d",strtotime($_REQUEST['endtime'])))]; $senddata[$t_gid] += $game[$t_gid]; $this->setPromoteRadio($senddata[$t_gid]['ratio_data'][$v['begin_time']],$is_inside);