GameGroupLogic.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }