checkLogin(); if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']); $user_id = $user_info['uid']; $company_id = $user_info['company_id']; // 验证规则 $Request->scene('list')->validate(); $map = []; // 权限判断 $map['company_id'] = $company_id; $map['custom_uid'] = $user_id; // 接收参数 $status = request('status'); $limit = request('limit', config('page_num', 10)); $start_time = request('start_time', ''); $end_time = request('end_time', ''); // 时间条件 if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time . ' 00:00:00')]; if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time . ' 23:59:59')]; if (!is_null($status)) $map[] = ['status', '=', $status]; // 查询系统用户 $result = $NoticesModel->where($map)->orderByDesc('id')->paginate($limit); // 告知结果 return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]); } /** * 修改状态 * @author: 唐远望 * @version: 1.0 * @date: 2026-03-30 */ public function set_status(Request $request, NoticesModel $NoticesModel) { $user_info = $this->checkLogin(); if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']); $user_id = $user_info['uid']; $company_id = $user_info['company_id']; // 验证参数 $request->scene('set_status')->validate(); $map = []; // 权限判断 $map['company_id'] = $company_id; $map['custom_uid'] = $user_id; // 设置状态 $id = request('id', 0); $status = request('status', 0); $map[] = ['id', '=', $id]; // 查询用户 $oldData = $NoticesModel->where($map)->first(); // 如果用户不存在 if (!$oldData) return json_send(['code' => 'error', 'msg' => '通知消息记录不存在']); // 执行修改 $result = $NoticesModel->where($map)->update(['status' => $status, 'update_time' => time()]); // 提示新增失败 if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '设置成功', 'data' => '']); } /** * 消息数统计 * @author: 唐远望 * @version: 1.0 * @date: 2026-03-30 */ public function message_count(Request $Request, NoticesModel $NoticesModel) { $user_info = $this->checkLogin(); if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']); $user_id = $user_info['uid']; $company_id = $user_info['company_id']; // 验证规则 $Request->scene('message_count')->validate(); $map = []; // 权限判断 $map['company_id'] = $company_id; $map['custom_uid'] = $user_id; $map[] = ['status', '=', 0]; // 查询系统用户 $unread_count = $NoticesModel->where($map)->orderByDesc('id')->count(); // 告知结果 return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => ['unread_count' => $unread_count]]); } }