增加技术端与客户端聊天
This commit is contained in:
89
server/app/common/model/chat/ChatMessage.php
Normal file
89
server/app/common/model/chat/ChatMessage.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
namespace app\common\model\chat;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ChatMessage extends Model
|
||||
{
|
||||
|
||||
|
||||
// 定义时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
protected $createTime = 'create_time';
|
||||
|
||||
// 消息类型
|
||||
const TYPE_TEXT = 1; // 文本
|
||||
const TYPE_IMAGE = 2; // 图片
|
||||
const TYPE_VOICE = 3; // 语音
|
||||
|
||||
// 发送者类型
|
||||
const SENDER_USER = 1; // 用户
|
||||
const SENDER_TECH = 2; // 技师
|
||||
|
||||
// 读取状态
|
||||
const UNREAD = 0; // 未读
|
||||
const READ = 1; // 已读
|
||||
|
||||
/**
|
||||
* 获取消息类型文本
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return string
|
||||
*/
|
||||
public function getMessageTypeTextAttr($value, $data)
|
||||
{
|
||||
$status = [
|
||||
self::TYPE_TEXT => '文本',
|
||||
self::TYPE_IMAGE => '图片',
|
||||
self::TYPE_VOICE => '语音',
|
||||
];
|
||||
return $status[$data['message_type']] ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取发送者类型文本
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return string
|
||||
*/
|
||||
public function getSenderTypeTextAttr($value, $data)
|
||||
{
|
||||
$status = [
|
||||
self::SENDER_USER => '用户',
|
||||
self::SENDER_TECH => '技师',
|
||||
];
|
||||
return $status[$data['sender_type']] ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取读取状态文本
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return string
|
||||
*/
|
||||
public function getReadStatusTextAttr($value, $data)
|
||||
{
|
||||
$status = [
|
||||
self::UNREAD => '未读',
|
||||
self::READ => '已读',
|
||||
];
|
||||
return $status[$data['read_status']] ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会话
|
||||
*/
|
||||
public function conversation()
|
||||
{
|
||||
return $this->belongsTo('app\common\model\chat\ChatConversation', 'conversation_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联订单
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo('app\common\model\order\Order', 'order_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user