| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- <?php
- /**
- * 游戏推广落地页控制器
- *
- */
- namespace app\api\controller;
- use app\common\model\Game;
- use app\common\model\SdkGameList;
- use app\common\model\GameBand;
- use app\common\model\PromotionShortLink;
- use app\common\library\jssdk;
- use think\Controller;
- use think\Db;
- use think\Config;
- class GamePromotion extends Controller
- {
- public function _initialize()
- {
- }
- // 双端推广页
- public function index($mark = ''){
- $shortLinkModel = new PromotionShortLink;
- $short_link = pathinfo($_SERVER['REQUEST_URI'])['filename'];
- if (strpos($short_link, '?')) {
- $short_link = substr($short_link, 0, strpos($short_link, '?'));
- }
- if (mb_strlen($short_link, 'UTF-8') == 8 || isset($mark)) {
- $shortLinkInfo = $shortLinkModel->where(['short_link' => $short_link])->find();
- if (empty($shortLinkInfo)) $this->error('短链接记录不存在');
- $game_id = $shortLinkInfo['game_id'];
- $channel_id = $shortLinkInfo['channel_id'];
- $package_type = $shortLinkInfo['package_type'];
- } else {
- $game_id = input('game_id', 0, 'intval');
- $channel_id = input('channel_id', 0, 'intval');
- $package_type = input('package_type', 0, 'intval');
- }
- if (empty($game_id)) {
- $this->error('游戏参数错误');
- }
- if (empty($channel_id)) {
- $this->error('渠道参数错误');
- }
- // 游戏详情
- $gameInfo = Db::table('cy_game')->alias('g')
- ->join('cy_gameinfo info', 'g.id=info.game_id', 'left')
- ->join('nw_android_sdk_config nasc', 'g.android_sdk_id=nasc.id', 'left')
- ->field('g.id as game_id, g.type, g.name, g.cooperation_status, g.pinyin, info.mobileicon as logo_img, info.landing_img, info.landing_page_status, nasc.version')
- ->where(['g.id' => $game_id])->find();
- if (empty($gameInfo)) {
- $this->error('游戏信息不存在!');
- }
- if (!empty($gameInfo['cooperation_status']) && $gameInfo['cooperation_status'] != 1) {
- if($gameInfo['cooperation_status'] == 3){
- $this->error('当前游戏已下架!');
- }
- if($gameInfo['cooperation_status'] != 1){
- $this->error('当前游戏未上线!');
- }
- }
- $gameName = cleanGameName($gameInfo['name'])??'';
- $landing_page_msg = "{$gameName} · {$gameInfo['version']} · 杭州祈点信息技术有限公司";
- // 游戏推广数据
- $gameData = [
- 'game_id' => $game_id, // 游戏ID
- 'channel_id' => $channel_id, // 渠道ID
- 'game_name' => $gameName, // 游戏名称
- 'game_type' => $gameInfo['type'], // 游戏类型:1=ios、2=安卓、3=h5
- // 'logo_img' => STATIC_DOMAIN . "/favicon.ico", // 游戏图标
- 'landing_page_status' => $gameInfo['landing_page_status'], // 落地页状态开关:1=开启、2=关闭
- 'landing_page_msg' => $landing_page_msg, // 落地页状态内容
- 'user_agreement' => T_DOMAIN."/user_agreement.html", // 用户协议
- 'game_privacy' => T_DOMAIN."/game_privacy.html", // 隐私协议
- 'landing_img' => 'https://t.qmgames.cn/static/images/test_bg.png', // 落地页背景图
- // 'landing_img' => 'http://static.qmgames.cn//image/game/landing/20250723162068809b3725435.png', // 落地页背景图
- // 'landing_img' => 'http://sdkapi.newsdk.com/static/game_img.jpg', // 落地页背景图
- // 安卓下载地址
- 'android_info' => [
- 'down_url' => '', // 包下载地址
- 'result_status' => 3, // 状态:1=正常,2=游戏问题,3=分包问题、4=程序异常
- 'result_msg' => '没有当前 安卓游戏 分包!', // 说明
- ],
- // IOS下载地址
- 'ios_info' => [
- 'down_url' => '', // 包下载地址
- 'result_status' => 3, // 状态:1=正常,2=游戏问题,3=分包问题、4=程序异常
- 'result_msg' => '没有当前 IOS游戏 分包!', // 说明
- ],
- // H5下载地址
- 'h5_info' => [
- 'down_url' => '', // 包下载地址
- 'result_status' => 3, // 状态:1=正常,2=游戏问题,3=分包问题、4=程序异常
- 'result_msg' => '没有当前 H5游戏 分包!', // 说明
- ],
- ];
- if(!empty($gameInfo['logo_img'])){
- $gameData['logo_img'] = STATIC_DOMAIN . '/' . $gameInfo['logo_img'];
- }
- if(!empty($gameInfo['landing_img'])){
- $gameData['landing_img'] = STATIC_DOMAIN . $gameInfo['landing_img'];
- }
- // 根据游戏ID 和类型,查询双端推广页
- $bandWhere = [];
- if($gameInfo['type'] == 1){
- $bandWhere['ios_game_id'] = $gameInfo['game_id'];
- } else if ($gameInfo['type'] == 2) {
- $bandWhere['android_game_id'] = $gameInfo['game_id'];
- } else if ($gameInfo['type'] == 3) {
- $bandWhere['h5_game_id'] = $gameInfo['game_id'];
- }
- $gameBandInfo = Db::table('nw_game_band')->where($bandWhere)->field('id,android_game_id,ios_game_id,h5_game_id')->find();
- // 判断游戏是否是H5,不是H5则查询双端
- $gameIds = [];
- if($gameInfo['type'] == 3){
- $gameIds[] = $gameInfo['game_id'];
- }else{
- if(!empty($gameBandInfo['android_game_id'])){
- $gameIds[] = $gameBandInfo['android_game_id'];
- }
- if(!empty($gameBandInfo['ios_game_id'])){
- $gameIds[] = $gameBandInfo['ios_game_id'];
- }
- // if(!empty($gameBandInfo['h5_game_id'])){
- // $gameIds[] = $gameBandInfo['h5_game_id'];
- // }
- }
- $appInfo = Db::table('cy_sdkgamelist')->alias('cs')
- ->join('cy_game cg', "cs.gameid = cg.id", 'left')
- ->where(['cs.gameid' => ['in', $gameIds], 'cs.channel_id' => $channel_id])->field('cs.gameid,cs.filename,cs.upload_status,cs.status, cg.type,cg.pinyin,cg.cooperation_status')->select();
- if(!$appInfo){
- $gameData['result_status'] = 2;
- $gameData['result_msg'] = '当前游戏没有包数据,请联系上级确认!';
- }
- foreach($appInfo as $v){
- if($v['type'] == 1){
- $gamePageInfo = $this->getGamePackInfo($v);
- if($gamePageInfo['result_status'] === 1){
- $gamePageInfo['down_url'] = getHandleCdnGamesByIds($v['gameid']) . '/sygame/' . $v['pinyin'] . '/' . str_replace(".ipa", ".plist", $v['filename']);
- }
- $gameData['ios_info'] = $gamePageInfo;
- } else if($v['type'] == 2){
- $gamePageInfo = $this->getGamePackInfo($v);
- if($gamePageInfo['result_status'] === 1){
- $gamePageInfo['down_url'] = getHandleCdnGamesByIds($v['gameid']) . '/sygame/' . $v['pinyin'] . '/' . $v['filename'];
- }
- $gameData['android_info'] = $gamePageInfo;
- } else if($v['type'] == 3){
- $gamePageInfo = $this->getGamePackInfo($v);
- if($gamePageInfo['result_status'] === 1){
- $gamePageInfo['down_url'] = getChannelH5Url($v['filename'], $v['gameid']);
- }
- $gameData['h5_info'] = $gamePageInfo;
- }
- }
- $this->assign('gameData', $gameData);
- return $this->fetch();
- }
- // 游戏&游戏包 状态判断
- private function getGamePackInfo($info){
- $result = [
- 'result_status' => 1, // 状态:1=正常,2=游戏问题,3=分包问题、4=程序异常
- 'result_msg' => '', // 说明
- 'down_url' => '', // 包下载地址
- ];
- // ## 判断游戏是否正常
- // if(empty($info['cooperation_status'])){
- // $result['result_status'] = 2;
- // $result['result_msg'] = '当前游戏没有相关包,请联系上级确认!';
- // } else
- if ($info['cooperation_status'] == 3) {
- $result['result_status'] = 2;
- $result['result_msg'] = '当前游戏已下架!';
- } else
- // if ($info['cooperation_status'] != 1) {
- // $result['result_status'] = 2;
- // $result['result_msg'] = '当前游戏未开放,请联系商务确认!';
- // }
- // ## 判断游戏包是否正常
- if($info['status'] != 1){
- $result['result_status'] = 3;
- $result['result_msg'] = '当前 游戏包已禁用,请联系商务!';
- }
- switch ($info['upload_status']){
- case 1:
- // 游戏包正常
- break;
- case 4:
- $result['result_status'] = 3;
- $result['result_msg'] = '游戏正在打包中,请稍后重试...';
- break;
- case 5:
- $result['result_status'] = 3;
- $result['result_msg'] = '游戏包 打包失败,请联系商务!';
- break;
- case 9:
- $result['result_status'] = 3;
- $result['result_msg'] = '当前 游戏包已禁用,请联系商务!';
- break;
- default:
- $result['result_status'] = 3;
- $result['result_msg'] = '游戏包 异常,请联系商务!';
- }
- // ## 游戏包下载地址
- if(!$info['filename']){
- $result['result_status'] = 3;
- $result['result_msg'] = '当前游戏 未打包 或 打包异常,请联系商务确认!';
- }
- return $result;
- }
- /**
- * 推广落地页
- */
- public function indexOld($mark = '')
- {
- $sdkGameListModel = new SdkGameList;
- $shortLinkModel = new PromotionShortLink;
- $short_link = pathinfo($_SERVER['REQUEST_URI'])['filename'];
- if (strpos($short_link, '?')) {
- $short_link = substr($short_link, 0, strpos($short_link, '?'));
- }
- if (mb_strlen($short_link, 'UTF-8') == 8 || isset($mark)) {
- $shortLinkInfo = $shortLinkModel->where(['short_link' => $short_link])->find();
- if (empty($shortLinkInfo)) $this->error('短链接记录不存在');
- $game_id = $shortLinkInfo['game_id'];
- $channel_id = $shortLinkInfo['channel_id'];
- $package_type = $shortLinkInfo['package_type'];
- } else {
- $game_id = input('game_id', 0, 'intval');
- $channel_id = input('channel_id', 0, 'intval');
- $package_type = input('package_type', 0, 'intval');
- }
- if (empty($game_id)) {
- $this->error('游戏参数错误');
- }
- if (empty($channel_id)) {
- $this->error('渠道参数错误');
- }
- // 游戏详情
- $gameInfo = (new Game)->alias('g')->join('cy_gameinfo info', 'g.id=info.game_id', 'left')
- ->field('g.id as game_id, g.type, g.name, g.cooperation_status, g.pinyin, info.mobileicon as logo_img, info.title_img, info.landing_img')
- ->where(['g.id' => $game_id])->find();
- if (empty($gameInfo)) {
- $this->error('游戏信息不存在!');
- }
- if (!empty($gameInfo['cooperation_status']) && $gameInfo['cooperation_status'] != 1) {
- if($gameInfo['cooperation_status'] == 3){
- $this->error('当前游戏已下架!');
- }
- if($gameInfo['cooperation_status'] != 1){
- $this->error('当前游戏未上线!');
- }
- }
- if(!empty($gameInfo['logo_img'])){
- $gameInfo['logo_img'] = STATIC_DOMAIN . '/' . $gameInfo['logo_img'];
- }else{
- $gameInfo['logo_img'] = STATIC_DOMAIN . "/favicon.ico";
- }
- if(!empty($gameInfo['title_img'])){
- $gameInfo['title_img'] = $gameInfo['title_img'];
- }
- if(!empty($gameInfo['landing_img'])){
- $gameInfo['landing_img'] = STATIC_DOMAIN . '/' . $gameInfo['landing_img'];
- }
- // 分包详情
- $appInfo = $sdkGameListModel->where(['gameid' => $game_id, 'channel_id' => $channel_id, 'package_type' => $package_type])->field('filename,upload_status,status')->find();
- if (empty($appInfo)) {
- $this->error('当前 游戏包不存在!');
- }
- if($appInfo['status'] != 1){
- $this->error('当前 游戏包已禁用,请联系商务!');
- }
- switch ($appInfo['upload_status']){
- case 1:
- // 游戏包正常
- break;
- case 4:
- $this->error('游戏包 正在打包中,请稍后重试!');
- break;
- case 5:
- $this->error('游戏包 打包失败,请联系商务!');
- break;
- case 9:
- $this->error('游戏包 已禁用!');
- break;
- default:
- $this->error('游戏包 异常,请联系商务!');
- }
- // 下载地址
- $downUrl = getHandleCdnGamesByIds($game_id) . '/sygame/' . $gameInfo['pinyin'] . '/' . $appInfo['filename'];
- if($gameInfo['type'] == 1){
- $downUrl = "itms-services://?action=download-manifest&url=" . str_replace(".ipa", ".plist", $downUrl);
- }else if($gameInfo['type'] == 2){
- $downUrl = getHandleCdnGamesByIds($game_id) . '/sygame/' . $gameInfo['pinyin'] . '/' . $appInfo['filename'];
- }else if($gameInfo['type'] == 3){
- $downUrl = getChannelH5Url($appInfo['filename'], $game_id);
- }
- if(!$downUrl){
- $this->error('游戏打包异常,请确认相关配置以及分包情况!');
- }
- $gameInfo['down_url'] = $downUrl;
- $this->assign('gameInfo', $gameInfo);
- return $this->fetch();
- }
- /**
- * IOS
- *
- * @return mixed
- */
- public function ios()
- {
- $sdkGameListModel = new SdkGameList;
- $shortLinkModel = new PromotionShortLink;
- $short_link = pathinfo($_SERVER['REQUEST_URI'])['filename'];
- if (strpos($short_link, '?')) {
- $short_link = substr($short_link, 0, strpos($short_link, '?'));
- }
- if (mb_strlen($short_link, 'UTF-8') == 8) {
- $shortLinkInfo = $shortLinkModel->where(['short_link' => $short_link])->find();
- if (empty($shortLinkInfo)) $this->error('短链接记录不存在');
- $game_id = $shortLinkInfo['game_id'];
- $channel_id = $shortLinkInfo['channel_id'];
- $package_type = $shortLinkInfo['package_type'];
- } else {
- $game_id = input('game_id', 0, 'intval');
- $channel_id = input('channel_id', 0, 'intval');
- $package_type = input('package_type', 0, 'intval');
- }
- if (empty($game_id)) {
- $this->error('游戏参数错误');
- }
- if (empty($channel_id)) {
- $this->error('渠道参数错误');
- }
- $isWeixin = $this->isWeixin();
- $signPackage = false;
- if ($isWeixin) {
- $jssdk = new jssdk(Config::get('wx_jssdk')['appid'], Config::get('wx_jssdk')['appsecret']);
- $signPackage = $jssdk->getSignPackage();
- if (empty($signPackage)) {
- $this->error($jssdk->getError());
- }
- }
- //$gamePromotionModel = Db::name('nw_game_promotion');
- $gameModel = new Game;
- $gameBandModel = new GameBand;
- //$promotionInfo = $gamePromotionModel->field('background_image,background_color_image,title_image,specific_show,specific_title_image,specific_image')->where(['game_id'=>$game_id])->find();
- /*if(empty($promotionInfo)){
- $this->error('推广信息还未配置');
- }*/
- $gameInfo = $gameModel->table('cy_game g,cy_gameinfo info')
- ->field('g.id as game_id,g.name,g.nickname,g.image,g.pinyin,g.publicity,info.mobileicon,info.bigimage,info.video,info.video_image,info.platform,info.drawingImg,info.landing_img,info.title_img,info.new_back_img')->where('g.id = info.game_id')->where(['g.id' => $game_id])->find();
- if (empty($gameInfo)) {
- $this->error('游戏信息不存在');
- }
- //当前游戏的包名
- $filename = $sdkGameListModel->where(['gameid' => $game_id, 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => $package_type])->value('filename');
- $out_img = [];
- if ($gameInfo['bigimage']) {
- $bigimage_list = explode(';', $gameInfo['bigimage']);
- if ($gameInfo['drawingImg']) {
- $draw_list = json_decode($gameInfo['drawingImg'], 1);
- unset($gameInfo['drawingImg']);
- }
- foreach ($bigimage_list as $key => $value) {
- $out_img[$key]['backimg'] = $bigimage_list[$key];
- $out_img[$key]['drawimg'] = isset($draw_list[$key]) ? $draw_list[$key] : '';
- }
- } else {
- $bigimage_list = '';
- }
- //默认
- if (!$gameInfo['video_image']) {
- $gameInfo['video_image'] = 'image/game/videoImg/2020091114135f5b159963833.png';
- }
- //$this->assign('promotionInfo', $promotionInfo);
- $this->assign('gameInfo', $gameInfo);
- $this->assign('bigimage_list', $out_img); //游戏截图
- //安卓游戏
- if ($gameInfo['platform'] == 0) {
- $ios_down_url = '';
- $gameBandInfo = $gameBandModel->table('nw_game_band b,cy_game g')->field('b.ios_game_id,g.id,g.pinyin')
- ->where('b.ios_game_id = g.id')
- ->where(['b.android_game_id' => $game_id])->find();
- if (!empty($gameBandInfo)) {
- //绑定的游戏包名
- $bandFilename = $sdkGameListModel->where(['gameid' => $gameBandInfo['id'], 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => 0])->value('filename');
- if (!empty($bandFilename)) {
- $ios_down_url = APK_DOWN_DOMAIN . '/sygame/' . $gameBandInfo['pinyin'] . '/' . str_replace(".ipa", ".plist", $bandFilename);
- }
- }
- $this->assign('android_down_url', (!empty($filename) ? APK_DOWN_DOMAIN . '/sygame/' . $gameInfo['pinyin'] . '/' . $filename : ''));
- $this->assign('ios_down_url', $ios_down_url);
- // 获取当前游戏的title_image 落地页背景图片 back_img 游戏图标
- $this->assign("title_image", $gameInfo['title_image'] ?: null);
- $this->assign("back_img", $gameInfo['new_back_img'] ?: null);
- } //IOS游戏
- else {
- $android_down_url = '';
- $gameBandInfo = $gameBandModel->table('nw_game_band b,cy_game g')->field('b.android_game_id,g.id,g.pinyin')
- ->where('b.android_game_id = g.id')
- ->where(['b.ios_game_id' => $game_id])->find();
- if (!empty($gameBandInfo)) {
- //绑定的游戏包名
- $bandFilename = $sdkGameListModel->where(['gameid' => $gameBandInfo['id'], 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => 0])->value('filename');
- if (!empty($bandFilename)) {
- $android_down_url = APK_DOWN_DOMAIN . '/sygame/' . $gameBandInfo['pinyin'] . '/' . $bandFilename;
- }
- }
- $this->assign('android_down_url', $android_down_url);
- $this->assign('ios_down_url', (!empty($filename) ? APK_DOWN_DOMAIN . '/sygame/' . $gameInfo['pinyin'] . '/' . str_replace(".ipa", ".plist", $filename) : ''));
- // 获取当前游戏的title_image 落地页背景图片 back_img 游戏图标
- $this->assign("title_image", $gameInfo['title_image'] ?: null);
- $this->assign("back_img", $gameInfo['new_back_img'] ?: null);
- }
- return $this->fetch();
- }
- /**
- * 是否是通过微信访问
- *
- * @return boolean
- */
- function isWeixin()
- {
- if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
- return true;
- }
- return false;
- }
- public function abc()
- {
- return $this->fetch();
- }
- public function wlxx()
- {
- return $this->fetch();
- }
- /**
- * 微信中安卓游戏包下载
- *
- *//*
- public function download() {
-
- $android_down_url = input('android_down_url');
-
- if ( empty($android_down_url) ) {
- exit('参数不正确');
- }
-
- $header = get_headers($android_down_url, true);
-
- if ( strpos($header[0], '200') === false ) {
- $android_down_url = '';
- }
-
- if ( empty($android_down_url) ) {
- exit('下载文件不存在');
- }
-
- $name = basename($android_down_url);
-
- header("Content-Type: application/zip");
- header("Content-Length: " . $header['Content-Length']);
- header("Content-Disposition: attachment; filename=\"{$name}\"");
- header('Content-Transfer-Encoding: binary');
- header("Expires: 0");
- header("Cache-control: private");
- header("Pragma: no-cache");
- readfile($android_down_url);
- exit;
- }*/
- }
|