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中对应的方法复制到当前控制器,然后进行修改 */ }