GameLogic.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. $query = $this->search($where);
  35. $query->order('sort', 'desc');
  36. $data = $this->getList($query);
  37. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  38. foreach ($data['data'] as $key => $value) {
  39. $data['data'][$key]['main_game_name'] = $mainGameMap[$value['main_id']] ?? '';
  40. }
  41. return $data;
  42. }
  43. /**
  44. * 获取游戏options列表
  45. * @return array
  46. */
  47. public function getGameOptions()
  48. {
  49. $list = $this->model->field('id,name')->where('status', 1)->order('sort', 'desc')->select()->toArray();
  50. $list = array_map(function ($item) {
  51. return [
  52. 'label' => $item['name'],
  53. 'value' => $item['id']
  54. ];
  55. }, $list);
  56. return $list;
  57. }
  58. /**
  59. * 获取所有的游戏数据
  60. */
  61. public function getAllGameData()
  62. {
  63. $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
  64. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  65. $groupedGames = [];
  66. foreach ($game_list as $game) {
  67. $mainId = $game['main_id'];
  68. $groupedGames[$mainId]['id'] = $mainId;
  69. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  70. $groupedGames[$mainId]['children'][] = [
  71. 'id' => $game['id'],
  72. 'name' => $game['name']
  73. ];
  74. }
  75. return array_values($groupedGames);
  76. }
  77. /**
  78. * 根据权限获取游戏列表
  79. */
  80. public function getGameListByPermission()
  81. {
  82. $game_list = $this->getAllGameData();
  83. return $game_list;
  84. }
  85. /**
  86. * 根据部门ID获取游戏列表
  87. * @param array $where
  88. * @return array
  89. */
  90. public function getGameListByDeptId($dept_id)
  91. {
  92. $game_ids = $this->systemDeptLogic->getGameIdsByDeptId($dept_id);
  93. $game_list = [];
  94. if($game_ids==='*'){
  95. $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
  96. }else{
  97. $game_list = $this->model->where('id', 'in', $game_ids)->where('status', 1)->order('sort', 'desc')->select()->toArray();
  98. }
  99. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  100. $groupedGames = [];
  101. foreach ($game_list as $game) {
  102. $mainId = $game['main_id'];
  103. $groupedGames[$mainId]['id'] = $mainId;
  104. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  105. $groupedGames[$mainId]['children'][] = [
  106. 'id' => $game['id'],
  107. 'name' => $game['name']
  108. ];
  109. }
  110. return array_values($groupedGames);
  111. }
  112. /**
  113. * 设置部门游戏权限
  114. * @param array $where
  115. * @param array $game_list
  116. * @return void
  117. */
  118. public function setGameListByDeptId($dept_id, $game_list)
  119. {
  120. $this->systemDeptLogic->setGameListByDeptId($dept_id, $game_list);
  121. }
  122. }