MemGameController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * MemGameController.php UTF-8
  4. * 玩家小程序游戏
  5. *
  6. * @date : 2018/8/15 14:31
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HuoMP 1.0
  11. */
  12. namespace box\api\controller;
  13. use box\common\controller\V2ApiBaseController;
  14. use huo\controller\agent\AgentGame;
  15. use huo\controller\game\GameCache;
  16. use huo\model\agent\AgentGameModel;
  17. use huo\model\user\UserModel;
  18. use huolib\constant\CommonConst;
  19. use huolib\constant\GameConst;
  20. use huolib\status\CommonStatus;
  21. use huolib\status\GameStatus;
  22. use huolib\status\MemberStatus;
  23. use huomp\logic\game\AgentGameListLogic;
  24. use huomp\logic\game\MemGameLogic;
  25. class MemGameController extends V2ApiBaseController {
  26. public function _initialize() {
  27. parent::_initialize();
  28. }
  29. /**
  30. * 玩家的推广游戏列表
  31. * http://doc.1tsdk.com/159?page_id=4397
  32. * 【域名】/mem/game/list
  33. */
  34. public function index() {
  35. $_to_mem_id = get_val($this->rq_data, 'to_mem_id', null);
  36. $_page = get_val($this->rq_data, 'page', 1);
  37. $_offset = get_val($this->rq_data, 'offset', 10);
  38. if (!empty($_to_mem_id)) {
  39. //查看别人的推广游戏
  40. $_agent_info = (new UserModel())->getInfoByMemId($_to_mem_id);
  41. } else {
  42. //查看自己的推广游戏
  43. $_agent_info = (new UserModel())->getInfoByMemId($this->mem_id);
  44. }
  45. if (empty($_agent_info)) {
  46. $_code = MemberStatus::YOU_ARE_NOT_AGENT;
  47. $this->error(MemberStatus::getMsg($_code), [], $_code);
  48. }
  49. $_param = ['agent_id' => $_agent_info['id'], 'classify' => GameConst::GAME_MP];
  50. $_page = $_page.','.$_offset;
  51. $_order = '-gameext.down_cnt';
  52. $_rdata = (new AgentGameListLogic())->getAgentGames($this->mem_id, $_param, $_page, $_order);
  53. $_code = CommonStatus::NO_ERROR;
  54. $this->success(CommonStatus::getMsg($_code), $_rdata, $_code);
  55. }
  56. /**
  57. * 玩家添加推广游戏
  58. * http://doc.1tsdk.com/159?page_id=4398
  59. * 【域名】/mem/game/add
  60. */
  61. public function add() {
  62. $this->checkLogin();
  63. $_game_id = get_val($this->rq_data, 'game_id');
  64. if (empty($_game_id)) {
  65. $_code = GameStatus::GAME_ID_EMPTY;
  66. $this->error(GameStatus::getMsg($_code), [], $_code);
  67. }
  68. $_app_info = (new GameCache())->getInfoByAppId($_game_id);
  69. if (empty($_app_info)) {
  70. $_code = GameStatus::GAME_NOT_EXISTS;
  71. $this->error(GameStatus::getMsg($_code), [], $_code);
  72. }
  73. if ($_app_info['is_delete'] != CommonConst::CONST_NOT_DELETE) {
  74. $_code = GameStatus::GAME_NOT_EXISTS;
  75. $this->error(GameStatus::getMsg($_code), [], $_code);
  76. }
  77. if ($_app_info['status'] != GameConst::GAME_STATUS_ON) {
  78. $_code = GameStatus::GAME_ONLINE_NO;
  79. $this->error(GameStatus::getMsg($_code), [], $_code);
  80. }
  81. // if ($_app_info['promote_switch'] != GameConst::GAME_PROMOTE_SWITCH_CAN) {
  82. // $_code = GameStatus::GAME_PROMOTE_SWITCH_NO;
  83. // $this->error(GameStatus::getMsg($_code), [], $_code);
  84. // }
  85. $_agent_info = (new UserModel())->getInfoByMemId($this->mem_id);
  86. if (empty($_agent_info)) {
  87. $_code = MemberStatus::YOU_ARE_NOT_AGENT;
  88. $this->error(MemberStatus::getMsg($_code), [], $_code);
  89. }
  90. $_rs = (new AgentGame())->addGame($_agent_info['id'], $_game_id);
  91. if (!$_rs) {
  92. $_code = CommonStatus::INNER_ERROR;
  93. $this->error(CommonStatus::getMsg($_code), [], $_code);
  94. }
  95. $_code = CommonStatus::NO_ERROR;
  96. $this->success(CommonStatus::getMsg($_code), [], $_code);
  97. }
  98. /**
  99. * 玩家取消推广游戏
  100. * http://doc.1tsdk.com/159?page_id=4399
  101. * 【域名】/mem/game/cancel
  102. */
  103. public function cancel() {
  104. $this->checkLogin();
  105. $_game_id = get_val($this->rq_data, 'game_id');
  106. if (empty($_game_id)) {
  107. $_code = GameStatus::GAME_ID_EMPTY;
  108. $this->error(GameStatus::getMsg($_code), [], $_code);
  109. }
  110. $_app_info = (new GameCache())->getInfoByAppId($_game_id);
  111. if (empty($_app_info)) {
  112. $_code = GameStatus::GAME_NOT_EXISTS;
  113. $this->error(GameStatus::getMsg($_code), [], $_code);
  114. }
  115. $_agent_info = (new UserModel())->getInfoByMemId($this->mem_id);
  116. if (empty($_agent_info)) {
  117. $_code = MemberStatus::YOU_ARE_NOT_AGENT;
  118. $this->error(MemberStatus::getMsg($_code), [], $_code);
  119. }
  120. $_ag_model = new AgentGameModel();
  121. $_ag_info = $_ag_model->getInfoByAgentIdAppId($_agent_info['id'], $_game_id);
  122. if (empty($_ag_info)) {
  123. $_code = GameStatus::NOT_YET_ADDED_GAME;
  124. $this->error(GameStatus::getMsg($_code), [], $_code);
  125. }
  126. if ($_ag_info['is_delete'] == CommonConst::CONST_DELETED) {
  127. //已被删除,直接返回
  128. $_code = CommonStatus::NO_ERROR;
  129. $this->success(CommonStatus::getMsg($_code), [], $_code);
  130. } else {
  131. $_ag_info['is_delete'] = CommonConst::CONST_DELETED;
  132. $_ag_info['delete_time'] = time();
  133. $_rs = $_ag_model->updateData($_ag_info, $_ag_info['id']);
  134. if (!$_rs) {
  135. $_code = CommonStatus::INNER_ERROR;
  136. $this->error(CommonStatus::getMsg($_code), [], $_code);
  137. }
  138. $_code = CommonStatus::NO_ERROR;
  139. $this->success(CommonStatus::getMsg($_code), [], $_code);
  140. }
  141. }
  142. /**
  143. * 我玩过的游戏列表
  144. * http://doc.1tsdk.com/159?page_id=4498
  145. * 【域名】/mem/game/playlist
  146. */
  147. public function playList() {
  148. $this->checkLogin();
  149. $_page = get_val($this->rq_data, 'page', 1);
  150. $_offset = get_val($this->rq_data, 'offset', 10);
  151. //查看自己的推广游戏
  152. $_agent_info = (new UserModel())->getInfoByMemId($this->mem_id);
  153. if (empty($_agent_info)) {
  154. $_code = MemberStatus::YOU_ARE_NOT_AGENT;
  155. $this->error(MemberStatus::getMsg($_code), [], $_code);
  156. }
  157. $_param = [];
  158. $_page = $_page.','.$_offset;
  159. $_mg_logic = new MemGameLogic();
  160. $_rdata = $_mg_logic->getApiMemGame($this->mem_id, $_param, $_page);
  161. $_code = CommonStatus::NO_ERROR;
  162. $this->success(CommonStatus::getMsg($_code), $_rdata, $_code);
  163. }
  164. }