You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
208 lines
5.6 KiB
208 lines
5.6 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 学员端消息管理控制器
|
|
// +----------------------------------------------------------------------
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\api\controller\student;
|
|
|
|
use app\service\api\student\MessageService;
|
|
use core\base\BaseController;
|
|
|
|
/**
|
|
* 学员端消息管理控制器
|
|
*/
|
|
class MessageController extends BaseController
|
|
{
|
|
private MessageService $messageService;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->messageService = new MessageService();
|
|
}
|
|
|
|
/**
|
|
* 获取学员消息列表
|
|
* @param int $student_id 学员ID
|
|
* @return array
|
|
*/
|
|
public function getMessageList($student_id = 0)
|
|
{
|
|
try {
|
|
// 获取请求参数
|
|
$data = [
|
|
'message_type' => input('message_type', ''),
|
|
'page' => input('page', 1),
|
|
'limit' => input('limit', 10),
|
|
'keyword' => input('keyword', ''),
|
|
'is_read' => input('is_read', '')
|
|
];
|
|
|
|
$data['student_id'] = (int)$student_id;
|
|
|
|
// 参数验证
|
|
if (empty($data['student_id'])) {
|
|
return fail('学员ID不能为空');
|
|
}
|
|
|
|
// 获取消息列表
|
|
$result = $this->messageService->getMessageList($data);
|
|
|
|
return success($result);
|
|
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取消息详情
|
|
* @param int $message_id 消息ID
|
|
* @return array
|
|
*/
|
|
public function getMessageDetail($message_id = 0)
|
|
{
|
|
try {
|
|
// 获取请求参数
|
|
$data = [
|
|
'student_id' => input('student_id', 0)
|
|
];
|
|
|
|
$data['message_id'] = (int)$message_id;
|
|
|
|
// 参数验证
|
|
if (empty($data['message_id']) || empty($data['student_id'])) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
// 获取消息详情
|
|
$result = $this->messageService->getMessageDetail($data);
|
|
|
|
return success($result);
|
|
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 标记消息已读
|
|
* @return array
|
|
*/
|
|
public function markMessageRead()
|
|
{
|
|
try {
|
|
// 获取请求参数
|
|
$data = [
|
|
'message_id' => input('message_id', 0),
|
|
'student_id' => input('student_id', 0)
|
|
];
|
|
|
|
// 参数验证
|
|
if (empty($data['message_id']) || empty($data['student_id'])) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
// 标记已读
|
|
$result = $this->messageService->markMessageRead($data);
|
|
|
|
return success($result, '操作成功');
|
|
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 批量标记消息已读
|
|
* @return array
|
|
*/
|
|
public function markBatchRead()
|
|
{
|
|
try {
|
|
// 获取请求参数
|
|
$data = [
|
|
'message_ids' => input('message_ids', []),
|
|
'student_id' => input('student_id', 0),
|
|
'message_type' => input('message_type', '')
|
|
];
|
|
|
|
// 参数验证
|
|
if (empty($data['student_id'])) {
|
|
return fail('学员ID不能为空');
|
|
}
|
|
|
|
if (empty($data['message_ids']) && empty($data['message_type'])) {
|
|
return fail('请指定要标记的消息');
|
|
}
|
|
|
|
// 批量标记已读
|
|
$result = $this->messageService->markBatchRead($data);
|
|
|
|
return success($result, '操作成功');
|
|
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取学员消息统计
|
|
* @param int $student_id 学员ID
|
|
* @return array
|
|
*/
|
|
public function getMessageStats($student_id = 0)
|
|
{
|
|
try {
|
|
if (empty($student_id)) {
|
|
return fail('学员ID不能为空');
|
|
}
|
|
|
|
// 获取消息统计
|
|
$result = $this->messageService->getMessageStats((int)$student_id);
|
|
|
|
return success($result);
|
|
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索消息
|
|
* @param int $student_id 学员ID
|
|
* @return array
|
|
*/
|
|
public function searchMessages($student_id = 0)
|
|
{
|
|
try {
|
|
// 获取请求参数
|
|
$data = [
|
|
'keyword' => input('keyword', ''),
|
|
'message_type' => input('message_type', ''),
|
|
'page' => input('page', 1),
|
|
'limit' => input('limit', 10)
|
|
];
|
|
|
|
$data['student_id'] = (int)$student_id;
|
|
|
|
// 参数验证
|
|
if (empty($data['student_id'])) {
|
|
return fail('学员ID不能为空');
|
|
}
|
|
|
|
if (empty($data['keyword'])) {
|
|
return fail('搜索关键词不能为空');
|
|
}
|
|
|
|
// 搜索消息
|
|
$result = $this->messageService->searchMessages($data);
|
|
|
|
return success($result);
|
|
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
}
|