2025-06-25 10:53:11 +08:00

183 lines
6.4 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2023-2024 美天智能科技
* @author 李志强
* @link http://www.meteteme.com
*/
declare(strict_types=1);
namespace app\api\controller;
use app\api\BaseController;
use think\facade\Db;
class Appendix extends BaseController
{
//添加修改
public function add()
{
$param = get_params();
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$fid = Db::name('FileInterfix')->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('Log')->strict(false)->field(true)->insert($log_data);
return to_assign(0, '', $fid);
}
}
//删除
public function delete()
{
if (request()->isDelete()) {
$id = get_params("id");
$detail = Db::name('FileInterfix')->where('id', $id)->find();
if (Db::name('FileInterfix')->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('Log')->strict(false)->field(true)->insert($log_data);
return to_assign(0, "删除成功");
} else {
return to_assign(0, "删除失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
//链接添加修改
public function add_link()
{
$param = get_params();
$validate = \think\facade\Validate::rule([
'url' => 'url',
]);
if (!$validate->check($param)) {
return to_assign(1, $validate->getError());
}
if (!empty($param['id']) && $param['id'] > 0) {
$param['update_time'] = time();
$res = Db::name('LinkInterfix')->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('Log')->strict(false)->field(true)->insert($log_data);
return to_assign(0, '编辑成功');
}
} else {
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$lid = Db::name('LinkInterfix')->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('Log')->strict(false)->field(true)->insert($log_data);
return to_assign(0, '添加成功', $lid);
}
}
}
//删除
public function delete_link()
{
if (request()->isDelete()) {
$id = get_params("id");
$detail = Db::name('LinkInterfix')->where('id', $id)->find();
if (Db::name('LinkInterfix')->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('Log')->strict(false)->field(true)->insert($log_data);
return to_assign(0, "删除成功");
} else {
return to_assign(0, "删除失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
//添加联系人
public function add_contact()
{
$param = get_params();
if (!empty($param['id']) && $param['id'] > 0) {
$param['update_time'] = time();
$res = BusinessContact::where(['admin_id' => $this->uid, 'id' => $param['id']])->strict(false)->field(true)->update($param);
if ($res) {
add_log('edit', $param['id'], $param);
return to_assign();
}
} else {
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$cid = BusinessContact::strict(false)->field(true)->insertGetId($param);
if ($cid) {
add_log('add', $cid, $param);
//sendMessage($users,1,['title'=>$param['title'],'action_id'=>$sid]);
return to_assign();
}
}
}
//删除联系人
public function delete_contact()
{
if (request()->isDelete()) {
$id = get_params("id");
$detail = Businesscontact::where(['admin_id' => $this->uid, 'id' => $id])->find();
if (Businesscontact::where(['admin_id' => $this->uid, 'id' => $id])->update(['delete_time' => time()]) !== false) {
add_log('delete', $id, $detail);
return to_assign(0, "删除成功");
} else {
return to_assign(0, "删除失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
}