| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\api\controller\v2;
- use app\api\controller\Api;
- use app\common\logic\SubPackage as SubChannel;
- use app\common\model\AndroidSdk;
- use app\common\model\Game;
- use app\common\model\PromotionShortLink;
- use app\common\model\SdkGameList;
- class GameVersion extends Api
- {
- // 游戏版本更新检测
- public function getNew(){
- $channel_version = $this->input('channel_version', ''); // 游戏强更版本号
- $channel_id = $this->input('channel_id', '');
- $game_id = $this->input('gameid', '');
- if ( empty($channel_version) ) {
- $this->jsonResult('', 0, '游戏的强更版本号不能为空');
- }
- $gameModel = new Game;
- $gameInfo = $gameModel->alias('cg')
- ->field('cg.id,cg.name,cg.pinyin,cg.pinyin,cgi.mobileicon as icon,cg.channel_version as game_num,nasc.version as game_version')
- ->join('cy_gameinfo cgi', 'cg.id=cgi.game_id', 'left')
- ->join('nw_android_sdk_config nasc', 'cg.android_sdk_id=nasc.id', 'left')
- ->where(['cg.id' => $game_id])->find();
- if(!$gameInfo){
- $this->jsonResult([], 0, '游戏信息不存在');
- }
- $gameInfo['icon'] = $gameInfo['icon']?STATIC_DOMAIN.$gameInfo['icon']:'';
- $shortModel = new PromotionShortLink;
- $shortInfo = $shortModel->where(['channel_id' => $channel_id, 'game_id' => $game_id])->field('id,short_link')->find();
- $short_link = '';
- if($shortInfo){
- $short_link = $shortInfo['short_link']?T_DOMAIN.'/'.$shortInfo['short_link']:'';
- }
- $sdkGameModel = new SdkGameList;
- $sdkInfo = $sdkGameModel->where(['channel_id' => $channel_id, 'gameid' => $game_id])->field('id,filename,upload_status,channel_version')->find();
- $fileUrl = '';
- if($sdkInfo && isset($sdkInfo['filename'])){
- $fileUrl = APK_DOWN_DOMAIN_NEW.'/sygame/'.$gameInfo['pinyin'].'/'.$sdkInfo['filename'];
- }
- unset($gameInfo['pinyin']);
- $status = 1; // 状态:1=已是最新版本、2=有新包可下载(立即下载)、3=获取最新分包、4=分包更新中(请求中)、5=分包失败(重新提交分包)
- // upload_status:文件状态:0=待处理、1=已处理、2=待审核、3=申请拒绝、4=分包中、5=打包失败、9=已禁用
- if (in_array($sdkInfo['upload_status'], [0, 1, 2, 3, 9]) && $channel_version == $gameInfo['game_num']) {
- $status = 1;
- } elseif ($sdkInfo['upload_status'] == 4) {
- $status = 4;
- } elseif ($sdkInfo['upload_status'] == 5) {
- $status = 5;
- } elseif ($channel_version < $gameInfo['game_num'] && $gameInfo['game_num'] == $sdkInfo['channel_version']) {
- $status = 2;
- } elseif ($channel_version < $gameInfo['game_num'] || $gameInfo['game_num'] < $sdkInfo['channel_version']) {
- $status = 3;
- }
- $this->jsonResult([
- 'game' => $gameInfo,
- 'short_link' => $short_link,
- 'file_url' => $fileUrl,
- 'status' => $status,
- 'channel_version' => $sdkInfo['channel_version']??0,
- ], 1, '');
- }
- // 获取打包
- public function getPackage(){
- $channel_version = $this->input('channel_version', '');
- $channel_id = $this->input('channel_id', '');
- // $device = $this->input('device', '');
- $game_id = $this->input('gameid', '');
- if ( empty($channel_version) ) {
- $this->jsonResult('', 0, '游戏的强更版本号不能为空');
- }
- $gameModel = new Game;
- $gameInfo = $gameModel->where(['id' => $game_id])->find();
- $sdkGameModel = new SdkGameList;
- $sdkInfo = $sdkGameModel->where(['channel_id' => $channel_id, 'gameid' => $game_id])->field('id,filename,upload_status,channel_version')->find();
- if ($sdkInfo && in_array($sdkInfo['upload_status'], [1, 5]) && $channel_version <= $gameInfo['channel_version']) {
- if ($gameInfo['channel_version'] == $sdkInfo['channel_version'] && $sdkInfo['upload_status'] == 1) {
- $this->jsonResult([], 1, '已是最新包,可立即下载!');
- }
- $subChannel = new SubChannel;
- // $platform = $gameInfo['type'] == 1 ? 1 : 0; // 设备类型:1=ios、2=安卓、3=h5
- $res = $subChannel->index($channel_id, $game_id, 'ydd_fb', $gameInfo['type'], 0);
- if ($res['code'] === 0) {
- $sdkGameModel->save(['upload_status' => 4, 'update_time' => time()], ['channel_id' => $channel_id, 'gameid' => $game_id]);
- $this->jsonResult([], 1, '提交成功,稍等重新查看!');
- }else{
- $this->jsonResult([], 0, $res['msg']);
- }
- }
- $this->jsonResult([], 0, '暂无当前游戏包更新!');
- }
- }
|