upgrade/application/api/controller/Ver.php

86 lines
2.9 KiB
PHP

<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
use think\Cache;
/**
* 首页接口
*/
class Ver extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$this->model = model('Version');
}
public function index()
{
$base_url = Config::get('app_base_url');
$site = Config::get("site");
$num = !empty($site['version_list_num']) ? intval($site['version_list_num']) : 0;
$sys = $this->request->get("sys", '');
$oem = $this->request->get("oem", '');
$cpu = $this->request->get("cpu", '');
$app = $this->request->get("app", '');
if(empty($app)){
$this->success('参数错误', [], 0);
}
$dev_type = $this->request->get("dev_type", '');
$key = 'version_last';
$reqKey = md5($sys . $oem . $cpu . $app . $dev_type);
$redis = getRedis();
$rt = $redis->hget($key, $reqKey);
$data = [];
if(empty($rt)){
if(!empty($sys) && $sys != '')
$this->model = $this->model->where('sys', '=', $sys);
if(!empty($oem) && $oem != '')
$this->model = $this->model->where('oem', '=', $oem);
if(!empty($cpu) && $cpu != '')
$this->model = $this->model->where('cpu', '=', $cpu);
if(!empty($app) && $app != '')
$this->model = $this->model->where('app', '=', $app);
if(!empty($dev_type) && $dev_type != '')
$this->model = $this->model->where('dev_type', '=', $dev_type);
//查询最新版本
$list = collection($this->model->order('id','desc')->limit($num)->field('version,size,content,downloadurl,md5,bug')->select())->toArray();
if(!empty($list)){
foreach($list as $v){
$data[] = [
'full' => $base_url . $v['downloadurl'],
'size' => $v['size'],
'desc' => $v['content'] ?? '',
'bug' => $v['bug'] ?? '',
'md5' => $v['md5'] ?? '',
'v' => $v['version'] ?? ''
];
}
}
$redis->hset($key, $reqKey, json_encode($data));
}else{
$data = json_decode($rt, true);
}
$this->success('返回成功', $data);
}
//上报开关
public function setting(){
$data = [];
$report_switch = intval(config('site.report_switch'));
$collapse_switch = intval(config('site.collapse_switch'));
$device_info_switch = intval(config('site.device_info_switch'));
$data = ['report_switch' => $report_switch, 'collapse_switch' => $collapse_switch, 'device_info_switch' => $device_info_switch];
$this->success('返回成功', $data);
}
}