Files
hospital-applets-api/app/Model/Coupon.php
T

152 lines
5.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use Carbon\Carbon;
use Hyperf\Database\Model\Collection;
use Hyperf\Snowflake\Concern\Snowflake;
/**
* @property string $coupon_id 主键id
* @property string $coupon_name 优惠卷名称
* @property string $coupon_icon 优惠卷图片
* @property int $coupon_client 使用平台(1:小程序)
* @property int $coupon_type 优惠卷类型(1:无门槛 2:满减 3:数量)
* @property int $coupon_status 状态(1:正常 2:强制失效 3:结束 4:删除)
* @property int $distribution_object 发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户)
* @property int $application_scope 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别类别适用 5:单品使用)
* @property int $inquiry_type 关联问诊类型,适用范围为问诊时存在生效(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
* @property int $brand_id 关联品牌id(如不限制品牌,此项为空)
* @property int $is_mutex 是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用
* @property int $is_display 是否展示(0:否 1:是)
* @property int $distribution_with_day 发放关联天数(发放对象为近期消费等类型时规定天数)
* @property int $min_usable_number 单商品最小可使用数量(默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处)
* @property int $coupon_count 发放数量
* @property int $coupon_take_count 已领取数量
* @property int $coupon_used_count 已使用数量
* @property string $coupon_price 优惠卷金额
* @property string $with_amount 符合满减标准金额(优惠卷类型为满减时使用)
* @property int $valid_type 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)
* @property int $valid_days 自领取之日起有效天数
* @property string $valid_start_time 开始使用时间
* @property string $valid_end_time 结束使用时间
* @property string $product_id 关联商品id,逗号分隔,指定商品时,填入此项。
* @property int $reissue_interval_days 确认收货后的再次发放间隔天数(如果设置为 0,则表示不再次发放。当适用范围为商品时生效)
* @property int $is_reissuable_after_expire 过期之后是否允许再次发放(0:否 1:是)
* @property int $is_popup 是否首页弹窗(0:否 1:是)
* @property Carbon $created_at 创建时间
* @property Carbon $updated_at 修改时间
*/
class Coupon extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'coupon';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['coupon_id', 'coupon_name', 'coupon_icon', 'coupon_client', 'coupon_type', 'coupon_status', 'distribution_object', 'application_scope', 'inquiry_type', 'brand_id', 'is_mutex', 'is_display', 'distribution_with_day', 'min_usable_number', 'coupon_count', 'coupon_take_count', 'coupon_used_count', 'coupon_price', 'with_amount', 'valid_type', 'valid_days', 'valid_start_time', 'valid_end_time', 'product_id', 'reissue_interval_days', 'is_reissuable_after_expire', 'is_popup', 'created_at', 'updated_at'];
protected string $primaryKey = "coupon_id";
/**
* 获取-单条
* @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 $params
* @param string $field
* @param float $numeral
* @return int
*/
public static function inc(array $params,string $field,float $numeral = 1): int
{
return self::where($params)->increment($field,$numeral);
}
/**
* 自减
* @param array $params
* @param string $field
* @param float $numeral
* @return int
*/
public static function dec(array $params,string $field,float $numeral = 1): int
{
return self::where($params)->decrement($field,$numeral);
}
// 获取注册用户可领取的优惠卷列表
public static function getRegisterCouponList(): Collection|array
{
return self::where("coupon_client",1)
->where("coupon_status",1)
->whereIn("distribution_object",[1,2])
->get();
}
/**
* 获取购买服务包的用户可领取的优惠卷列表
* @return Collection|array
*/
public static function getOrderServicePackageCouponList(): Collection|array
{
return self::where("coupon_client",1)
->where("coupon_status",1)
->whereIn("distribution_object",[7])
->get();
}
/**
* 获取今日过期优惠卷
* @param array $params
* @param array $valid_end_time
* @param array $fields
* @return Collection|array
*/
public static function getTodayExpiredCoupon(array $params,array $valid_end_time,array $fields = ['*']): Collection|array
{
return self::where($params)
->whereBetween('valid_end_time', $valid_end_time)
->get($fields);
}
/**
* 修改
* @param array $params
* @param array $data
* @return int
*/
public static function edit(array $params = [], array $data = []): int
{
return self::where($params)->update($data);
}
}