GameLogic.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * 根据部门ID获取游戏列表
  117. * @param array $where
  118. * @return array
  119. */
  120. public function getGameListByDeptId($dept_id)
  121. {
  122. $game_ids = $this->systemDeptLogic->getGameIdsByDeptId($dept_id);
  123. $game_list = [];
  124. if($game_ids==='*'){
  125. $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
  126. }else{
  127. $game_list = $this->model->where('id', 'in', $game_ids)->where('status', 1)->order('sort', 'desc')->select()->toArray();
  128. }
  129. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  130. $groupedGames = [];
  131. foreach ($game_list as $game) {
  132. $mainId = $game['main_id'];
  133. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  134. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  135. $groupedGames[$mainId]['children'][] = [
  136. 'id' => $game['id'],
  137. 'name' => '【'.$game['id'].'】'.$game['name']
  138. ];
  139. }
  140. return array_values($groupedGames);
  141. }
  142. /**
  143. * 设置部门游戏权限
  144. * @param array $where
  145. * @param array $game_list
  146. * @return void
  147. */
  148. public function setGameListByDeptId($dept_id, $game_list)
  149. {
  150. $this->systemDeptLogic->setGameListByDeptId($dept_id, $game_list);
  151. }
  152. }