149 lines
5.0 KiB
PHP
149 lines
5.0 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Model;
|
||
|
||
|
||
use Hyperf\Database\Model\Builder;
|
||
use Hyperf\Database\Model\Collection;
|
||
use Hyperf\Snowflake\Concern\Snowflake;
|
||
|
||
/**
|
||
* @property int $notice_id 主键id
|
||
* @property int $user_id 用户id(接受者)
|
||
* @property int $user_type 用户类型(1:患者端 2:医师端 3:药师端)
|
||
* @property int $notice_type 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息)
|
||
* @property int $notice_system_type 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
|
||
* @property int $read_status 读取状态(0:未读 1:已读)
|
||
* @property string $from_name 发送人姓名
|
||
* @property string $notice_brief_title 缩略消息标题(列表页展示)
|
||
* @property string $notice_title 消息标题
|
||
* @property string $notice_send_time 发送时间
|
||
* @property string $notice_content 内容
|
||
* @property int $send_status 发送状态(0:未处理 1:已发送 2:发送失败)
|
||
* @property string $send_fail_reason 发送失败原因
|
||
* @property int $button_type 按钮类型(1:我的账户 2:联系客服 3:查看协议 4:订单详情 5:查看处方 6:问诊详情 )
|
||
* @property int $link_type 跳转页面类型(1:聊天详情页 2:问诊结束列表页 3:问诊消息列表页 4:我的名片 5:我的简介 6:我的账户 7:我的福利 8:药品订单详情页 9:物流详情 10:问诊订单详情 11:联系客服 12:协议详情 13:处方详情 14:多点执业认证页)
|
||
* @property string $link_params 跳转参数(json)
|
||
* @property int $show_type 展示类型(1:医生数据)
|
||
* @property string $show_params 展示数据(json)
|
||
* @property \Carbon\Carbon $created_at 创建时间
|
||
* @property \Carbon\Carbon $updated_at 修改时间
|
||
*/
|
||
class MessageNotice extends Model
|
||
{
|
||
use Snowflake;
|
||
|
||
/**
|
||
* The table associated with the model.
|
||
*/
|
||
protected ?string $table = 'message_notice';
|
||
|
||
/**
|
||
* The attributes that are mass assignable.
|
||
*/
|
||
protected array $fillable = ['notice_id', 'user_id', 'user_type', 'notice_type', 'notice_system_type', 'read_status', 'from_name', 'notice_brief_title', 'notice_title', 'notice_send_time', 'notice_content', 'send_status', 'send_fail_reason', 'button_type', 'link_type', 'link_params', 'show_type', 'show_params', 'created_at', 'updated_at'];
|
||
|
||
protected string $primaryKey = "notice_id";
|
||
|
||
/**
|
||
* 获取是否存在
|
||
* @param array $params
|
||
* @return bool
|
||
*/
|
||
public static function getExists(array $params): bool
|
||
{
|
||
return self::where($params)->exists();
|
||
}
|
||
|
||
/**
|
||
* 获取信息-单条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取数据-多
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return Collection|array
|
||
*/
|
||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||
{
|
||
return self::where($params)->get($fields);
|
||
}
|
||
|
||
/**
|
||
* 新增
|
||
* @param array $data
|
||
* @return MessageNotice|\Hyperf\Database\Model\Model
|
||
*/
|
||
public static function addMessageNotice(array $data): MessageNotice|\Hyperf\Database\Model\Model
|
||
{
|
||
return self::create($data);
|
||
}
|
||
|
||
/**
|
||
* 获取数据-分页
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @param int|null $page
|
||
* @param int|null $per_page
|
||
* @return array
|
||
*/
|
||
public static function getMessageNoticePage(array $params, array $fields = ["*"], int $page = null, ?int $per_page = 10): array
|
||
{
|
||
$results = self::where($params)
|
||
->orderBy('notice_send_time','desc')
|
||
->paginate($per_page, $fields, "page", $page);
|
||
|
||
$data = array();
|
||
$data['current_page'] = $results->currentPage();// 当前页码
|
||
$data['total'] = $results->total();//数据总数
|
||
$data['data'] = $results->items();//数据
|
||
$data['per_page'] = $results->perPage();//每页个数
|
||
$data['last_page'] = $results->lastPage();//最后一页
|
||
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* 修改
|
||
* @param array $params
|
||
* @param array $data
|
||
* @return int
|
||
*/
|
||
public static function edit(array $params = [], array $data = []): int
|
||
{
|
||
return self::where($params)->update($data);
|
||
}
|
||
|
||
/**
|
||
* 获取单条
|
||
* @param array $params
|
||
* @param string $order_field
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getOrderOne(array $params, string $order_field,array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->orderBy($order_field,'desc')->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取数量
|
||
* @param array $params
|
||
* @return int
|
||
*/
|
||
public static function getCount(array $params): int
|
||
{
|
||
return self::where($params)->count();
|
||
}
|
||
}
|