feat(ota): 新增OTA远程升级功能

- 创建OTA版本管理表结构,支持版本名称、构建号、APK文件等信息存储
- 实现后台OTA版本管理界面,包含新增、编辑、删除和发布功能
- 开发API接口用于设备版本检查和更新包下载
- 实现版本发布逻辑,自动归档旧版本并计算APK文件哈希值
- 添加强制更新、目标设备白名单和最低版本限制功能
- 集成文件上传和选择组件,支持APK文件管理
- 实现版本状态管理(草稿、已发布、已归档)和权限控制
This commit is contained in:
2026-04-09 17:51:34 +08:00
parent ab27bb6bf6
commit 1e22f5b452
11 changed files with 731 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
<?php
namespace app\admin\controller\ota;
use app\common\controller\Backend;
/**
* OTA 版本管理管理
*
* @icon fa fa-circle-o
*/
class Version extends Backend
{
/**
* Version模型对象
* @var \app\admin\model\ota\Version
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\ota\Version;
$this->view->assign("statusList", $this->model->getStatusList());
}
/**
* 发布版本
*
* 将指定版本设为 published 状态,同时自动归档其他已发布版本,
* 并计算 APK 文件大小和 SHA-256 哈希值。
*
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function publish()
{
$id = $this->request->param('ids');
if (!$id) {
$this->error('参数错误');
}
// 先归档其他已发布版本
$this->model->where('status', 'published')->update(['status' => 'archived']);
// 获取待发布版本
$row = $this->model->get($id);
if (!$row) {
$this->error('记录不存在');
}
// 计算 APK 文件信息
if ($row['apk_file']) {
$fullPath = root_path() . 'public' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . ltrim($row['apk_file'], '/');
if (file_exists($fullPath)) {
$row->file_size = filesize($fullPath);
$row->sha256 = hash_file('sha256', $fullPath);
}
}
$row->status = 'published';
$row->save();
$this->success('发布成功');
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
}