更新判断

This commit is contained in:
shengchanzhe 2023-12-21 16:40:13 +08:00
parent 5940e5c6b6
commit a63a444cb7

View File

@ -1543,49 +1543,25 @@ class Auth extends BaseController
//获取app版本更新信息
public function appVersion()
{
$brandArray = [
'huawei',
'honor',
'iphone',
'samsung',
'xiaomi',
'redmi',
'mi',
'oppo',
'vivo',
'nokia',
'meizu',
'moto'
];
Log::info("请求版本参数:" . json_encode(request()->param()));
$type = $this->request->param('type', '-1');
$version = $this->request->param('version', '');
$phoneBrand = $this->request->param('phone_brand', '');
$queryBuilder = Db::name('AppUpdate')->where('type', $type);
// $version = $this->request->param('version', '');
// $phoneBrand = $this->request->param('phone_brand', '');
// $queryBuilder = Db::name('AppUpdate')->where('type', $type);
if ($type == 3) {
$android = (Db::name('AppUpdate')->where('type', 1)->where('phone_brand', '')->order('id', 'desc')->find()) ?? (object)[];
$ios = (Db::name('AppUpdate')->where('type', 2)->where('phone_brand', '')->order('id', 'desc')->find()) ?? (object)[];
return app('json')->success(compact('android', 'ios'));
} else {
if ($version) {
$queryBuilder = $queryBuilder->where('version', '>', $version);
}
if ($phoneBrand) {
$spos = false;
foreach ($brandArray as $b) {
$pos = stripos($phoneBrand, $b);
if ($pos !== false) {
$spos = true;
$queryBuilder = $queryBuilder->where('phone_brand', $b);
}
}
if ($spos === false) {
$queryBuilder = $queryBuilder->where('phone_brand', '');
}
}
$appInfo = $queryBuilder->order('version', 'desc')->fetchSql(false)->find();
if (empty($appInfo)) {
$appInfo = (Db::name('AppUpdate')->where('type', $type)->where('version', '>', $version)->find()) ?? (object)[];
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
// 检查是否为iOS设备包括iPhone和iPad
if (strpos($agent, 'iphone') !== false || strpos($agent, 'ipad') !== false) {
$appInfo=[];
} elseif (strpos($agent, 'android') !== false) {
// 检查是否为Android设备
$appInfo = Db::name('AppUpdate')->where('type', $type)->order('id','desc')->find();
} else {
$appInfo=[];
// 如果都不是,则输出其他
}
}