first commit
This commit is contained in:
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\model\AdminLog;
|
||||
use app\model\Project;
|
||||
use app\model\Task;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
//未读消息统计
|
||||
$msg_map[] = ['to_uid', '=', $this->uid];
|
||||
$msg_map[] = ['read_time', '=', 0];
|
||||
$msg_map[] = ['status', '=', 1];
|
||||
$msg_count = Db::name('Message')->where($msg_map)->count();
|
||||
return to_assign(0, 'ok', ['msg_num' => $msg_count]);
|
||||
} else {
|
||||
$install = false;
|
||||
if (file_exists(CMS_ROOT . 'app/install')) {
|
||||
$install = true;
|
||||
}
|
||||
|
||||
//公告相关
|
||||
$now_time = time();
|
||||
$note_list = Db::name('Note')
|
||||
->field('a.*,c.title as cate_title')
|
||||
->alias('a')
|
||||
->join('note_cate c', 'a.cate_id = c.id')
|
||||
->where([['a.delete_time', '=', 0], ['start_time', '<=', $now_time], ['end_time', '>=', $now_time]])
|
||||
->order('a.id desc')
|
||||
->limit(5)
|
||||
->select()->toArray();
|
||||
foreach ($note_list as $key => $val) {
|
||||
$note_list[$key]['create_time'] = date('Y-m-d H:i', $val['create_time']);
|
||||
}
|
||||
|
||||
//项目相关
|
||||
$project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id');
|
||||
$project_list = Db::name('Project')->where([['delete_time', '=', 0], ['id', 'in', $project_ids]])->order('id desc')->limit(10)->select()->toArray();
|
||||
foreach ($project_list as $k => &$v) {
|
||||
$v['director_name'] = Db::name('Admin')->where(['id' => $v['director_uid']])->value('name');
|
||||
$v['status_name'] = Project::$Status[(int) $v['status']];
|
||||
$v['plan_time'] = date('Y-m-d', $v['start_time']) . '至' . date('Y-m-d', $v['end_time']);
|
||||
|
||||
$task_map = [];
|
||||
$task_map[] = ['project_id', '=', $v['id']];
|
||||
$task_map[] = ['delete_time', '=', 0];
|
||||
$v['tasks'] = Db::name('Task')->where($task_map)->count();
|
||||
}
|
||||
|
||||
$project_count = Db::name('Project')->where([['delete_time', '=', 0], ['id', 'in', $project_ids]])->count();
|
||||
$project_count_ok = Db::name('Project')->where([['delete_time', '=', 0], ['id', 'in', $project_ids], ['status', '=', 3]])->count();
|
||||
|
||||
$project = [
|
||||
'list' => $project_list,
|
||||
'count' => $project_count,
|
||||
'count_ok' => $project_count_ok,
|
||||
'count_no' => $project_count - $project_count_ok,
|
||||
'count_lv' => $project_count == 0 ? 100 : round($project_count_ok * 100 / $project_count, 2),
|
||||
];
|
||||
|
||||
//任务相关
|
||||
$task_map1 = [
|
||||
['admin_id', '=', $this->uid],
|
||||
];
|
||||
$task_map2 = [
|
||||
['director_uid', '=', $this->uid],
|
||||
];
|
||||
$task_map3 = [
|
||||
['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',assist_admin_ids)")],
|
||||
];
|
||||
$task_list = Db::name('Task')
|
||||
->where(function ($query) use ($task_map1, $task_map2, $task_map3) {
|
||||
$query->where($task_map1)->whereor($task_map2)->whereor($task_map3);
|
||||
})
|
||||
->where([['delete_time', '=', 0]])
|
||||
->order('flow_status asc')
|
||||
->order('id desc')
|
||||
->limit(10)->select()->toArray();
|
||||
foreach ($task_list as $k => &$v) {
|
||||
$v['end_time'] = date('Y-m-d', $v['end_time']);
|
||||
$v['priority_name'] = Task::$Priority[(int) $v['priority']];
|
||||
$v['belong_project'] = Db::name('Project')->where(['id' => $v['project_id']])->value('name_short');
|
||||
$v['flow_name'] = Task::$FlowStatus[(int) $v['flow_status']];
|
||||
$v['type_name'] = Db::name('TaskCate')->where(['id' => $v['type']])->value('title');
|
||||
}
|
||||
|
||||
$task_count = Db::name('Task')
|
||||
->where(function ($query) use ($task_map1, $task_map2, $task_map3) {
|
||||
$query->where($task_map1)->whereor($task_map2)->whereor($task_map3);
|
||||
})
|
||||
->where([['delete_time', '=', 0]])->count();
|
||||
|
||||
$task_count_ok = Db::name('Task')
|
||||
->where(function ($query) use ($task_map1, $task_map2, $task_map3) {
|
||||
$query->where($task_map1)->whereor($task_map2)->whereor($task_map3);
|
||||
})
|
||||
->where([['delete_time', '=', 0], ['flow_status', '>', 2]])->count();
|
||||
|
||||
$task_delay = Db::name('Task')
|
||||
->where(function ($query) use ($task_map1, $task_map2, $task_map3) {
|
||||
$query->where($task_map1)->whereor($task_map2)->whereor($task_map3);
|
||||
})
|
||||
->where(function ($query) {
|
||||
$query->where([['flow_status', '<', 3], ['end_time', '<', time()]])->whereor([['flow_status', '=', 3], ['end_time', '<', 'over_time']]);
|
||||
})
|
||||
->where([['delete_time', '=', 0]])->count();
|
||||
$task = [
|
||||
'list' => $task_list,
|
||||
'count' => $task_count,
|
||||
'count_ok' => $task_count_ok,
|
||||
'count_no' => $task_count - $task_count_ok,
|
||||
'count_lv' => $task_count == 0 ? 100 : round($task_count_ok * 100 / $task_count, 2),
|
||||
'delay' => $task_delay,
|
||||
'delay_lv' => $task_count == 0 ? 100 : round($task_delay * 100 / $task_count, 2),
|
||||
];
|
||||
|
||||
//知识相关
|
||||
$knowledge_map1 = [
|
||||
['admin_id', '=', $this->uid],
|
||||
['is_share', '=', 2],
|
||||
];
|
||||
$knowledge_map2 = [
|
||||
['is_share', '=', 1],
|
||||
];
|
||||
$knowledge_list = Db::name('Knowledge')
|
||||
->where(function ($query) use ($knowledge_map1, $knowledge_map2) {
|
||||
$query->where($knowledge_map1)->whereor($knowledge_map2);
|
||||
})
|
||||
->where('delete_time', 0)
|
||||
->order('id desc')
|
||||
->limit(10)->select()->toArray();
|
||||
foreach ($knowledge_list as $k => &$v) {
|
||||
$v['create_time'] = date('Y-m-d H:i', $v['create_time']);
|
||||
$v['admin_name'] = Db::name('Admin')->where(['id' => $v['admin_id']])->value('name');
|
||||
$v['cate_name'] = Db::name('KnowledgeCate')->where(['id' => $v['cate_id']])->value('title');
|
||||
$v['views'] = Db::name('KnowledgeDoc')->where([['delete_time', '=', 0], ['knowledge_id', '=', $v['id']]])->sum('read');
|
||||
$v['sections'] = Db::name('KnowledgeDoc')->where([['delete_time', '=', 0], ['knowledge_id', '=', $v['id']]])->count();
|
||||
}
|
||||
|
||||
//工时相关
|
||||
$work_count = Db::name('Schedule')->where(['delete_time' => 0])->count();
|
||||
$work_hours = Db::name('Schedule')->where(['delete_time' => 0])->sum('labor_time');
|
||||
$work = [
|
||||
'count' => $work_count,
|
||||
'hours' => $work_hours,
|
||||
];
|
||||
|
||||
$count = [
|
||||
'product' => Db::name('Product')->where(['delete_time' => 0])->count(),
|
||||
'projects' => Db::name('Project')->where(['delete_time' => 0])->count(),
|
||||
'tasks' => Db::name('Task')->where(['delete_time' => 0])->count(),
|
||||
'knowledges' => Db::name('Knowledge')->where(['delete_time' => 0])->count(),
|
||||
];
|
||||
|
||||
View::assign([
|
||||
'install' => $install,
|
||||
'note_list' => $note_list,
|
||||
'project' => $project,
|
||||
'task' => $task,
|
||||
'knowledge_list' => $knowledge_list,
|
||||
'work' => $work,
|
||||
'count' => $count,
|
||||
'TP_VERSION' => \think\facade\App::version(),
|
||||
]);
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
//查看公告
|
||||
public function note_detail()
|
||||
{
|
||||
$id = empty(get_params('id')) ? 0 : get_params('id');
|
||||
$note = Db::name('Note')->where(['id' => $id])->find();
|
||||
$note['admin_name'] = Db::name('Admin')->where(['id' => $note['admin_id']])->value('name');
|
||||
Db::name('Note')->where(['id' => $id])->inc('read')->update();
|
||||
View::assign('note', $note);
|
||||
return view();
|
||||
}
|
||||
|
||||
//系统操作日志
|
||||
public function log_list()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$log = new AdminLog();
|
||||
$content = $log->get_log_list($param);
|
||||
return table_assign(0, '', $content);
|
||||
} else {
|
||||
return view('home@log/log_list');
|
||||
}
|
||||
}
|
||||
|
||||
//获取chart数据
|
||||
public function get_view_data()
|
||||
{
|
||||
$param = get_params();
|
||||
$first_time = time();
|
||||
$second_time = $first_time - 86400;
|
||||
$three_time = $first_time - 86400 * 365;
|
||||
$begin_first = strtotime(date('Y-m-d', $first_time) . " 00:00:00");
|
||||
$end_first = strtotime(date('Y-m-d', $first_time) . " 23:59:59");
|
||||
$begin_second = strtotime(date('Y-m-d', $second_time) . " 00:00:00");
|
||||
$end_second = strtotime(date('Y-m-d', $second_time) . " 23:59:59");
|
||||
$begin_three = strtotime(date('Y-m-d', $three_time) . " 00:00:00");
|
||||
$data_first = Db::name('AdminLog')->field('create_time')->whereBetween('create_time', "$begin_first,$end_first")->select();
|
||||
$data_second = Db::name('AdminLog')->field('create_time')->whereBetween('create_time', "$begin_second,$end_second")->select();
|
||||
$data_three = Db::name('AdminLog')->field('create_time')->whereBetween('create_time', "$begin_three,$end_first")->select();
|
||||
|
||||
//获取员工活跃数据
|
||||
$times = strtotime("-30 day");
|
||||
$where = [];
|
||||
//$where[] = ['uid','<>',1];
|
||||
$where[] = ['create_time', '>', $times];
|
||||
$content = Db::name('AdminLog')->field("id,uid,name")->where($where)->select();
|
||||
$logs = array();
|
||||
foreach ($content as $index => $value) {
|
||||
$uid = $value['uid'];
|
||||
if (empty($logs[$uid])) {
|
||||
$logs[$uid]['count'] = 1;
|
||||
$logs[$uid]['name'] = $value['name'];
|
||||
} else {
|
||||
$logs[$uid]['count'] += 1;
|
||||
}
|
||||
}
|
||||
$counts = array_column($logs, 'count');
|
||||
array_multisort($counts, SORT_DESC, $logs);
|
||||
//攫取前10
|
||||
$data_logs = array_slice($logs, 0, 10);
|
||||
return to_assign(0, '', ['data_first' => hour_document($data_first), 'data_second' => hour_document($data_second), 'data_three' => date_document($data_three), 'data_logs' => $data_logs]);
|
||||
}
|
||||
|
||||
public function errorShow()
|
||||
{
|
||||
echo '错误';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
use app\home\validate\UserCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Session;
|
||||
|
||||
class Login
|
||||
{
|
||||
//登录
|
||||
public function index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
//错误页面
|
||||
public function errorshow()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
//提交登录
|
||||
public function login_submit()
|
||||
{
|
||||
$param = get_params();
|
||||
try {
|
||||
validate(UserCheck::class)->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
|
||||
$admin = Db::name('Admin')->where(['username' => $param['username']])->find();
|
||||
if (empty($admin)) {
|
||||
$admin = Db::name('Admin')->where(['mobile' => $param['username']])->find();
|
||||
if (empty($admin)) {
|
||||
return to_assign(1, '用户名或密码错误');
|
||||
}
|
||||
}
|
||||
$param['pwd'] = set_password($param['password'], $admin['salt']);
|
||||
if ($admin['pwd'] !== $param['pwd']) {
|
||||
return to_assign(1, '用户名或密码错误');
|
||||
}
|
||||
if ($admin['status'] != 1) {
|
||||
return to_assign(1, '该用户禁止登录,请与管理者联系');
|
||||
}
|
||||
$data = [
|
||||
'last_login_time' => time(),
|
||||
'last_login_ip' => request()->ip(),
|
||||
'login_num' => $admin['login_num'] + 1,
|
||||
];
|
||||
Db::name('admin')->where(['id' => $admin['id']])->update($data);
|
||||
$session_admin = get_config('app.session_admin');
|
||||
Session::set($session_admin, $admin);
|
||||
$token = make_token();
|
||||
set_cache($token, $admin, 7200);
|
||||
$admin['token'] = $token;
|
||||
add_log('login', $admin['id'], $data);
|
||||
return to_assign(0, '登录成功', ['uid' => $admin['id']]);
|
||||
}
|
||||
|
||||
//退出登录
|
||||
public function login_out()
|
||||
{
|
||||
$session_admin = get_config('app.session_admin');
|
||||
Session::delete($session_admin);
|
||||
return to_assign(0, "退出成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,552 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\model\Message as MessageList;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Message extends BaseController
|
||||
{
|
||||
//获取消息列表
|
||||
public function getList($map = [], $param = [], $uid = 0)
|
||||
{
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
//垃圾箱列表特殊处理
|
||||
if ($param['status'] == 0) {
|
||||
$where = [['from_uid', '=', $uid], ['to_uid', '=', $uid]];
|
||||
$mail = MessageList::withoutField('content')
|
||||
->where($map)
|
||||
->where(function ($query) use ($where) {
|
||||
$query->whereOr($where);
|
||||
})
|
||||
->order('create_time desc')
|
||||
->paginate($rows, false, ['query' => $param])
|
||||
->each(function ($item, $key) {
|
||||
if ($item->template == 0) {
|
||||
$item->msg_type = '个人信息';
|
||||
$item->from_name = Db::name('Admin')->where(['id' => $item->from_uid])->value('name');
|
||||
} else {
|
||||
$item->msg_type = '系统信息';
|
||||
$item->from_name = '系统';
|
||||
}
|
||||
$item->send_time = empty($item->send_time) ? '-' : date('Y-m-d H:i:s', $item->send_time);
|
||||
$item->to_name = Db::name('Admin')->where(['id' => $item->to_uid])->value('name');
|
||||
$item->type_title = MessageList::$Type[(int) $item->type];
|
||||
$item->delete_source_title = MessageList::$Source[(int) $item->delete_source];
|
||||
$item->files = Db::name('MessageFileInterfix')->where(['mid' => $item->id])->count();
|
||||
});
|
||||
return $mail;
|
||||
} else {
|
||||
$mail = MessageList::withoutField('content')
|
||||
->where($map)
|
||||
->order('create_time desc')
|
||||
->paginate($rows, false, ['query' => $param])
|
||||
->each(function ($item, $key) {
|
||||
if ($item->template == 0) {
|
||||
$item->msg_type = '个人信息';
|
||||
$item->from_name = Db::name('Admin')->where(['id' => $item->from_uid])->value('name');
|
||||
} else {
|
||||
$item->msg_type = '系统信息';
|
||||
$item->from_name = '系统';
|
||||
}
|
||||
$item->send_time = empty($item->send_time) ? '-' : date('Y-m-d H:i:s', $item->send_time);
|
||||
$item->to_name = Db::name('Admin')->where(['id' => $item->to_uid])->value('name');
|
||||
$item->type_title = MessageList::$Type[(int) $item->type];
|
||||
$item->files = Db::name('MessageFileInterfix')->where(['mid' => $item->id])->count();
|
||||
});
|
||||
return $mail;
|
||||
}
|
||||
}
|
||||
|
||||
//收件箱
|
||||
public function inbox()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$param['status'] = 1;
|
||||
$map = [];
|
||||
if (!empty($param['keywords'])) {
|
||||
$map[] = ['title', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
if (!empty($param['read'])) {
|
||||
if ($param['read'] == 1) {
|
||||
$map[] = ['read_time', '=', 0];
|
||||
} else {
|
||||
$map[] = ['read_time', '>', 0];
|
||||
}
|
||||
}
|
||||
if (!empty($param['template'])) {
|
||||
if ($param['template'] == 1) {
|
||||
$map[] = ['template', '=', 0];
|
||||
} else {
|
||||
$map[] = ['template', '>', 0];
|
||||
}
|
||||
}
|
||||
$map[] = ['to_uid', '=', $this->uid];
|
||||
$map[] = ['status', '=', $param['status']];
|
||||
$list = $this->getList($map, $param, $this->uid);
|
||||
return table_assign(0, '', $list);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
//发件箱
|
||||
public function sendbox()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$param['status'] = 1;
|
||||
$map = [];
|
||||
if (!empty($param['keywords'])) {
|
||||
$map[] = ['title', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$map[] = ['from_uid', '=', $this->uid];
|
||||
$map[] = ['to_uid', '=', 0];
|
||||
$map[] = ['status', '=', $param['status']];
|
||||
$map[] = ['is_draft', '=', 1];
|
||||
//按时间检索
|
||||
$start_time = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0;
|
||||
$end_time = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0;
|
||||
if ($start_time > 0 && $end_time > 0) {
|
||||
$map[] = ['send_time', 'between', "$start_time,$end_time"];
|
||||
}
|
||||
$list = $this->getList($map, $param, $this->uid);
|
||||
return table_assign(0, '', $list);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//草稿箱
|
||||
public function draft()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$param['status'] = 2;
|
||||
$map = [];
|
||||
if (!empty($param['keywords'])) {
|
||||
$map[] = ['title', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$map[] = ['from_uid', '=', $this->uid];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_draft', '=', $param['status']];
|
||||
//按时间检索
|
||||
$start_time = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0;
|
||||
$end_time = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0;
|
||||
if ($start_time > 0 && $end_time > 0) {
|
||||
$map[] = ['send_time', 'between', "$start_time,$end_time"];
|
||||
}
|
||||
$list = $this->getList($map, $param, $this->uid);
|
||||
return table_assign(0, '', $list);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//垃圾箱
|
||||
public function rubbish()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$param['status'] = 0;
|
||||
$map = [];
|
||||
if (!empty($param['keywords'])) {
|
||||
$map[] = ['title', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$map[] = ['status', '=', $param['status']];
|
||||
//按时间检索
|
||||
$start_time = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0;
|
||||
$end_time = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0;
|
||||
if ($start_time > 0 && $end_time > 0) {
|
||||
$map[] = ['send_time', 'between', "$start_time,$end_time"];
|
||||
}
|
||||
$list = $this->getList($map, $param, $this->uid);
|
||||
return table_assign(0, '', $list);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//新增信息
|
||||
public function add()
|
||||
{
|
||||
$id = empty(get_params('id')) ? 0 : get_params('id');
|
||||
$fid = 0;
|
||||
if ($id > 0) {
|
||||
$detail = Db::name('Message')->where(['id' => $id, 'from_uid' => $this->uid])->find();
|
||||
if (empty($detail)) {
|
||||
$this->error('该信息不存在');
|
||||
}
|
||||
$fid = $detail['fid'];
|
||||
$person_name = [];
|
||||
if ($detail['type'] == 1) { //人员
|
||||
$users = Db::name('Admin')->where('status', 1)->where('id', 'in', $detail['type_user'])->select()->toArray();
|
||||
$person_name = array_column($users, 'name');
|
||||
} elseif ($detail['type'] == 2) { //部门
|
||||
$departments = Db::name('Department')->where('id', 'in', $detail['type_user'])->select()->toArray();
|
||||
$person_name = array_column($departments, 'title');
|
||||
} elseif ($detail['type'] == 3) { //角色
|
||||
$group_uid = Db::name('PositionGroup')->where('group_id', 'in', $detail['type_user'])->select()->toArray();
|
||||
$pids = array_column($group_uid, 'pid');
|
||||
$positions = Db::name('Position')->where('id', 'in', $pids)->select()->toArray();
|
||||
$person_name = array_column($positions, 'title');
|
||||
}
|
||||
$detail['person_name'] = implode(",", $person_name);
|
||||
$file_array = Db::name('MessageFileInterfix')
|
||||
->field('mf.id,mf.mid,mf.file_id,f.name,f.filesize,f.filepath')
|
||||
->alias('mf')
|
||||
->join('file f', 'mf.file_id = f.id', 'LEFT')
|
||||
->order('mf.create_time desc')
|
||||
->where(array('mf.mid' => $id))
|
||||
->select()->toArray();
|
||||
$interfix_ids = array_column($file_array, 'file_id');
|
||||
$detail['file_ids'] = implode(",", $interfix_ids);
|
||||
|
||||
//引用消息的附件
|
||||
if ($fid > 0) {
|
||||
$detail['from_content'] = Db::name('Message')->where(['id' => $fid])->value('content');
|
||||
$from_file_array = Db::name('MessageFileInterfix')
|
||||
->field('mf.id,mf.mid,mf.file_id,f.name,f.filesize,f.filepath')
|
||||
->alias('mf')
|
||||
->join('file f', 'mf.file_id = f.id', 'LEFT')
|
||||
->order('mf.create_time desc')
|
||||
->where(array('mf.mid' => $fid))
|
||||
->select()->toArray();
|
||||
$detail['from_file_array'] = $from_file_array;
|
||||
}
|
||||
View::assign('file_array', $file_array);
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
View::assign('id', $id);
|
||||
View::assign('fid', $fid);
|
||||
return view();
|
||||
}
|
||||
|
||||
//回复和转发消息
|
||||
public function reply()
|
||||
{
|
||||
$id = empty(get_params('id')) ? 0 : get_params('id');
|
||||
$type = empty(get_params('type')) ? 0 : get_params('type');
|
||||
$detail = Db::name('Message')->where(['id' => $id, 'template' => 0])->find();
|
||||
if (empty($detail)) {
|
||||
$this->error('该信息不存在');
|
||||
}
|
||||
if ($detail['to_uid'] != $this->uid && $detail['from_uid'] != $this->uid) {
|
||||
$this->error('该信息不存在');
|
||||
}
|
||||
$sender = get_admin($detail['from_uid']);
|
||||
$detail['person_name'] = $sender['name'];
|
||||
$file_array = Db::name('MessageFileInterfix')
|
||||
->field('mf.id,mf.mid,mf.file_id,f.name,f.filesize,f.filepath')
|
||||
->alias('mf')
|
||||
->join('file f', 'mf.file_id = f.id', 'LEFT')
|
||||
->order('mf.create_time desc')
|
||||
->where(array('mf.mid' => $id))
|
||||
->select()->toArray();
|
||||
$interfix_ids = array_column($file_array, 'file_id');
|
||||
$detail['file_ids'] = implode(",", $interfix_ids);
|
||||
View::assign('file_array', $file_array);
|
||||
View::assign('detail', $detail);
|
||||
View::assign('fid', $id);
|
||||
View::assign('type', $type);
|
||||
return view();
|
||||
}
|
||||
|
||||
//查看消息
|
||||
public function read()
|
||||
{
|
||||
$param = get_params();
|
||||
$id = $param['id'];
|
||||
$detail = Db::name('Message')->where(['id' => $id])->find();
|
||||
if (empty($detail)) {
|
||||
$this->error('该信息不存在');
|
||||
}
|
||||
if ($detail['to_uid'] != $this->uid && $detail['from_uid'] != $this->uid) {
|
||||
$this->error('该信息不存在');
|
||||
}
|
||||
Db::name('Message')->where(['id' => $id])->update(['read_time' => time()]);
|
||||
if ($detail['from_uid'] == 0) {
|
||||
$detail['person_name'] = '系统管理员';
|
||||
} else {
|
||||
$sender = get_admin($detail['from_uid']);
|
||||
$detail['person_name'] = $sender['name'];
|
||||
}
|
||||
//引用消息的附件
|
||||
if ($detail['fid'] > 0) {
|
||||
$detail['from_content'] = Db::name('Message')->where(['id' => $detail['fid']])->value('content');
|
||||
$from_file_array = Db::name('MessageFileInterfix')
|
||||
->field('mf.id,mf.mid,mf.file_id,f.name,f.filesize,f.filepath')
|
||||
->alias('mf')
|
||||
->join('file f', 'mf.file_id = f.id', 'LEFT')
|
||||
->order('mf.create_time desc')
|
||||
->where(array('mf.mid' => $detail['fid']))
|
||||
->select()->toArray();
|
||||
$detail['from_file_array'] = $from_file_array;
|
||||
}
|
||||
|
||||
//当前消息的附件
|
||||
$file_array = Db::name('MessageFileInterfix')
|
||||
->field('mf.id,mf.mid,mf.file_id,f.name,f.filesize,f.filepath')
|
||||
->alias('mf')
|
||||
->join('file f', 'mf.file_id = f.id', 'LEFT')
|
||||
->order('mf.create_time desc')
|
||||
->where(array('mf.mid' => $detail['id']))
|
||||
->select()->toArray();
|
||||
$detail['file_array'] = $file_array;
|
||||
$detail['send_time'] = date('Y-m-d H:i:s', $detail['send_time']);
|
||||
//发送人查询
|
||||
$user_names = [];
|
||||
//已读回执
|
||||
$read_user_names = [];
|
||||
if ($detail['from_uid'] == $this->uid) {
|
||||
$mails = Db::name('Message')->where(['pid' => $id])->select()->toArray();
|
||||
$read_mails = Db::name('Message')->where([['pid', '=', $id], ['read_time', '>', 2]])->select()->toArray();
|
||||
$read_user_ids = array_column($read_mails, 'to_uid');
|
||||
$read_users = Db::name('Admin')->where('status', 1)->where('id', 'in', $read_user_ids)->select()->toArray();
|
||||
$read_user_names = array_column($read_users, 'name');
|
||||
} else {
|
||||
$mails = Db::name('Message')->where(['pid' => $detail['pid']])->select()->toArray();
|
||||
}
|
||||
$user_ids = array_column($mails, 'to_uid');
|
||||
$users = Db::name('Admin')->where('status', 1)->where('id', 'in', $user_ids)->select()->toArray();
|
||||
$user_names = array_column($users, 'name');
|
||||
|
||||
$detail['users'] = implode(",", $user_names);
|
||||
$detail['read_users'] = implode(",", $read_user_names);
|
||||
View::assign('detail', $detail);
|
||||
return view();
|
||||
}
|
||||
|
||||
//保存到草稿
|
||||
public function save()
|
||||
{
|
||||
$param = get_params();
|
||||
$id = empty($param['id']) ? 0 : $param['id'];
|
||||
$fid = empty($param['fid']) ? 0 : $param['fid'];
|
||||
//接受人类型判断
|
||||
if ($param['type'] == 1) {
|
||||
if (!$param['uids']) {
|
||||
return to_assign(1, '人员不能为空');
|
||||
} else {
|
||||
$type_user = $param['uids'];
|
||||
}
|
||||
} elseif ($param['type'] == 2) {
|
||||
if (!$param['dids']) {
|
||||
return to_assign(1, '部门不能为空');
|
||||
} else {
|
||||
$type_user = $param['dids'];
|
||||
}
|
||||
} elseif ($param['type'] == 3) {
|
||||
if (!$param['pids']) {
|
||||
return to_assign(1, '岗位不能为空');
|
||||
} else {
|
||||
$type_user = $param['pids'];
|
||||
}
|
||||
} else {
|
||||
$type_user = '';
|
||||
}
|
||||
//基础信息数据
|
||||
$admin_id = $this->uid;
|
||||
$basedata = [];
|
||||
$basedata['from_uid'] = $admin_id;
|
||||
$basedata['fid'] = $fid;
|
||||
$basedata['is_draft'] = 2; //默认是草稿信息
|
||||
$basedata['title'] = $param['title'];
|
||||
$basedata['type'] = $param['type'];
|
||||
$basedata['type_user'] = $type_user;
|
||||
$basedata['content'] = $param['content'];
|
||||
$basedata['controller_name'] = $this->controller;
|
||||
$basedata['module_name'] = $this->module;
|
||||
$basedata['action_name'] = $this->action;
|
||||
if ($id > 0) {
|
||||
//编辑信息的情况
|
||||
$basedata['update_time'] = time();
|
||||
$basedata['id'] = $id;
|
||||
$res = Db::name('Message')->strict(false)->field(true)->update($basedata);
|
||||
} else {
|
||||
//新增信息的情况
|
||||
$basedata['create_time'] = time();
|
||||
$res = Db::name('Message')->strict(false)->field(true)->insertGetId($basedata);
|
||||
}
|
||||
if ($res !== false) {
|
||||
//信息附件处理
|
||||
if ($id > 0) {
|
||||
$mid = $id;
|
||||
Db::name('MessageFileInterfix')->where(['mid' => $mid])->delete();
|
||||
} else {
|
||||
$mid = $res;
|
||||
}
|
||||
//附件插入附件
|
||||
if (!empty($param['file_ids'])) {
|
||||
$file_array = explode(',', $param['file_ids']);
|
||||
$file_data = array();
|
||||
foreach ($file_array as $key => $value) {
|
||||
if (!$value) {
|
||||
continue;
|
||||
}
|
||||
$file_data[] = array(
|
||||
'file_id' => $value,
|
||||
'mid' => $mid,
|
||||
'admin_id' => $admin_id,
|
||||
'create_time' => time()
|
||||
);
|
||||
}
|
||||
if ($file_data) {
|
||||
$sql = Db::name('MessageFileInterfix')->insertAll($file_data);
|
||||
}
|
||||
}
|
||||
add_log('save', $mid);
|
||||
return to_assign(0, '保存成功', $mid);
|
||||
} else {
|
||||
return to_assign(1, '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
//发送消息
|
||||
public function send()
|
||||
{
|
||||
$param = get_params();
|
||||
//查询要发的消息
|
||||
$msg = Db::name('Message')->where(['id' => $param['id']])->find();
|
||||
$users = [];
|
||||
if ($msg) {
|
||||
$admin_id = $msg['from_uid'];
|
||||
//查询全部收件人
|
||||
if ($msg['type'] == 1) { //人员
|
||||
$users = Db::name('Admin')->where('status', 1)->where('id', 'in', $msg['type_user'])->select()->toArray();
|
||||
} elseif ($msg['type'] == 2) { //部门
|
||||
$users = Db::name('Admin')->where('status', 1)->where('did', 'in', $msg['type_user'])->select()->toArray();
|
||||
} elseif ($msg['type'] == 3) { //角色
|
||||
$group_uid = Db::name('PositionGroup')->where('group_id', 'in', $msg['type_user'])->select()->toArray();
|
||||
$pids = array_column($group_uid, 'pid');
|
||||
$users = Db::name('Admin')->where('status', 1)->where('position_id', 'in', $pids)->select()->toArray();
|
||||
} elseif ($msg['type'] == 4) { //全部
|
||||
$users = Db::name('Admin')->where('status', 1)->select()->toArray();
|
||||
}
|
||||
//组合要发的消息
|
||||
$send_data = [];
|
||||
foreach ($users as $key => $value) {
|
||||
if (!$value || ($value['id'] == $admin_id)) {
|
||||
continue;
|
||||
}
|
||||
$send_data[] = array(
|
||||
'pid' => $param['id'],
|
||||
//来源发件箱关联id
|
||||
'to_uid' => $value['id'],
|
||||
//接收人
|
||||
'fid' => $msg['fid'],
|
||||
//转发或回复消息关联id
|
||||
'title' => $msg['title'],
|
||||
'content' => $msg['content'],
|
||||
'type' => $msg['type'],
|
||||
//接收人类型
|
||||
'type_user' => $msg['type_user'],
|
||||
//接收人数据
|
||||
'from_uid' => $this->uid,
|
||||
//发送人
|
||||
'controller_name' => $this->controller,
|
||||
'module_name' => $this->module,
|
||||
'action_name' => $this->action,
|
||||
'send_time' => time(),
|
||||
'create_time' => time()
|
||||
);
|
||||
}
|
||||
$res = Db::name('Message')->strict(false)->field(true)->insertAll($send_data);
|
||||
if ($res !== false) {
|
||||
//查询原来的附件,并插入
|
||||
$file_array = Db::name('MessageFileInterfix')->where('mid', $msg['id'])->select()->toArray();
|
||||
if ($file_array) {
|
||||
$mids = Db::name('Message')->where('pid', $msg['id'])->select()->toArray();
|
||||
foreach ($mids as $k => $v) {
|
||||
$file_data = array();
|
||||
foreach ($file_array as $key => $value) {
|
||||
if (!$value) {
|
||||
continue;
|
||||
}
|
||||
$file_data[] = array(
|
||||
'mid' => $v['id'],
|
||||
'file_id' => $value['file_id'],
|
||||
'create_time' => time(),
|
||||
'admin_id' => $admin_id,
|
||||
);
|
||||
}
|
||||
if ($file_data) {
|
||||
Db::name('MessageFileInterfix')->strict(false)->field(true)->insertAll($file_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
//草稿消息变成已发消息
|
||||
Db::name('Message')->where(['id' => $msg['id']])->update(['is_draft' => '1', 'send_time' => time(), 'update_time' => time()]);
|
||||
add_log('send', $msg['id']);
|
||||
return to_assign(0, '发送成功');
|
||||
} else {
|
||||
return to_assign(1, '发送失败');
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, '发送失败,找不到要发送的内容');
|
||||
}
|
||||
}
|
||||
|
||||
//状态修改
|
||||
public function check()
|
||||
{
|
||||
$param = get_params();
|
||||
$type = empty($param['type']) ? 0 : $param['type'];
|
||||
$source = empty($param['source']) ? 0 : $param['source'];
|
||||
$ids = empty($param['ids']) ? 0 : $param['ids'];
|
||||
$idArray = explode(',', $ids);
|
||||
$list = [];
|
||||
foreach ($idArray as $key => $val) {
|
||||
if ($type == 1) { //设置信息为已读
|
||||
$list[] = [
|
||||
'read_time' => time(),
|
||||
'id' => $val,
|
||||
];
|
||||
} else if ($type == 2) { //设置信息进入垃圾箱
|
||||
$list[] = [
|
||||
'status' => 0,
|
||||
'id' => $val,
|
||||
'delete_source' => $source,
|
||||
'update_time' => time(),
|
||||
];
|
||||
} else if ($type == 3) { //设置信息从垃圾箱恢复
|
||||
$list[] = [
|
||||
'status' => 1,
|
||||
'id' => $val,
|
||||
'update_time' => time(),
|
||||
];
|
||||
} else if ($type == 4) { //设置信息彻底删除
|
||||
$list[] = [
|
||||
'status' => -1,
|
||||
'id' => $val,
|
||||
'update_time' => time(),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($list as $key => $v) {
|
||||
if (Db::name('Message')->update($v) !== false) {
|
||||
if ($type = 1) {
|
||||
add_log('view', $v['id']);
|
||||
} else if ($type = 2) {
|
||||
add_log('delete', $v['id']);
|
||||
} else if ($type = 3) {
|
||||
add_log('recover', $v['id']);
|
||||
} else if ($type = 4) {
|
||||
add_log('clear', $v['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return to_assign(0, '操作成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\AdminCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Session;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class User extends BaseController
|
||||
{
|
||||
public function setting()
|
||||
{
|
||||
$install = false;
|
||||
if (file_exists(CMS_ROOT . 'app/install')) {
|
||||
$install = true;
|
||||
}
|
||||
View::assign('install', $install);
|
||||
$conf = Db::name('Config')->where('id', 1)->find();
|
||||
$config = [];
|
||||
if ($conf['content']) {
|
||||
$config = unserialize($conf['content']);
|
||||
}
|
||||
View::assign('admin', get_admin($this->uid));
|
||||
View::assign('config', $config);
|
||||
View::assign('TP_VERSION', \think\facade\App::version());
|
||||
return View();
|
||||
}
|
||||
//修改个人信息
|
||||
public function edit_personal()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$uid = $this->uid;
|
||||
Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param);
|
||||
$session_admin = get_config('app.session_admin');
|
||||
Session::set($session_admin, Db::name('Admin')->where(['id' => $uid])->find());
|
||||
return to_assign();
|
||||
} else {
|
||||
$admin = Db::name('Admin')->where('id', $this->uid)->find();
|
||||
$admin['department'] = Db::name('Department')->where('id', $admin['did'])->value('title');
|
||||
$admin['position'] = Db::name('Position')->where('id', $admin['position_id'])->value('title');
|
||||
return view('', [
|
||||
'admin' => $admin,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//修改密码
|
||||
public function edit_password()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
try {
|
||||
validate(AdminCheck::class)->scene('editPwd')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$uid = $this->uid;
|
||||
|
||||
$admin = Db::name('Admin')->where(['id' => $uid])->find();
|
||||
$old_psw = set_password($param['old_pwd'], $admin['salt']);
|
||||
if ($admin['pwd'] != $old_psw) {
|
||||
return to_assign(1, '旧密码错误');
|
||||
}
|
||||
|
||||
$salt = set_salt(20);
|
||||
$new_pwd = set_password($param['pwd'], $salt);
|
||||
$data = [
|
||||
'reg_pwd' => '',
|
||||
'salt' => $salt,
|
||||
'pwd' => $new_pwd,
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($data);
|
||||
$session_admin = get_config('app.session_admin');
|
||||
Session::set($session_admin, Db::name('admin')->find($uid));
|
||||
return to_assign();
|
||||
} else {
|
||||
return view('', [
|
||||
'admin' => get_admin($this->uid),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//保存密码修改
|
||||
public function password_submit()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
try {
|
||||
validate(AdminCheck::class)->scene('editpwd')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$admin = get_admin($this->uid);
|
||||
if (set_password($param['old_pwd'], $admin['salt']) !== $admin['pwd']) {
|
||||
return to_assign(1, '旧密码不正确!');
|
||||
}
|
||||
unset($param['username']);
|
||||
$param['salt'] = set_salt(20);
|
||||
$param['pwd'] = set_password($param['pwd'], $param['salt']);
|
||||
Db::name('Admin')->where([
|
||||
'id' => $admin['id'],
|
||||
])->strict(false)->field(true)->update($param);
|
||||
$session_admin = get_config('app.session_admin');
|
||||
Session::set($session_admin, Db::name('admin')->find($admin['id']));
|
||||
return to_assign();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user