Game.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\GameBand;
  4. use app\common\model\GameInfo;
  5. use app\common\model\SdkGameList;
  6. use think\Db;
  7. use think\Env;
  8. use think\Request;
  9. class Game extends Api
  10. {
  11. // public function __construct ()
  12. // {
  13. // parent::__construct();
  14. // $this->isApiDebug = true;
  15. // }
  16. public function _initialize ()
  17. {
  18. $this->isApiDebug = true;
  19. // parent::_initialize(); // TODO: Change the autogenerated stub
  20. }
  21. public function index()
  22. {
  23. $cid = input('cid');
  24. $channel_id = auth_code(base64_decode($cid), "DECODE", Env::get('auth_key'));
  25. if (empty($channel_id)) {
  26. $this->error('渠道参数错误');
  27. }
  28. $list = (new SdkGameList())->alias('a')->join('cy_game b', 'a.gameid=b.id')
  29. ->where(['a.channel_id' => $channel_id, 'a.upload_status' => 1, 'a.package_type' => 0, 'b.cooperation_status' => ['in', [1, 2]]])
  30. ->order('a.gameid desc')
  31. ->column('a.filename,a.gameid,b.nickname,b.pinyin,b.type,b.subject,a.filename,a.update_time', 'a.gameid');
  32. $data = [];
  33. if ($list) {
  34. $ids = array_keys($list);
  35. $gameInfo = (new GameInfo())->alias('a')
  36. ->join('nw_game_package_upload b','a.game_id=b.game_id','left')
  37. ->whereIn('a.game_id', $ids)
  38. ->column('mobileicon,platform,convert((bag_size/1024/1024),decimal(10,2)) as size', 'a.game_id');
  39. $gameType = Db::name('cy_gametype')->column('name', 'id'); // 类目
  40. $gameSubject = Db::name('cy_gamesubject')->column('name', 'id'); // 题材
  41. foreach ($list as $k => $v) {
  42. $down_url = "";
  43. if ($v['type'] == 1) {
  44. $down_url = 'itms-services://?action=download-manifest&url='.getHandleCdnGamesByIds($v['gameid']) . '/sygame/' . $v['pinyin'] . '/' . str_replace(".ipa", ".plist", $v['filename']);
  45. } elseif ($v['type'] == 2) {
  46. $down_url = getHandleCdnGamesByIds($v['gameid']) . '/sygame/' . $v['pinyin'] . '/' . $v['filename'];
  47. } elseif ($v['type'] == 3) {
  48. $down_url = getChannelH5Url($v['filename'], $v['gameid']);
  49. }
  50. $type_str = isset($gameType[$v['type']]) ? $gameType[$v['type']] : '';
  51. $subject_str = isset($gameSubject[$v['subject']]) ? $gameSubject[$v['subject']] : '';
  52. $data[] = [
  53. 'game_id' => $v['gameid'],
  54. 'game_name' => $v['nickname'],
  55. 'down_url' => $down_url,
  56. 'type' => $v['type'],
  57. 'mobileicon' => isset($gameInfo[$v['gameid']]) ? STATIC_DOMAIN . $gameInfo[$v['gameid']]['mobileicon'] : '',
  58. 'type_str' => $type_str . '·' . $subject_str,
  59. 'size' => isset($gameInfo[$v['gameid']]['size']) ? $gameInfo[$v['gameid']]['size'].'MB' : '',
  60. ];
  61. }
  62. }
  63. $this->assign("cid", $cid);
  64. $this->assign("data", $data);
  65. return $this->fetch();
  66. }
  67. public function detail()
  68. {
  69. $game_id = input('gid', 0, 'intval');
  70. $channel_id = auth_code(base64_decode(input('cid')), "DECODE", Env::get('auth_key'));
  71. if (empty($game_id)) {
  72. $this->error('游戏参数错误');
  73. }
  74. if (empty($channel_id)) {
  75. $this->error('渠道参数错误');
  76. }
  77. $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();
  78. if (!$gameInfo) {
  79. $this->error('游戏信息不存在');
  80. }
  81. $gameBandModel = new GameBand();
  82. $gameType = Db::name('cy_gametype')->column('name', 'id');
  83. $gameSubject = Db::name('cy_gamesubject')->column('name', 'id');
  84. //当前游戏的包名
  85. $appInfo = (new SdkGameList())->where(['gameid' => $game_id, 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => 0])->find();
  86. $filename = $appInfo['filename'];
  87. if ($gameInfo['platform'] == 2) {
  88. // 安卓游戏
  89. $ios_down_url = '';
  90. $gameBandInfo = $gameBandModel->table('nw_game_band b,cy_game g')->field('b.ios_game_id,g.id,g.pinyin')
  91. ->where('b.ios_game_id = g.id')
  92. ->where(['b.android_game_id' => $game_id])->find();
  93. if (!empty($gameBandInfo)) {
  94. //绑定的游戏包名
  95. $bandFilename = (new SdkGameList())->where(['gameid' => $gameBandInfo['id'], 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => 0])->value('filename');
  96. if (!empty($bandFilename)) {
  97. $ios_down_url = getHandleCdnGamesByIds($game_id) . '/sygame/' . $gameBandInfo['pinyin'] . '/' . str_replace(".ipa", ".plist", $bandFilename);
  98. if ($appInfo['update_time'] > 1711596600) {
  99. }else{
  100. $ios_down_url = APK_DOWN_DOMAIN . '/sygame/' . $gameBandInfo['pinyin'] . '/' . str_replace(".ipa", ".plist", $bandFilename);
  101. }
  102. }
  103. }
  104. $android_down_url = (!empty($filename) ? getHandleCdnGamesByIds($game_id) . '/sygame/' . $gameInfo['pinyin'] . '/' . $filename : '');
  105. } else if ($gameInfo['platform'] == 1) {
  106. // IOS游戏
  107. $android_down_url = '';
  108. $gameBandInfo = $gameBandModel->table('nw_game_band b,cy_game g')->field('b.android_game_id,g.id,g.pinyin')
  109. ->where('b.android_game_id = g.id')
  110. ->where(['b.ios_game_id' => $game_id])->find();
  111. if (!empty($gameBandInfo)) {
  112. //绑定的游戏包名
  113. $bandFilename = (new SdkGameList())->where(['gameid' => $gameBandInfo['id'], 'channel_id' => $channel_id, 'upload_status' => 1, 'package_type' => 0])->value('filename');
  114. if (!empty($bandFilename)) {
  115. $android_down_url = getHandleCdnGamesByIds($gameBandInfo['id']) . '/sygame/' . $gameBandInfo['pinyin'] . '/' . $bandFilename;
  116. }
  117. }
  118. $ios_down_url = !empty($filename) ? APK_DOWN_DOMAIN . '/sygame/' . $gameInfo['pinyin'] . '/' . str_replace(".ipa", ".plist", $filename) : '';
  119. } else if ($gameInfo['platform'] == 3) {
  120. // H5 游戏
  121. }
  122. $bigimage = explode(';', $gameInfo['bigimage']);
  123. $tmp = [];
  124. foreach ($bigimage as $k => $v) {
  125. if($v){
  126. $tmp[] = STATIC_DOMAIN . '/' . $v;
  127. }
  128. }
  129. $data = [
  130. 'game_id' => $gameInfo['game_id'],
  131. 'game_name' => $gameInfo['nickname'],
  132. 'android_down_url' => $android_down_url,
  133. 'ios_down_url' => $ios_down_url,
  134. 'mobileicon' => STATIC_DOMAIN . $gameInfo['mobileicon'],
  135. 'type_str' => isset($gameType[$gameInfo['type']]) ? $gameType[$gameInfo['type']] : '',
  136. 'subject_str' => isset($gameSubject[$gameInfo['subject']]) ? $gameSubject[$gameInfo['subject']] : '',
  137. 'size' => $gameInfo['size'],
  138. 'description' => $gameInfo['description'],
  139. 'bigimage' => $tmp,
  140. 'create_time'=>date('Y-m-d',$gameInfo['create_time'])
  141. ];
  142. $this->assign("data", $data);
  143. return $this->fetch();
  144. }
  145. /**
  146. * 获取渠道和游戏信息(不需要效验是因为,前端初始化时候没有游戏信息可以提供,无法效验)
  147. *
  148. * @return void
  149. */
  150. public function getChannelOrGame(){
  151. $input = Request::instance()->only([
  152. 'gameid', // 游戏ID
  153. 'code', // 分包标识
  154. 'channel_mark' // 聚合渠道标识
  155. ]);;
  156. if(empty($input['gameid'])){
  157. $this->jsonResult('', -121, '游戏标识为空!');
  158. }
  159. $packageInfo = Db::table('nw_game_package_upload')->where(['game_id' => $input['gameid'], 'platform_type' => 3])->field('path, bag_version')->find();
  160. if(!$packageInfo){
  161. $this->jsonResult('', -122, '当前游戏原包不存在!(请确认配置)');
  162. }
  163. if(!$packageInfo['path']){
  164. $this->jsonResult('', -122, '当前游戏原包未配置!(请确认配置)');
  165. }
  166. $channel_id = 103; // 设置H5默认渠道
  167. if(!empty($input['code'])){
  168. $channelInfo = Db::table('cy_sdkgamelist')->where(['gameid' => $input['gameid'], 'filename' => $input['code']])->field('channel_id, status')->find();
  169. if(!$channelInfo){
  170. $this->jsonResult('', -122, '当前游戏分包不存在!');
  171. }
  172. if(!$channelInfo){
  173. $this->jsonResult('', -122, '当前游戏分包已禁用!');
  174. }
  175. $channel_id = $channelInfo['channel_id'];
  176. }
  177. $complexInfo = [
  178. 'complex_channel_id' => '',
  179. 'sdk' => '',
  180. ];
  181. if(!empty($input['channel_mark'])){
  182. $complex_channel_id = Db::table('nw_complex_channel')->where(['mark' => $input['channel_mark']])->value('id');
  183. if(!$complex_channel_id){
  184. $this->jsonResult('', -122, '没有当前渠道信息!');
  185. }
  186. $complexInfo['complex_channel_id'] = $complex_channel_id;
  187. $complexInfo['sdk'] = sprintf('%s/static/complex_sdk/%s_sdk.js', H5_DOMAIN_URL, $input['channel_mark']);
  188. }
  189. $this->jsonResult(['channel_id' => $channel_id, 'game_url' => $packageInfo['path'], 'complex_info' => $complexInfo], 1, 'success');
  190. }
  191. // 测试包&物料下载
  192. public function external(){
  193. // dump(base64_encode(10));
  194. // dump(base64_decode('MTA='));
  195. $code = input('code', '', 'trim');
  196. if (empty($code)) {
  197. return "非法操作!";
  198. }
  199. $gameId = base64_decode($code);
  200. if (!preg_match('/^[a-zA-Z0-9=]+$/', $gameId) || $gameId <= 0) {
  201. return "操作异常!";
  202. }
  203. $gameInfo = Db::table('cy_game')->where(['id' => $gameId])->field('name')->where('cooperation_status', '<>', 3)->find();
  204. if(!$gameInfo){
  205. return "当前游戏不存在或已下架!";
  206. }
  207. $info = Db::table('nw_game_package_test')->where(['game_id' => $gameId, 'status' => 1])->field('name,path_url,material_url,remarks')->find();
  208. if(!$info){
  209. return "当前游戏不存在或已关闭!";
  210. }
  211. $mobileicon = Db::table('cy_gameinfo')->where(['game_id' => $gameId])->field('mobileicon')->find();
  212. $info['logo_url'] = 'https://static.qmgames.cn//image/game/icons/2023091416266502c3cc46898.png';
  213. if($mobileicon['mobileicon']){
  214. $info['logo_url'] = STATIC_DOMAIN .'/'. $mobileicon['mobileicon'];
  215. }
  216. // $info['bg_image'] = "https://s2.loli.net/2025/08/07/OnhgDQSbfmuF31T.jpg";
  217. // $info['bg_image'] = "https://s2.loli.net/2025/08/07/EdcSnQZhGfMKTFA.jpg";
  218. $info['bg_image'] = "https://s2.loli.net/2025/08/07/7IQWrjz6vBJMydo.jpg";
  219. $this->assign("info", $info);
  220. return $this->fetch();
  221. }
  222. }