GameGroupLogic.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\v1\logic\center;
  3. use plugin\saiadmin\basic\BaseLogic;
  4. use app\v1\model\center\GameGroup;
  5. use support\think\Db;
  6. /**
  7. * 游戏分组逻辑层
  8. */
  9. class GameGroupLogic extends BaseLogic
  10. {
  11. /**
  12. * 构造函数
  13. */
  14. public function __construct()
  15. {
  16. $this->model = new GameGroup();
  17. }
  18. /**
  19. * 读取数据
  20. * @param $id
  21. * @return mixed
  22. */
  23. public function read($id): mixed
  24. {
  25. $data = $this->model->where('id', $id)->find();
  26. $gameIds = explode(',', $data['game_list']);
  27. $gameList = Db::connect('db_center')->table('pf_game')->where("id", $gameIds)->column('name', 'id');
  28. foreach ($gameList as $id => &$name) {
  29. $name = '[' . $id . ']' . $name;
  30. }
  31. $data['game_list_str'] = $gameList;
  32. return $data;
  33. }
  34. /**
  35. * 给游戏分组用的游戏列表,主要作用,返回可选或者可编辑的游戏列表
  36. * $where['game_group_id]
  37. */
  38. public function getGameListOptionsByGroup($where): array
  39. {
  40. // Todo 获取非自己的已选中
  41. $gameGroupId = $where['game_group_id'];
  42. $data = $this->model->where('id', '<>', $gameGroupId)->column("game_list");
  43. $gameIdList = [];
  44. foreach ($data as $gameIds) {
  45. $gameIds = explode(',', $gameIds);
  46. $gameIdList = array_merge($gameIdList, $gameIds);
  47. }
  48. // Todo 获取游戏分组
  49. $groupWhere = [
  50. 'status'=>1
  51. ];
  52. if (!empty($gameIdList)) {
  53. $groupWhere[] = [ 'id', 'notin', implode(',', $gameIdList)];
  54. }
  55. // 平台游戏
  56. $pfCame = Db::connect('db_center')->table('pf_game')->where($groupWhere)->select()->toArray();
  57. return (new GameLogic())->gameMainTree($pfCame);
  58. }
  59. /**
  60. * 获取游戏根据部门ID, 返回根据分组后的游戏列表
  61. */
  62. public function getGameListOptionsByDeptId($where): array
  63. {
  64. $deptId = $where['dept_id'];
  65. // 1. 根据部门ID获取游戏列表
  66. $deptGameList = Db::connect('db_system')
  67. ->table('sa_system_dept')
  68. ->field('game_list')
  69. ->where('id', $deptId)
  70. ->select()->toArray();
  71. $deptGameList = $deptGameList[0]['game_list'];
  72. // 2. 所有游戏信息列表
  73. $pfGameList = Db::connect('db_center')
  74. ->table('pf_game')
  75. ->field('id,name')
  76. ->select()->toArray();
  77. $pfGameList = array_column($pfGameList, null, 'id');
  78. // 3. 分组列表
  79. $groupList = Db::connect('db_center')
  80. ->table('game_group')
  81. ->select()->toArray();
  82. if(!empty($deptGameList)){
  83. // 返回分组所有游戏
  84. if($deptGameList == '*'){
  85. foreach($groupList as &$group){
  86. $group['id'] = 'group_'.$group['id'];
  87. $gameList = explode(',', $group['game_list']);
  88. foreach($gameList as $gameId){
  89. $group['children'][] = [
  90. 'id' => $pfGameList[$gameId]['id'],
  91. 'name' => '['.$pfGameList[$gameId]['id'].']'.$pfGameList[$gameId]['name']
  92. ];
  93. }
  94. }
  95. $gameList = $groupList;
  96. }else{
  97. // 根据权限 4,5,7
  98. // $deptGameList = 4,5,7
  99. // $group['game_list'] 取交集
  100. $deptGameList = explode(',', $deptGameList);
  101. foreach($groupList as &$group){
  102. $group['id'] = 'group_'.$group['id'];
  103. $gameList = explode(',', $group['game_list']);
  104. $group['game_list'] = array_intersect($deptGameList, $gameList);
  105. foreach($group['game_list'] as $gameId){
  106. $group['children'][] = [
  107. 'id' => $pfGameList[$gameId]['id'],
  108. 'name' => '['.$pfGameList[$gameId]['id'].']'.$pfGameList[$gameId]['name']
  109. ];
  110. }
  111. }
  112. $groupList = array_filter($groupList, function($group){
  113. return !empty($group['game_list']);
  114. });
  115. $gameList = $groupList;
  116. }
  117. }else{
  118. $gameList = [];
  119. }
  120. return $gameList;
  121. }
  122. }