first commit

This commit is contained in:
2025-06-25 10:53:11 +08:00
commit 9f374011ae
1240 changed files with 181139 additions and 0 deletions
+270
View File
@@ -0,0 +1,270 @@
<?php
/**
* @copyright Copyright (c) 2023-2024 美天智能科技
* @link http://www.meteteme.com
*/
declare(strict_types=1);
namespace app\information\controller;
use app\base\BaseController;
use app\model\Information as InformationList;
use app\business_info\validate\InformationCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Index extends BaseController
{
public function index()
{
if (request()->isAjax()) {
$param = get_params();
$rows = empty($param['limit']) ? get_md_contentconfig('app.page_size') : $param['limit'];
$list = InformationList::withoutField('')
->where('delete_time', null)
->order('id desc')
->paginate($rows, false, ['query' => $param])
->each(function ($item, $key) {
$bi = Db::name('Information')->where(['id' => $item->id])->find();
// 获取对应product id的name
$product = Db::name('Product')->where(['id' => $bi['product']])->find();
$productName = $product ? $product['name'] : '';
$item->name = $bi['name'];
$item->email = $bi['email'];
$item->phone = $bi['phone'];
$item->message = $bi['message'];
$item->product = $productName; // 将产品名称传递给前端
$item->company = $bi['company'];
$item->create_time = $bi['create_time'];
$item->update_time = $bi['update_time'];
$item->delete_time = $bi['delete_time'];
})
->filter(function ($item) {
return $item->delete_time === null;
});
return table_assign(0, '', $list);
} else {
return view();
}
}
// 获取信息列表(分页,每页10条)
public function list()
{
try {
// 查询数据,分页设置每页10条
$list = Db::name('Information')
// ->field('id, title, content, create_time, update_time') // 选择所需字段
->order('id desc') // 按 id 倒序排序
->paginate(10); // 每页10条记录
// 返回成功响应
return json([
'code' => 1, // 成功状态码
'msg' => '获取成功', // 提示信息
'data' => $list->items(), // 当前页数据
'pagination' => [
'total' => $list->total(), // 总记录数
'per_page' => $list->listRows(), // 每页条数
'current_page' => $list->currentPage(), // 当前页码
'last_page' => $list->lastPage() // 总页数
]
]);
} catch (\Exception $e) {
// 捕获异常并返回错误信息
return json([
'code' => 0, // 失败状态码
'msg' => '获取失败: ' . $e->getMessage(), // 错误信息
'data' => [] // 空数据
]);
}
}
//增加商机(app端)
public function addbusinessinfo()
{
$param = get_params();
if (request()->isPost()) {
// 新增逻辑
$param['create_time'] = time();
$sid = InformationList::strict(false)->field(true)->insertGetId($param);
if ($sid) {
add_log('add', $sid, $param);
return json(["code" => 0, "msg" => "添加成功"]); // 返回JSON格式数据
} else {
return json(["code" => 1, "msg" => "添加失败"]); // 返回JSON格式数据
}
} else {
$id = isset($param['id']) ? $param['id'] : 0;
if ($id > 0) {
$businessinfoLists = InformationList::where('id', $id)
->field('id, name, email, phone, message, product, company, create_time')
->find();
if (empty($businessinfoLists)) {
return json(["code" => 1, "msg" => "信息不存在"]); // 返回JSON格式数据
}
}
json(["code" => 0, "msg" => "编辑成功"]); // 返回JSON格式数据
}
}
//添加
public function add()
{
$param = get_params();
if (request()->isPost()) {
if (!empty($param['id']) && $param['id'] > 0) {
$information = (new InformationList())->detail($param['id']);
try {
validate(InformationCheck::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$param['update_time'] = time();
$res = InformationList::where('id', $param['id'])->strict(false)->field(true)->update($param);
if ($res) {
add_log('edit', $param['id'], $param, $information);
}
return to_assign();
} else {
try {
validate(InformationCheck::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$exist = InformationList::where('name', $param['name'])
->where('id', '<>', $param['id'])->find();
if ($exist) {
return to_assign(1, '该信息已存在');
}
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$sid = InformationList::strict(false)->field(true)->insertGetId($param);
if ($sid) {
add_log('add', $sid, $param);
$log_data = array(
'module' => 'business_info',
'id' => $sid,
'new_content' => $param['name'],
'field' => 'new',
'action' => 'add',
'admin_id' => $this->uid,
'create_time' => time(),
);
Db::name('Log')->strict(false)->field(true)->insert($log_data);
}
return to_assign(2, '添加成功!');
}
} else {
$id = isset($param['id']) ? $param['id'] : 0;
if ($id > 0) {
$detail = (new InformationList())->detail($id);
if (empty($detail)) {
return to_assign(1, '1.信息不存在');
}
View::assign('detail', $detail);
}
View::assign('id', $id);
return view();
}
}
//查看
public function view()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$detail = (new InformationList())->detail($id);
// print_r($id);
if (empty($detail)) {
return to_assign(1, '2.信息不存在');
} else {
if ($this->uid != $detail['admin_id']) { // 当前登录用户必须是上传者才能查看
return to_assign(1, '您没权限查看该信息');
}
$role_uid = [$detail['admin_id'], $detail['director_uid']];
$role_edit = 'edit';
$view_uid = $role_uid;
// if (!empty($detail['check_admin_ids'])) {
// $view_uid = array_merge($role_uid, explode(",", $detail['check_admin_ids']));
// }
if (!in_array($this->uid, $view_uid) && $detail['is_open'] == 1) {
return to_assign(1, '您没权限查看该信息');
}
$contact_array = Db::name('Businesscontact')
->field('i.id,i.business_id,i.contact,i.post,i.phone,i.email,i.wechat,i.qq,a.name as admin_name')
->alias('i')
->join('Admin a', 'i.admin_id = a.id', 'LEFT')
->join('Information b', 'i.business_id = b.id', 'LEFT')
->order('i.create_time desc')
->where(array('i.business_id' => $id))
->where('i.delete_time', null)
->select()->toArray();
$file_array = Db::name('FileInterfix')
->field('i.id,i.topic_id,i.admin_id,f.name,f.filesize,f.filepath,a.name as admin_name')
->alias('i')
->join('File f', 'i.file_id = f.id', 'LEFT')
->join('Admin a', 'i.admin_id = a.id', 'LEFT')
->order('i.create_time desc')
->where(array('i.topic_id' => $id, 'i.module' => 'picbed'))
->select()->toArray();
$link_array = Db::name('LinkInterfix')
->field('i.id,i.topic_id,i.admin_id,i.desc,i.url,a.name as admin_name')
->alias('i')
->join('Admin a', 'i.admin_id = a.id', 'LEFT')
->order('i.create_time desc')
->where(array('i.topic_id' => $id, 'i.module' => 'picbed', 'delete_time' => 0))
->select()->toArray();
View::assign('detail', $detail);
View::assign('contact_array', $contact_array);
View::assign('file_array', $file_array);
View::assign('link_array', $link_array);
View::assign('role_edit', $role_edit);
View::assign('id', $id);
return view();
}
}
//删除
public function delete()
{
$request = request();
if ($request->isDelete() || $request->isAjax()) {
$id = get_params("id");
$detail = Db::name('Information')->where('id', $id)->find();
// if ($detail['admin_id'] != $this->uid) {
// return to_assign(1, "你不是图片的上传人,无权限删除");
// }
if (Db::name('Information')->where('id', $id)->update(['delete_time' => time()]) !== false) {
$log_data = array(
'module' => 'picbed',
'field' => 'delete',
'action' => 'delete',
'admin_id' => $this->uid,
'old_content' => '',
'new_content' => $detail['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, "错误的请求");
}
}
}