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.
57 lines
1.2 KiB
57 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Message;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* 短消息
|
|
* Class MessageController
|
|
* @package App\Http\Controllers\Api
|
|
*/
|
|
class MessageController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$page = request()->input('page');
|
|
if ($page && !ctype_digit($page)) {
|
|
return $this->error('页码错误');
|
|
}
|
|
|
|
$list = Message::where('user_id', $this->user_id)
|
|
->select('id', 'title', 'is_read', 'created_at')
|
|
->orderBy('id', 'DESC')
|
|
->simplePaginate(15);
|
|
return $this->success($list);
|
|
}
|
|
|
|
public function show()
|
|
{
|
|
$id = request()->input('id');
|
|
if (!$id || !ctype_digit($id)) {
|
|
return $this->error('错误的ID');
|
|
}
|
|
|
|
$message = Message::where('agent_id', $this->agent_id)->find($id);
|
|
if (!$message) {
|
|
return $this->error('短消息不存在或已被删除');
|
|
}
|
|
return $this->success($message);
|
|
}
|
|
|
|
//标记短消息为已读
|
|
public function setRead()
|
|
{
|
|
$id = request()->input('id');
|
|
if (!$id || !ctype_digit($id)) {
|
|
return $this->error('错误的ID');
|
|
}
|
|
|
|
$message = Message::where(['id' => $id, 'user_id' => $this->user_id])->find($id);
|
|
$message->is_read = 1;
|
|
$message->save();
|
|
return $this->success();
|
|
}
|
|
}
|