GameController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. $cp_callback_type = $data['cp_callback_type'];
  55. if($cp_callback_type == 1){
  56. // 读取主游戏的KEY
  57. if(!$data['main_game_id']){
  58. return $this->fail('请选择主游戏');
  59. }
  60. $main_game_info = $this->logic->read($data['main_game_id']);
  61. $data['appkey'] = $main_game_info['appkey'];
  62. $data['login_key'] = $main_game_info['login_key'];
  63. $data['pay_key'] = $main_game_info['pay_key'];
  64. }else{
  65. // 生成新的KEY
  66. $data['appkey'] = md5('appkey'.uniqid());
  67. $data['login_key'] = md5('login_key'.uniqid());
  68. $data['pay_key'] = md5('pay_key'.uniqid());
  69. }
  70. $this->logic->add($data);
  71. return $this->success();
  72. }
  73. /**
  74. * 更新游戏
  75. */
  76. public function updateGame(Request $request, $id): Response
  77. {
  78. $data = $request->post();
  79. // 如果主游戏ID改变,则获取主游戏KEY
  80. if($data['main_game_id']){
  81. $game_info = $this->logic->read($data['main_game_id']);
  82. $data['appkey'] = $game_info['appkey'];
  83. $data['login_key'] = $game_info['login_key'];
  84. $data['pay_key'] = $game_info['pay_key'];
  85. }else{
  86. // 如果主游戏ID为空,则生成新的KEY
  87. $data['appkey'] = md5('appkey'.uniqid());
  88. $data['login_key'] = md5('login_key'.uniqid());
  89. $data['pay_key'] = md5('pay_key'.uniqid());
  90. }
  91. $this->logic->edit($id, $data);
  92. return $this->success();
  93. }
  94. /**
  95. * 获取所有的游戏数据
  96. */
  97. public function getAllGameData(Request $request): Response
  98. {
  99. $list = $this->logic->getAllGameData();
  100. return $this->success($list);
  101. }
  102. /**
  103. * 根据部门ID获取游戏列表
  104. */
  105. public function getGameListByDeptId(Request $request): Response
  106. {
  107. $dept_id = $request->get('dept_id');
  108. $game_list = $this->logic->getGameListByDeptId($dept_id);
  109. return $this->success($game_list);
  110. }
  111. /**
  112. * 设置部门游戏权限
  113. */
  114. public function setGameListByDeptId(Request $request): Response
  115. {
  116. $game_list = $request->post('game_list');
  117. $dept_id = $request->post('dept_id');
  118. $this->logic->setGameListByDeptId($dept_id, $game_list);
  119. return $this->success();
  120. }
  121. }