项目链接管理

This commit is contained in:
yaooo 2023-10-31 14:50:06 +08:00
parent c00b731717
commit fdb2f4b773
1 changed files with 90 additions and 3 deletions

View File

@ -434,10 +434,97 @@ class ProjectIndex extends ApiController
'create_time' => time(),
);
Db::name('ProjectLog')->strict(false)->field(true)->insert($log_data);
$this->apiSuccess('删除成功');;
$this->apiSuccess('删除成功');
} else {
$this->apiError('删除失败');
}
}
//链接添加修改
public function add_link()
{
$param = get_params();
$this->uid = JWT_UID;
if (empty($param['topic_id'])) {
$this->apiError("项目id不能为空");
}
if (empty($param['url'])) {
$this->apiError("url不能为空");
}
if (empty($param['desc'])) {
$this->apiError("说明不能为空");
}
if (empty($param['module'])) {
// project
$this->apiError("模块不能为空");
}
$validate = \think\facade\Validate::rule([
'url' => 'url',
]);
if (!$validate->check($param)) {
$this->apiError($validate->getError());
}
if (!empty($param['id']) && $param['id'] > 0) {
$param['update_time'] = time();
$res = Db::name('ProjectLink')->where('id', $param['id'])->strict(false)->field(true)->update($param);
if ($res) {
$log_data = array(
'module' => $param['module'],
'field' => 'link',
'action' => 'edit',
$param['module'] . '_id' => $param['topic_id'],
'admin_id' => $this->uid,
'old_content' => $param['url'],
'new_content' => $param['desc'],
'create_time' => time(),
);
Db::name('ProjectLog')->strict(false)->field(true)->insert($log_data);
$this->apiSuccess('编辑成功');
}
} else {
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$lid = Db::name('ProjectLink')->strict(false)->field(true)->insertGetId($param);
if ($lid) {
$log_data = array(
'module' => $param['module'],
'field' => 'link',
'action' => 'add',
$param['module'] . '_id' => $param['topic_id'],
'admin_id' => $this->uid,
'new_content' => $param['desc'],
'create_time' => time(),
);
Db::name('ProjectLog')->strict(false)->field(true)->insert($log_data);
$this->apiSuccess('添加成功');
}
}
}
//删除
public function delete_link()
{
$id = get_params("id");
if (empty($id)) {
$this->apiError("项目链接id不能为空");
}
$id = get_params("id");
$detail = Db::name('ProjectLink')->where('id', $id)->find();
if ($detail && Db::name('ProjectLink')->where('id', $id)->update(['delete_time' => time()]) !== false) {
$log_data = array(
'module' => $detail['module'],
'field' => 'link',
'action' => 'delete',
$detail['module'] . '_id' => $detail['topic_id'],
'admin_id' => $this->uid,
'new_content' => $detail['desc'],
'create_time' => time(),
);
Db::name('ProjectLog')->strict(false)->field(true)->insert($log_data);
$this->apiSuccess('删除成功');
} else {
$this->apiError('删除失败');
}
}
}
}