|
|
|
@ -160,14 +160,14 @@ class CouponController extends BaseController |
|
|
|
$type = $this->request->input('type',1); |
|
|
|
# 店铺类型id
|
|
|
|
$storetypeId = $this->request->input('storetype_id',0); |
|
|
|
$storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); |
|
|
|
|
|
|
|
// 获取用户优惠券
|
|
|
|
$currentTime = time(); |
|
|
|
|
|
|
|
$container = ApplicationContext::getContainer(); |
|
|
|
$redis = $container->get(Redis::class); |
|
|
|
$couponDayUsed = $redis->hGetAll('coupon_day_used'); |
|
|
|
$couponRecIds = array_values($couponDayUsed); |
|
|
|
$couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); |
|
|
|
|
|
|
|
$data = Db::table('ims_system_coupon_user_receive as receive') |
|
|
|
->select([ |
|
|
|
@ -183,31 +183,21 @@ class CouponController extends BaseController |
|
|
|
'coupon.discount_type' |
|
|
|
]) |
|
|
|
->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') |
|
|
|
->whereNotIn('receive.id', $couponRecIds) |
|
|
|
->where(['receive.user_id' => $userId]) |
|
|
|
->where(['receive.user_id' => $userId]) |
|
|
|
->whereIn('coupon.type', [1,$type]) |
|
|
|
->whereIn('receive.status', [0,1]) |
|
|
|
->where('receive.number_remain', '>', 0) |
|
|
|
->where('receive.number_remain', '>', 0); |
|
|
|
|
|
|
|
if (is_array($couponIds)&&!empty($couponIds)) { |
|
|
|
$data->whereNotIn('coupon.id', $couponIds); |
|
|
|
} |
|
|
|
|
|
|
|
$data = $data->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]) |
|
|
|
->where(function ($query) use ($storetypeId) { |
|
|
|
$query->whereOr( |
|
|
|
[ |
|
|
|
[ |
|
|
|
['coupon.type', 'in', [1,2]], |
|
|
|
['coupon.storetype_id', '=', 0] |
|
|
|
], |
|
|
|
[ |
|
|
|
['coupon.type', 'in', [1,3]], |
|
|
|
['coupon.storetype_id', '=', $storetypeId] |
|
|
|
] |
|
|
|
] |
|
|
|
); |
|
|
|
}) |
|
|
|
->whereIn('coupon.storetype_id', $storetypeIds) |
|
|
|
->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') |
|
|
|
->get(); |
|
|
|
|
|
|
|
|