| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- <?php
- // +----------------------------------------------------------------------
- // | saiadmin [ saiadmin快速开发框架 ]
- // +----------------------------------------------------------------------
- // | Author: your name
- // +----------------------------------------------------------------------
- namespace app\v1\logic\center;
- use plugin\saiadmin\basic\BaseLogic;
- use app\v1\model\center\Game;
- use plugin\saiadmin\app\logic\system\SystemDeptLogic;
- use support\think\Db;
- /**
- * 游戏列表逻辑层
- */
- class GameLogic extends BaseLogic
- {
- protected $gameMainLogic;
- protected $systemDeptLogic;
- protected $gameGroupLogic;
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->model = new Game();
- $this->gameMainLogic = new GameMainLogic();
- $this->systemDeptLogic = new SystemDeptLogic();
- $this->gameGroupLogic = new GameGroupLogic();
- }
- /**
- * 获取游戏列表
- * @param array $where
- * @return array
- */
- public function getIndex($where)
- {
- $auth_game_list = request()->header('auth_game_list');
- $query = $this->search($where);
- if(!empty($auth_game_list)) {
- $authGameList = explode(',', $auth_game_list);
- $query->where('id', 'in', $authGameList);
- }
- $query->order('sort', 'desc');
- $data = $this->getList($query);
- $mainGameMap = $this->gameMainLogic->getMainGameMap();
- foreach ($data['data'] as $key => $value) {
- $data['data'][$key]['main_game_name'] = $mainGameMap[$value['main_id']] ?? '';
- }
- return $data;
- }
- /**
- * 获取游戏options列表(有权限)
- * @return array
- */
- public function getGameOptions($where)
- {
- $has_package = $where['has_package']??false;
- unset($where['has_package']);
- $auth_game_list = request()->header('auth_game_list');
- $query = $this->search($where);
- if(!empty($auth_game_list)) {
- $authGameList = explode(',', $auth_game_list);
- $query->where('id', 'in', $authGameList);
- }
- $query->where('status', 1);
- $list = $query->select()->toArray();
- // 携带分组信息
- $gameGroupList = Db::connect('db_center')->table('game_group')->where('1=1')->select()->toArray();
- $gameListMap = array_column($list, null, 'id');
- // 按照gameGroupList分组输出,组内携带game_list(如2,3,4),并将gameListMap中的游戏信息塞入分组,树形结构输出
- $result = [];
- foreach ($gameGroupList as $group) {
- $groupGames = [];
- if (!empty($group['game_list'])) {
- $gameIds = explode(',', $group['game_list']);
-
- foreach ($gameIds as $gid) {
- $gid = trim($gid);
- if (isset($gameListMap[$gid])) {
- $gameInfo = $gameListMap[$gid];
- // 兼容输出格式
- $groupGames[] = [
- 'id' => $gameInfo['id'],
- 'name' => $has_package ? $gameInfo['id'].':'.$gameInfo['name'].':'.$gameInfo['package_name'] : '['.$gameInfo['id'].']'.$gameInfo['name'],
- ];
- }
- }
- }
- $result[] = [
- 'id' =>'group_id_'.$group['id'],
- 'name' => $group['name'],
- 'children' => $groupGames
- ];
- }
- return $result;
-
- }
- /**
- * 获取游戏options列表(无权限)
- * @return array
- */
- public function getGameOptionsNoAuth($where)
- {
- $query = $this->search($where);
- $query->where('status', 1);
- $list = $query->select()->toArray();
- // 携带分组信息
- $gameGroupList = Db::connect('db_center')->table('game_group')->where('1=1')->select()->toArray();
- $gameListMap = array_column($list, null, 'id');
- // 按照gameGroupList分组输出,组内携带game_list(如2,3,4),并将gameListMap中的游戏信息塞入分组,树形结构输出
- $result = [];
- foreach ($gameGroupList as $group) {
- $groupGames = [];
- if (!empty($group['game_list'])) {
- $gameIds = explode(',', $group['game_list']);
- foreach ($gameIds as $gid) {
- $gid = trim($gid);
- if (isset($gameListMap[$gid])) {
- $gameInfo = $gameListMap[$gid];
- // 兼容输出格式
- $groupGames[] = [
- 'id' => $gameInfo['id'],
- 'name' =>'['.$gameInfo['id'].']'.$gameInfo['name'],
- ];
- }
- }
- }
- $result[] = [
- 'id' =>'group_id_'.$group['id'],
- 'name' => $group['name'],
-
- 'children' => $groupGames
- ];
- }
- return $result;
- }
-
- /**
- * 获取所有的游戏数据
- */
- public function getAllGameData($where)
- {
- $auth_game_list = request()->header('auth_game_list');
- $query = $this->search($where);
- if(!empty($auth_game_list)) {
- $authGameList = explode(',', $auth_game_list);
- $query->where('id', 'in', $authGameList);
- }
- $query->where('status', 1);
- $query->order('sort', 'desc');
- $gameList = $this->getList($query);
- return $this->gameTree($gameList);
- }
- public function gameTree($gameList)
- {
- $mainGameMap = $this->gameMainLogic->getMainGameMap();
- $groupedGames = [];
- foreach ($gameList as $game) {
- $mainId = $game['main_id'];
- $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
- $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
- $groupedGames[$mainId]['children'][] = [
- 'id' => $game['id'],
- 'name' => '['.$game['id'].']'.$game['name']
- ];
- }
- return array_values($groupedGames);
- }
- /**
- * 根据权限获取游戏列表
- */
- public function getGameListByPermission($where)
- {
- $auth_game_list = request()->header('auth_game_list');
- $query = $this->search($where);
- if(!empty($auth_game_list)) {
- $authGameList = explode(',', $auth_game_list);
- $query->where('id', 'in', $authGameList);
- }
- $query->where('status', 1);
- $query->order('sort', 'desc');
- return $query->select()->toArray();
- }
- /**
- * 根据权限获取游戏列表树形(无权限)
- */
- public function getGameListTreeNoAuth($where)
- {
-
- $pfGame = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
- $mainGameMap = $this->gameMainLogic->getMainGameMap();
- $groupedGames = [];
- foreach ($pfGame as $game) {
- $mainId = $game['main_id'];
- $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
- $groupedGames[$mainId]['disabled'] = ($where['single'] ?? false);
- $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
- $groupedGames[$mainId]['children'][] = [
- 'id' => $game['id'],
- 'name' => '['.$game['id'].']'.$game['name']
- ];
- }
- return array_values($groupedGames);
- }
- /**
- * 根据权限获取游戏列表树形(有权限)
- */
- public function getGameListTree($where)
- {
- $auth_game_list = request()->header('auth_game_list');
- $query = $this->search();
- if(!empty($auth_game_list)) {
- $authGameList = explode(',', $auth_game_list);
- $query->where('id', 'in', $authGameList);
- }
- $query->where('status', 1);
- $query->order('sort', 'desc');
- $gameList = $query->select()->toArray();
- $mainGameMap = $this->gameMainLogic->getMainGameMap();
- $groupedGames = [];
- foreach ($gameList as $game) {
- $mainId = $game['main_id'];
- $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
- $groupedGames[$mainId]['disabled'] = ($where['single'] ?? false);
- $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
- $groupedGames[$mainId]['children'][] = [
- 'id' => $game['id'],
- 'name' => '['.$game['id'].']'.$game['name']
- ];
- }
- return array_values($groupedGames);
- }
- /**
- * 根据部门ID获取游戏列表
- * @param array $where
- * @return array
- */
- public function getGameListByDeptId($dept_id)
-
- {
- $game_ids = $this->systemDeptLogic->getGameIdsByDeptId($dept_id);
- if($game_ids==='*'){
- $gameList = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
- }else{
- $gameList = $this->model->where('id', 'in', $game_ids)->where('status', 1)->order('sort', 'desc')->select()->toArray();
- }
- return $this->gameTree($gameList);
- }
- /**
- * 设置部门游戏权限
- * @param array $where
- * @param array $gameList
- * @return void
- */
- public function setGameListByDeptId($dept_id, $gameList)
- {
- $this->systemDeptLogic->setGameListByDeptId($dept_id, $gameList);
- }
- }
|