init commit
This commit is contained in:
108
application/admin/model/wdsxh/message/MemberNotification.php
Normal file
108
application/admin/model/wdsxh/message/MemberNotification.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\model\wdsxh\message;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 会员消息通知模型
|
||||
*/
|
||||
class MemberNotification extends Model
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'wdsxh_member_notification';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = false;
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'is_read_text',
|
||||
'createtime_text'
|
||||
];
|
||||
|
||||
// 已读状态列表
|
||||
public static $isReadList = [
|
||||
0 => '未读',
|
||||
1 => '已读'
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取已读状态文本
|
||||
*/
|
||||
public function getIsReadTextAttr($value, $data)
|
||||
{
|
||||
return isset(self::$isReadList[$data['is_read']]) ? self::$isReadList[$data['is_read']] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取创建时间文本
|
||||
*/
|
||||
public function getCreatetimeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
|
||||
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member()
|
||||
{
|
||||
return $this->belongsTo('app\admin\model\wdsxh\member\Member', 'member_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记为已读
|
||||
*/
|
||||
public function markAsRead()
|
||||
{
|
||||
if ($this->is_read == 0) {
|
||||
$this->is_read = 1;
|
||||
$this->read_time = time();
|
||||
return $this->save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读数量
|
||||
* @param int $member_id 会员ID
|
||||
* @return int
|
||||
*/
|
||||
public static function getUnreadCount($member_id)
|
||||
{
|
||||
return self::where('member_id', $member_id)
|
||||
->where('is_read', 0)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量标记为已读
|
||||
* @param array $ids 消息ID数组
|
||||
* @param int $member_id 会员ID
|
||||
* @return bool
|
||||
*/
|
||||
public static function markBatchAsRead($ids, $member_id)
|
||||
{
|
||||
return self::where('id', 'in', $ids)
|
||||
->where('member_id', $member_id)
|
||||
->update([
|
||||
'is_read' => 1,
|
||||
'read_time' => time()
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user