@ -26,6 +26,17 @@ class CompanyGameRatioController extends AdminController
$this->DBModel = M("company_game_ratio","tab_");
parent::_initialize();
}
public function setCompanyBelong($company_belong = 0) {
if($company_belong == '0') {
return '内团';
} elseif($company_belong == '0') {
return '外团';
} else {
return '外团-分发';
}
}
public function index()
{
$params = I('get.');
@ -103,9 +114,9 @@ class CompanyGameRatioController extends AdminController
->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->where($where)->group("company_id,m.relation_game_id")->select();
$dbres = $dbres->where($where)->group("company_id,m.relation_game_id,m.company_belong ")->select();
}else{
$dbres = $dbres->where($where)->page($page, $row)->group("company_id,m.relation_game_id")->select();
$dbres = $dbres->where($where)->page($page, $row)->group("company_id,m.relation_game_id,m.company_belong ")->select();
}
foreach($dbres as $k=>& $v){
@ -135,7 +146,9 @@ class CompanyGameRatioController extends AdminController
//
// $v["valid"] = "{$v['begin_time']} ~ {$v['end_time']}";
$v['company_belong'] ="下游".getCompanyBlong($v['company_belong']);
// $v['company_belong'] ="下游".getCompanyBlong($v['company_belong']);
$v['company_belong'] ="下游".$this->setCompanyBelong($v['company_belong']);
if (isset($params['export'])) {
$symbol = "\n";
} else {
@ -165,7 +178,7 @@ class CompanyGameRatioController extends AdminController
->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)
->group("company_id,m.relation_game_id")
->group("company_id,m.relation_game_id,m.company_belong ")
->select(false);
$count = M()->table("({$count})a")->count();
@ -243,7 +256,7 @@ 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,p .company_belong,IFNULL(r.settlement_type,0) settlement_type")
->field("m.*,g.*,p.company_name,m .company_belong,IFNULL(r.settlement_type,0) 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)")
@ -271,7 +284,8 @@ class CompanyGameRatioController extends AdminController
}
$v['company_belong'] ="下游".getCompanyBlong($v['company_belong']);
// $v['company_belong'] ="下游".getCompanyBlong($v['company_belong']);
$v['company_belong'] ="下游".$this->setCompanyBelong($v['company_belong']);
$v['verify_log'] = json_decode($v['verify_log'], true);
if (isset($params['export'])) {
$symbol = "\n";
@ -447,6 +461,7 @@ class CompanyGameRatioController extends AdminController
//保存到其他表
//查找是否存在
$ratiov = [
'company_belong'=>$v['company_belong'],
"company_id"=>$v['company_id'],
"relation_game_id"=>$v['relation_game_id'],
"ratio"=>$v['ratio'],
@ -456,7 +471,7 @@ class CompanyGameRatioController extends AdminController
"turnover_type"=>$v['turnover_type'],
];
$this->companyRatioTimeChange($v['company_id'],$v['relation_game_id'],$v['begin_time'],$v['end_time'],$ratiov);
$this->companyRatioTimeChange($v['company_belong'],$v['company_ id'],$v['relation_game_id'],$v['begin_time'],$v['end_time'],$ratiov);
// $has = $company_game_ratio->where("company_id='{$v['company_id']}' and relation_game_id='{$v['relation_game_id']}' and begin_time={$v['begin_time']} and end_time={$v['end_time']}")->find();
// if(isset($has['id'])){
@ -474,29 +489,29 @@ class CompanyGameRatioController extends AdminController
));
}
public function companyRatioTimeChange($company_id = 0, $relation_game_id = 0, $begin_time = 0, $end_time = 0,$ratiov=[]) {
public function companyRatioTimeChange($company_belong = 0,$company_ id = 0, $relation_game_id = 0, $begin_time = 0, $end_time = 0,$ratiov=[]) {
if (!$company_id || !$relation_game_id) {
$this->error("公司与游戏的参数错误.");
}
// dump($end_time);dump($begin_time);die();
$check_data = M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$begin_time,'end_time'=>$end_time])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$begin_time,'end_time'=>$end_time])
->find();
if ($check_data) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$begin_time,'end_time'=>$end_time])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$begin_time,'end_time'=>$end_time])
->save($ratiov);
return;
}
M("company_game_ratio","tab_")
// ->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>['egt',$begin_time],'end_time'=>['elt',$end_time]])
->where("company_id={$company_id} and relation_game_id={$relation_game_id} and begin_time>={$begin_time} and end_time < = {$end_time} and end_time!=0")
->where("company_belong={$company_belong} and company_ id={$company_id} and relation_game_id={$relation_game_id} and begin_time>={$begin_time} and end_time < = {$end_time} and end_time!=0")
->delete();
$data = M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id])
->order("begin_time DESC")
->select();
@ -506,7 +521,7 @@ class CompanyGameRatioController extends AdminController
if (!$end_time) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->delete();
continue;
}
@ -517,18 +532,18 @@ class CompanyGameRatioController extends AdminController
if ($end_time > $value['begin_time'] & & ($end_time < $value['end_time']||$value['end_time']==0)) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['begin_time'=>$end_time+1]);
} else if ($end_time > $value['begin_time'] & & ($end_time >= $value['end_time']& & $value['end_time']!=0)) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['begin_time'=>$begin_time,'end_time'=>$end_time]);
}
} else if ($value['begin_time'] < = $begin_time) {
if (!$end_time& & ($value['end_time']>$begin_time||$value['end_time']==0)) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['end_time'=>$begin_time-1]);
continue;
}else if (!$end_time) {
@ -540,11 +555,11 @@ class CompanyGameRatioController extends AdminController
}
if ($begin_time > $value['begin_time'] & & ($end_time >= $value['end_time'] & & $value['end_time']!=0)) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['end_time'=>$begin_time-1]);
} else if ($begin_time > $value['begin_time'] & & ($end_time < $value['end_time']||$value['end_time']==0)) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['end_time'=>$begin_time-1]);
$dataValue = $value;
$dataValue['begin_time'] = $end_time+1;
@ -553,15 +568,15 @@ class CompanyGameRatioController extends AdminController
} else if ($begin_time == $value['begin_time'] & & ($end_time < $value['end_time']||$value['end_time']==0)) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['begin_time'=>$end_time+1]);
} else if ($end_time == $value['end_time']& & $begin_time>$value['begin_time']) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['end_time'=>$begin_time-1]);
} else if ($end_time == $value['end_time']& & $begin_time == $value['begin_time']) {
M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->where(['company_belong'=>$company_belong,'company_ id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['begin_time'=>$begin_time,'end_time'=>$end_time]);
}
@ -694,6 +709,8 @@ class CompanyGameRatioController extends AdminController
->join("left JOIN tab_promote_company p ON m.company_id = p.id")
->where($map)
->find();
$dbres['company_belong'] ="下游".$this->setCompanyBelong($dbres['company_belong']);
$dbres['turnover_ratio'] = $dbres['turnover_ratio'] ? json_decode($dbres['turnover_ratio'], true) : $dbres['turnover_ratio'];
$dbres['begin_time'] = date("Y-m-d",$dbres['begin_time']);
$dbres['end_time'] = empty($dbres['end_time']) ? '' :date("Y-m-d",$dbres['end_time']);
@ -761,6 +778,7 @@ class CompanyGameRatioController extends AdminController
->join("left JOIN tab_promote_company p ON m.company_id = p.id")
->where($map)
->find();
$dbres['company_belong'] ="下游".$this->setCompanyBelong($dbres['company_belong']);
$dbres['turnover_ratio'] = $dbres['turnover_ratio'] ? json_decode($dbres['turnover_ratio'], true) : $dbres['turnover_ratio'];
$dbres['begin_time'] = date("Y-m-d",$dbres['begin_time']);
$dbres['end_time'] = empty($dbres['end_time']) ? '' :date("Y-m-d",$dbres['end_time']);