ChatController.php 2.1 KB
<?php
/**
 * @remark :
 * @name   :ChatController.php
 * @author :lyh
 * @method :post
 * @time   :2025/4/1 14:33
 */

namespace App\Http\Controllers\Bside\Gpt;

use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Gpt\ChatLogic;
use App\Models\Gpt\Chat;
use App\Models\Gpt\ChatItem;

class ChatController extends BaseController
{
    /**
     * @remark :获取消息列表
     * @name   :list
     * @author :lyh
     * @method :post
     * @time   :2025/4/2 15:51
     */
    public function list(Chat $chat){
        $list = $chat->lists(['user_id'=>$this->user['id'],'status'=>1],$this->page,$this->row);
        $this->response('success',Code::SUCCESS,$list);
    }

    /**
     * @remark :获取所有子消息
     * @name   :itemList
     * @author :lyh
     * @method :post
     * @time   :2025/4/2 15:55
     */
    public function itemList(ChatItem $chatItem){
        $this->request->validate([
            'chat_id'=>['required'],
        ],[
            'chat_id.required' => 'chat_id不能为空',
        ]);
        $list = $chatItem->list(['user_id'=>$this->user['id'],'chat_id'=>$this->map['chat_id'],'status'=>1]);
        $this->response('success',Code::SUCCESS,$list);
    }

    /**
     * @remark :发送消息
     * @name   :sendMessage
     * @author :lyh
     * @method :post
     * @time   :2025/4/1 14:35
     */
    public function sendMessage(ChatLogic $logic){
        $this->request->validate([
            'message'=>['required'],
        ],[
            'message.required' => '消息内容不能为空',
        ]);
        $data = $logic->sendMessage();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :删除消息
     * @name   :del
     * @author :lyh
     * @method :post
     * @time   :2025/4/2 15:54
     */
    public function del(Chat $chat){
        $this->request->validate([
            'id'=>['required'],
        ],[
            'id.required' => 'id不能为空',
        ]);
        $data = $chat->edit(['status'=>0],['id'=>$this->param['id']]);
        $this->response('success',Code::SUCCESS,$data);
    }
}