GameVersion.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\api\controller\v2;
  3. use app\api\controller\Api;
  4. use app\common\logic\SubPackage as SubChannel;
  5. use app\common\model\AndroidSdk;
  6. use app\common\model\Game;
  7. use app\common\model\PromotionShortLink;
  8. use app\common\model\SdkGameList;
  9. class GameVersion extends Api
  10. {
  11. // 游戏版本更新检测
  12. public function getNew(){
  13. $channel_version = $this->input('channel_version', ''); // 游戏强更版本号
  14. $channel_id = $this->input('channel_id', '');
  15. $game_id = $this->input('gameid', '');
  16. if ( empty($channel_version) ) {
  17. $this->jsonResult('', 0, '游戏的强更版本号不能为空');
  18. }
  19. $gameModel = new Game;
  20. $gameInfo = $gameModel->alias('cg')
  21. ->field('cg.id,cg.name,cg.pinyin,cg.pinyin,cgi.mobileicon as icon,cg.channel_version as game_num,nasc.version as game_version')
  22. ->join('cy_gameinfo cgi', 'cg.id=cgi.game_id', 'left')
  23. ->join('nw_android_sdk_config nasc', 'cg.android_sdk_id=nasc.id', 'left')
  24. ->where(['cg.id' => $game_id])->find();
  25. if(!$gameInfo){
  26. $this->jsonResult([], 0, '游戏信息不存在');
  27. }
  28. $gameInfo['icon'] = $gameInfo['icon']?STATIC_DOMAIN.$gameInfo['icon']:'';
  29. $shortModel = new PromotionShortLink;
  30. $shortInfo = $shortModel->where(['channel_id' => $channel_id, 'game_id' => $game_id])->field('id,short_link')->find();
  31. $short_link = '';
  32. if($shortInfo){
  33. $short_link = $shortInfo['short_link']?T_DOMAIN.'/'.$shortInfo['short_link']:'';
  34. }
  35. $sdkGameModel = new SdkGameList;
  36. $sdkInfo = $sdkGameModel->where(['channel_id' => $channel_id, 'gameid' => $game_id])->field('id,filename,upload_status,channel_version')->find();
  37. $fileUrl = '';
  38. if($sdkInfo && isset($sdkInfo['filename'])){
  39. $fileUrl = APK_DOWN_DOMAIN_NEW.'/sygame/'.$gameInfo['pinyin'].'/'.$sdkInfo['filename'];
  40. }
  41. unset($gameInfo['pinyin']);
  42. $status = 1; // 状态:1=已是最新版本、2=有新包可下载(立即下载)、3=获取最新分包、4=分包更新中(请求中)、5=分包失败(重新提交分包)
  43. // upload_status:文件状态:0=待处理、1=已处理、2=待审核、3=申请拒绝、4=分包中、5=打包失败、9=已禁用
  44. if (in_array($sdkInfo['upload_status'], [0, 1, 2, 3, 9]) && $channel_version == $gameInfo['game_num']) {
  45. $status = 1;
  46. } elseif ($sdkInfo['upload_status'] == 4) {
  47. $status = 4;
  48. } elseif ($sdkInfo['upload_status'] == 5) {
  49. $status = 5;
  50. } elseif ($channel_version < $gameInfo['game_num'] && $gameInfo['game_num'] == $sdkInfo['channel_version']) {
  51. $status = 2;
  52. } elseif ($channel_version < $gameInfo['game_num'] || $gameInfo['game_num'] < $sdkInfo['channel_version']) {
  53. $status = 3;
  54. }
  55. $this->jsonResult([
  56. 'game' => $gameInfo,
  57. 'short_link' => $short_link,
  58. 'file_url' => $fileUrl,
  59. 'status' => $status,
  60. 'channel_version' => $sdkInfo['channel_version']??0,
  61. ], 1, '');
  62. }
  63. // 获取打包
  64. public function getPackage(){
  65. $channel_version = $this->input('channel_version', '');
  66. $channel_id = $this->input('channel_id', '');
  67. // $device = $this->input('device', '');
  68. $game_id = $this->input('gameid', '');
  69. if ( empty($channel_version) ) {
  70. $this->jsonResult('', 0, '游戏的强更版本号不能为空');
  71. }
  72. $gameModel = new Game;
  73. $gameInfo = $gameModel->where(['id' => $game_id])->find();
  74. $sdkGameModel = new SdkGameList;
  75. $sdkInfo = $sdkGameModel->where(['channel_id' => $channel_id, 'gameid' => $game_id])->field('id,filename,upload_status,channel_version')->find();
  76. if ($sdkInfo && in_array($sdkInfo['upload_status'], [1, 5]) && $channel_version <= $gameInfo['channel_version']) {
  77. if ($gameInfo['channel_version'] == $sdkInfo['channel_version'] && $sdkInfo['upload_status'] == 1) {
  78. $this->jsonResult([], 1, '已是最新包,可立即下载!');
  79. }
  80. $subChannel = new SubChannel;
  81. // $platform = $gameInfo['type'] == 1 ? 1 : 0; // 设备类型:1=ios、2=安卓、3=h5
  82. $res = $subChannel->index($channel_id, $game_id, 'ydd_fb', $gameInfo['type'], 0);
  83. if ($res['code'] === 0) {
  84. $sdkGameModel->save(['upload_status' => 4, 'update_time' => time()], ['channel_id' => $channel_id, 'gameid' => $game_id]);
  85. $this->jsonResult([], 1, '提交成功,稍等重新查看!');
  86. }else{
  87. $this->jsonResult([], 0, $res['msg']);
  88. }
  89. }
  90. $this->jsonResult([], 0, '暂无当前游戏包更新!');
  91. }
  92. }