Files
fdesk/app/common/model/MessageNotifications.php
T
2025-08-21 19:26:28 +08:00

98 lines
2.0 KiB
PHP

<?php
namespace app\common\model;
use support\Model;
class MessageNotifications extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'message_notifications';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
// const UPDATED_AT = false;
// protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'msg_no', 'sender_id', 'sender_type', 'recipient', 'title', 'content', 'scene', 'push_method', 'created_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
// 消息创建
const SCENE = [
self::SCENE0 => '系统消息',
self::SCENE1 => '系统通知'
];
const SCENE0 = 0;
const SCENE1 = 1;
// 推送方式
const PUSH_METHOD = [
self::PUSH_METHOD0 => '系统推送',
self::PUSH_METHOD1 => '手动推送'
];
const PUSH_METHOD0 = 0;
const PUSH_METHOD1 = 1;
/**
* 关联用户消息状态 (一对多)
*/
public function userStatuses()
{
return $this->hasMany(MessageUserStatus::class, 'msg_id', 'id');
}
/**
* 获取已读用户状态
*/
public function readUsers()
{
return $this->hasMany(MessageUserStatus::class, 'msg_id', 'id')
->where('status', 1);
}
/**
* 获取未读用户状态
*/
public function unreadUsers()
{
return $this->hasMany(MessageUserStatus::class, 'msg_id', 'id')
->where('status', 0);
}
public function sender()
{
return $this->belongsTo(User::class, 'sender_id', 'id');
}
}