| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <?php
- namespace app\api\controller;
- use app\common\model\GameBand;
- use app\common\model\GameInfo;
- use app\common\model\SdkGameList;
- use think\Db;
- use think\Env;
- use think\Request;
- class Game extends Api
- {
- // public function __construct ()
- // {
- // parent::__construct();
- // $this->isApiDebug = true;
- // }
-
- public function _initialize ()
- {
- $this->isApiDebug = true;
- // parent::_initialize(); // TODO: Change the autogenerated stub
- }
-
- public function index()
- {
- $cid = input('cid');
- $channel_id = auth_code(base64_decode($cid), "DECODE", Env::get('auth_key'));
- if (empty($channel_id)) {
- $this->error('渠道参数错误');
- }
- $list = (new SdkGameList())->alias('a')->join('cy_game b', 'a.gameid=b.id')
- ->where(['a.channel_id' => $channel_id, 'a.upload_status' => 1, 'a.package_type' => 0, 'b.cooperation_status' => ['in', [1, 2]]])
- ->order('a.gameid desc')
- ->column('a.filename,a.gameid,b.nickname,b.pinyin,b.type,b.subject,a.filename,a.update_time', 'a.gameid');
- $data = [];
- if ($list) {
- $ids = array_keys($list);
- $gameInfo = (new GameInfo())->alias('a')
- ->join('nw_game_package_upload b','a.game_id=b.game_id','left')
- ->whereIn('a.game_id', $ids)
- ->column('mobileicon,platform,convert((bag_size/1024/1024),decimal(10,2)) as size', 'a.game_id');
- $gameType = Db::name('cy_gametype')->column('name', 'id'); // 类目
- $gameSubject = Db::name('cy_gamesubject')->column('name', 'id'); // 题材
- foreach ($list as $k => $v) {
- $down_url = "";
- if ($v['type'] == 1) {
- $down_url = 'itms-services://?action=download-manifest&url='.getHandleCdnGamesByIds($v['gameid']) . '/sygame/' . $v['pinyin'] . '/' . str_replace(".ipa", ".plist", $v['filename']);
- } elseif ($v['type'] == 2) {
- $down_url = getHandleCdnGamesByIds($v['gameid']) . '/sygame/' . $v['pinyin'] . '/' . $v['filename'];
- } elseif ($v['type'] == 3) {
- $down_url = getChannelH5Url($v['filename'], $v['gameid']);
- }
- $type_str = isset($gameType[$v['type']]) ? $gameType[$v['type']] : '';
- $subject_str = isset($gameSubject[$v['subject']]) ? $gameSubject[$v['subject']] : '';
- $data[] = [
- 'game_id' => $v['gameid'],
- 'game_name' => $v['nickname'],
- 'down_url' => $down_url,
- 'type' => $v['type'],
- 'mobileicon' => isset($gameInfo[$v['gameid']]) ? STATIC_DOMAIN . $gameInfo[$v['gameid']]['mobileicon'] : '',
- 'type_str' => $type_str . '·' . $subject_str,
- 'size' => isset($gameInfo[$v['gameid']]['size']) ? $gameInfo[$v['gameid']]['size'].'MB' : '',
- ];
- }
- }
-
- $this->assign("cid", $cid);
- $this->assign("data", $data);
- return $this->fetch();
- }
- public function detail()
- {
- $game_id = input('gid', 0, 'intval');
- $channel_id = auth_code(base64_decode(input('cid')), "DECODE", Env::get('auth_key'));
- if (empty($game_id)) {
- $this->error('游戏参数错误');
- }
- if (empty($channel_id)) {
- $this->error('渠道参数错误');
- }
- $gameInfo = (new \app\common\model\Game())->table('cy_game g,cy_gameinfo info')->field('g.id as game_id,g.name,g.nickname,info.platform,info.size,g.type,g.subject,info.mobileicon,info.description,info.bigimage,g.create_time,g.pinyin')->where('g.id = info.game_id')->where(['g.id' => $game_id])->find();
- if (!$gameInfo) {
- $this->error('游戏信息不存在');
- }
- $gameBandModel = new GameBand();
- $gameType = Db::name('cy_gametype')->column('name', 'id');
- $gameSubject = Db::name('cy_gamesubject')->column('name', 'id');
- //当前游戏的包名
- $appInfo = (new SdkGameList())->where(['gameid' => $game_id, 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => 0])->find();
- $filename = $appInfo['filename'];
- if ($gameInfo['platform'] == 2) {
- // 安卓游戏
- $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 = (new SdkGameList())->where(['gameid' => $gameBandInfo['id'], 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => 0])->value('filename');
- if (!empty($bandFilename)) {
- $ios_down_url = getHandleCdnGamesByIds($game_id) . '/sygame/' . $gameBandInfo['pinyin'] . '/' . str_replace(".ipa", ".plist", $bandFilename);
- if ($appInfo['update_time'] > 1711596600) {
- }else{
- $ios_down_url = APK_DOWN_DOMAIN . '/sygame/' . $gameBandInfo['pinyin'] . '/' . str_replace(".ipa", ".plist", $bandFilename);
- }
- }
- }
- $android_down_url = (!empty($filename) ? getHandleCdnGamesByIds($game_id) . '/sygame/' . $gameInfo['pinyin'] . '/' . $filename : '');
- } else if ($gameInfo['platform'] == 1) {
- // IOS游戏
- $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 = (new SdkGameList())->where(['gameid' => $gameBandInfo['id'], 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => 0])->value('filename');
- if (!empty($bandFilename)) {
- $android_down_url = getHandleCdnGamesByIds($gameBandInfo['id']) . '/sygame/' . $gameBandInfo['pinyin'] . '/' . $bandFilename;
- }
- }
- $ios_down_url = !empty($filename) ? APK_DOWN_DOMAIN . '/sygame/' . $gameInfo['pinyin'] . '/' . str_replace(".ipa", ".plist", $filename) : '';
- } else if ($gameInfo['platform'] == 3) {
- // H5 游戏
- }
-
- $bigimage = explode(';', $gameInfo['bigimage']);
- $tmp = [];
- foreach ($bigimage as $k => $v) {
- if($v){
- $tmp[] = STATIC_DOMAIN . '/' . $v;
- }
- }
- $data = [
- 'game_id' => $gameInfo['game_id'],
- 'game_name' => $gameInfo['nickname'],
- 'android_down_url' => $android_down_url,
- 'ios_down_url' => $ios_down_url,
- 'mobileicon' => STATIC_DOMAIN . $gameInfo['mobileicon'],
- 'type_str' => isset($gameType[$gameInfo['type']]) ? $gameType[$gameInfo['type']] : '',
- 'subject_str' => isset($gameSubject[$gameInfo['subject']]) ? $gameSubject[$gameInfo['subject']] : '',
- 'size' => $gameInfo['size'],
- 'description' => $gameInfo['description'],
- 'bigimage' => $tmp,
- 'create_time'=>date('Y-m-d',$gameInfo['create_time'])
- ];
- $this->assign("data", $data);
- return $this->fetch();
- }
- /**
- * 获取渠道和游戏信息(不需要效验是因为,前端初始化时候没有游戏信息可以提供,无法效验)
- *
- * @return void
- */
- public function getChannelOrGame(){
- $input = Request::instance()->only([
- 'gameid', // 游戏ID
- 'code', // 分包标识
- 'channel_mark' // 聚合渠道标识
- ]);;
- if(empty($input['gameid'])){
- $this->jsonResult('', -121, '游戏标识为空!');
- }
- $packageInfo = Db::table('nw_game_package_upload')->where(['game_id' => $input['gameid'], 'platform_type' => 3])->field('path, bag_version')->find();
- if(!$packageInfo){
- $this->jsonResult('', -122, '当前游戏原包不存在!(请确认配置)');
- }
- if(!$packageInfo['path']){
- $this->jsonResult('', -122, '当前游戏原包未配置!(请确认配置)');
- }
- $channel_id = 103; // 设置H5默认渠道
- if(!empty($input['code'])){
- $channelInfo = Db::table('cy_sdkgamelist')->where(['gameid' => $input['gameid'], 'filename' => $input['code']])->field('channel_id, status')->find();
- if(!$channelInfo){
- $this->jsonResult('', -122, '当前游戏分包不存在!');
- }
- if(!$channelInfo){
- $this->jsonResult('', -122, '当前游戏分包已禁用!');
- }
- $channel_id = $channelInfo['channel_id'];
- }
- $complexInfo = [
- 'complex_channel_id' => '',
- 'sdk' => '',
- ];
- if(!empty($input['channel_mark'])){
- $complex_channel_id = Db::table('nw_complex_channel')->where(['mark' => $input['channel_mark']])->value('id');
- if(!$complex_channel_id){
- $this->jsonResult('', -122, '没有当前渠道信息!');
- }
- $complexInfo['complex_channel_id'] = $complex_channel_id;
- $complexInfo['sdk'] = sprintf('%s/static/complex_sdk/%s_sdk.js', H5_DOMAIN_URL, $input['channel_mark']);
- }
- $this->jsonResult(['channel_id' => $channel_id, 'game_url' => $packageInfo['path'], 'complex_info' => $complexInfo], 1, 'success');
- }
- // 测试包&物料下载
- public function external(){
- // dump(base64_encode(10));
- // dump(base64_decode('MTA='));
- $code = input('code', '', 'trim');
- if (empty($code)) {
- return "非法操作!";
- }
- $gameId = base64_decode($code);
- if (!preg_match('/^[a-zA-Z0-9=]+$/', $gameId) || $gameId <= 0) {
- return "操作异常!";
- }
- $gameInfo = Db::table('cy_game')->where(['id' => $gameId])->field('name')->where('cooperation_status', '<>', 3)->find();
- if(!$gameInfo){
- return "当前游戏不存在或已下架!";
- }
- $info = Db::table('nw_game_package_test')->where(['game_id' => $gameId, 'status' => 1])->field('name,path_url,material_url,remarks')->find();
- if(!$info){
- return "当前游戏不存在或已关闭!";
- }
- $mobileicon = Db::table('cy_gameinfo')->where(['game_id' => $gameId])->field('mobileicon')->find();
- $info['logo_url'] = 'https://static.qmgames.cn//image/game/icons/2023091416266502c3cc46898.png';
- if($mobileicon['mobileicon']){
- $info['logo_url'] = STATIC_DOMAIN .'/'. $mobileicon['mobileicon'];
- }
- // $info['bg_image'] = "https://s2.loli.net/2025/08/07/OnhgDQSbfmuF31T.jpg";
- // $info['bg_image'] = "https://s2.loli.net/2025/08/07/EdcSnQZhGfMKTFA.jpg";
- $info['bg_image'] = "https://s2.loli.net/2025/08/07/7IQWrjz6vBJMydo.jpg";
- $this->assign("info", $info);
- return $this->fetch();
- }
- }
|