<?php
|
|
namespace app\common\model\supplier\member;
|
|
use app\common\model\BaseModel;
|
|
/**
|
* 供应商会员模型
|
* 记录供应商拥有的年卡信息
|
*/
|
class Member extends BaseModel
|
{
|
// 表名
|
protected $name = 'supplier_member';
|
protected $pk = 'member_id';
|
protected $append=['expire_time_text'];
|
/**
|
* 过期时间文本
|
*/
|
public function getExpireTimeTextAttr($value, $data)
|
{
|
return $data['expire_time'] > 0 ? date('Y-m-d H:i:s', $data['expire_time']) : '长期有效';
|
}
|
|
/**
|
* 关联供应商表
|
*/
|
public function supplier()
|
{
|
return $this->belongsTo('app\common\model\supplier\Supplier', 'shop_supplier_id', 'shop_supplier_id');
|
}
|
|
/**
|
* 关联年卡计划表
|
*/
|
public function plan()
|
{
|
return $this->belongsTo('app\common\model\supplier\member\Plan', 'plan_id', 'plan_id');
|
}
|
|
/**
|
* 判断是否过期
|
*/
|
public function isExpired()
|
{
|
return $this->expire_time < time();
|
}
|
|
/**
|
* 获取供应商当前有效的年卡
|
*/
|
public static function getCurrentMember($supplierId, $appId)
|
{
|
return self::where([
|
'shop_supplier_id' => $supplierId,
|
'app_id' => $appId,
|
'is_expire' => 0
|
])->where('expire_time', '>', time())->find();
|
}
|
|
/**
|
* 获取详情
|
*/
|
public static function detail($memberId)
|
{
|
return (new static())->where('member_id', '=', $memberId)->where('is_expire', '=', 0)->find();
|
}
|
}
|