78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
use Hyperf\Database\Model\Relations\HasOne;
|
|
use Hyperf\Snowflake\Concern\Snowflake;
|
|
|
|
/**
|
|
* @property int $order_coupon_id 主键id
|
|
* @property int $order_product_id 订单-商品id
|
|
* @property int $user_coupon_id 用户优惠卷表id
|
|
* @property string $coupon_name 优惠卷名称
|
|
* @property string $coupon_use_price 优惠卷使用金额
|
|
* @property Carbon $created_at 创建时间
|
|
* @property Carbon $updated_at 修改时间
|
|
*/
|
|
class OrderProductCoupon extends Model
|
|
{
|
|
use Snowflake;
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'order_product_coupon';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = ['order_coupon_id', 'order_product_id', 'user_coupon_id', 'coupon_name', 'coupon_use_price', 'created_at', 'updated_at'];
|
|
|
|
protected string $primaryKey = "order_coupon_id";
|
|
|
|
/**
|
|
* 关联优惠券表
|
|
*/
|
|
public function UserCoupon(): HasOne
|
|
{
|
|
return $this->hasOne(Coupon::class, 'user_coupon_id', 'user_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 object|null
|
|
*/
|
|
public static function getList(array $params, array $fields = ['*']): object|null
|
|
{
|
|
return self::where($params)->get($fields);
|
|
}
|
|
|
|
/**
|
|
* 新增
|
|
* @param array $data
|
|
* @return OrderProductCoupon|\Hyperf\Database\Model\Model
|
|
*/
|
|
public static function addOrderProductCoupon(array $data): \Hyperf\Database\Model\Model|OrderProductCoupon
|
|
{
|
|
return self::create($data);
|
|
}
|
|
}
|