| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace app\v1\logic\center;
- use plugin\saiadmin\basic\BaseLogic;
- use app\v1\model\center\GameGroup;
- use support\think\Db;
- /**
- * 游戏分组逻辑层
- */
- class GameGroupLogic extends BaseLogic
- {
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->model = new GameGroup();
- }
-
- /**
- * 读取数据
- * @param $id
- * @return mixed
- */
- public function read($id): mixed
- {
- $data = $this->model->where('id', $id)->find();
- $gameIds = explode(',', $data['game_list']);
- $gameList = Db::connect('db_center')->table('pf_game')->where("id", 'in', $gameIds)->column('name', 'id');
- foreach ($gameList as $id => &$name) {
- $name = '[' . $id . ']' . $name;
- }
- $data['game_list_str'] = $gameList;
- return $data;
- }
- /**
- * 给游戏分组用的游戏列表,主要作用,返回可选或者可编辑的游戏列表
- * $where['game_group_id]
- */
- public function getGameListOptionsByGroup($where): array
- {
- // Todo 获取非自己的已选中
- $gameGroupId = $where['game_group_id'];
- $data = $this->model->where('id', '<>', $gameGroupId)->column("game_list");
- $gameIdList = [];
- foreach ($data as $gameIds) {
- $gameIds = explode(',', $gameIds);
- $gameIdList = array_merge($gameIdList, $gameIds);
- }
- // Todo 获取游戏分组
- $groupWhere = [
- 'status'=>1
- ];
- if (!empty($gameIdList)) {
- $groupWhere[] = [ 'id', 'notin', implode(',', $gameIdList)];
- }
- // 平台游戏
- $pfCame = Db::connect('db_center')->table('pf_game')->where($groupWhere)->select()->toArray();
- return (new GameLogic())->gameMainTree($pfCame);
- }
- /**
- * 获取游戏根据部门ID, 返回根据分组后的游戏列表
- */
- public function getGameListOptionsByDeptId($where): array
- {
- $deptId = $where['dept_id'];
- // 1. 根据部门ID获取游戏列表
- $deptGameList = Db::connect('db_system')
- ->table('sa_system_dept')
- ->field('game_list')
- ->where('id', $deptId)
- ->select()->toArray();
- $deptGameList = $deptGameList[0]['game_list'];
- // 2. 所有游戏信息列表
- $pfGameList = Db::connect('db_center')
- ->table('pf_game')
- ->field('id,name')
- ->select()->toArray();
- $pfGameList = array_column($pfGameList, null, 'id');
-
- // 3. 分组列表
- $groupList = Db::connect('db_center')
- ->table('game_group')
- ->select()->toArray();
-
- if(!empty($deptGameList)){
- // 返回分组所有游戏
- if($deptGameList == '*'){
- foreach($groupList as &$group){
- $group['id'] = 'group_'.$group['id'];
- $gameList = explode(',', $group['game_list']);
- foreach($gameList as $gameId){
- $group['children'][] = [
- 'id' => $pfGameList[$gameId]['id'],
- 'name' => '['.$pfGameList[$gameId]['id'].']'.$pfGameList[$gameId]['name']
- ];
- }
- }
- $gameList = $groupList;
- }else{
- // 根据权限 4,5,7
- // $deptGameList = 4,5,7
- // $group['game_list'] 取交集
- $deptGameList = explode(',', $deptGameList);
- foreach($groupList as &$group){
- $group['id'] = 'group_'.$group['id'];
- $gameList = explode(',', $group['game_list']);
- $group['game_list'] = array_intersect($deptGameList, $gameList);
- foreach($group['game_list'] as $gameId){
- $group['children'][] = [
- 'id' => $pfGameList[$gameId]['id'],
- 'name' => '['.$pfGameList[$gameId]['id'].']'.$pfGameList[$gameId]['name']
- ];
- }
-
- }
- $groupList = array_filter($groupList, function($group){
- return !empty($group['game_list']);
- });
-
- $gameList = $groupList;
- }
-
- }else{
- $gameList = [];
- }
-
- return $gameList;
- }
- }
|