* @version : HUOSDK 7.0 */ namespace huosdk\share; use huosdk\game\Game; use huosdk\game\Gamepack; use think\Config; use think\Db; use think\Loader; use think\Session; class Share { /** * 玩家ID与游戏ID为为空时 表示分享app * * @param int $mem_id * @param int $game_id * * @return string */ public function getGame($mem_id = 0, $game_id = 0) { $_app_id = $game_id; $_mem_id = $mem_id; $cfg_app_congig = Config::get('config.HUOAPP'); if (empty($_mem_id)) { return false; } // $_url = Url::build('wap/Game/read', ['gameid' => $_app_id, 'agentid' => $_mem_agent_id]); // $_url = Config::get('domain.SDKSITE').$_url; // if (in_array($_app_id, $cfg_app_congig)) { //没考虑双端问题 if ($_app_id == $cfg_app_congig['APP_APPID']) {//安卓 //分享app, 则分享每个app的下载地址 $_gp_class = new Gamepack($mem_id); $_url = $_gp_class->getMemAppurl($mem_id); } elseif ($_app_id == $cfg_app_congig['IOS_APP_APPID']) {//ios $_url = SDKSITE."/ios/index.html"; } else { //分享游戏 则分享官方游戏 $_g_class = new Game(); $_url = $_g_class->getDownlink($_app_id); } //生成分享信息 $_title = Db::name('game_info')->where('app_id', $_app_id)->value('publicity'); $_content = Db::name('game_info')->where('app_id', $_app_id)->value('description'); $_share_id = $this->genLog($_mem_id, $_app_id, $_url, $_title, $_content); Loader::import('phpqrcode.phpqrcode'); $object = new \QRcode(); $level = 3; $size = 4; $errorCorrectionLevel = intval($level);//容错级别 $matrixPointSize = intval($size);//生成图片大小 $filename = $_mem_id.".png"; $_path = Config::get('config.UPLOADPATH'); $_savepath = ROOT_SITE_PATH.$_path.$filename; $object->png($_url, $_savepath, $errorCorrectionLevel, $matrixPointSize, 2); $_rdata['shareid'] = $_share_id; $_rdata['title'] = $_title ? $_title : '早游戏'; $_rdata['url'] = $_url; $_rdata['sharetext'] = $_content ? $_content : '早游戏下载地址'; $_rdata['codeurl'] = Config::get('domain.STATICSITE').'/upload/share/'.$filename; // 2017年8月4日23:38:23 wc $_rdata['sharetotal'] = $this->getShareTotal($_mem_id); $_rdata['memcnt'] = $this->getMemShareCnt($_mem_id); // 判断是否分包成功 $_url = 1; if ($_url) { // 获取玩家分享获得的金币数 $_res = Db::name('options')->where(['option_name' => 'mem_share_icon'])->value('option_value'); $_mem_share_data = json_decode($_res, true); $_mem_share_icon = $_mem_share_data['option_value']; // 添加玩家积分 $_mitg_class = new \huosdk\integral\Memitg($_mem_id); $_mitg_class->addbyAction(ITG_SHARE, $_mem_id); } return $_rdata; } /** * 获取玩家分享获得的总金额 */ public function getShareTotal($_mem_id) { $_sharetotal = Db::name('mem_integral_log') ->where(array('mem_id' => $_mem_id)) ->sum('give_integral'); return empty($_sharetotal) ? 0 : ceil(100 * $_sharetotal) / 100; } /** * 获取玩家分享获取的好友数 */ public function getMemShareCnt($_mem_id) { $_memcnt = Db::name('members') ->where(array('parent_mem_id' => $_mem_id)) ->count('id'); return empty($_memcnt) ? 0 : $_memcnt; } /** * 生成分享ID * * @param int $mem_id * @param int $app_id * @param string $url * @param string $title * @param string $content * * @return bool|int|string */ public function genLog($mem_id = 0, $app_id = 0, $url = '', $title = '', $content = '') { $_share_data['mem_id'] = $mem_id; $_share_data['app_id'] = $app_id; $_share_data['imei'] = empty(Session::get('device_id', 'device')) ? '' : Session::get('device_id', 'device'); $_share_data['deviceinfo'] = empty(Session::get('deviceinfo', 'device')) ? '' : Session::get( 'deviceinfo', 'device' ); $_share_data['userua'] = empty(Session::get('userua', 'device')) ? '' : Session::get('userua', 'device'); $_share_data['from'] = empty(Session::get('from', 'device')) ? '' : Session::get('from', 'device'); $_share_data['create_time'] = time(); $_share_data['title'] = empty($title) ? "" : $title; $_share_data['content'] = empty($content) ? "" : $content; $_share_data['url'] = $url; $_id = Db::name('share_log')->insertGetId($_share_data); if (false === $_id) { return false; } return $_id; } public function getList(array $map, $page = 1, $offset = 10) { $_mem_id = Session::get('id', 'user'); if (!$_mem_id) { $_mem_id = Session::get('user.id'); } $_map['parent_mem_id'] = $_mem_id; $_field = [ 'm.id' => 'id', 'FROM_UNIXTIME(m.reg_time)' => 'time', "m.nickname" => 'username', "g.name" => 'gamename' ]; $_join = [ [ Config::get('database.prefix').'game g', 'g.id=m.app_id', 'LEFT' ] ]; $_rdata['count'] = Db::name('members') ->alias('m') ->join($_join) ->where($_map) ->count(); if ($_rdata['count'] > 0) { $_page = $page." , ".$offset; $_list = Db::name('members') ->alias('m') ->field($_field) ->join($_join) ->where($_map) ->order("m.reg_time desc") ->page($_page) ->select(); if (empty($_list)) { $_rdata['list'] = null; } else { $_rdata['list'] = $_list; } } else { $_rdata = null; } return $_rdata; } }