diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 4565025..26296c6 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -63,13 +63,18 @@ class CouponController extends BaseController // 当前用户可领的优惠券ID $couponIds = array_diff($c_ids, $cr_ids); + $whereC = [ + ['u.end_time','>',$nowTime], + ['u.start_time','<=',$nowTime], + ['u.status','=',1], + ]; + + if (env('SUB_CHANNEL') == 1) { + array_push($whereC, ['type.receive_type','=',$receive_type]); + } + $c = Db::table('ims_system_coupon_user as u') - ->where([ - ['u.end_time','>',$nowTime], - ['u.start_time','<=',$nowTime], - ['type.receive_type','=',$receive_type], - ['u.status','=',1], - ]) + ->where($whereC) ->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) @@ -136,12 +141,16 @@ class CouponController extends BaseController //$cps = Coupon::whereIn('id', $ids)->sharedLock()->get(); foreach ($cps as $key => $cp) { - $crt = CouponUserRecType::where( - [ - 'system_coupon_user_id' => $cp->id, - 'receive_type' => $receiveType - ] - )->first(); + + $where = [ + 'system_coupon_user_id' => $cp->id, + ]; + + if (env('SUB_CHANNEL') == 1) { + $where['receive_type'] = $receiveType; + } + + $crt = CouponUserRecType::where($where)->first(); $cr = new CouponRec; $cr->user_id = $userId;