优化公司控制会长游戏规则

master
chenzhi 4 years ago
parent e8eb963fc1
commit 04ac1da1d7

@ -1031,15 +1031,27 @@ class PromoteCompanyController extends ThinkController
protected function changePromoteGameids($company_id,$game_ids){
$old_info = M("PromoteCompany","tab_")->field("company_belong,develop_type,game_ids")->where("id = {$company_id}")->find();
$is_change_game = false;
$Promote = M("Promote", "tab_");
if($old_info['game_ids'] != $game_ids){
if($old_info['company_belong'] == 1 || $old_info['company_belong'] == 2){
//外团跟随公司
$new_game_ids = D("Game")->changeRelationGameidToGameid($game_ids,true);
$new_game_ids = implode(',',$new_game_ids);
$save = [
"game_ids"=>$new_game_ids
];
$dbres = $Promote->where("company_id = '{$company_id}'")->save($save);
}else{
$oids = explode(',', $old_info['game_ids']);
$nids = explode(',',$game_ids);
$diff_ids = [];
if(count($oids) == 0){
if(empty($old_info['game_ids'])){
$is_change_game = false;
}elseif(count($nids) == 0){
}elseif(empty($game_ids)){
$is_change_game = true;
$diff_ids = $oids;
}else{
$is_change_game = true;
foreach ($oids as $k => $v) {
if(!in_array($v,$nids)){
$diff_ids[] = $v;
@ -1047,11 +1059,8 @@ class PromoteCompanyController extends ThinkController
}
}
if(count($diff_ids) > 0){
$is_change_game = true;
$diff_ids = $this->changeRelationGameidToGameid($diff_ids,true);
$diff_ids = D("Game")->changeRelationGameidToGameid($diff_ids,true);
}
$Promote = M("Promote", "tab_");
if($is_change_game){
$dbres = $Promote->field("id,game_ids")->where("company_id = '{$company_id}'")->select();
foreach ($dbres as $k=>&$v) {
@ -1060,7 +1069,7 @@ class PromoteCompanyController extends ThinkController
$Promote->save($v);
}
}
}
}
}
/**
@ -1269,7 +1278,7 @@ class PromoteCompanyController extends ThinkController
}else{
$v['list'] = [];
$v['row']=0;
$v['game_ids'] = $this->changeGameidToRelationGameid($v['game_ids']);
$v['game_ids'] = D("Game")->changeGameidToRelationGameid($v['game_ids']);
$game_arr = array_flip(explode(",",$v['game_ids']));
foreach($game_arr as $ke=>$va){
if(isset($ratio[$ke])){
@ -1349,27 +1358,7 @@ class PromoteCompanyController extends ThinkController
}
return $gameinfo;
}
//普通游戏id转唯一游戏id
protected function changeGameidToRelationGameid($ids,$type=false)
{
$rid = M('game', 'tab_')->field('relation_game_id')->where(["id"=>["in",$ids]])->group("relation_game_id")->select();
if($type){
return array_column($rid,'relation_game_id');
}else{
return implode(",",array_column($rid,'relation_game_id'));
}
}
//唯一游戏id转普通游戏id
protected function changeRelationGameidToGameid($ids,$type=false)
{
$rid = M('game', 'tab_')->field('id')->where(["relation_game_id"=>["in",$ids]])->select();
if($type){
return array_column($rid,'id');
}else{
return implode(",",array_column($rid,'id'));
}
}
//判断公司是否能被删除
protected function promoteCompanyIsCanDel($company_id){
$r = M("Promote","tab_")->where("company_id={$company_id}")->count();
if($r > 0){
@ -1377,9 +1366,6 @@ class PromoteCompanyController extends ThinkController
}else{
return true;
}
}
}

@ -453,6 +453,39 @@ class GameModel extends Model{
return $this->field($field)->where($where)->group("relation_game_id")->select();
}
/**
* 关联游戏id转普通游戏id
*
* @param [string/array] $ids
* @param boolean $type false:返回数组 true:返回string
* @return void
*/
public function changeRelationGameidToGameid($ids,$type=false)
{
$rid = $this->field('id')->where(["relation_game_id"=>["in",$ids]])->select();
if($type){
return array_column($rid,'id');
}else{
return implode(",",array_column($rid,'id'));
}
}
/**
* 普通游戏id转关联游戏id
*
* @param [string/array] $ids
* @param boolean $type false:返回数组 true:返回string
* @return void
*/
public function changeGameidToRelationGameid($ids,$type=false)
{
$rid = $this->field('relation_game_id')->where(["id"=>["in",$ids]])->group("relation_game_id")->select();
if($type){
return array_column($rid,'relation_game_id');
}else{
return implode(",",array_column($rid,'relation_game_id'));
}
}
}

Loading…
Cancel
Save