CheckUpdate.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * 检测客户端游戏更新
  4. */
  5. namespace app\api\controller\v1;
  6. use app\api\controller\Api;
  7. use app\common\model\SdkGameList;
  8. use app\common\model\Game;
  9. class CheckUpdate extends Api
  10. {
  11. protected $sdkGameListModel;
  12. protected $gameModel;
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. $this->sdkGameListModel = new SdkGameList;
  17. $this->gameModel = new Game;
  18. }
  19. /**
  20. * IOS-热更新
  21. */
  22. public function checkClientUpdate()
  23. {
  24. $gameId = $this->input('gameid'); //游戏ID
  25. $channelId = $this->input('channel_id'); //渠道ID
  26. $channelVersion = $this->input('channel_version'); // 游戏版本构造号
  27. $checkResult = $this->validate($this->input,
  28. [
  29. ['gameid', 'require|integer', '游戏id不能为空|游戏ID必须为整型'],
  30. ['channel_id', 'require|integer', '渠道ID不能为空|渠道ID必须为整型'],
  31. ['channel_version', 'require|integer|egt:0', '游戏版本构造号不能为空|游戏版本构造号必须为整型|游戏版本构造号必须为大于等于0的整型'],
  32. ]);
  33. if (true !== $checkResult) {
  34. $this->jsonResult('', 0, $checkResult);
  35. }
  36. $where =[
  37. 'gameid' => $gameId,
  38. 'channel_id' => $channelId,
  39. 'upload_status' => 1
  40. ];
  41. $sdkgameInfo = $this->sdkGameListModel->where($where)->field('filename, channel_version')->find();
  42. $gameInfo = $this->gameModel->where(['id' => $gameId])->field('channel_version, pinyin')->find();
  43. $short_link = '';
  44. $update = false;
  45. if($channelVersion < $gameInfo['channel_version'] && $sdkgameInfo['channel_version'] >= $gameInfo['channel_version']){
  46. $short_link = db('nw_promotion_short_link')->where(['game_id'=>$gameId,'channel_id'=>$channelId,'package_type'=>0, 'type' => 1])->value('short_link');
  47. if (!empty($short_link)) {
  48. $short_link = T_DOMAIN.'/'.$short_link;
  49. $update = true;
  50. }
  51. }
  52. $data = [
  53. 'status' => $update,
  54. 'url' => $short_link,
  55. ];
  56. $this->jsonResult($data , 1, '请求成功!');
  57. }
  58. /**
  59. * 安卓sdk版本(热更)
  60. */
  61. public function version()
  62. {
  63. $sdkModel = model('common/AndroidSdk');
  64. $sdkInfo = $sdkModel->getLastVersionInfo();
  65. if (! empty($sdkInfo)) {
  66. $sdkInfo['status'] = true; // 默认需要强更
  67. $sdkInfo['filename'] = STATIC_DOMAIN.$sdkInfo['filename'];
  68. $this->jsonResult($sdkInfo, 1);
  69. } else {
  70. $this->jsonResult([], 0, '版本不存在');
  71. }
  72. }
  73. public function setting(){
  74. $this->jsonResult([], 0, '获取成功');
  75. }
  76. }