@ -14,6 +14,12 @@ class CompanyGameRatioController extends AdminController
"1"=>"市场部通过",
"2"=>"管理员通过"
];
public $SettlementType=[
"-1"=>"未设定",
"0"=>"无",
"1"=>"周结",
"2"=>"月结"
];
public function _initialize()
{
$this->admininfo = $_SESSION['onethink_admin']['user_auth'];
@ -36,23 +42,56 @@ class CompanyGameRatioController extends AdminController
$gamewhere['relation_game_id'] = $params['relation_game_id'];
$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_id'])){
$where['m.company_id'] = $params['company_id'];
}
// $this->checkListOrCountAuthRestMap($where);
if(isset($params['game_type'])){
$gamewhere['game_type_id'] = $params['game_type'];
}
if(isset($params['settlement_type'])){
$companyid = $this->returnSettlementTypeCompanyid($params['settlement_type']);
if(empty($companyid)){
$where['_string'] = "m.company_id = -1";
}else{
if($params['settlement_type'] != -1){
$where['_string'] = "m.company_id in ({$companyid})";
}else{
$where['_string'] = "m.company_id NOT IN ({$companyid})";
}
}
}
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})";
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$where["_string"] = "end_time >= {$time_start} OR end_time = 0";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$where["_string"] = "begin_time < = {$time_end}";
}
$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,p.company_belong,IFNULL(r.settlement_type,0) settlement_type")
->join("left 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);
->field("m.*,g.*,p.company_name,p.company_belong,IFNULL(r.settlement_type,-1) settlement_type")
->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_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)");
if(isset($params['export'])){
$dbres = $dbres->select();
$dbres = $dbres->where($where)-> select();
}else{
$dbres = $dbres->page($page, $row)->select();
$dbres = $dbres->where($where)-> page($page, $row)->select();
}
foreach($dbres as $k=>& $v){
$v['begin_time'] = date("Y-m-d",$v['begin_time']);
@ -66,11 +105,9 @@ class CompanyGameRatioController extends AdminController
} else {
$symbol = "< br > ";
}
if($v['settlement_type'] == 0){
$v['settlement_type'] = '--';
}else{
$v['settlement_type'] = $v['settlement_type']== 1 ? "周结" : '月结';
}
$v['settlement_type'] = $this->SettlementType[$v['settlement_type']];
//新
$thisTurnoverRatios = $v['turnover_ratio'] ? json_decode($v['turnover_ratio'], true) : [];
$thisRatioDtl = "默认:{$v['ratio']}%";
@ -101,7 +138,10 @@ class CompanyGameRatioController extends AdminController
));
}
$count = M("company_game_ratio","tab_")->alias('m')->field("count(id) count")->where($where)->find()['count'];
$count = M("company_game_ratio","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'];
$this->assign('data', $dbres);
$page = set_pagination($count, $row);
if($page) {
@ -110,6 +150,7 @@ class CompanyGameRatioController extends AdminController
$this->assign("companyList",D("PromoteCompany")->getList());
$this->assign("gameList",D("Game")->getRelationGameLits());
$this->assign("SettlementType",$this->SettlementType);
$this->display();
}
@ -129,20 +170,56 @@ class CompanyGameRatioController extends AdminController
$gamewhere['relation_game_id'] = $params['relation_game_id'];
$where['m.relation_game_id'] = $params['relation_game_id'];
}
if(isset($params['status'])){
$where['m.status'] = $params['status'];
}
$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'];
}
if(isset($params['status'])){
$where['m.status'] = $params['status'];
if(isset($params['game_type'])){
$gamewhere['game_type_id'] = $params['game_type'];
}
if(isset($params['settlement_type'])){
$companyid = $this->returnSettlementTypeCompanyid($params['settlement_type']);
if(empty($companyid)){
$where['_string'] = "m.company_id = -1";
}else{
if($params['settlement_type'] != -1){
$where['_string'] = "m.company_id in ({$companyid})";
}else{
$where['_string'] = "m.company_id NOT IN ({$companyid})";
}
}
}
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})";
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$where["_string"] = "end_time >= {$time_start} OR end_time = 0";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$where["_string"] = "begin_time < = {$time_end}";
}
//TODO:未计算公司类型
// $this->checkListOrCountAuthRestMap($where);
$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,p.company_belong,IFNULL(r.settlement_type,0) settlement_type")
->join("left 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("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_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");
@ -152,11 +229,7 @@ class CompanyGameRatioController extends AdminController
$dbres = $dbres->page($page, $row)->select();
}
foreach($dbres as $k=>& $v){
if($v['settlement_type'] == 0){
$v['settlement_type'] = '--';
}else{
$v['settlement_type'] = $v['settlement_type']== 1 ? "周结" : '月结';
}
$v['settlement_type'] = $this->SettlementType[$v['settlement_type']];
$v['begin_time'] = date("Y-m-d",$v['begin_time']);
$v['end_time'] = $v['end_time'] ? date('Y-m-d', $v['end_time']) : '永久';
@ -239,7 +312,10 @@ class CompanyGameRatioController extends AdminController
));
}
$count = M("company_game_ratio_log","tab_")->alias('m')->field("count(id) count")->where($where)->find()['count'];
$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'];
$this->assign('data', $dbres);
$page = set_pagination($count, $row);
if($page) {
@ -251,6 +327,7 @@ class CompanyGameRatioController extends AdminController
$this->assign("companyList",D("PromoteCompany")->getList());
$this->assign("gameList",D("Game")->getRelationGameLits());
$this->assign("SettlementType",$this->SettlementType);
$this->display();
}
@ -646,6 +723,31 @@ class CompanyGameRatioController extends AdminController
$data =json_encode(['msg'=>$data,"code"=>4000],JSON_UNESCAPED_UNICODE);
exit($data);
}
protected function returnSettlementTypeCompanyid($st)
{
if($st != -1){
$setwhere = [
"settlement_type"=>$st,
"_string"=>"first_company_type=2 OR second_company_type=2"
];
}else{
$setwhere = [
"_string"=>"first_company_type=2 OR second_company_type=2"
];
}
$scompany_id = M("company_relation","tab_")->field("first_company_type,second_company_type,first_company_id,second_company_id")->where($setwhere)->select();
$company_id = [];
foreach($scompany_id as $k=>$v){
if($v['first_company_type'] == 0){
$company_id[] = $v['second_company_id'];
}else{
$company_id[] = $v['first_company_id'];
}
}
unset($scompany_id);
$company_id = implode(",",$company_id);
return $company_id;
}
}