GameController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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\GameLogic;
  10. use app\v1\validate\center\GameValidate;
  11. use plugin\saiadmin\app\logic\system\SystemDeptLogic;
  12. use plugin\saiadmin\exception\ApiException;
  13. use support\Request;
  14. use support\Response;
  15. /**
  16. * 游戏列表控制器
  17. */
  18. class GameController extends BaseController
  19. {
  20. protected $systemDeptLogic;
  21. /**
  22. * 构造函数
  23. */
  24. public function __construct()
  25. {
  26. $this->logic = new GameLogic();
  27. $this->validate = new GameValidate;
  28. $this->systemDeptLogic = new SystemDeptLogic();
  29. parent::__construct();
  30. }
  31. /**
  32. * 数据列表
  33. * @param Request $request
  34. * @return Response
  35. */
  36. public function index(Request $request): Response
  37. {
  38. $where = $request->more([
  39. ['id', ''],
  40. ['main_id', ''],
  41. ['name', ''],
  42. ['os', ''],
  43. ['status', ''],
  44. ]);
  45. $list = $this->logic->getIndex($where);
  46. return $this->success($list);
  47. }
  48. /**
  49. * 添加游戏
  50. */
  51. public function addGame(Request $request): Response
  52. {
  53. $data = $request->post();
  54. // 如果主游戏ID改变,则获取主游戏KEY
  55. if($data['main_game_id']){
  56. $game_info = $this->logic->read($data['main_game_id']);
  57. $data['appkey'] = $game_info['appkey'];
  58. $data['login_key'] = $game_info['login_key'];
  59. $data['pay_key'] = $game_info['pay_key'];
  60. }else{
  61. // 如果主游戏ID为空,则生成新的KEY
  62. $data['appkey'] = md5('appkey'.uniqid());
  63. $data['login_key'] = md5('login_key'.uniqid());
  64. $data['pay_key'] = md5('pay_key'.uniqid());
  65. }
  66. $this->logic->add($data);
  67. return $this->success();
  68. }
  69. /**
  70. * 更新游戏
  71. */
  72. public function updateGame(Request $request, $id): Response
  73. {
  74. $data = $request->post();
  75. // 如果主游戏ID改变,则获取主游戏KEY
  76. if($data['main_game_id']){
  77. $game_info = $this->logic->read($data['main_game_id']);
  78. $data['appkey'] = $game_info['appkey'];
  79. $data['login_key'] = $game_info['login_key'];
  80. $data['pay_key'] = $game_info['pay_key'];
  81. }else{
  82. // 如果主游戏ID为空,则生成新的KEY
  83. $data['appkey'] = md5('appkey'.uniqid());
  84. $data['login_key'] = md5('login_key'.uniqid());
  85. $data['pay_key'] = md5('pay_key'.uniqid());
  86. }
  87. $this->logic->edit($id, $data);
  88. return $this->success();
  89. }
  90. /**
  91. * 获取所有的游戏数据
  92. */
  93. public function getAllGameData(Request $request): Response
  94. {
  95. $list = $this->logic->getAllGameData();
  96. return $this->success($list);
  97. }
  98. /**
  99. * 根据部门ID获取游戏列表
  100. */
  101. public function getGameListByDeptId(Request $request): Response
  102. {
  103. $dept_id = $request->get('dept_id');
  104. $game_list = $this->logic->getGameListByDeptId($dept_id);
  105. return $this->success($game_list);
  106. }
  107. /**
  108. * 设置部门游戏权限
  109. */
  110. public function setGameListByDeptId(Request $request): Response
  111. {
  112. $game_list = $request->post('game_list');
  113. $dept_id = $request->post('dept_id');
  114. $this->logic->setGameListByDeptId($dept_id, $game_list);
  115. return $this->success();
  116. }
  117. }