- 实现OTA版本列表页面,支持版本信息展示 - 添加版本名称、版本号、APK文件等字段显示 - 集成文件上传和SHA-256校验功能 - 实现强制更新开关和状态管理 - 添加发布按钮支持版本发布操作 - 集成表格增删改查基础功能 - 实现文件大小格式化显示 - 添加目标设备
79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?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中对应的方法复制到当前控制器,然后进行修改
|
|
*/
|
|
|
|
|
|
}
|