GameLogic.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. * 获取游戏options列表(无权限)
  65. * @return array
  66. */
  67. public function getGameOptionsNoAuth($where)
  68. {
  69. $query = $this->search($where);
  70. $list = $query->select()->toArray();
  71. return $list;
  72. }
  73. /**
  74. * 获取所有的游戏数据
  75. */
  76. public function getAllGameData($where)
  77. {
  78. $auth_game_list = request()->header('auth_game_list');
  79. $query = $this->search($where);
  80. if(!empty($auth_game_list)) {
  81. $authGameList = explode(',', $auth_game_list);
  82. $query->where('id', 'in', $authGameList);
  83. }
  84. $query->where('status', 1);
  85. $query->order('sort', 'desc');
  86. $game_list = $this->getList($query);
  87. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  88. $groupedGames = [];
  89. foreach ($game_list as $game) {
  90. $mainId = $game['main_id'];
  91. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  92. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  93. $groupedGames[$mainId]['children'][] = [
  94. 'id' => $game['id'],
  95. 'name' => '['.$game['id'].']'.$game['name']
  96. ];
  97. }
  98. return array_values($groupedGames);
  99. }
  100. /**
  101. * 根据权限获取游戏列表
  102. */
  103. public function getGameListByPermission($where)
  104. {
  105. $auth_game_list = request()->header('auth_game_list');
  106. $query = $this->search($where);
  107. if(!empty($auth_game_list)) {
  108. $authGameList = explode(',', $auth_game_list);
  109. $query->where('id', 'in', $authGameList);
  110. }
  111. $query->where('status', 1);
  112. $query->order('sort', 'desc');
  113. return $query->select()->toArray();
  114. }
  115. /**
  116. * 根据权限获取游戏列表树形(无权限)
  117. */
  118. public function getGameListTreeNoAuth($where)
  119. {
  120. $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
  121. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  122. $groupedGames = [];
  123. foreach ($game_list as $game) {
  124. $mainId = $game['main_id'];
  125. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  126. $groupedGames[$mainId]['disabled'] = ($where['single'] ?? false);
  127. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  128. $groupedGames[$mainId]['children'][] = [
  129. 'id' => $game['id'],
  130. 'name' => '['.$game['id'].']'.$game['name']
  131. ];
  132. }
  133. return array_values($groupedGames);
  134. }
  135. /**
  136. * 根据权限获取游戏列表树形(有权限)
  137. */
  138. public function getGameListTree($where)
  139. {
  140. $auth_game_list = request()->header('auth_game_list');
  141. $query = $this->search();
  142. if(!empty($auth_game_list)) {
  143. $authGameList = explode(',', $auth_game_list);
  144. $query->where('id', 'in', $authGameList);
  145. }
  146. $query->where('status', 1);
  147. $query->order('sort', 'desc');
  148. $game_list = $query->select()->toArray();
  149. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  150. $groupedGames = [];
  151. foreach ($game_list as $game) {
  152. $mainId = $game['main_id'];
  153. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  154. $groupedGames[$mainId]['disabled'] = ($where['single'] ?? false);
  155. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  156. $groupedGames[$mainId]['children'][] = [
  157. 'id' => $game['id'],
  158. 'name' => '['.$game['id'].']'.$game['name']
  159. ];
  160. }
  161. return array_values($groupedGames);
  162. }
  163. /**
  164. * 根据部门ID获取游戏列表
  165. * @param array $where
  166. * @return array
  167. */
  168. public function getGameListByDeptId($dept_id)
  169. {
  170. $game_ids = $this->systemDeptLogic->getGameIdsByDeptId($dept_id);
  171. $game_list = [];
  172. if($game_ids==='*'){
  173. $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
  174. }else{
  175. $game_list = $this->model->where('id', 'in', $game_ids)->where('status', 1)->order('sort', 'desc')->select()->toArray();
  176. }
  177. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  178. $groupedGames = [];
  179. foreach ($game_list as $game) {
  180. $mainId = $game['main_id'];
  181. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  182. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  183. $groupedGames[$mainId]['children'][] = [
  184. 'id' => $game['id'],
  185. 'name' => '['.$game['id'].']'.$game['name']
  186. ];
  187. }
  188. return array_values($groupedGames);
  189. }
  190. /**
  191. * 设置部门游戏权限
  192. * @param array $where
  193. * @param array $game_list
  194. * @return void
  195. */
  196. public function setGameListByDeptId($dept_id, $game_list)
  197. {
  198. $this->systemDeptLogic->setGameListByDeptId($dept_id, $game_list);
  199. }
  200. }