|
|
|
@ -34,17 +34,35 @@ class CouponController extends BaseController |
|
|
|
$this->success(['not_reveive' => []]); |
|
|
|
} |
|
|
|
|
|
|
|
$c_ids = CouponUserRecType::where('receive_type', $receive_type)->pluck('system_coupon_user_id'); |
|
|
|
$c_ids = []; |
|
|
|
// 渠道开启,查询该渠道可以领取的优惠券ID
|
|
|
|
// 渠道未开启,查询所有优惠券
|
|
|
|
if (env('SUB_CHANNEL') == 1) { |
|
|
|
$c_ids = CouponUserRecType::where('receive_type', $receive_type)->pluck('system_coupon_user_id'); |
|
|
|
} else { |
|
|
|
$c_ids = Coupon::pluck('id'); |
|
|
|
} |
|
|
|
|
|
|
|
$nowTime = time(); |
|
|
|
$cr_ids = CouponRec::where([ |
|
|
|
['user_id',"=",$user_id], |
|
|
|
['receive_type',"=",$receive_type] |
|
|
|
])->pluck('system_coupon_user_id'); |
|
|
|
|
|
|
|
$where = [ |
|
|
|
['user_id',"=",$user_id] |
|
|
|
]; |
|
|
|
|
|
|
|
// 渠道开启,查询该用户在此渠道领过的优惠券ID
|
|
|
|
if (env('SUB_CHANNEL') == 1) { |
|
|
|
array_push($where, ['receive_type', "=", $receive_type]); |
|
|
|
} |
|
|
|
|
|
|
|
$cr_ids = CouponRec::where($where)->pluck('system_coupon_user_id'); |
|
|
|
|
|
|
|
//领过券的ID
|
|
|
|
$c_ids = $c_ids->toArray(); |
|
|
|
$cr_ids = $cr_ids->toArray(); |
|
|
|
|
|
|
|
// 当前用户可领的优惠券ID
|
|
|
|
$couponIds = array_diff($c_ids, $cr_ids); |
|
|
|
|
|
|
|
$c = Db::table('ims_system_coupon_user as u') |
|
|
|
->where([ |
|
|
|
['u.end_time','>',$nowTime], |
|
|
|
@ -54,8 +72,9 @@ class CouponController extends BaseController |
|
|
|
]) |
|
|
|
->join('ims_system_coupon_user_receivetype as type', 'u.id', '=', 'type.system_coupon_user_id') |
|
|
|
->whereRaw('u.inventory_use <= u.inventory and u.inventory-u.inventory_use > type.one_receive_number') |
|
|
|
->whereIn('u.id',$c_ids) |
|
|
|
->whereNotIn('u.id',$cr_ids) |
|
|
|
// ->whereIn('u.id',$c_ids)
|
|
|
|
// ->whereNotIn('u.id',$cr_ids)
|
|
|
|
->whereIn('u.id', $couponIds) |
|
|
|
->select('u.*','type.one_receive_number') |
|
|
|
->orderBy('u.weigh','desc') |
|
|
|
// ->orderByRaw('FIELD(u.id, '.implode(", " , $ids).')')
|
|
|
|
|