GameList.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <?php
  2. /**
  3. * GameList.php UTF-8
  4. *
  5. *
  6. * @date : 2018/5/3 17:55
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\game;
  13. use huo\controller\agent\Agent;
  14. use huo\controller\common\Base;
  15. use huo\controller\gift\GiftCache;
  16. use huo\controller\rate\Rate;
  17. use huo\controller\rate\RateCache;
  18. use huo\logic\agent\AgentGameLogic;
  19. use huo\logic\agent\AgentLogic;
  20. use huo\logic\game\GameLogic;
  21. use huo\model\agent\AgentGameModel;
  22. use huolib\constant\AgentConst;
  23. use huolib\constant\GameConst;
  24. use huolib\status\GameStatus;
  25. use huolib\utils\GameUtils;
  26. class GameList extends Base {
  27. /**
  28. * 获取推荐游戏列表
  29. *
  30. * @param string $from
  31. * @param string $page
  32. *
  33. * @return array
  34. */
  35. public function getRcmdList($from = '', $page = '1,10') {
  36. $_param['hot'] = GameConst::GAME_IS_HOT;
  37. $_map['classify'] = $from;
  38. return $this->getList($_param, $page, $_map);
  39. }
  40. /**
  41. * 获取新游列表
  42. *
  43. * @param string $from
  44. * @param string $page
  45. *
  46. * @return array
  47. */
  48. public function getNewList($from = '', $page = '1,10') {
  49. $_param['is_new'] = GameConst::GAME_IS_NEW;
  50. $_map['classify'] = $from;
  51. return $this->getList($_param, $page, $_map);
  52. }
  53. /**
  54. * 获取热门列表
  55. *
  56. * @param string $from
  57. * @param string $page
  58. *
  59. * @return array
  60. */
  61. public function getHotList($from = '', $page = '1,10') {
  62. $_param['hot'] = GameConst::GAME_IS_HOT;
  63. $_map = [];
  64. if (!empty($from)) {
  65. $_map['classify'] = $from;
  66. }
  67. return $this->getList($_param, $page, $_map);
  68. }
  69. /**
  70. * 渠道渠道申请游戏列表
  71. *
  72. * @param int $agent_id
  73. * @param array $param
  74. * @param string $page
  75. *
  76. * @return array
  77. */
  78. public function getAgentApplyList($agent_id, $param = [], $page = '1,10') {
  79. $_map = $param;
  80. $_map['agent_id'] = $agent_id;
  81. if (!empty($_map['classify'])) {
  82. $_classify = $_map['classify'];
  83. if (3 == substr($_classify, 0, 1)) {
  84. $_map['classify'] = [
  85. ['eq', 3],
  86. ['between', [300, 399]],
  87. 'or'
  88. ];
  89. } elseif (4 == substr($_classify, 0, 1) && 401 != $_classify) {
  90. $_map['classify'] = [
  91. ['eq', 4],
  92. ['between', [400, 499]],
  93. 'or'
  94. ];
  95. } else {
  96. $_map['classify'] = $_classify;
  97. }
  98. }
  99. $_data = (new AgentGameLogic())->getAgentGames($_map, $page);
  100. if (false == is_array($_data)) {
  101. return $_data;
  102. }
  103. $_list = $_data['list'];
  104. if (!empty($_list)) {
  105. unset($_data['list']);
  106. $_data['list'] = $this->getGameExtInfo($_list);
  107. }
  108. $_code = GameStatus::NO_ERROR;
  109. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);
  110. }
  111. /**
  112. * 下级渠道列表
  113. *
  114. * @param int $agent_id
  115. * @param array $param
  116. * @param string $page
  117. *
  118. * @return array
  119. */
  120. public function getSubAgentList($agent_id, $param = [], $page = '1,10') {
  121. $_agent_arr = (new AgentLogic())->getAgentIds($agent_id, false, [4]);
  122. $_map = $param;
  123. $_map['agent_id'] = ['in', $_agent_arr];
  124. $_data = (new AgentGameLogic())->getAgentGames($_map, $page);
  125. if (false == is_array($_data)) {
  126. return $_data;
  127. }
  128. $_list = $_data['list'];
  129. if (!empty($_list)) {
  130. unset($_data['list']);
  131. $_data['list'] = $this->getSelfGameExtInfo($agent_id, $_list);
  132. }
  133. $_code = GameStatus::NO_ERROR;
  134. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);
  135. }
  136. /**
  137. * @param int $agent_id
  138. * @param array $data
  139. *
  140. * @return mixed
  141. */
  142. public function getSelfGameExtInfo($agent_id, $data) {
  143. if (empty($data)) {
  144. return $data;
  145. }
  146. $_rate_class = RateCache::ins();
  147. foreach ($data as $_k => $_v) {
  148. $_self_rate = $_rate_class->getInfoByAppIdAgentId($_v['game_id'], $agent_id);
  149. if (empty($_self_rate)) {
  150. $_self_rate = $_rate_class->getInfoByAppId($_v['game_id']);
  151. }
  152. $data[$_k]['sub_agent_rate'] = $_v['agent_rate'];
  153. $data[$_k]['sub_agent_rebate'] = $_v['agent_rebate'];
  154. if (false == $_self_rate) {
  155. $data[$_k]['agent_rate'] = 1;
  156. $data[$_k]['agent_rebate'] = 0;
  157. continue;
  158. }
  159. $data[$_k]['agent_rate'] = $_self_rate['agent_rate'];
  160. $data[$_k]['agent_rebate'] = $_self_rate['agent_rebate'];
  161. }
  162. return $data;
  163. }
  164. /**
  165. * 获取渠道可申请游戏列表
  166. *
  167. * @param $agent_id
  168. * @param array $param
  169. * @param string $page
  170. *
  171. * @return array
  172. */
  173. public function getAgentNoApplyList($agent_id, $param = [], $page = '1,10') {
  174. $_game_ids = (new AgentGameModel())->getGameIdsByAgentId($agent_id);
  175. $_map = [];
  176. $_classify = $param['classify'];
  177. if (!empty($_classify)) {
  178. if (3 == substr($_classify, 0, 1)) {
  179. $_map['classify'] = [
  180. ['eq', 3],
  181. ['between', [300, 399]],
  182. 'or'
  183. ];
  184. } elseif (4 == substr($_classify, 0, 1) && 401 != $_classify) {
  185. $_map['classify'] = [
  186. ['eq', 4],
  187. ['between', [400, 499]],
  188. 'or'
  189. ];
  190. } else {
  191. $_map['classify'] = $_classify;
  192. }
  193. }
  194. $_order = '-list_order';
  195. $_map['promote_switch'] = ['in', [GameConst::GAME_PROMOTE_SWITCH_CAN, GameConst::GAME_PROMOTE_SWITCH_CHECK]];
  196. if (!empty($_game_ids)) {
  197. $_map['id'] = ['not in', $_game_ids];
  198. }
  199. $_data = $this->getGameListDetail($_map, $page, $_order);
  200. if (is_numeric($_data)) {
  201. $_code = $_data;
  202. return $this->huoError($_code, GameStatus::getMsg($_code));
  203. }
  204. $_code = GameStatus::NO_ERROR;
  205. if (empty($_data['list'])) {
  206. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);
  207. }
  208. $_list = $_data['list'];
  209. unset($_data['list']);
  210. $_data['list'] = $this->getGameRateExt($agent_id, $_list);
  211. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);
  212. }
  213. /**
  214. * @param int $agent_id
  215. * @param $data
  216. *
  217. * @return mixed
  218. */
  219. public function getGameRateExt($agent_id, $data) {
  220. if (empty($data)) {
  221. return $data;
  222. }
  223. $_role_type = (new Agent())->getRoleType($agent_id);
  224. $_rate_class = RateCache::ins();
  225. foreach ($data as $_k => $_v) {
  226. $_game_rate = $_rate_class->getInfoByAppId($_v['game_id']);
  227. if (false == $_game_rate) {
  228. $data[$_k]['agent_rate'] = 1;
  229. $data[$_k]['agent_rebate'] = 0;
  230. $data[$_k]['benefit_type'] = 0;
  231. continue;
  232. }
  233. $data[$_k]['agent_rate'] = AgentConst::ROLE_TYPE_GROUP == $_role_type ? $_game_rate['agent_rate']
  234. : $_game_rate['sub_agent_rate'];
  235. $data[$_k]['agent_rebate'] = AgentConst::ROLE_TYPE_GROUP == $_role_type ? $_game_rate['agent_rebate']
  236. : $_game_rate['sub_agent_rebate'];
  237. $data[$_k]['benefit_type'] = $_game_rate['benefit_type'];
  238. }
  239. return $data;
  240. }
  241. /**
  242. * 获取热门列表
  243. *
  244. * @param int $mem_id 玩家ID
  245. * @param string $from
  246. * @param string $page
  247. *
  248. * @return array
  249. */
  250. public function getPlayedList($mem_id = 0, $from = '', $page = '1,10') {
  251. $_game_logic = new GameLogic();
  252. $_id_arr = $_game_logic->getMemGameIDs($mem_id, $from, $page);
  253. if (is_numeric($_id_arr)) {
  254. $_code = $_id_arr;
  255. return $this->huoError($_code, GameStatus::getMsg($_code));
  256. }
  257. $_count = $_id_arr['count'];
  258. $_list = $_id_arr['list'];
  259. $_param['is_new'] = GameConst::GAME_IS_NEW;
  260. $_map['id'] = ['in', $_list];
  261. $_rdata = $this->getList($_param, $page, $_map);
  262. if (!empty($_rdata['data']) && is_array($_rdata['data'])) {
  263. $_rdata['data']['count'] = $_count;
  264. return $this->huoSuccess($_rdata['code'], $_rdata['msg'], $_rdata['data']);
  265. } else {
  266. return $_rdata;
  267. }
  268. }
  269. /**
  270. * 获取开服游戏列表
  271. *
  272. * @param int $server_type 开服类型
  273. * @param string $from
  274. * @param string $page
  275. *
  276. * @param int $app_id 游戏ID
  277. *
  278. * @return array
  279. */
  280. public function getServerList($server_type = 0, $from = '', $page = '1,10', $app_id = 0) {
  281. $_chk_rs = GameUtils::checkServerType($server_type);
  282. if (GameStatus::NO_ERROR != $_chk_rs) {
  283. return $this->huoError($_chk_rs, GameStatus::getMsg($_chk_rs));
  284. }
  285. $_game_logic = new GameLogic();
  286. $_server_arr = $_game_logic->getServerList($server_type, $from, $page, $app_id);
  287. if (is_numeric($_server_arr)) {
  288. $_code = $_server_arr;
  289. return $this->huoError($_code, GameStatus::getMsg($_code));
  290. }
  291. /* 附加游戏信息 */
  292. // $_app_id_arr = [];
  293. // $_count = $_server_arr['count'];
  294. // $_list = $_server_arr['list'];
  295. // foreach ($_list as $_key => $_val) {
  296. // $_app_id_arr[] = $_val['app_id'];
  297. // }
  298. // $_map['id'] = ['in', $_app_id_arr];
  299. // $_rdata = $this->getGameListDetail($_map, $page);
  300. // if (empty($_count)) {
  301. // $_code = GameStatus::SERVER_CNT_ZERO;
  302. // return $this->huoError($_code, GameStatus::getMsg($_code));
  303. // }
  304. $_server_arr['list'] = $this->getGameExtInfo($_server_arr['list']);
  305. // // TODO: liuhongliang 2018/5/9 合并开服信息到游戏详情信息中???
  306. // foreach ($_list as $_key => $_val) {
  307. // $_server_arr['list'][$_key] = array_merge($_val,$_rdata['list'][$_val['app_id']]);
  308. // }
  309. $_code = GameStatus::NO_ERROR;
  310. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_server_arr);
  311. }
  312. /**
  313. * 获取游戏列表
  314. *
  315. * @param array $param
  316. * @param string $page
  317. *
  318. * @param array $where
  319. *
  320. * @return array
  321. */
  322. public function getList($param = [], $page, $where = []) {
  323. $_map = $where;
  324. $_order = '-run_time';
  325. if (isset($param['hot']) && GameConst::GAME_IS_HOT == $param['hot']) {
  326. /* hottest默认排序按照最近一段时间的下载量,加一个指定游戏规则 */
  327. $_order = '+hot_order';
  328. } else if (isset($param['rank']) && GameConst::GAME_IS_RANK == $param['rank']) {
  329. /* Ranking默认规则可以是游戏评价,然后加一个制定规则;所有都是指定游戏的规则优先 */
  330. $_order = '-list_order';
  331. } else if (isset($param['is_new']) && GameConst::GAME_IS_NEW == $param['is_new']) {
  332. /* New games默认排序规则可以按照上架时间,然后加一个规则就是我们指定的游戏优先 */
  333. $_order = '-run_time';
  334. } else if (isset($param['remd']) && GameConst::GAME_IS_NEW == $param['is_new']) {
  335. /* remd games默认排序规则可以按照上架时间,然后加一个规则就是我们指定的游戏优先 */
  336. $_order = '-like_order';
  337. } else if (isset($param['down_sort'])) {
  338. /* 下载排行榜排序 */
  339. $_order = '-ext.down_cnt';
  340. } else if (isset($param['pay_sort'])) {
  341. /* 支付人数排序 */
  342. $_order = '-ext.pay_user_cnt';
  343. } else if (isset($param['is_fine'])) {
  344. /* 精品排序 */
  345. $_order = '-fine_order';
  346. }
  347. if (!empty($param['is_single']) && GameConst::GAME_IS_SINGLE == $param['is_single']) {
  348. $_map['is_single'] = 2;
  349. }
  350. if (!empty($param['type'])) {
  351. $_cates = $param['type'];
  352. $_data = $_data = (new GameLogic())->getCateList($_cates, $page, $_order);
  353. // $this->huoReturn($_data);
  354. $_code = GameStatus::NO_ERROR;
  355. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);
  356. }
  357. if (!empty($param['keywords'])) {
  358. $_map['name|en_name'] = ['like', '%'.$param['keywords'].'%'];
  359. }
  360. if (!empty($param['classify'])) {
  361. $_map['classify'] = $param['classify'];
  362. }
  363. if (!empty($param['is_bt']) && GameConst::GAME_IS_BT == $param['is_bt']) {
  364. $_map['is_bt'] = GameConst::GAME_IS_BT;
  365. } else if (!empty($param['is_rate'])) {
  366. $_map['is_bt'] = GameConst::GAME_NOT_BT;
  367. }
  368. $_data = $this->getGameListDetail($_map, $page, $_order);
  369. if (is_numeric($_data)) {
  370. $_code = $_data;
  371. $_data = [
  372. 'count' => 0,
  373. 'list' => []
  374. ];
  375. return $this->huoError($_code, GameStatus::getMsg($_code), $_data);
  376. }
  377. $_code = GameStatus::NO_ERROR;
  378. return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);
  379. }
  380. /**
  381. * @param array $map
  382. * @param string $page
  383. * @param string $_order
  384. *
  385. * @param array $field
  386. *
  387. * @return mixed
  388. */
  389. public function getGameListDetail($map = [], $page = '', $_order = '', $field = []) {
  390. $_data = (new GameLogic())->getList($map, $page, $_order, $field);
  391. if (false == is_array($_data)) {
  392. return $_data;
  393. }
  394. $_list = $_data['list'];
  395. if (empty($_list)) {
  396. return $_data;
  397. }
  398. unset($_data['list']);
  399. $_data['list'] = $this->getGameExtInfo($_list);
  400. return $_data;
  401. }
  402. /**
  403. * 获取礼包扩展信息
  404. *
  405. * @param array $data
  406. *
  407. * @return array
  408. */
  409. public function getGameExtInfo($data = []) {
  410. if (empty($data)) {
  411. return $data;
  412. }
  413. $_cate_class = CategoryCache::ins();
  414. $_gift_class = GiftCache::ins();
  415. $_rate_class = (new Rate(0));
  416. foreach ($data as $_k => $_v) {
  417. if (empty($_v['type'])) {
  418. $data[$_k]['type'] = null;
  419. } else {
  420. $data[$_k]['type'] = $_cate_class->getNameByIds(GameConst::CATEGORY_TYPE_CATE, $_v['type']);
  421. }
  422. if (empty($_v['tags'])) {
  423. $data[$_k]['tags'] = null;
  424. } else {
  425. $data[$_k]['tags'] = $_cate_class->getNameByIds(GameConst::CATEGORY_TYPE_TAG, $_v['tags']);
  426. }
  427. $data[$_k]['gift_cnt'] = $_gift_class->getGiftCntByGameId($_v['game_id']);
  428. $_rate_class->setGameRate($_v['game_id']);
  429. $data[$_k]['rate'] = $_rate_class->getFirstMemRate();
  430. }
  431. return $data;
  432. }
  433. /**
  434. * 查询拥有礼包的游戏列表
  435. *
  436. * @param array $map
  437. * @param string $page
  438. *
  439. * @return array
  440. */
  441. public function getHasGiftList($page = '1,10') {
  442. $_map = [
  443. 'ext.real_gift_cnt' => ['>', 0],
  444. ];
  445. return (new GameLogic())->getList($_map, $page);
  446. }
  447. /**
  448. * 获取排行游戏列表
  449. *
  450. * @param int $rank_type 1为下载榜,2为畅销榜,3为热搜榜(取推荐)
  451. */
  452. public function getRankList($rank_type = 1, $page) {
  453. if (1 == $rank_type) {
  454. $_param['down_sort'] = true;
  455. } elseif (2 == $rank_type) {
  456. $_param['pay_sort'] = true;
  457. } else {
  458. $_param['remd'] = GameConst::GAME_IS_NEW;
  459. return $this->getList($_param, $page);
  460. }
  461. return $this->getList($_param, $page);
  462. }
  463. }