123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- <?php
- /**
- * Down.php UTF-8
- * IOS 游戏落地页下载游戏
- *
- * @date : 2018/3/24 17:02
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : ouzhongfu <ozf@huosdk.com>
- * @version : HUOSDK 7.2
- * Add by wuyonghong 2018/3/27 2018/3/27 ISSUES:5283 IOS 广告
- */
- namespace api\down\controller;
- use ads\Agent;
- use api\common\controller\V2ApiBaseController;
- use Endroid\QrCode\QrCode;
- use huo\controller\agent\AgentCache;
- use huo\logic\agent\AgentGameLogic;
- use huo\logic\game\GameLogic;
- use huo\model\game\CategoryModel;
- use think\Cookie;
- use think\Exception;
- use think\Log;
- use think\Db;
- class DownController extends V2ApiBaseController {
- function _initialize() {
- parent::_initialize();
- }
- /**
- * ios下载落地页
- * http://doc.1tsdk.com/43?page_id=3012
- *
- * @return mixed
- */
- function index() {
- $_app_id = $this->request->param('app_id/s', 0);
- $_client_id = $this->request->param('client_id/s', 0);
- $_apple_id = $this->request->param('apple_id/s', '');
- $_id_str = $this->request->param('id/s', 0);
- $_game_id = $this->request->param('game_id/d', 0);
- $_lp_id = $this->request->param('lp_id/s', 0); /*landing_page_id 此处缩写为lp_id*/
- if (!empty($_app_id) || !empty($_apple_id)) {
- /* 表示ios中获取cookie */
- return $this->sdkOpen($_app_id, $_client_id, $_apple_id);
- }
- /* Modified by linjiebin BEGIN 2018/4/21 ISSUES:5569 安卓 广告-落地页 */
- $_agent_down_url = '';
- if (!empty($_id_str)) {
- $_agent_game_id = intval(base_convert($_id_str, 36, 10));
- $_agent_game_info = $this->getAgInfo($_agent_game_id);
- if (empty($_agent_game_info)) {
- $this->error('参数错误');
- }
- $_rdata['agent_id']=$_agent_game_info['agent_id'];
- $_ads_agent_class = new Agent();
- $_ads_agent_class->setAgentGameId($_agent_game_id);
- $_ag_code = $_ads_agent_class->genAgentCode();
- $_game_id = $_agent_game_info['app_id'];
- $_agent_down_url = DOWNSITE.$_agent_game_info['package_url'];
- } else {
- $_ag_code = 0;
- }
- $_where = ['id' => $_game_id];
- $_game_info = (new GameLogic())->getDetail($_where);
- $_rdata['ag_code'] = $_ag_code;
- $_rdata['gameid'] = $_game_info['game_id'];
- $_rdata['classify'] = $_game_info['classify'];
- $_rdata['icon'] = $_game_info['icon'];
- $_rdata['gamename'] = $_game_info['gamename'];
- $_rdata['type'] = (new CategoryModel())->getNameByIds($_game_info['type']);
- $_rdata['size'] = $_game_info['size'];
- $_rdata['down_cnt'] = $_game_info['down_cnt'];
- $_rdata['star_cnt'] = $_game_info['star_cnt'];
- $_rdata['hot'] = $_game_info['hot_order'];
- $_rdata['ios_url'] = '';
- $_rdata['and_url'] = '';
- if (3 == $_rdata['classify']) {
- $_rdata['and_url'] = isset($_game_info['down_url']) ? $_game_info['down_url'] : '';
- $_rdata['and_url'] = empty($_agent_down_url) ? $_rdata['and_url'] : $_agent_down_url;
- } else {
- $_rdata['ios_url'] = !empty($_game_info['down_url']) ? $_game_info['down_url'] : '';
- }
- /* END 2018/4/21 ISSUES:5569 */
- $_rdata['gift_cnt'] = $_game_info['gift_cnt'];
- $_rdata['package_name'] = $_game_info['package_name'];
- $_rdata['desc'] = $_game_info['desc'];
- $_rdata['image'] = json_encode($_game_info['image']);
- $_rdata['version'] = $_game_info['version'];
- $_rdata['qr_code'] = $this->getImageUrl($_id_str, $_rdata['icon']);
- $this->assign($_rdata);
- Cookie::set('huoagentcode', $_ag_code);
- /* Modified by guxiannong BEGIN 2018/7/31 ISSUES:5842 买量系统 */
- if (!empty($_agent_game_id)) {
- $_temp_data = $this->getTemp($_agent_game_id);
- if (!empty($_temp_data)) {
- $this->assign("src_url", $_temp_data['src_url']);
- return $this->fetch($_temp_data['access_url']);
- }
- }
- if (!empty($_lp_id)) {
- $_lp_data = $this->getLandpageData($_lp_id);
- $this->assign("src_url", $_lp_data['src_url']);
- return $this->fetch($_lp_data['access_url']);
- }
- /* END 2018/7/31 ISSUES:5842 */
- return $this->fetch();
- }
- /**
- * http://doc.1tsdk.com/43?page_id=3019
- * ios免越狱信任页面
- *
- * @return mixed
- */
- public function trust() {
- $this->assign('embedded_url', DOWNIP.'embedded.mobileprovision');
- return $this->fetch();
- }
- /**
- * 通过
- *
- * @param int $ag_id 渠道游戏ID
- *
- * @return array|bool|false|mixed|\PDOStatement|string|\think\Model
- */
- function getAgInfo($ag_id) {
- if (empty($ag_id)) {
- return '';
- }
- try {
- $_rdata = (new AgentCache())->getAgInfoByAgId($ag_id);
- } catch (Exception $_e) {
- Log::write('getAgentGame error:'.$_e->getMessage(), 'error');
- $_rdata = false;
- }
- return $_rdata;
- }
- /**
- * 游戏中初始化后打开页面
- *
- * @param int $app_id
- * @param int $client_id
- * @param string $apple_id
- */
- public function sdkOpen($app_id = 0, $client_id = 0, $apple_id = '') {
- $_ag_code = Cookie::get('huoagentcode');
- $_ads_agent_class = new Agent();
- $_ag_id = $_ads_agent_class->getIdByCode($_ag_code);
- $_agentgame = '';
- if (!empty($_ag_id)) {
- $_agentgame = (new AgentGameLogic())->getAgentGameById($_ag_id);
- }
- $_rt_string = 'agentgame='.$_agentgame;
- if (!empty($app_id)) {
- $_url = 'h'.DOCDOMAIN.$app_id.$client_id.'://ag?'.$_rt_string;
- } else {
- $_url = 'h'.DOCDOMAIN.$apple_id.'://ag?'.$_rt_string;
- }
- header('Location:'.$_url);
- exit;
- }
- public function getImageUrl($src_ag_id = '', $icon_url = '') {
- $_root_path = CMF_ROOT.'public';
- $_img_path = '/upload/qrcode/'.$src_ag_id.'.png';
- $_destination = $_root_path.$_img_path;
- if (file_exists($_destination)) {
- return STATICSITE.$_img_path;
- }
- $_path = dirname($_destination);
- if (false == is_dir($_path)) {
- mkdir($_path, 0755, true);
- }
- $_url = SDKSITE.'/down/down?id='.$src_ag_id;
- // $_url = url('down/down/index', ['id' => $src_ag_id], false, SDKSITE);
- $qrCode = new QrCode($_url);
- $qrCode->setSize(300);
- $qrCode->setWriterByName('png');
- $qrCode->setMargin(10);
- $qrCode->setEncoding('UTF-8');
- $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
- $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
- $_len = strlen(STATICSITE);
- $_icon_path = substr($icon_url, $_len);
- if (is_file($_root_path.$_icon_path)) {
- $qrCode->setLogoPath($_root_path.$_icon_path);
- }
- $qrCode->setLogoWidth(50);
- $qrCode->setValidateResult(false);
- $qrCode->writeFile($_destination);
- return STATICSITE.$_img_path;
- }
- /* **** 买量相关 start ***** */
- /**
- * 浏览次数统计
- */
- public function visitLog() {
- /*1 获取agent_id跟app_id,ip*/
- $_agent_id = request()->param('agent_id', 0);
- $_app_id = request()->param('app_id', 0);
- $_ip = request()->ip();
- /*2 插入记录表 promotion_visit_log*/
- $_log_data['agent_id'] = $_agent_id;
- $_log_data['app_id'] = $_app_id;
- $_log_data['ip'] = $_ip;
- $_log_data['create_time'] = time();
- $_rs = Db::name('promotion_visit_log')->insert($_log_data);
- /*3 插入每日记录 */
- $_check_map['agent_id'] = $_agent_id;
- $_check_map['app_id'] = $_app_id;
- $_check_map['ip'] = $_ip;
- $_check = Db::name('promotion_visit_log')->where($_check_map)->count();
- /*3.1 查看promotion_day_log中是否有记录*/
- $_day_check_map = array();
- $_day_check_map['agent_id'] = $_agent_id;
- $_day_check_map['app_id'] = $_app_id;
- $_day_check_map['date'] = date('Y-m-d');
- $_day_check = Db::name('promotion_day_log')->where($_day_check_map)->find();
- if (empty($_day_check)) {
- /*3.2 不存在则插入*/
- $_inster_data['agent_id'] = $_agent_id;
- $_inster_data['app_id'] = $_app_id;
- $_inster_data['date'] = date('Y-m-d');
- $_inster_data['visit_cnt'] = 1;
- $_inster_data['distinct_visit_cnt'] = 1;
- $_rrs = Db::name('promotion_day_log')->insert($_inster_data);
- } else {
- if (is_object($_day_check)) {
- $_day_check = $_day_check->toArray();
- }
- /*3.3 存在则修改*/
- if ($_check <= 1) {
- $_day_data['distinct_visit_cnt'] = $_day_check['distinct_visit_cnt'] + 1;
- }
- $_day_data['visit_cnt'] = $_day_check['visit_cnt'] + 1;
- $_rrs = Db::name('promotion_day_log')->where($_day_check_map)->update($_day_data);
- }
- }
- /**
- * 下载次数统计
- */
- public function downLog() {
- /*1 获取agent_id跟app_id,ip*/
- $_agent_id = request()->param('agent_id', 0);
- $_app_id = request()->param('app_id', 0);
- $_ip = request()->ip();
- /*2 插入记录表 promotion_down_log*/
- $_log_data['agent_id'] = $_agent_id;
- $_log_data['app_id'] = $_app_id;
- $_log_data['ip'] = $_ip;
- $_log_data['create_time'] = time();
- $_rs = Db::name('promotion_down_log')->insert($_log_data);
- /*3 插入每日记录 */
- $_check_map = array();
- $_check_map['agent_id'] = $_agent_id;
- $_check_map['app_id'] = $_app_id;
- $_check_map['ip'] = $_ip;
- $_check = Db::name('promotion_down_log')->where($_check_map)->count();
- /*3.1 查看promotion_day_log中是否有记录*/
- $_day_check_map['agent_id'] = $_agent_id;
- $_day_check_map['app_id'] = $_app_id;
- $_day_check_map['date'] = date('Y-m-d');
- $_day_check = Db::name('promotion_day_log')->where($_day_check_map)->find();
- if (empty($_day_check)) {
- /*3.2 不存在则插入*/
- $_inster_data['agent_id'] = $_agent_id;
- $_inster_data['app_id'] = $_app_id;
- $_inster_data['date'] = date('Y-m-d');
- $_inster_data['down_cnt'] = 1;
- $_inster_data['distinct_down_cnt'] = 1;
- $_rrs = Db::name('promotion_day_log')->insert($_inster_data);
- } else {
- if (is_object($_day_check)) {
- $_day_check = $_day_check->toArray();
- }
- /*3.3 存在则修改*/
- if ($_check <= 1) {
- $_day_data['distinct_down_cnt'] = $_day_check['distinct_down_cnt'] + 1;
- }
- $_day_data['down_cnt'] = $_day_check['down_cnt'] + 1;
- $_rrs = Db::name('promotion_day_log')->where($_day_check_map)->update($_day_data);
- }
- }
- /**
- * 获取模板
- *
- * @param $agent_game_id
- *
- * @return array|string
- */
- public function getTemp($agent_game_id) {
- if (empty($agent_game_id)) {
- return '';
- }
- $_ag_map['id'] = $agent_game_id;
- $_agent_game_data = Db::name('agent_game')->where($_ag_map)->find();
- if (empty($_agent_game_data)) {
- return '';
- }
- $_lp_map['agent_id'] = $_agent_game_data['agent_id'];
- $_lp_map['app_id'] = $_agent_game_data['app_id'];
- $_access_url = Db::name('promotion_detail')->where($_lp_map)->value('access_url');
- if (empty($_access_url)) {
- return '';
- }
- $_landing_page_id = Db::name('promotion_detail')->where($_lp_map)->value('landing_page_id');
- if (empty($_landing_page_id)) {
- return '';
- }
- $_src_map['id'] = $_landing_page_id;
- $_glp_data_src_url = Db::name('game_landing_page')->where($_src_map)->value('src_url');
- if (empty($_glp_data_src_url)) {
- return '';
- }
- $_rdata = [
- 'access_url' => "down/".$_access_url."/index",
- 'src_url' => $_glp_data_src_url,
- ];
- return $_rdata;
- }
- /**
- * 获取落地页信息
- *
- * @param int $lp_id
- *
- * @return array|string
- */
- public function getLandpageData($lp_id = 0) {
- if (empty($lp_id)) {
- return '';
- }
- $_src_map['id'] = $lp_id;
- $_glp_data = Db::name('game_landing_page')->where($_src_map)->find();
- if (empty($_glp_data)) {
- return '';
- }
- $_rdata = [
- 'access_url' => "down/".$_glp_data['app_id'].'/'.$_glp_data['id']."/index",
- 'src_url' => $_glp_data['src_url'],
- ];
- return $_rdata;
- }
- /* **** 买量相关 end ***** */
- }
|