Files
hyperf_service/app/Model/UserCoupon.php
2025-03-04 17:42:49 +08:00

67 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use App\Constants\Common\CouponCode;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property int $coupon_template_id
* @property int $coupon_dispense_id
* @property int $user_id
* @property int $status
* @property string $coupon_name
* @property string $use_time
* @property string $validity_start_time
* @property string $validity_end_time
* @property string $create_time
* @property string $update_time
*/
class UserCoupon extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'user_coupon';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
protected array $guarded = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'coupon_template_id' => 'integer', 'coupon_dispense_id' => 'integer', 'user_id' => 'integer', 'status' => 'integer'];
const string CREATED_AT = 'created_time';
const string UPDATED_AT = 'updated_time';
public function getReceiveCountByUserIds(int $user_id,array $couponIdArr): array
{
return $this
->where('user_id', $user_id)
->whereIn('coupon_id', $couponIdArr)
->pluck('coupon_id')
->toArray();
}
/**
* @param int $userId
* @return Builder[]|Collection
*/
public function getNoUseCouponByUserId(int $userId): Collection|array
{
return $this
->where('user_id', $userId)
->where('status', CouponCode::COUPON_STATUS_UNUSED)
->get();
}
}