GameGroupLogic.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 plugin\saiadmin\exception\ApiException;
  10. use plugin\saiadmin\utils\Helper;
  11. use app\v1\model\center\GameGroup;
  12. use support\think\Db;
  13. /**
  14. * 游戏分组逻辑层
  15. */
  16. class GameGroupLogic extends BaseLogic
  17. {
  18. private $gameMainLogic;
  19. /**
  20. * 构造函数
  21. */
  22. public function __construct()
  23. {
  24. $this->model = new GameGroup();
  25. $this->gameMainLogic = new GameMainLogic();
  26. }
  27. /**
  28. * 读取数据
  29. * @param $id
  30. * @return mixed
  31. */
  32. public function read($id): mixed
  33. {
  34. $data = $this->model->where('id', $id)->find();
  35. $game_list = explode(',', $data['game_list']);
  36. $allGameList = Db::connect('db_center')->table('pf_game')->field('id,name')->select()->toArray();
  37. $allGameList = array_column($allGameList, 'name', 'id');
  38. $gameList = [];
  39. foreach ($game_list as $game_id) {
  40. $gameList[] = '[' . $game_id . ']' . $allGameList[$game_id] ?? '';
  41. }
  42. $data['game_list_str'] = $gameList;
  43. return $data;
  44. }
  45. /**
  46. * 给游戏分组用的游戏列表
  47. * $where['game_group_id]
  48. */
  49. public function getGameListOptionsByGroup($where)
  50. {
  51. // 获取gameGroupId, 如果存在,则返回的游戏需要加上这个分组的game_list
  52. $gameGroupId = $where['game_group_id'];
  53. // 游戏分组数据
  54. $data = $this->model->where('1=1')->order('sort', 'desc')->order('id', 'desc')->select()->toArray();
  55. // 已经存在分组的game_list
  56. $gameIdList = [];
  57. foreach ($data as $item) {
  58. // 传入的分组,不加入筛选去除筛选,用于编辑回显示
  59. if($item['id']!=$gameGroupId){
  60. $temGameListArray = explode(',', $item['game_list']);
  61. $gameIdList = array_merge($gameIdList, $temGameListArray);
  62. }
  63. }
  64. $groupWhere = [];
  65. $groupWhere[] = ['status', '=', 1];
  66. if (!empty($gameIdList)) {
  67. $groupWhere[] = [ 'id', 'notin', implode(',', $gameIdList)];
  68. }
  69. // 平台游戏
  70. $pfCame = Db::connect('db_center')->table('pf_game')->where($groupWhere)->select()->toArray();
  71. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  72. $groupedGames = [];
  73. foreach ($pfCame as $item) {
  74. $mainId = $item['main_id'];
  75. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  76. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  77. $groupedGames[$mainId]['children'][] = [
  78. 'id' => $item['id'],
  79. 'name' => '['.$item['id'].']'.$item['name']
  80. ];
  81. }
  82. return array_values($groupedGames);
  83. }
  84. }