diff --git a/Application/Admin/Controller/PromoteCompanyController.class.php b/Application/Admin/Controller/PromoteCompanyController.class.php index abbc73e48..fb6f58fd9 100644 --- a/Application/Admin/Controller/PromoteCompanyController.class.php +++ b/Application/Admin/Controller/PromoteCompanyController.class.php @@ -1031,36 +1031,45 @@ 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){ - $oids = explode(',', $old_info['game_ids']); - $nids = explode(',',$game_ids); - $diff_ids = []; - if(count($oids) == 0){ - $is_change_game = false; - }elseif(count($nids) == 0){ - $diff_ids = $oids; + 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{ - foreach ($oids as $k => $v) { - if(!in_array($v,$nids)){ - $diff_ids[] = $v; + $oids = explode(',', $old_info['game_ids']); + $nids = explode(',',$game_ids); + $diff_ids = []; + if(empty($old_info['game_ids'])){ + $is_change_game = false; + }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; + } } } - } - if(count($diff_ids) > 0){ - $is_change_game = true; - $diff_ids = $this->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) { - $temp_ids = explode(',', $v['game_ids']); - $v['game_ids'] = implode(',', array_diff($temp_ids, $diff_ids)); - $Promote->save($v); + if(count($diff_ids) > 0){ + $diff_ids = D("Game")->changeRelationGameidToGameid($diff_ids,true); + } + if($is_change_game){ + $dbres = $Promote->field("id,game_ids")->where("company_id = '{$company_id}'")->select(); + foreach ($dbres as $k=>&$v) { + $temp_ids = explode(',', $v['game_ids']); + $v['game_ids'] = implode(',', array_diff($temp_ids, $diff_ids)); + $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,37 +1358,14 @@ 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){ + //判断公司是否能被删除 + protected function promoteCompanyIsCanDel($company_id){ $r = M("Promote","tab_")->where("company_id={$company_id}")->count(); if($r > 0){ return false; }else{ return true; } - - } - - + } } diff --git a/Application/Admin/Model/GameModel.class.php b/Application/Admin/Model/GameModel.class.php index 797ef88dd..e95fb98aa 100644 --- a/Application/Admin/Model/GameModel.class.php +++ b/Application/Admin/Model/GameModel.class.php @@ -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')); + } + } }