GameGroupLogic.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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): array
  48. {
  49. // Todo 获取非自己的已选中
  50. $gameGroupId = $where['game_group_id'];
  51. $data = $this->model->where('id', '<>', $gameGroupId)->column("game_list");
  52. $gameIdList = [];
  53. foreach ($data as $gameIds) {
  54. $gameIds = explode(',', $gameIds);
  55. $gameIdList = array_merge($gameIdList, $gameIds);
  56. }
  57. // Todo 获取游戏分组
  58. $groupWhere = [
  59. 'status'=>1
  60. ];
  61. if (!empty($gameIdList)) {
  62. $groupWhere[] = [ 'id', 'notin', implode(',', $gameIdList)];
  63. }
  64. // 平台游戏
  65. $pfCame = Db::connect('db_center')->table('pf_game')->where($groupWhere)->select()->toArray();
  66. return (new GameLogic())->gameTree($pfCame);
  67. }
  68. }