diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 9cb74eb..78cacc1 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -169,33 +169,45 @@ class CouponController extends BaseController $data = Db::table('ims_system_coupon_user_receive as receive') - ->leftJoin('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') - ->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('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( - [ + ->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]) + ->where(['receive.user_id' => $userId]) + ->whereIn('coupon.type', [1,$type]) + ->whereIn('receive.status', [0,1]) + ->where('receive.number_remain', '>', 0) + ->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] + [ + ['coupon.type', 'in', [1,2]], + ['coupon.storetype_id', '=', 0] + ], + [ + ['coupon.type', 'in', [1,3]], + ['coupon.storetype_id', '=', $storetypeId] + ] ] - ] - ); - }) - ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') - ->get(); + ); + }) + ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') + ->get(); //var_dump($d); return $this->success($data);