GameLogic.php 3.7 KB

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