123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- /**
- * Share.php UTF-8
- * 分享
- *
- * @date : 2017/2/7 22:30
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 7.0
- */
- namespace huomp\controller\share;
- use huo\controller\agent\AgentCache;
- use huo\controller\common\Base;
- use huo\controller\game\GameCache;
- use huo\controller\member\MemCache;
- use huo\controller\request\Device;
- use huolib\constant\OptionConst;
- use huolib\status\CommonStatus;
- use huomp\controller\agent\AgentState;
- use huomp\logic\share\ShareLogic;
- use huomp\model\game\GameMiniModel;
- class ShareOut extends Base {
- /**
- * 获取分享信息
- *
- * @param int $mem_id
- * @param int $app_id
- *
- * @return array
- */
- public function getAllShareInfo($mem_id, $app_id) {
- $_data['state'] = (new AgentState())->getCodeByMemApp($mem_id, $app_id);
- $_share_info = [];
- if (!empty($app_id)) {
- $_game_data = (new GameCache())->getInfoByAppId($app_id);
- $_share_data = !empty($_game_data['ext_info']['share_img']) ? $_game_data['ext_info']['share_img'] : [];
- foreach ($_share_data as $_k => $_v) {
- $_share['title'] = get_val($_v, 'title', '');
- $_share['image'] = cmf_get_image_url(
- get_val($_v, 'url', '')
- );
- $_share_info[] = $_share;
- }
- }
- if (empty($_share_info)) {
- $_share_setting = (new ShareLogic())->getShareSetting($app_id);
- $_share['title'] = $_share_setting[OptionConst::SETTING_SHARE_TITLE]; /* 分享名称 */
- $_share['image'] = cmf_get_image_preview_url(
- $_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]
- );
- $_share_info[] = $_share;
- }
- $_data['shareinfo'] = $_share_info;
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
- }
- /**
- * 获取小程序分享信息
- *
- * @param int $mem_id 玩家ID
- * @param int $app_id 应用ID
- *
- * @param string $path 分享路径
- * @param Device $device 设备信息
- *
- * @return array
- */
- public function getShareInfo($mem_id, $app_id, $path, Device $device) {
- $_state = (new AgentState())->getCodeByMemApp($mem_id, $app_id);
- $_share_logic = new ShareLogic();
- $_share_setting = $_share_logic->getShareSetting($app_id);
- $_title = $_share_setting[OptionConst::SETTING_SHARE_TITLE]; /* 分享名称 */
- $_image = cmf_get_image_preview_url($_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]); /* 分享群背景图 */
- $_pyq_bg = cmf_get_image_preview_url($_share_setting[OptionConst::SETTING_SHARE_IMG_MP]); /* 朋友圈分享背景图 */
- // $_mp_qr_arr = (new QrCodeOut())->getQrCode($mem_id, $app_id, $path);/* 小程序码 */
- // if (CommonStatus::NO_ERROR != $_mp_qr_arr['code']) {
- // $_mp_qr = '';
- // } else {
- // $_mp_qr = $_mp_qr_arr['data']['image'];
- // }
- $_mp_qr = '';
- $_share_data['title'] = $_title;
- $_share_data['content'] = $_title;
- $_share_data['url'] = $path;
- //写入分享log
- $_rs = $_share_logic->insertShareLog($mem_id, $_share_data, $device);
- if (false == $_rs) {
- $_code = CommonStatus::INNER_ERROR;
- return $this->huoError($_code, CommonStatus::getMsg($_code));
- }
- $_rdata['share_id'] = $_rs;
- $_rdata['title'] = $_title;
- $_rdata['image'] = $_image;
- $_rdata['mp_qr'] = $_mp_qr;
- $_rdata['pyq_bg'] = $_pyq_bg;
- $_rdata['state'] = $_state;
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
- }
- /**
- * @param int $share_id 分享ID
- * @param string $to_target 分享对象wx pyq
- * @param string $more 更多信息
- *
- * @return array
- */
- public function upShare($share_id, $to_target, $more = '') {
- $_rs = (new ShareLogic())->updateShareLog($share_id, $to_target, $more);
- if (false === $_rs) {
- $_code = CommonStatus::INNER_ERROR;
- return $this->huoError($_code, CommonStatus::getMsg($_code));
- }
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code));
- }
- /**
- * 获取分享落地页
- *
- * @param string $state 分享者标记信息
- * @param int $game_id 游戏id
- *
- * @return array
- */
- public function getSharePage($state, $game_id) {
- $_parent_ag_id = (new AgentState())->getIdByCode($state);
- $_mem = [
- 'mem_id' => 0,
- 'avatar' => '',
- 'username' => '',
- 'nickname' => ''
- ];
- $_game = [
- 'game_id' => 0,
- 'mini_app_id' => 0,
- 'gamename' => '',
- 'icon' => '',
- 'oneword' => ''
- ];
- if (!empty($_parent_ag_id)) {
- $_ac_class = AgentCache::ins();
- $_parent_agent_id = $_ac_class->getAgentIdByAgId($_parent_ag_id);
- $_parent_mem_id = $_ac_class->getMemIdByAgentId($_parent_agent_id);
- $_mem_data = MemCache::ins()->getInfoById($_parent_mem_id);
- if (!empty($_mem_data)) {
- $_mem = [
- 'mem_id' => $_mem_data['id'],
- 'avatar' => $_mem_data['avatar'],
- 'username' => $_mem_data['username'],
- 'nickname' => $_mem_data['nickname']
- ];
- }
- }
- if (!empty($game_id)) {
- $_game_data = GameCache::ins()->getInfoByAppId($game_id);
- $_game_mini_data = (new GameMiniModel())->getDataByAppId($game_id);
- $_game = [
- 'game_id' => $game_id,
- 'mini_app_id' => empty($_game_mini_data) ? '' : $_game_mini_data['mini_app_id'],
- 'gamename' => empty($_game_data) ? '' : $_game_data['name'],
- 'icon' => empty($_game_data) ? '' : cmf_get_image_preview_url($_game_data['icon']),
- 'oneword' => empty($_game_data) ? '' : $_game_data['publicity'],
- 'url' => empty($_game_data['gv']) ? '' : $_game_data['gv'][0]['package_url']
- ];
- }
- $_rdata = [
- 'mem' => $_mem,
- 'game' => $_game
- ];
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
- }
- /**
- * 获取分享规则图片
- *
- * @param $app_id
- */
- public function getShareRuleImg($app_id) {
- $_game_data = GameCache::ins()->getInfoByAppId($app_id);
- return empty($_game_data['ext_info']['share_rule_img'])
- ? '' : cmf_get_image_preview_url($_game_data['ext_info']['share_rule_img']);
- }
- }
|