ChatRecordItem.php 2.4 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 模型层:AI聊天记录 模型类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Models\Chat
 * @package   App\Models\Chat
 * @author    Richer <yangzi1028@163.com>
 * @date      2023年4月23日16:38:09
 * @copyright 2014-2023 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Models\Chat;

use App\Models\BaseModel;
use App\Models\User\User;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Arr;

/**
 * Class ChatRecordItem
 * @property mixed user_id
 * @property mixed record_id
 * @property mixed user_type
 * @property mixed content
 * @property mixed ai_model
 * @package App\Models
 */
class ChatRecordItem extends BaseModel
{
    // 指定数据库表
    const TABLE = 'chat_record_items';
    protected $table = self::TABLE ;

    // 指定对象显示名称:方便系统统一查询和做其他处理
    const OBJ_NAME = 'chat-record-item';
    const OBJ_NAME_ZH = 'AI聊天记录明细';

    /**
     * 类型业务常量配置
     */
    const USER  = 1;// 用户
    const AI    = 2;// AI
    const TYPE_OPTIONS = [
        self::USER  => '用户',
        self::AI    => 'AI',
    ];

    /**
     * 访问器被附加到模型数组的形式。
     *
     * @var array
     */
    protected $appends = ['user_type_show'];

    /**
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class)->withTrashed();
    }

    /**
     * @return BelongsTo
     */
    public function record(): BelongsTo
    {
        return $this->belongsTo(ChatRecord::class, 'record_id');
    }

    /**
     * 获取状态的中文显示
     *
     * @return mixed
     */
    public function getUserTypeShowAttribute()
    {
        return Arr::get(self::TYPE_OPTIONS, $this->user_type ? : self::USER);
    }  /**
     * 获取状态的中文显示
     *
     * @return mixed
     */
    public function getBodyAttribute($value)
    {
        if ($this->body_all) {
            $value = $this->body_all;
        }
        return $value;
    }
}