|
|
@ -15,11 +15,6 @@ class MessageController extends Controller |
|
|
{ |
|
|
{ |
|
|
public function index() |
|
|
public function index() |
|
|
{ |
|
|
{ |
|
|
$page = request()->input('page'); |
|
|
|
|
|
if ($page && !ctype_digit($page)) { |
|
|
|
|
|
return $this->error('页码错误'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$list = Message::where('user_id', $this->user_id) |
|
|
$list = Message::where('user_id', $this->user_id) |
|
|
->select('id', 'title', 'is_read', 'created_at') |
|
|
->select('id', 'title', 'is_read', 'created_at') |
|
|
->orderBy('id', 'DESC') |
|
|
->orderBy('id', 'DESC') |
|
|
@ -29,29 +24,20 @@ class MessageController extends Controller |
|
|
|
|
|
|
|
|
public function show() |
|
|
public function show() |
|
|
{ |
|
|
{ |
|
|
$id = request()->input('id'); |
|
|
|
|
|
if (!$id || !ctype_digit($id)) { |
|
|
|
|
|
return $this->error('错误的ID'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$id = (int)request()->input('id'); |
|
|
|
|
|
|
|
|
$message = Message::where('agent_id', $this->agent_id)->find($id); |
|
|
|
|
|
if (!$message) { |
|
|
|
|
|
return $this->error('短消息不存在或已被删除'); |
|
|
|
|
|
} |
|
|
|
|
|
return $this->success($message); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$message = Message::query() |
|
|
|
|
|
->where(['agent_id' => $this->agent_id, 'user_id' => $this->user_id]) |
|
|
|
|
|
->find($id); |
|
|
|
|
|
|
|
|
//标记短消息为已读
|
|
|
|
|
|
public function setRead() |
|
|
|
|
|
{ |
|
|
|
|
|
$id = request()->input('id'); |
|
|
|
|
|
if (!$id || !ctype_digit($id)) { |
|
|
|
|
|
return $this->error('错误的ID'); |
|
|
|
|
|
|
|
|
if (!$message) { |
|
|
|
|
|
return $this->error('消息不存在或已删除'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$message = Message::where(['id' => $id, 'user_id' => $this->user_id])->find($id); |
|
|
|
|
|
|
|
|
//标记短消息为已读
|
|
|
$message->is_read = 1; |
|
|
$message->is_read = 1; |
|
|
$message->save(); |
|
|
$message->save(); |
|
|
return $this->success(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($message); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |