Merge commit 'ed96e0f8589042fb8e9d6cfee713c5150612bb34'

This commit is contained in:
mzl
2025-08-22 18:16:13 +08:00
parent d715708728
commit 11165fcfb9
23 changed files with 1465 additions and 32 deletions
+98
View File
@@ -0,0 +1,98 @@
<?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');
}
}
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace app\common\model;
use support\Model;
class MessageUserStatus 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_user_status';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
// protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'msg_id', 'uid', 'status', 'read_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
/**
* 关联消息 (多对一)
*/
public function message()
{
return $this->belongsTo(MessageNotifications::class, 'msg_id', 'id');
}
/**
* 关联用户 (假设你有 User 模型)
*/
public function user()
{
return $this->belongsTo(User::class, 'uid', 'id');
}
}