feat : coupon
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Common\CouponCode;
|
||||
use Hyperf\Collection\Collection;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
@@ -68,4 +70,32 @@ class CouponTemplate extends Model
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return Collection
|
||||
*/
|
||||
public function getNoUseCouponByUserId(int $userId): Collection
|
||||
{
|
||||
return $this
|
||||
->join('user_coupon', function ($join) use ($userId) {
|
||||
$join->on('user_coupon.coupon_template_id', '=', 'coupon_template.id')
|
||||
->where('user_coupon.user_id', '=', $userId)
|
||||
->where('user_coupon.status', '=', CouponCode::COUPON_STATUS_UNUSED)
|
||||
->where('validity_start_time', '<=', date('Y-m-d H:i:s'))
|
||||
->where('validity_end_time', '>=', date('Y-m-d H:i:s'))
|
||||
->select([
|
||||
'coupon_template.coupon_type',
|
||||
'coupon_template.amount',
|
||||
'coupon_template.ratio',
|
||||
'user_coupon.id',
|
||||
'user_coupon.coupon_template_id',
|
||||
'user_coupon.coupon_name',
|
||||
'user_coupon.status',
|
||||
'user_coupon.validity_start_time',
|
||||
'user_coupon.validity_end_time',
|
||||
]);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user