GameController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * GameController.php UTF-8
  4. * 游戏入口
  5. *
  6. * @date : 2017/11/15 17:21
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace api\wapapp\controller\v8;
  13. use api\common\controller\V2ApiBaseController;
  14. use huo\controller\game\Game;
  15. use huo\controller\game\GameList;
  16. use huo\controller\game\GameServer;
  17. use huolib\constant\CommonConst;
  18. use huolib\constant\GameConst;
  19. class GameController extends V2ApiBaseController {
  20. public function __construct() {
  21. parent::__construct();
  22. }
  23. /**
  24. * 游戏列表
  25. * http://doc.huosdk.com/138?page_id=3525
  26. * 【域名】/game/list
  27. */
  28. public function index() {
  29. $_channel_rq = $this->setChannelData();
  30. $_device_rq = $this->setDeviceData();
  31. $_agent_id = $_channel_rq->getAgentId();
  32. $_page = get_val($this->rq_data, 'page', 1); /* 页码 默认为1 代表第一页 1 */
  33. $_offset = get_val($this->rq_data, 'offset', 10); /* 每页显示数量 默认为10 */
  34. $_hot = get_val($this->rq_data, 'hot', 0); /* 是否热门 2 热门 1 普通 */
  35. $_is_single = get_val($this->rq_data, 'is_single', 0); /* 是否单机 1 单机 2 网游 0 所有 */
  36. $_is_new = get_val($this->rq_data, 'is_new', 0); /* 是否新游 2 新游 0 所有 默认为0 */
  37. $_remd = get_val($this->rq_data, 'remd', 0); /* 2 推荐 1 普通 */
  38. $_type = get_val($this->rq_data, 'type', ''); /* 游戏类型 可以逗号隔开 类型id */
  39. $_hasgift = get_val($this->rq_data, 'hasgift', 0); /* 是否有礼包 2 有礼包 其他 无礼包 */
  40. $_rank_type = get_val($this->rq_data, 'rank_type', 0); /* 排行类型,1为下载榜,2为畅销榜,3为热搜榜(取推荐)*/
  41. $_keywords = get_val($this->rq_data, 'keywords', ''); /* 搜索关键词 */
  42. $_is_fine = get_val($this->rq_data, 'is_fine', 0); /* 是否精品 2 精品 1 普通 */
  43. $_is_rate = get_val($this->rq_data, 'is_rate', 0); /* 是否折扣 2 折扣 1 其他 */
  44. $_is_bt = get_val($this->rq_data, 'is_bt ', 0); /* 是否BT 2 BT 1 其他 */
  45. $_classify = $_device_rq->getFrom();
  46. $_page = $_page.','.$_offset;
  47. if (!empty($_hasgift)) {
  48. $_datas = (new GameList())->getHasGiftList($_page);
  49. } elseif (!empty($_rank_type)) {
  50. $_datas = (new GameList())->getRankList($_rank_type, $_page);
  51. } else {
  52. $_param = [];
  53. !empty($_hot) && $_param['hot'] = $_hot;
  54. !empty($_is_single) && $_param['is_single'] = $_is_single;
  55. !empty($_is_new) && $_param['is_new'] = $_is_new;
  56. !empty($_remd) && $_param['remd'] = $_remd;
  57. !empty($_type) && $_param['type'] = $_type;
  58. !empty($_keywords) && $_param['keywords'] = $_keywords;
  59. !empty($_is_fine) && $_param['is_fine'] = $_is_fine;
  60. !empty($_classify) && $_param['classify'] = $_classify;
  61. !empty($_is_rate) && $_param['is_rate'] = $_is_rate;
  62. !empty($_is_bt) && $_param['is_bt'] = $_is_bt;
  63. $_rs = (new GameList())->getList($_param, $_page);
  64. $_datas = isset($_rs['data']) ? $_rs['data'] : [];
  65. }
  66. $this->success(lang('SUCCESS'), $_datas);
  67. }
  68. /**
  69. * 游戏详情
  70. * http://doc.1tsdk.com/138?page_id=3527
  71. * 【域名】/game/detail
  72. */
  73. public function read() {
  74. $_device_rq = $this->setDeviceData();
  75. $_app_id = get_val($this->rq_data, 'game_id'); /* 游戏id */
  76. if (empty($_app_id)) {
  77. $this->error(lang('app_id is null'));
  78. }
  79. $_rs = (new Game())->getDetail($_app_id, $this->mem_id, $_device_rq->getFrom());
  80. $_data = isset($_rs['data']) ? $_rs['data'] : [];
  81. $this->success(lang('SUCCESS'), $_data);
  82. }
  83. /**
  84. * 开服游戏列表
  85. * http://doc.1tsdk.com/138?page_id=3368
  86. * 【域名】/gameserver/list
  87. */
  88. public function getServerList() {
  89. $_page = get_val($this->rq_data, 'page', 1); /* 页码 默认为1 代表第一页 1 */
  90. $_offset = get_val($this->rq_data, 'offset', 10); /* 每页显示数量 默认为10 */
  91. $_server_type = get_val($this->rq_data, 'server_type', GameConst::GAME_SERVER_ALL); /*开服类型*/
  92. $_app_id = get_val($this->rq_data, 'game_id'); /* 游戏id */
  93. $_page = $_page.','.$_offset;
  94. $_device_rq = $this->setDeviceData();
  95. $_server_list = (new GameList())->getServerList($_server_type, $_device_rq->getFrom(), $_page, $_app_id);
  96. $this->returnData($_server_list);
  97. }
  98. /**
  99. * 获取游戏下载地址
  100. * http://doc.1tsdk.com/138?page_id=3528
  101. * 【域名】/game/down
  102. */
  103. public function down() {
  104. $_channel_rq = $this->setChannelData();
  105. $_agent_id = $_channel_rq->getAgentId();
  106. $_app_id = get_val($this->rq_data, 'game_id'); /* 游戏id */
  107. if (empty($_app_id)) {
  108. $this->error(lang('app_id is null'));
  109. }
  110. $_data = (new Game())->getDownUrl($_app_id, $_agent_id);
  111. $this->returnData($_data);
  112. }
  113. }