|
|
|
@ -199,65 +199,9 @@ class CouponController extends BaseController |
|
|
|
$type = $this->request->input('type', 1); |
|
|
|
# 店铺类型id
|
|
|
|
$storetypeId = $this->request->input('storetype_id', 0); |
|
|
|
$storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); |
|
|
|
|
|
|
|
$available = []; |
|
|
|
$notAvailable = []; |
|
|
|
|
|
|
|
if ($this->empty($orderAmount) || $this->empty($userId)) { |
|
|
|
return $this->success([ |
|
|
|
'available' => $available, |
|
|
|
'not_available' => array_values($notAvailable) |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取用户优惠券
|
|
|
|
$currentTime = time(); |
|
|
|
|
|
|
|
$data = Db::table('ims_system_coupon_user_receive as receive') |
|
|
|
->select([ |
|
|
|
'receive.id as receive_id', |
|
|
|
'receive.user_id', |
|
|
|
'receive.number_remain', |
|
|
|
'coupon.id', |
|
|
|
'coupon.title', |
|
|
|
'coupon.full_amount', |
|
|
|
'coupon.discounts', |
|
|
|
'coupon.usable_start_time', |
|
|
|
'coupon.usable_end_time', |
|
|
|
'coupon.discount_type' |
|
|
|
]) |
|
|
|
->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') |
|
|
|
->where(['receive.user_id' => $userId]) |
|
|
|
->whereIn('receive.status', [0,1]) |
|
|
|
->where('receive.number_remain', '>', 0) |
|
|
|
->whereIn('coupon.type', [1,$type]) |
|
|
|
->where('coupon.full_amount', '<=', $orderAmount) |
|
|
|
->where('coupon.usable_start_time', '<=', $currentTime) |
|
|
|
->where('coupon.usable_end_time', '>=', $currentTime) |
|
|
|
->where('coupon.usable_number', '<=', Db::raw('receive.number_remain')) |
|
|
|
->where('coupon.market_id', 'in', [0, $marketId]) |
|
|
|
->whereIn('coupon.storetype_id', $storetypeIds) |
|
|
|
->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') |
|
|
|
->get(); |
|
|
|
|
|
|
|
// 分离用户今天用过的优惠券种类
|
|
|
|
$container = ApplicationContext::getContainer(); |
|
|
|
$redis = $container->get(Redis::class); |
|
|
|
$couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); |
|
|
|
|
|
|
|
foreach ($data as $key => &$item) { |
|
|
|
if (in_array($item->id, $couponIds)) { |
|
|
|
$notAvailable[$item->id] = $item; |
|
|
|
} else { |
|
|
|
$available[] = $item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $this->success([ |
|
|
|
'available' => $available, |
|
|
|
'not_available' => array_values($notAvailable) |
|
|
|
]); |
|
|
|
|
|
|
|
$res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId); |
|
|
|
return $this->success($res); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|