项目添加删除附件

This commit is contained in:
yaooo 2023-10-31 14:03:57 +08:00
parent 56d6e17629
commit c00b731717
3 changed files with 75 additions and 0 deletions

View File

@ -375,4 +375,69 @@ class ProjectIndex extends ApiController
$this->apiError('删除失败');
}
}
//添加附件
public function add_file()
{
$param = get_params();
$this->uid = JWT_UID;
if (empty($param['topic_id'])) {
$this->apiError("项目id不能为空");
}
if (empty($param['file_id'])) {
$this->apiError("文件id不能为空");
}
if (empty($param['file_name'])) {
$this->apiError("文件名称不能为空");
}
if (empty($param['module'])) {
// project
$this->apiError("模块不能为空");
}
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$fid = Db::name('ProjectFile')->strict(false)->field(true)->insertGetId($param);
if ($fid) {
$log_data = array(
'module' => $param['module'],
'field' => 'file',
'action' => 'upload',
$param['module'] . '_id' => $param['topic_id'],
'admin_id' => $this->uid,
'old_content' => '',
'new_content' => $param['file_name'],
'create_time' => time(),
);
Db::name('ProjectLog')->strict(false)->field(true)->insert($log_data);
$this->apiSuccess('添加附件成功');
}
$this->apiError('添加附件失败');
}
//删除附件
public function delete_file()
{
$id = get_params("id");
if (empty($id)) {
$this->apiError("项目文件id不能为空");
}
$detail = Db::name('ProjectFile')->where('id', $id)->find();
if ($detail && Db::name('ProjectFile')->where('id', $id)->delete() !== false) {
$file_name = Db::name('File')->where('id', $detail['file_id'])->value('name');
$log_data = array(
'module' => $detail['module'],
'field' => 'file',
'action' => 'delete',
$detail['module'] . '_id' => $detail['topic_id'],
'admin_id' => $this->uid,
'new_content' => $file_name,
'create_time' => time(),
);
Db::name('ProjectLog')->strict(false)->field(true)->insert($log_data);
$this->apiSuccess('删除成功');;
} else {
$this->apiError('删除失败');
}
}
}

View File

@ -0,0 +1,10 @@
php think swoole
php think swoole restart
php think queue:work
composer require overtrue/pinyin:4.1.0
composer require jpush/jpush
git config --global credential.helper store
alias graph="git log --graph --oneline --decorate --all"

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB