Game.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /**
  3. * Game.php UTF-8
  4. * 游戏处理
  5. *
  6. * @date : 2017/11/16 17:31
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\game;
  13. use huo\controller\common\Base;
  14. use huo\controller\gift\Gift;
  15. use huo\controller\request\Channel;
  16. use huo\controller\request\Game as GameRq;
  17. use huo\logic\game\GameLogic;
  18. use huo\logic\posts\PostsLogic;
  19. use huo\model\game\GameversionModel;
  20. use huolib\constant\GameConst;
  21. use huolib\status\GameStatus;
  22. use huomp\controller\game\GameMini;
  23. class Game extends Base {
  24. protected $game_logic;
  25. public function __construct(GameLogic $game_logic = null) {
  26. if (null === $game_logic) {
  27. $this->game_logic = new GameLogic();
  28. } else {
  29. $this->game_logic = $game_logic;
  30. }
  31. }
  32. /**
  33. * 获取游戏 app_key
  34. *
  35. * @param int $app_id
  36. *
  37. * @return bool
  38. */
  39. public function getAppkey($app_id = 0) {
  40. $_game_data = GameCache::ins()->getInfoByAppId($app_id);
  41. if (empty($_game_data)) {
  42. return false;
  43. }
  44. $_app_key = get_val($_game_data, 'app_key', '');
  45. return $_app_key;
  46. }
  47. /**
  48. * 获取游戏 切换状态
  49. *
  50. * @param int $app_id
  51. *
  52. * @return bool
  53. */
  54. public function getPaySwitchStatus($app_id = 0) {
  55. $_game_data = GameCache::ins()->getInfoByAppId($app_id);
  56. if (empty($_game_data)) {
  57. return false;
  58. }
  59. $_pay_switch = get_val($_game_data, 'pay_switch', 2);
  60. return $_pay_switch;
  61. }
  62. /**
  63. * 获取游戏 切换状态
  64. *
  65. * @param int $app_id
  66. *
  67. * @return bool
  68. */
  69. public function getPayShowStatus($app_id = 0) {
  70. $_game_data = GameCache::ins()->getInfoByAppId($app_id);
  71. if (empty($_game_data)) {
  72. return false;
  73. }
  74. $_pay_switch = get_val($_game_data, 'pay_show', 2);
  75. return $_pay_switch;
  76. }
  77. /**
  78. * 获取游戏回调地址
  79. *
  80. * @param int $app_id
  81. *
  82. * @return bool
  83. */
  84. public function getCpPaybackUrl($app_id = 0) {
  85. $_game_data = GameCache::ins()->getInfoByAppId($app_id);
  86. if (empty($_game_data)) {
  87. return false;
  88. }
  89. $_cp_payback_url = get_val($_game_data, 'cp_payback_url', '');
  90. return $_cp_payback_url;
  91. }
  92. /**
  93. * 获取游戏地址
  94. *
  95. * @param int $app_id
  96. *
  97. * @return int|string
  98. */
  99. public function getPlayUrl($app_id = 0) {
  100. if (empty($app_id)) {
  101. return GameStatus::GAME_ID_EMPTY;
  102. }
  103. $_game_info = GameCache::ins()->getInfoByAppId($app_id);
  104. if (!isset($_game_info['gv'])) {
  105. return GameStatus::GAME_NOT_EXISTS;
  106. }
  107. $_play_url = !empty($_game_info['gv']['0']['package_url']) ? $_game_info['gv']['0']['package_url'] : '';
  108. if (empty($_play_url)) {
  109. return GameStatus::GAME_URL_EMPTY;
  110. }
  111. return $_play_url;
  112. }
  113. /**
  114. * 获取游戏详情
  115. *
  116. * @param int $app_id
  117. * @param int $mem_id
  118. *
  119. * @param int $from 来源
  120. *
  121. * @return array
  122. */
  123. public function getDetail($app_id, $mem_id = 0, $from = GameConst::GAME_H5) {
  124. if (empty($app_id)) {
  125. $this->huoError(GameStatus::INVALID_PARAMS);
  126. }
  127. $_map['app_id'] = $app_id;
  128. $_data = $this->game_logic->getDetail($_map, $field = '');
  129. if (is_numeric($_data)) {
  130. $_code = $_data;
  131. return $this->huoError($_code, GameStatus::getMsg($_code));
  132. }
  133. $_list[$_data['game_id']] = $_data;
  134. unset($_data);
  135. $_data = (new GameList())->getGameExtInfo($_list);
  136. $_game_data = $_data[$app_id];
  137. /* 获取游戏礼包 */
  138. $_map['app_id'] = $_game_data['game_id'];
  139. $_gift_list = (new Gift())->getGiftListDetail($mem_id, $_map, '', true);
  140. if (!empty($_gift_list)) {
  141. $_game_data['gift'] = $_gift_list['list'];
  142. }
  143. if (GameConst::GAME_H5 != $from && GameConst::GAME_MP_BOX != $from) {
  144. /* 获取最新资讯 */
  145. $_game_data['news'] = (new PostsLogic())->getTitleByAppId($app_id);
  146. /* 获取开服信息 */
  147. $_game_data['serlist'] = (new GameLogic())->getGameServerList($app_id, GameConst::GAME_SERVER_TODAY);
  148. } elseif (GameConst::GAME_MP_BOX == $from) {
  149. /* 获取最新资讯 */
  150. $_game_data['mini_app_id'] = (new GameMini())->getMiniIdByAppId($app_id);
  151. }
  152. $_code = GameStatus::NO_ERROR;
  153. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_game_data);
  154. }
  155. /**
  156. * 游戏下载接口与下载次数
  157. *
  158. * @param $app_id
  159. *
  160. * @return array
  161. */
  162. public function getDownUrl($app_id, $agent_id = 0) {
  163. $_down_cnt = $this->game_logic->getDownCnt($app_id);
  164. $_down_url = $this->game_logic->getDownUrl($app_id);
  165. $_data['down_cnt'] = $_down_cnt;
  166. $_data['down_url'] = $_down_url;
  167. $_code = GameStatus::NO_ERROR;
  168. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);
  169. }
  170. /**
  171. * 获取更新信息
  172. *
  173. * @param GameRq $game_rq
  174. * @param Channel $channel
  175. *
  176. * @return mixed
  177. */
  178. public function getUpInfo(GameRq $game_rq, Channel $channel) {
  179. // TODO: wuyonghong 2018/1/19 获取更新
  180. $_rs['up_status'] = 0;
  181. $_rs['url'] = '';
  182. $_rs['content'] = '';
  183. return $_rs;
  184. }
  185. /**
  186. * 获取H5游戏Cp游戏地址
  187. *
  188. * @param int $app_id
  189. *
  190. * @return string
  191. */
  192. public function getH5GameCpUrl($app_id) {
  193. return (new GameversionModel())->getPackageUrlByAppId($app_id);
  194. }
  195. }