feat : coupon
This commit is contained in:
@@ -37,13 +37,32 @@ class CouponListService extends BaseService
|
||||
{
|
||||
$limit = (int)$this->request->input('limit',20);
|
||||
|
||||
$searchStatus = (int)$this->request->input('searchStatus',CouponCode::COUPON_STATUS_UNUSED);
|
||||
|
||||
$data = $this->couponTemplateModel
|
||||
->join('user_coupon', function ($join) {
|
||||
->join('user_coupon', function ($join) use ($searchStatus) {
|
||||
$join->on('user_coupon.coupon_template_id', '=', 'coupon_template.id')
|
||||
->where('user_coupon.user_id', '=', $this->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'))
|
||||
->when($searchStatus, function ($query, $searchStatus) {
|
||||
$query->where('user_coupon.status','=',$searchStatus);
|
||||
switch ($searchStatus) {
|
||||
case CouponCode::COUPON_STATUS_UNUSED:
|
||||
$query->where('user_coupon.validity_end_time', '>=', date('Y-m-d H:i:s'));
|
||||
break;
|
||||
case CouponCode::COUPON_STATUS_EXPIRE:
|
||||
$query->where('user_coupon.validity_end_time', '<', date('Y-m-d H:i:s'));
|
||||
break;
|
||||
case CouponCode::COUPON_STATUS_CAN_USED:
|
||||
$query->where('user_coupon.validity_start_time', '<=', date('Y-m-d H:i:s'));
|
||||
break;
|
||||
case CouponCode::COUPON_STATUS_USED:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
// ->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',
|
||||
|
||||
Reference in New Issue
Block a user