|
|
|
@ -0,0 +1,57 @@ |
|
|
|
<?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(); |
|
|
|
} |
|
|
|
} |