hospital-applets-api/app/Model/CouponGrant.php

94 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Model;
use Carbon\Carbon;
use Hyperf\Database\Model\Collection;
/**
* @property int $grant_id 主键id
* @property int $coupon_id 优惠卷id
* @property int $grant_type 发放类型(1:具体用户 2:未拥有用户)
* @property int $user_id 用户id发放类型为具体用户时存在
* @property int $total_quantity 目标发放数量
* @property int $grant_quantity 已发放数量
* @property int $grant_result 发放结果1:成功 2:发放中 3:失败)
* @property string $stop_reason 停止原因
* @property int $admin_user_id 后台操作用户id
* @property Carbon $created_at 创建时间
* @property Carbon $updated_at 修改时间
*/
class CouponGrant extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'coupon_grant';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['grant_id', 'coupon_id', 'grant_type', 'user_id', 'total_quantity', 'grant_quantity', 'grant_result', 'stop_reason', 'admin_user_id', 'created_at', 'updated_at'];
protected string $primaryKey = "grant_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 $data 新增数据
* @return \Hyperf\Database\Model\Model|CouponGrant
*/
public static function addCouponGrant(array $data): \Hyperf\Database\Model\Model|CouponGrant
{
return self::create($data);
}
/**
* 修改-批量
* @param array $params
* @param array $data
* @return int
*/
public static function editCouponGrant(array $params = [], array $data = []): int
{
return self::where($params)->update($data);
}
/**
* 自增
* @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);
}
}