GameLogic.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: your name
  6. // +----------------------------------------------------------------------
  7. namespace app\v1\logic\center;
  8. use plugin\saiadmin\basic\BaseLogic;
  9. use app\v1\model\center\Game;
  10. use plugin\saiadmin\app\logic\system\SystemDeptLogic;
  11. /**
  12. * 游戏列表逻辑层
  13. */
  14. class GameLogic extends BaseLogic
  15. {
  16. protected $gameMainLogic;
  17. protected $systemDeptLogic;
  18. /**
  19. * 构造函数
  20. */
  21. public function __construct()
  22. {
  23. $this->model = new Game();
  24. $this->gameMainLogic = new GameMainLogic();
  25. $this->systemDeptLogic = new SystemDeptLogic();
  26. }
  27. /**
  28. * 获取游戏列表
  29. * @param array $where
  30. * @return array
  31. */
  32. public function getIndex($where)
  33. {
  34. $auth_game_list = request()->header('auth_game_list');
  35. $query = $this->search($where);
  36. if(!empty($auth_game_list)) {
  37. $authGameList = explode(',', $auth_game_list);
  38. $query->where('id', 'in', $authGameList);
  39. }
  40. $query->order('sort', 'desc');
  41. $data = $this->getList($query);
  42. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  43. foreach ($data['data'] as $key => $value) {
  44. $data['data'][$key]['main_game_name'] = $mainGameMap[$value['main_id']] ?? '';
  45. }
  46. return $data;
  47. }
  48. /**
  49. * 获取游戏options列表
  50. * @return array
  51. */
  52. public function getGameOptions($where)
  53. {
  54. $auth_game_list = request()->header('auth_game_list');
  55. $query = $this->search($where);
  56. if(!empty($auth_game_list)) {
  57. $authGameList = explode(',', $auth_game_list);
  58. $query->where('id', 'in', $authGameList);
  59. }
  60. $list = $query->select()->toArray();
  61. return $list;
  62. }
  63. /**
  64. * 获取所有的游戏数据
  65. */
  66. public function getAllGameData($where)
  67. {
  68. $auth_game_list = request()->header('auth_game_list');
  69. $query = $this->search($where);
  70. if(!empty($auth_game_list)) {
  71. $authGameList = explode(',', $auth_game_list);
  72. $query->where('id', 'in', $authGameList);
  73. }
  74. $query->where('status', 1);
  75. $query->order('sort', 'desc');
  76. $game_list = $this->getList($query);
  77. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  78. $groupedGames = [];
  79. foreach ($game_list as $game) {
  80. $mainId = $game['main_id'];
  81. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  82. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  83. $groupedGames[$mainId]['children'][] = [
  84. 'id' => $game['id'],
  85. 'name' => '【'.$game['id'].'】'.$game['name']
  86. ];
  87. }
  88. return array_values($groupedGames);
  89. }
  90. /**
  91. * 根据权限获取游戏列表
  92. */
  93. public function getGameListByPermission($where)
  94. {
  95. $auth_game_list = request()->header('auth_game_list');
  96. $query = $this->search($where);
  97. if(!empty($auth_game_list)) {
  98. $authGameList = explode(',', $auth_game_list);
  99. $query->where('id', 'in', $authGameList);
  100. }
  101. $query->where('status', 1);
  102. $query->order('sort', 'desc');
  103. return $query->select()->toArray();
  104. }
  105. /**
  106. * 根据部门ID获取游戏列表
  107. * @param array $where
  108. * @return array
  109. */
  110. public function getGameListByDeptId($dept_id)
  111. {
  112. $game_ids = $this->systemDeptLogic->getGameIdsByDeptId($dept_id);
  113. $game_list = [];
  114. if($game_ids==='*'){
  115. $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
  116. }else{
  117. $game_list = $this->model->where('id', 'in', $game_ids)->where('status', 1)->order('sort', 'desc')->select()->toArray();
  118. }
  119. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  120. $groupedGames = [];
  121. foreach ($game_list as $game) {
  122. $mainId = $game['main_id'];
  123. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  124. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  125. $groupedGames[$mainId]['children'][] = [
  126. 'id' => $game['id'],
  127. 'name' => '【'.$game['id'].'】'.$game['name']
  128. ];
  129. }
  130. return array_values($groupedGames);
  131. }
  132. /**
  133. * 设置部门游戏权限
  134. * @param array $where
  135. * @param array $game_list
  136. * @return void
  137. */
  138. public function setGameListByDeptId($dept_id, $game_list)
  139. {
  140. $this->systemDeptLogic->setGameListByDeptId($dept_id, $game_list);
  141. }
  142. }