GameLogic.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * 处理游戏tree数据
  59. * @return array
  60. */
  61. public function getGameTree($game_list)
  62. {
  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. $game_list = array_values($groupedGames);
  75. return $game_list;
  76. }
  77. /**
  78. * 获取所有的游戏数据
  79. */
  80. public function getAllGameData()
  81. {
  82. $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
  83. return $this->getGameTree($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->getGameListByDeptId($dept_id);
  93. if($game_ids==='*'){
  94. $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
  95. }else{
  96. $game_list = $this->model->where('id', 'in', $game_ids)->where('status', 1)->order('sort', 'desc')->select()->toArray();
  97. }
  98. return $game_list;
  99. }
  100. /**
  101. * 设置部门游戏权限
  102. * @param array $where
  103. * @param array $game_list
  104. * @return void
  105. */
  106. public function setGameListByDeptId($dept_id, $game_list)
  107. {
  108. $this->systemDeptLogic->setGameListByDeptId($dept_id, $game_list);
  109. }
  110. }