GameGroupLogic.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. $gameIds = explode(',', $data['game_list']);
  36. $gameList = Db::connect('db_center')->table('pf_game')->where("id", $gameIds)->column('name', 'id');
  37. foreach ($gameList as $id => &$name) {
  38. $name = '[' . $id . ']' . $name;
  39. }
  40. $data['game_list_str'] = $gameList;
  41. return $data;
  42. }
  43. /**
  44. * 给游戏分组用的游戏列表
  45. * $where['game_group_id]
  46. */
  47. public function getGameListOptionsByGroup($where)
  48. {
  49. // 获取gameGroupId, 如果存在,则返回的游戏需要加上这个分组的game_list
  50. $gameGroupId = $where['game_group_id'];
  51. // 游戏分组数据
  52. $data = $this->model->where('1=1')->order('sort', 'desc')->order('id', 'desc')->select()->toArray();
  53. // 已经存在分组的game_list
  54. $gameIdList = [];
  55. foreach ($data as $item) {
  56. // 传入的分组,不加入筛选去除筛选,用于编辑回显示
  57. if($item['id']!=$gameGroupId){
  58. $temGameListArray = explode(',', $item['game_list']);
  59. $gameIdList = array_merge($gameIdList, $temGameListArray);
  60. }
  61. }
  62. $groupWhere = [];
  63. $groupWhere[] = ['status', '=', 1];
  64. if (!empty($gameIdList)) {
  65. $groupWhere[] = [ 'id', 'notin', implode(',', $gameIdList)];
  66. }
  67. // 平台游戏
  68. $pfCame = Db::connect('db_center')->table('pf_game')->where($groupWhere)->select()->toArray();
  69. $mainGameMap = $this->gameMainLogic->getMainGameMap();
  70. $groupedGames = [];
  71. foreach ($pfCame as $item) {
  72. $mainId = $item['main_id'];
  73. $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
  74. $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
  75. $groupedGames[$mainId]['children'][] = [
  76. 'id' => $item['id'],
  77. 'name' => '['.$item['id'].']'.$item['name']
  78. ];
  79. }
  80. return array_values($groupedGames);
  81. }
  82. }