GameController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. $game_info = $this->logic->read($id);
  80. $cp_callback_type = $data['cp_callback_type'];
  81. $game_info_cp_callback_type = $game_info['cp_callback_type'];
  82. $main_game_id = $data['main_game_id'];
  83. $game_info_main_game_id = $game_info['main_game_id'];
  84. // 如果主游戏ID改变,并且游戏发货规则为1,则获取主游戏KEY
  85. if(($main_game_id !== $game_info_main_game_id) && $cp_callback_type===1){
  86. $main_game_info = $this->logic->read($main_game_id);
  87. $data['appkey'] = $main_game_info['appkey'];
  88. $data['login_key'] = $main_game_info['login_key'];
  89. $data['pay_key'] = $main_game_info['pay_key'];
  90. $this->logic->edit($id,$data);
  91. }else if($cp_callback_type !== $game_info_cp_callback_type){
  92. // 如果游戏发货规则改变,则根据规则生成新的KEY
  93. if($cp_callback_type == 0){
  94. // 如果是独立KEY, 则生成新的KEY
  95. $data['appkey'] = md5('appkey'.uniqid());
  96. $data['login_key'] = md5('login_key'.uniqid());
  97. $data['pay_key'] = md5('pay_key'.uniqid());
  98. }else{
  99. // 如果是主游戏KEY, 则获取主游戏KEY
  100. $appkey = $this->logic->read($main_game_id)['appkey'];
  101. $login_key = $this->logic->read($main_game_id)['login_key'];
  102. $pay_key = $this->logic->read($main_game_id)['pay_key'];
  103. $data['appkey'] = $appkey;
  104. $data['login_key'] = $login_key;
  105. $data['pay_key'] = $pay_key;
  106. }
  107. }
  108. $this->logic->edit($id, $data);
  109. return $this->success();
  110. }
  111. /**
  112. * 获取所有的游戏数据
  113. */
  114. public function getAllGameData(Request $request): Response
  115. {
  116. $list = $this->logic->getAllGameData();
  117. return $this->success($list);
  118. }
  119. /**
  120. * 根据部门ID获取游戏列表
  121. */
  122. public function getGameListByDeptId(Request $request): Response
  123. {
  124. $dept_id = $request->get('dept_id');
  125. $game_list = $this->logic->getGameListByDeptId($dept_id);
  126. return $this->success($game_list);
  127. }
  128. /**
  129. * 设置部门游戏权限
  130. */
  131. public function setGameListByDeptId(Request $request): Response
  132. {
  133. $game_list = $request->post('game_list');
  134. $dept_id = $request->post('dept_id');
  135. $this->logic->setGameListByDeptId($dept_id, $game_list);
  136. return $this->success();
  137. }
  138. }