GameMiniListLogic.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * GameMiniListLogic.php UTF-8
  4. * 小程序游戏列表逻辑
  5. *
  6. * @date : 2018/8/15 17:27
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HuoMP 1.0
  11. */
  12. namespace huomp\logic\game;
  13. use huo\controller\common\CommonFunc;
  14. use huo\controller\game\GameCache;
  15. use huo\model\agent\AgentGameModel;
  16. use huo\model\game\GamecategoryModel;
  17. use huo\model\member\MemGameModel;
  18. use huo\model\slide\SlideItemModel;
  19. use huo\model\slide\SlideModel;
  20. use huo\model\user\UserModel;
  21. use huolib\constant\CategoryConst;
  22. use huolib\constant\CommonConst;
  23. use huolib\constant\DeviceTypeConst;
  24. use huolib\constant\GameConst;
  25. use huolib\tool\Time;
  26. use huomp\model\common\CommonModel;
  27. use huomp\model\game\GameMiniModel;
  28. class GameMiniListLogic 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['promote_switch'])) {
  43. $_map['joingame.promote_switch'] = $param['promote_switch'];
  44. }
  45. $_map['joingame.is_delete'] = CommonConst::CONST_NOT_DELETE;
  46. return $_map;
  47. }
  48. protected function getOrder($order_type) {
  49. switch ($order_type) {
  50. case GameConst::RANK_TYPE_DOWN:
  51. $_order = '-gameext.down_cnt';
  52. break;
  53. case GameConst::RANK_TYPE_HOT_SALE:
  54. $_order = '-gameext.pay_user_cnt';
  55. break;
  56. case GameConst::RANK_TYPE_RECOMMEND:
  57. $_order = '-gameext.pay_user_cnt';
  58. break;
  59. case GameConst::RANK_TYPE_COMMISSION:
  60. $_order = '-gamerate.mem_agent_reward';
  61. break;
  62. default:
  63. $_order = '-gameext.down_cnt';
  64. }
  65. return $_order;
  66. }
  67. /**
  68. * 获取记录
  69. *
  70. * @param $agent_id
  71. * @param array $param
  72. * @param string $page
  73. * @param int $order_type
  74. *
  75. * @return array
  76. */
  77. public function getGameMiniList($agent_id, $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_RECOMMEND
  78. ) {
  79. $_map = $this->getWhere($param);
  80. $_order = $this->getOrder($order_type);
  81. $_field = [];
  82. return $this->getList($agent_id, $_field, $_map, $page, $_order);
  83. }
  84. /**
  85. * 获取列表
  86. *
  87. * @param int $agent_id
  88. * @param array $field
  89. * @param array $where
  90. * @param string $page
  91. * @param string $order
  92. *
  93. */
  94. public function getList($agent_id = 0, $field = [], $where, $page = '1,10', $order = '-create_time') {
  95. /* 获取玩家id */
  96. $_mem_id = (new UserModel())->getMemIdById($agent_id);
  97. $_map = $where;
  98. $_model = new GameMiniModel();
  99. $_count = $_model->with('joingame,gameext,gamerate')->where($_map)->count();
  100. if (empty($_count)) {
  101. return [
  102. 'count' => 0,
  103. 'list' => []
  104. ];
  105. }
  106. $_field = $field;
  107. if (empty($field)) {
  108. $_field = [];
  109. }
  110. $_order = $_model->orderFilter($order);
  111. $_datas = $_model
  112. ->with('joingame,gameext,gamerate,gv')
  113. ->where($_map)
  114. ->field($_field)
  115. ->order($_order)
  116. ->page($page)
  117. ->select();
  118. if (is_object($_datas)) {
  119. $_datas = $_datas->toArray();
  120. }
  121. if (empty($_datas)) {
  122. return [
  123. 'count' => $_count,
  124. 'list' => []
  125. ];
  126. }
  127. $_data = [];
  128. $_app_cache = new GameCache();
  129. $_agent_game_model = new AgentGameModel();
  130. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  131. foreach ($_datas as $_k => $_game_mini) {
  132. $_app_info = $_app_cache->getInfoByAppId($_game_mini['app_id']);
  133. $_mem_agent_reward = !empty($_game_mini['gamerate']) ? $_game_mini['gamerate']['mem_agent_reward'] : 0;
  134. $_mem_reward = !empty($_game_mini['gamerate']) ? $_game_mini['gamerate']['mem_reward'] : 0;
  135. $_is_add = false;
  136. if (!empty($agent_id)) {
  137. $_agent_game_info = $_agent_game_model->getInfoByAgentIdAppId($agent_id, $_game_mini['app_id']);
  138. }
  139. if (!empty($_agent_game_info) && $_agent_game_info['is_delete'] == CommonConst::CONST_NOT_DELETE) {
  140. $_is_add = true;
  141. }
  142. /* 判定是否获取过收益 */
  143. // $_integral = (new Income())->getOpenGain($_mem_id, $_game_mini['app_id']);
  144. // $_has_open = false;
  145. // if (is_numeric($_integral)) {
  146. // $_has_open = true;
  147. // }
  148. $_has_open = true;
  149. //判断是否为试玩列表游戏
  150. $_rs = (new GamecategoryModel())->isGameExist(CategoryConst::CATE_CATE_RP, $_game_mini['app_id']);
  151. if ($_rs) {
  152. list($today_start, $today_end) = Time::today();
  153. $_mem_game_model = new MemGameModel();
  154. $_rs = $_mem_game_model->hasOpen($_mem_id, $_game_mini['app_id'], $today_start);
  155. if (!$_rs) {
  156. $_has_open = false;
  157. }
  158. }
  159. $_share_data = !empty($_app_info['ext_info']['share_img']) ? $_app_info['ext_info']['share_img'] : [];
  160. $_share_title = '';
  161. $_share_img = '';
  162. if (!empty($_share_data)) {
  163. if (false === is_array($_share_data)) {
  164. $_share_data = (array)$_share_data;
  165. }
  166. $_key = array_rand($_share_data, 1);
  167. if (!empty($_share_data[$_key]['url'])) {
  168. $_share_title = get_val($_share_data[$_key], 'title', '');
  169. $_share_img = cmf_get_image_url($_share_data[$_key]['url']);
  170. }
  171. }
  172. $_data[] = [
  173. 'game_id' => $_game_mini['app_id'],
  174. 'mini_app_id' => $_game_mini['mini_app_id'],
  175. 'gamename' => !empty($_app_info) ? $_app_info['name'] : '',
  176. 'icon' => !empty($_app_info) ? cmf_get_image_url($_app_info['icon']) : '',
  177. 'oneword' => !empty($_app_info) ? $_app_info['publicity'] : '',
  178. 'down_cnt' => !empty($_game_mini['gameext']) ? $_game_mini['gameext']['down_cnt'] : 0,
  179. 'mem_agent_reward' => $_mem_agent_reward,
  180. 'mem_reward' => $_mem_reward,
  181. 'mem_agent_integral' => intval($_mem_agent_reward * $_gold_rmb_rate),
  182. 'mem_integral' => intval($_mem_reward * $_gold_rmb_rate),
  183. 'is_add' => $_is_add ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE,
  184. 'is_play' => $_has_open ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE,
  185. 'url' => !empty($_game_mini['gv']) ? $_game_mini['gv'][0]['package_url'] : '',
  186. 'share_title' => $_share_title,
  187. 'share_img' => $_share_img,
  188. 'need_popup' => $_game_mini['need_popup'],
  189. 'entrance_image' => cmf_get_image_preview_url($_game_mini['entrance_image'])
  190. ];
  191. }
  192. return [
  193. 'count' => $_count,
  194. 'list' => $_data
  195. ];
  196. }
  197. /**
  198. * 获取轮播小程序游戏列表
  199. */
  200. public function getSlideList() {
  201. $_codes = (new SlideModel())->getSlideCodesByDevice(DeviceTypeConst::DEVICE_TYPE_MP);
  202. $_cnt = 0;
  203. $_list = [];
  204. $_sl_model = new SlideItemModel();
  205. foreach ($_codes as $_k => $_v) {
  206. $_data = $_sl_model->getAdsByCode($_v);
  207. $_count = count($_data);
  208. $_cnt += $_count;
  209. $_list = array_merge($_list, $_data);
  210. }
  211. return [
  212. 'count' => $_cnt,
  213. 'list' => $_list,
  214. ];
  215. }
  216. }