做文章中心
This commit is contained in:
@@ -315,6 +315,7 @@ class UserController extends BaseController
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
//个人资料
|
||||
public function saveBasic()
|
||||
{
|
||||
// 检查用户是否登录
|
||||
@@ -582,6 +583,64 @@ class UserController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统通知列表
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
// 检查用户是否登录
|
||||
if (!cookie('user_account')) {
|
||||
return json(['code' => 1, 'msg' => '请先登录']);
|
||||
}
|
||||
|
||||
$type = $this->request->get('type', 'all'); // 获取通知类型:all, unread, read
|
||||
$userId = cookie('user_id');
|
||||
|
||||
try {
|
||||
// 构建查询条件
|
||||
$where = [
|
||||
['status', '=', 1] // 只获取启用的通知
|
||||
];
|
||||
|
||||
// 查询系统通知
|
||||
$notices = UserMessage::where($where)
|
||||
->order('is_top', 'desc') // 置顶的排在前面
|
||||
->order('create_time', 'desc')
|
||||
->select();
|
||||
|
||||
// 格式化数据
|
||||
$data = [];
|
||||
foreach ($notices as $notice) {
|
||||
// 检查用户是否已读该通知
|
||||
$isRead = UserMessage::where([
|
||||
['user_id', '=', $userId],
|
||||
['notice_id', '=', $notice->id],
|
||||
['is_read', '=', 1]
|
||||
])->find();
|
||||
|
||||
// 根据type过滤
|
||||
if ($type == 'unread' && $isRead)
|
||||
continue;
|
||||
if ($type == 'read' && !$isRead)
|
||||
continue;
|
||||
|
||||
$data[] = [
|
||||
'id' => $notice->id,
|
||||
'title' => $notice->title,
|
||||
'content' => $notice->content,
|
||||
'type' => $notice->type,
|
||||
'is_top' => $notice->is_top,
|
||||
'is_read' => $isRead ? 1 : 0,
|
||||
'create_time' => date('Y-m-d H:i:s', $notice->create_time)
|
||||
];
|
||||
}
|
||||
|
||||
return json(['code' => 0, 'msg' => '获取成功', 'data' => $data]);
|
||||
} catch (\Exception $e) {
|
||||
return json(['code' => 1, 'msg' => '获取失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
//修改密码
|
||||
public function updatePassword()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user