ShareOut.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. * Share.php UTF-8
  4. * 分享
  5. *
  6. * @date : 2017/2/7 22:30
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 7.0
  11. */
  12. namespace huomp\controller\share;
  13. use huo\controller\agent\AgentCache;
  14. use huo\controller\common\Base;
  15. use huo\controller\game\GameCache;
  16. use huo\controller\member\MemCache;
  17. use huo\controller\request\Device;
  18. use huolib\constant\OptionConst;
  19. use huolib\status\CommonStatus;
  20. use huomp\controller\agent\AgentState;
  21. use huomp\logic\share\ShareLogic;
  22. use huomp\model\game\GameMiniModel;
  23. class ShareOut extends Base {
  24. /**
  25. * 获取分享信息
  26. *
  27. * @param int $mem_id
  28. * @param int $app_id
  29. *
  30. * @return array
  31. */
  32. public function getAllShareInfo($mem_id, $app_id) {
  33. $_data['state'] = (new AgentState())->getCodeByMemApp($mem_id, $app_id);
  34. $_share_info = [];
  35. if (!empty($app_id)) {
  36. $_game_data = (new GameCache())->getInfoByAppId($app_id);
  37. $_share_data = !empty($_game_data['ext_info']['share_img']) ? $_game_data['ext_info']['share_img'] : [];
  38. foreach ($_share_data as $_k => $_v) {
  39. $_share['title'] = get_val($_v, 'title', '');
  40. $_share['image'] = cmf_get_image_url(
  41. get_val($_v, 'url', '')
  42. );
  43. $_share_info[] = $_share;
  44. }
  45. }
  46. if (empty($_share_info)) {
  47. $_share_setting = (new ShareLogic())->getShareSetting($app_id);
  48. $_share['title'] = $_share_setting[OptionConst::SETTING_SHARE_TITLE]; /* 分享名称 */
  49. $_share['image'] = cmf_get_image_preview_url(
  50. $_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]
  51. );
  52. $_share_info[] = $_share;
  53. }
  54. $_data['shareinfo'] = $_share_info;
  55. $_code = CommonStatus::NO_ERROR;
  56. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
  57. }
  58. /**
  59. * 获取小程序分享信息
  60. *
  61. * @param int $mem_id 玩家ID
  62. * @param int $app_id 应用ID
  63. *
  64. * @param string $path 分享路径
  65. * @param Device $device 设备信息
  66. *
  67. * @return array
  68. */
  69. public function getShareInfo($mem_id, $app_id, $path, Device $device) {
  70. $_state = (new AgentState())->getCodeByMemApp($mem_id, $app_id);
  71. $_share_logic = new ShareLogic();
  72. $_share_setting = $_share_logic->getShareSetting($app_id);
  73. $_title = $_share_setting[OptionConst::SETTING_SHARE_TITLE]; /* 分享名称 */
  74. $_image = cmf_get_image_preview_url($_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]); /* 分享群背景图 */
  75. $_pyq_bg = cmf_get_image_preview_url($_share_setting[OptionConst::SETTING_SHARE_IMG_MP]); /* 朋友圈分享背景图 */
  76. // $_mp_qr_arr = (new QrCodeOut())->getQrCode($mem_id, $app_id, $path);/* 小程序码 */
  77. // if (CommonStatus::NO_ERROR != $_mp_qr_arr['code']) {
  78. // $_mp_qr = '';
  79. // } else {
  80. // $_mp_qr = $_mp_qr_arr['data']['image'];
  81. // }
  82. $_mp_qr = '';
  83. $_share_data['title'] = $_title;
  84. $_share_data['content'] = $_title;
  85. $_share_data['url'] = $path;
  86. //写入分享log
  87. $_rs = $_share_logic->insertShareLog($mem_id, $_share_data, $device);
  88. if (false == $_rs) {
  89. $_code = CommonStatus::INNER_ERROR;
  90. return $this->huoError($_code, CommonStatus::getMsg($_code));
  91. }
  92. $_rdata['share_id'] = $_rs;
  93. $_rdata['title'] = $_title;
  94. $_rdata['image'] = $_image;
  95. $_rdata['mp_qr'] = $_mp_qr;
  96. $_rdata['pyq_bg'] = $_pyq_bg;
  97. $_rdata['state'] = $_state;
  98. $_code = CommonStatus::NO_ERROR;
  99. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
  100. }
  101. /**
  102. * @param int $share_id 分享ID
  103. * @param string $to_target 分享对象wx pyq
  104. * @param string $more 更多信息
  105. *
  106. * @return array
  107. */
  108. public function upShare($share_id, $to_target, $more = '') {
  109. $_rs = (new ShareLogic())->updateShareLog($share_id, $to_target, $more);
  110. if (false === $_rs) {
  111. $_code = CommonStatus::INNER_ERROR;
  112. return $this->huoError($_code, CommonStatus::getMsg($_code));
  113. }
  114. $_code = CommonStatus::NO_ERROR;
  115. return $this->huoSuccess($_code, CommonStatus::getMsg($_code));
  116. }
  117. /**
  118. * 获取分享落地页
  119. *
  120. * @param string $state 分享者标记信息
  121. * @param int $game_id 游戏id
  122. *
  123. * @return array
  124. */
  125. public function getSharePage($state, $game_id) {
  126. $_parent_ag_id = (new AgentState())->getIdByCode($state);
  127. $_mem = [
  128. 'mem_id' => 0,
  129. 'avatar' => '',
  130. 'username' => '',
  131. 'nickname' => ''
  132. ];
  133. $_game = [
  134. 'game_id' => 0,
  135. 'mini_app_id' => 0,
  136. 'gamename' => '',
  137. 'icon' => '',
  138. 'oneword' => ''
  139. ];
  140. if (!empty($_parent_ag_id)) {
  141. $_ac_class = AgentCache::ins();
  142. $_parent_agent_id = $_ac_class->getAgentIdByAgId($_parent_ag_id);
  143. $_parent_mem_id = $_ac_class->getMemIdByAgentId($_parent_agent_id);
  144. $_mem_data = MemCache::ins()->getInfoById($_parent_mem_id);
  145. if (!empty($_mem_data)) {
  146. $_mem = [
  147. 'mem_id' => $_mem_data['id'],
  148. 'avatar' => $_mem_data['avatar'],
  149. 'username' => $_mem_data['username'],
  150. 'nickname' => $_mem_data['nickname']
  151. ];
  152. }
  153. }
  154. if (!empty($game_id)) {
  155. $_game_data = GameCache::ins()->getInfoByAppId($game_id);
  156. $_game_mini_data = (new GameMiniModel())->getDataByAppId($game_id);
  157. $_game = [
  158. 'game_id' => $game_id,
  159. 'mini_app_id' => empty($_game_mini_data) ? '' : $_game_mini_data['mini_app_id'],
  160. 'gamename' => empty($_game_data) ? '' : $_game_data['name'],
  161. 'icon' => empty($_game_data) ? '' : cmf_get_image_preview_url($_game_data['icon']),
  162. 'oneword' => empty($_game_data) ? '' : $_game_data['publicity'],
  163. 'url' => empty($_game_data['gv']) ? '' : $_game_data['gv'][0]['package_url']
  164. ];
  165. }
  166. $_rdata = [
  167. 'mem' => $_mem,
  168. 'game' => $_game
  169. ];
  170. $_code = CommonStatus::NO_ERROR;
  171. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
  172. }
  173. /**
  174. * 获取分享规则图片
  175. *
  176. * @param $app_id
  177. */
  178. public function getShareRuleImg($app_id) {
  179. $_game_data = GameCache::ins()->getInfoByAppId($app_id);
  180. return empty($_game_data['ext_info']['share_rule_img'])
  181. ? '' : cmf_get_image_preview_url($_game_data['ext_info']['share_rule_img']);
  182. }
  183. }