60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
||
|
||
namespace App\Endpoint\Api\Http\Controllers;
|
||
|
||
use App\Exceptions\BizException;
|
||
use App\Models\AppVersion;
|
||
use Illuminate\Http\Request;
|
||
|
||
class AppVersionController extends Controller
|
||
{
|
||
/**
|
||
*
|
||
*
|
||
* @param \Illuminate\Http\Request $request
|
||
* @return void
|
||
*/
|
||
public function index(Request $request)
|
||
{
|
||
$cate = (string) $request->query('cate');
|
||
$v = (int) $request->query('v');
|
||
|
||
if (empty($cate)) {
|
||
return response()->json([]);
|
||
}
|
||
|
||
//只拿最新的版本信息
|
||
$appVersion = AppVersion::filter($request->all())
|
||
->orderBy('v', 'desc')->orderBy('created_at', 'desc')->first();
|
||
if (is_null($appVersion)) {
|
||
throw (new BizException('信息未找到'))->status(404);
|
||
}
|
||
|
||
//如果未传版本号,或者版本号为0,则返回最新的apk地址;
|
||
if (empty($v)) {
|
||
$res = [
|
||
'link' => (string) $appVersion->apk_link,
|
||
];
|
||
} elseif ($appVersion->v > ($v+1)) {//如果版本号差异大于1,则强制更新APK
|
||
$res = [
|
||
'title'=>$appVersion->title,
|
||
'context'=>$appVersion->context,
|
||
'name' => (string) $appVersion->name,
|
||
'v' => (int) $appVersion->v,
|
||
'is_force' => true,
|
||
'link' => (string) $appVersion->apk_link,
|
||
];
|
||
} else {
|
||
$res = [
|
||
'title'=>$appVersion->title,
|
||
'context'=>$appVersion->context,
|
||
'name' => (string) $appVersion->name,
|
||
'v' => (int) $appVersion->v,
|
||
'is_force' => (bool) $appVersion->is_force,
|
||
'link' => (string) ($appVersion->wgt_link ?? $appVersion->apk_link),
|
||
];
|
||
}
|
||
return response()->json($res);
|
||
}
|
||
}
|