AgentGameListLogic.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * AgentGameLogic.php UTF-8
  4. * 渠道游戏逻辑处理
  5. *
  6. * @date : 2018/5/17 20:43
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huomp\logic\game;
  13. use huo\controller\common\CommonFunc;
  14. use huo\model\agent\AgentGameModel;
  15. use huo\model\common\CommonModel;
  16. use huo\model\game\GamecategoryModel;
  17. use huo\model\game\GameModel;
  18. use huo\model\member\MemGameModel;
  19. use huolib\constant\CategoryConst;
  20. use huolib\constant\CommonConst;
  21. use huolib\constant\GameConst;
  22. use huolib\constant\OptionConst;
  23. use huolib\tool\Time;
  24. use huomp\logic\share\ShareLogic;
  25. class AgentGameListLogic extends CommonModel {
  26. /**
  27. * @param array $param
  28. *
  29. * @return array
  30. */
  31. protected function getWhere($param = []) {
  32. $_map = [];
  33. if (!empty($param['agent_id'])) {
  34. $_map['agent_game_model.agent_id'] = $param['agent_id'];
  35. }
  36. if (!empty($param['classify'])) {
  37. $_map['game.classify'] = $param['classify'];
  38. }
  39. if (!empty($param['app_id'])) {
  40. $_map['game.id'] = $param['app_id'];
  41. }
  42. $_map['agent_game_model.is_delete'] = CommonConst::CONST_NOT_DELETE;
  43. $_map['game.is_delete'] = CommonConst::CONST_NOT_DELETE;
  44. $_map['game.status'] = GameConst::GAME_STATUS_ON;
  45. return $_map;
  46. }
  47. /**
  48. * 获取渠道的游戏列表
  49. *
  50. * @param int $mem_id
  51. * @param array $where
  52. * @param string $page
  53. * @param string $order
  54. *
  55. * @return mixed
  56. */
  57. public function getAgentGames($mem_id, $where = [], $page = '1,10', $order = '-create_time') {
  58. $_map = $this->getWhere($where);
  59. $_ag_model = new AgentGameModel();
  60. $_count = $_ag_model->with('game')->where($_map)->count();
  61. if (empty($_count)) {
  62. return [
  63. 'count' => 0,
  64. 'list' => [],
  65. ];
  66. }
  67. $_order = $this->orderFilter($order);
  68. $_agent_games = $_ag_model
  69. ->with('gameext,game,gamemini,rate,gv')
  70. ->where($_map)
  71. ->order($_order)
  72. ->page($page)
  73. ->select();
  74. if (is_object($_agent_games)) {
  75. $_agent_games = $_agent_games->toArray();
  76. }
  77. if (empty($_agent_games)) {
  78. return [
  79. 'count' => $_count,
  80. 'list' => [],
  81. ];
  82. }
  83. $_list = [];
  84. $_share_logic = new ShareLogic();
  85. $_mg_model = new MemGameModel();
  86. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  87. foreach ($_agent_games as $_k => $_agent_game) {
  88. $_share_setting = $_share_logic->getShareSetting($_agent_game['app_id']);
  89. // /* 判定是否获取过收益 */
  90. // $_integral = (new Income())->getOpenGain($mem_id, $_agent_game['app_id']);
  91. // $_has_open = false;
  92. // if (is_numeric($_integral)) {
  93. // $_has_open = true;
  94. // }
  95. $_has_open = true;
  96. //判断是否为试玩列表游戏
  97. $_rs = (new GamecategoryModel())->isGameExist(CategoryConst::CATE_CATE_RP, $_agent_game['app_id']);
  98. if ($_rs) {
  99. list($today_start, $today_end) = Time::today();
  100. $_mem_game_model = new MemGameModel();
  101. $_rs = $_mem_game_model->hasOpen($mem_id, $_agent_game['app_id'], $today_start);
  102. if (!$_rs) {
  103. $_has_open = false;
  104. }
  105. }
  106. $_need_popup = empty($_v['gamemini']['need_popup']) ? GameConst::RATE_MP_NEED_POPUP_NOT
  107. : $_v['gamemini']['need_popup'];
  108. $_entrance_image = '';
  109. if (GameConst::RATE_MP_NEED_POPUP == $_need_popup) {
  110. $_entrance_image = empty($_v['gamemini']['entrance_image']) ? '' : $_v['gamemini']['entrance_image'];
  111. }
  112. $_data = [
  113. 'ag_id' => $_agent_game['id'],
  114. 'game_id' => $_agent_game['app_id'],
  115. 'mini_app_id' => !empty($_agent_game['gamemini']) ? $_agent_game['gamemini']['mini_app_id'] : '',
  116. 'gamename' => !empty($_agent_game['game']) ? $_agent_game['game']['name'] : '',
  117. 'icon' => !empty($_agent_game['game']) ? $_agent_game['game']['icon'] : '',
  118. 'oneword' => !empty($_agent_game['game']) ? $_agent_game['game']['publicity'] : '',
  119. 'down_cnt' => !empty($_agent_game['gameext']) ? $_agent_game['gameext']['down_cnt'] : '',
  120. 'mem_agent_reward' => !empty($_agent_game['rate']) ? $_agent_game['rate']['mem_agent_reward'] : '',
  121. 'mem_reward' => !empty($_agent_game['rate']) ? $_agent_game['rate']['mem_reward'] : '',
  122. 'url' => !empty($_agent_game['gv']) ? $_agent_game['gv'][0]['package_url'] : '',
  123. 'is_play' => $_has_open ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE,
  124. 'need_popup' => $_need_popup,
  125. 'entrance_image' => cmf_get_image_preview_url($_entrance_image),
  126. 'player' => (new MemGameLogic())->getPlayer($mem_id, $_agent_game['app_id']),
  127. ];
  128. $_data['mem_agent_integral'] = intval($_data['mem_agent_reward'] * $_gold_rmb_rate);
  129. $_data['mem_integral'] = intval($_data['mem_reward'] * $_gold_rmb_rate);
  130. $_data['share_title'] = $_share_setting[OptionConst::SETTING_SHARE_TITLE]; /* 分享名称 */
  131. $_data['share_img'] = cmf_get_image_preview_url(
  132. $_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]
  133. ); /* 分享群背景图 */
  134. $_data['share_background'] = cmf_get_image_preview_url(
  135. $_share_setting[OptionConst::SETTING_SHARE_IMG_MP]
  136. ); /* 朋友圈分享背景图 */
  137. $_list[] = $_data;
  138. }
  139. return [
  140. 'count' => $_count,
  141. 'list' => $_list,
  142. ];
  143. }
  144. /**
  145. * 获取有推广奖励的游戏
  146. *
  147. * @param int $limit 显示个数
  148. *
  149. * @return array
  150. */
  151. public function getRewardGame($limit = 3) {
  152. $_map = [
  153. 'status' => GameConst::GAME_STATUS_ON,
  154. 'mem_agent_reward' => ['neq', 0],
  155. ];
  156. $_game_ids = (new GameModel())->with('rate')->where($_map)->limit($limit)->column('game_model.id');
  157. return $_game_ids;
  158. }
  159. }