GameMiniCateListLogic.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <?php
  2. /**
  3. * GameMiniCateListLogic.php UTF-8
  4. * 游戏分类列表
  5. *
  6. * @date : 2018/9/13 11:37
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace huomp\logic\game;
  13. use huo\controller\common\CommonFunc;
  14. use huo\controller\integral\IaCache;
  15. use huo\model\game\GamecategoryModel;
  16. use huo\model\member\MemGameModel;
  17. use huolib\constant\CacheConst;
  18. use huolib\constant\CategoryConst;
  19. use huolib\constant\CommonConst;
  20. use huolib\constant\GameConst;
  21. use huolib\constant\IaConst;
  22. use huolib\constant\OptionConst;
  23. use huolib\tool\StrUtils;
  24. use huolib\tool\Time;
  25. use huomp\logic\share\ShareLogic;
  26. use huomp\model\common\CommonModel;
  27. use think\Cache;
  28. class GameMiniCateListLogic extends CommonModel {
  29. /**
  30. * @param array $param
  31. *
  32. * @return array
  33. */
  34. protected function getWhere($param = []) {
  35. $_map = [];
  36. if (!empty($param['status'])) {
  37. $_map['joingame.status'] = $param['status'];
  38. }
  39. if (!empty($param['classify'])) {
  40. $_map['joingame.classify'] = $param['classify'];
  41. }
  42. if (!empty($param['cate_id'])) {
  43. $_map['gamecategory_model.cate_id'] = $param['cate_id'];
  44. }
  45. if (!empty($param['promote_switch'])) {
  46. $_map['joingame.promote_switch'] = $param['promote_switch'];
  47. }
  48. return $_map;
  49. }
  50. protected function getOrder($order_type) {
  51. switch ($order_type) {
  52. case GameConst::RANK_TYPE_DOWN:
  53. $_order = '-gameext.down_cnt';
  54. break;
  55. case GameConst::RANK_TYPE_HOT_SALE:
  56. $_order = '-gameext.pay_user_cnt';
  57. break;
  58. case GameConst::RANK_TYPE_RECOMMEND:
  59. $_order = '-gameext.pay_user_cnt';
  60. break;
  61. case GameConst::RANK_TYPE_COMMISSION:
  62. $_order = '-gamerate.mem_agent_reward';
  63. break;
  64. case GameConst::RANK_TYPE_LIST_ORDER:
  65. $_order = '-gamecategory_model.list_order';
  66. break;
  67. case GameConst::RANK_TYPE_FIND_TIME:
  68. $_order = '-gamecategory_model.find_time,-gamecategory_model.list_order';
  69. break;
  70. default:
  71. $_order = '-gameext.down_cnt';
  72. }
  73. return $_order;
  74. }
  75. /**
  76. * 获取记录
  77. *
  78. * @param array $param
  79. * @param string $page
  80. * @param int $order_type
  81. *
  82. * @return array
  83. */
  84. public function getCateGameList(
  85. $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_LIST_ORDER
  86. ) {
  87. $_map = $this->getWhere($param);
  88. $_map['gamecategory_model.find_time'] = ['egt', 0];
  89. $_order = $this->getOrder($order_type);
  90. $_field = [];
  91. $_game_data = $this->getList($_field, $_map, $page, $_order);
  92. $_game_list = [];
  93. $_item_cnt = get_val($param, 'item_cnt', 0);
  94. $_mem_agent_integral = 0;
  95. $_mem_agent_reward = 0;
  96. $_ia_data = IaCache::ins()->getIa(IaConst::IA_PLAY_3);
  97. if (!empty($_ia_data['integral'])) {
  98. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  99. $_mem_agent_integral = $_ia_data['integral'];
  100. $_mem_agent_reward = StrUtils::formatNumber($_mem_agent_integral / $_gold_rmb_rate);
  101. }
  102. $_mem_game_model = new MemGameModel();
  103. $_gc_model = new GamecategoryModel();
  104. list($today_start, $today_end) = Time::today();
  105. foreach ($_game_data['list'] as $_k => $_v) {
  106. $_v_add = $_v;
  107. if (2 == $_item_cnt) {
  108. $_v_add['icon'] = empty($_v['fine_image']) ? $_v_add['icon'] : $_v['fine_image'];
  109. }
  110. $_has_open = true;
  111. $_mem_id = get_val($param, 'mem_id', 0);
  112. /* 判定是否获取过收益 */
  113. // $_integral = (new Income())->getOpenGain($_mem_id, $_v['game_id']);
  114. // if (is_numeric($_integral)) {
  115. // $_has_open = true;
  116. // }
  117. //判断是否为试玩列表游戏
  118. $_rs = $_gc_model->isGameExist(CategoryConst::CATE_CATE_RP, $_v['game_id']);
  119. if ($_rs) {
  120. $_rs = $_mem_game_model->hasOpen($_mem_id, $_v['game_id'], $today_start);
  121. if (!$_rs) {
  122. $_has_open = false;
  123. }
  124. $_v_add['mem_agent_integral'] = $_mem_agent_integral;
  125. $_v_add['mem_agent_reward'] = $_mem_agent_reward;
  126. }
  127. $_v_add['is_add'] = $_has_open ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE;
  128. $_game_list[] = $_v_add;
  129. }
  130. return [
  131. 'count' => $_game_data['count'],
  132. 'list' => $_game_list,
  133. ];
  134. }
  135. /**
  136. * 获取记录
  137. *
  138. * @param array $param
  139. * @param string $page
  140. * @param int $order_type
  141. *
  142. * @return array
  143. */
  144. public function getFindGameList(
  145. $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_FIND_TIME
  146. ) {
  147. $_map = $this->getWhere($param);
  148. $_order = $this->getOrder($order_type);
  149. $_field = [];
  150. $_date = date('Y-m-d');
  151. $_game_data = $this->getList($_field, $_map, $page, $_order);
  152. $_game_list = [];
  153. $_game_cnt = 0;
  154. $_cnt = 0;
  155. $_list = [];
  156. $_mem_logic = new MemGameLogic();
  157. $_gc_model = new GamecategoryModel();
  158. $_mem_game_model = new MemGameModel();
  159. list($today_start, $today_end) = Time::today();
  160. foreach ($_game_data['list'] as $_k => $_v) {
  161. $_in_date = date('Y-m-d', $_v['find_time']);
  162. if ($_date != $_in_date) {
  163. if (!empty($_game_list)) {
  164. $_list[] = [
  165. 'date' => $_date,
  166. 'game_cnt' => $_game_cnt,
  167. 'gamelist' => $_game_list,
  168. ];
  169. $_cnt++;
  170. }
  171. $_game_cnt = 0;
  172. $_game_list = [];
  173. $_date = $_in_date;
  174. }
  175. $_v_add = $_v;
  176. // /* 判定是否获取过收益 */
  177. // $_integral = (new Income())->getOpenGain($param['mem_id'], $_v['game_id']);
  178. // $_has_open = false;
  179. // if (is_numeric($_integral)) {
  180. // $_has_open = true;
  181. // }
  182. $_has_open = true;
  183. $_mem_id = $param['mem_id'];
  184. //判断是否为试玩列表游戏
  185. $_rs = $_gc_model->isGameExist(CategoryConst::CATE_CATE_RP, $_v['game_id']);
  186. if ($_rs) {
  187. $_rs = $_mem_game_model->hasOpen($_mem_id, $_v['game_id'], $today_start);
  188. if (!$_rs) {
  189. $_has_open = false;
  190. }
  191. }
  192. $_v_add['is_add'] = $_has_open ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE;
  193. $_v_add['player'] = $_mem_logic->getPlayer($_mem_id, $_v['game_id']);
  194. $_game_list[] = $_v_add;
  195. $_game_cnt++;
  196. }
  197. $_rdata = [
  198. 'count' => $_cnt,
  199. 'list' => $_list,
  200. ];
  201. return $_rdata;
  202. }
  203. /**
  204. * 获取记录
  205. *
  206. * @param int $_mem_id
  207. * @param array $param
  208. * @param string $page
  209. * @param int $order_type
  210. *
  211. * @return array
  212. */
  213. public function getRpGameList($_mem_id, $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_LIST_ORDER
  214. ) {
  215. $_map = $this->getWhere($param);
  216. $_order = $this->getOrder($order_type);
  217. $_field = [];
  218. $_game_data = $this->getList($_field, $_map, $page, $_order);
  219. if (empty($_game_data['count'])) {
  220. return $_game_data;
  221. }
  222. $_list = [];
  223. $_share_logic = new ShareLogic();
  224. $_ia_cache = IaCache::ins();
  225. foreach ($_game_data['list'] as $_k => $_v) {
  226. /* 获取试玩状态 */
  227. $_status = $this->getRpStatus($_mem_id, $_v['game_id']);
  228. $_mem_agent_integral = 0;
  229. $_mem_agent_reward = 0;
  230. $_ia_data = $_ia_cache->getIa(IaConst::IA_PLAY_3);
  231. if (!empty($_ia_data['integral'])) {
  232. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  233. $_mem_agent_integral = $_ia_data['integral'];
  234. $_mem_agent_reward = StrUtils::formatNumber($_mem_agent_integral / $_gold_rmb_rate);
  235. }
  236. $_share_setting = $_share_logic->getShareSetting($_v['game_id']);
  237. $_list[] = [
  238. 'game_id' => $_v['game_id'],
  239. 'mini_app_id' => $_v['mini_app_id'],
  240. 'gamename' => $_v['gamename'],
  241. 'icon' => $_v['icon'],
  242. 'oneword' => $_v['oneword'],
  243. 'down_cnt' => $_v['down_cnt'],
  244. 'mem_agent_reward' => $_mem_agent_reward,
  245. 'mem_agent_integral' => $_mem_agent_integral,
  246. 'rp_image' => $_v['rp_image'],
  247. 'status' => $_status,
  248. 'need_popup' => $_v['need_popup'],
  249. 'entrance_image' => $_v['entrance_image'],
  250. 'player' => (new MemGameLogic())->getPlayer($_mem_id, $_v['game_id']),
  251. 'share_title' => $_share_setting[OptionConst::SETTING_SHARE_TITLE],
  252. 'share_img' => cmf_get_image_preview_url(
  253. $_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]
  254. ),
  255. ];
  256. }
  257. $_rdata = [
  258. 'count' => $_game_data['count'],
  259. 'list' => $_list,
  260. ];
  261. return $_rdata;
  262. }
  263. /**
  264. * 获取记录
  265. *
  266. * @param int $_mem_id
  267. * @param array $param
  268. * @param string $page
  269. * @param int $order_type
  270. *
  271. * @return array
  272. */
  273. public function getPlayGameList($_mem_id, $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_LIST_ORDER
  274. ) {
  275. $_map = $this->getWhere($param);
  276. $_order = $this->getOrder($order_type);
  277. $_field = [];
  278. $_game_data = $this->getList($_field, $_map, $page, $_order);
  279. if (empty($_game_data['count'])) {
  280. return $_game_data;
  281. }
  282. $_list = [];
  283. $_share_logic = new ShareLogic();
  284. $_gc_model = new GamecategoryModel();
  285. $_ia_cache = IaCache::ins();
  286. $_mg_logic = new MemGameLogic();
  287. foreach ($_game_data['list'] as $_k => $_v) {
  288. /* 获取试玩状态 */
  289. $_status = $this->getRpStatus($_mem_id, $_v['game_id']);
  290. $_mem_agent_integral = 0;
  291. $_mem_agent_reward = 0;
  292. $_rs = $_gc_model->isGameExist(CategoryConst::CATE_CATE_RP, $_v['game_id']);
  293. if ($_rs) {
  294. $_ia_data = $_ia_cache->getIa(IaConst::IA_PLAY_3);
  295. if (!empty($_ia_data['integral'])) {
  296. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  297. $_mem_agent_integral = $_ia_data['integral'];
  298. $_mem_agent_reward = StrUtils::formatNumber($_mem_agent_integral / $_gold_rmb_rate);
  299. }
  300. }
  301. $_share_setting = $_share_logic->getShareSetting($_v['game_id']);
  302. $_list[] = [
  303. 'game_id' => $_v['game_id'],
  304. 'mini_app_id' => $_v['mini_app_id'],
  305. 'gamename' => $_v['gamename'],
  306. 'icon' => $_v['icon'],
  307. 'oneword' => $_v['oneword'],
  308. 'down_cnt' => $_v['down_cnt'],
  309. 'mem_agent_reward' => $_mem_agent_reward,
  310. 'mem_agent_integral' => $_mem_agent_integral,
  311. 'rp_image' => $_v['rp_image'],
  312. 'status' => $_status,
  313. 'need_popup' => $_v['need_popup'],
  314. 'entrance_image' => $_v['entrance_image'],
  315. 'single_tag' => $_v['single_tag'],
  316. 'player' => $_mg_logic->getPlayer($_mem_id, $_v['game_id']),
  317. 'share_title' => $_share_setting[OptionConst::SETTING_SHARE_TITLE],
  318. 'share_img' => cmf_get_image_preview_url(
  319. $_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]
  320. ),
  321. ];
  322. }
  323. $_rdata = [
  324. 'count' => $_game_data['count'],
  325. 'list' => $_list,
  326. ];
  327. return $_rdata;
  328. }
  329. /**
  330. * 获取列表
  331. *
  332. * @param array $field
  333. * @param array $where
  334. * @param string $page
  335. * @param string $order
  336. *
  337. */
  338. public function getList($field = [], $where, $page = '1,10', $order = '-create_time') {
  339. $_cache_key = CacheConst::CACHE_GAME_LIST_PREFIX.md5(json_encode(array($field, $where, $page, $order)));
  340. $_cache_tag = CacheConst::TAG_GAME_LIST;
  341. $_rdata = json_decode(Cache::tag($_cache_tag)->get($_cache_key), true);
  342. if (!empty($_rdata)) {
  343. return $_rdata;
  344. }
  345. $_map = $where;
  346. $_model = new GamecategoryModel();
  347. $_count = $_model->with('joingame,gameext,gamerate')->with('gamemini')->where($_map)->count();
  348. if (empty($_count)) {
  349. $_rdata = [
  350. 'count' => 0,
  351. 'list' => []
  352. ];
  353. Cache::tag($_cache_tag, $_cache_key)->set($_cache_key, json_encode($_rdata));
  354. return $_rdata;
  355. }
  356. $_field = $field;
  357. if (empty($field)) {
  358. $_field = [];
  359. }
  360. $_order = $_model->orderFilter($order);
  361. $_datas = $_model
  362. ->with('joingame,gameext,gamerate')
  363. ->with('gamemini,gv')
  364. ->where($_map)
  365. ->field($_field)
  366. ->order($_order)
  367. ->page($page)
  368. ->select();
  369. if (is_object($_datas)) {
  370. $_datas = $_datas->toArray();
  371. }
  372. if (empty($_datas)) {
  373. $_rdata = [
  374. 'count' => 0,
  375. 'list' => []
  376. ];
  377. Cache::tag($_cache_tag, $_cache_key)->set($_cache_key, json_encode($_rdata));
  378. return $_rdata;
  379. }
  380. $_data = [];
  381. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  382. foreach ($_datas as $_k => $_v) {
  383. $_mem_reward = !empty($_v['gamerate']) ? $_v['gamerate']['mem_reward'] : 0;
  384. $_need_popup = empty($_v['gamemini']['need_popup']) ? GameConst::RATE_MP_NEED_POPUP_NOT
  385. : $_v['gamemini']['need_popup'];
  386. $_entrance_image = '';
  387. if (GameConst::RATE_MP_NEED_POPUP == $_need_popup) {
  388. $_entrance_image = empty($_v['gamemini']['entrance_image']) ? '' : $_v['gamemini']['entrance_image'];
  389. }
  390. $_single_tag = !empty($_v['joingame']['ext_info']) ? explode('|', $_v['joingame']['single_tag']) : [];
  391. $_is_add = false;
  392. $_data[] = [
  393. 'game_id' => $_v['app_id'],
  394. 'single_tag' => $_single_tag,
  395. 'find_time' => $_v['find_time'],
  396. 'fine_image' => !empty($_v['joingame']['ext_info'])
  397. && !empty($_v['joingame']['ext_info']['fine_image']) ? cmf_get_image_url(
  398. $_v['joingame']['ext_info']['fine_image']
  399. ) : '',
  400. 'find_image' => !empty($_v['joingame']['ext_info'])
  401. && !empty($_v['joingame']['ext_info']['find_image']) ? cmf_get_image_url(
  402. $_v['joingame']['ext_info']['find_image']
  403. ) : '',
  404. 'rp_image' => !empty($_v['joingame']['ext_info'])
  405. && !empty($_v['joingame']['ext_info']['rp_image']) ? cmf_get_image_url(
  406. $_v['joingame']['ext_info']['rp_image']
  407. ) : '',
  408. 'mini_app_id' => $_v['gamemini']['mini_app_id'],
  409. 'gamename' => !empty($_v['joingame']['name']) ? $_v['joingame']['name'] : '',
  410. 'icon' => !empty($_v['joingame']['icon']) ? cmf_get_image_url($_v['joingame']['icon'])
  411. : '',
  412. 'oneword' => !empty($_v['joingame']['publicity']) ? $_v['joingame']['publicity'] : '',
  413. 'down_cnt' => !empty($_v['gameext']['down_cnt']) ? $_v['gameext']['down_cnt'] : 0,
  414. 'mem_agent_reward' => $_mem_reward,
  415. 'mem_agent_integral' => intval($_mem_reward * $_gold_rmb_rate),
  416. 'is_add' => $_is_add ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE,
  417. 'url' => empty($_v['gv']) ? '' : $_v['gv'][0]['package_url'],
  418. 'need_popup' => $_need_popup,
  419. 'entrance_image' => cmf_get_image_preview_url($_entrance_image),
  420. ];
  421. }
  422. $_rdata = [
  423. 'count' => $_count,
  424. 'list' => $_data
  425. ];
  426. Cache::tag($_cache_tag, $_cache_key)->set($_cache_key, json_encode($_rdata));
  427. return $_rdata;
  428. }
  429. /**
  430. * 获取游戏试玩状态
  431. *
  432. * @param $mem_id
  433. * @param $app_id
  434. *
  435. * @return int 1 未完成 2 已完成
  436. */
  437. public function getRpStatus($mem_id, $app_id) {
  438. if (empty($mem_id) || empty($app_id)) {
  439. return IaConst::IA_STATUS_SUC;
  440. }
  441. list($today_start, $today_end) = Time::today();
  442. $_rs = (new MemGameModel())->hasOpen($mem_id, $app_id, $today_start);
  443. if (false == $_rs) {
  444. return IaConst::IA_STATUS_NOT;
  445. }
  446. return IaConst::IA_STATUS_SUC;
  447. }
  448. }