GameGroupController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: your name
  6. // +----------------------------------------------------------------------
  7. namespace app\v1\controller\center;
  8. use plugin\saiadmin\basic\BaseController;
  9. use app\v1\logic\center\GameGroupLogic;
  10. use app\v1\validate\center\GameGroupValidate;
  11. use support\Request;
  12. use support\Response;
  13. use support\think\Db;
  14. /**
  15. * 游戏分组控制器
  16. */
  17. class GameGroupController extends BaseController
  18. {
  19. /**
  20. * 构造函数
  21. */
  22. public function __construct()
  23. {
  24. $this->logic = new GameGroupLogic();
  25. $this->validate = new GameGroupValidate;
  26. parent::__construct();
  27. }
  28. /**
  29. * 数据列表
  30. * @param Request $request
  31. * @return Response
  32. */
  33. public function index(Request $request): Response
  34. {
  35. $where = $request->more([
  36. ['name', ''],
  37. ]);
  38. $query = $this->logic->search($where);
  39. $query->order('sort', 'desc');
  40. $data = $this->logic->getList($query);
  41. $allGameList = Db::connect('db_center')->table('pf_game')->field('id,name')->select()->toArray();
  42. $allGameList = array_column($allGameList, 'name', 'id');
  43. foreach ($data['data'] as $key => $value) {
  44. $gameList = [];
  45. $game_list = explode(',', $value['game_list']);
  46. foreach ($game_list as $game_id) {
  47. $gameList[] = $allGameList[$game_id] ?? '';
  48. }
  49. $data['data'][$key]['game_list_str'] = $gameList;
  50. }
  51. return $this->success($data);
  52. }
  53. }