From 3eadf7d5e843d217a00d9dba4679df8135fa4445 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 17 Jul 2020 09:47:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 672fc2c..9d1aa90 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -68,8 +68,42 @@ class CouponController extends BaseController $userId = $this->request->input("user_id"); $receiveType = $this->request->input("receive_type"); $ids = $this->request->input("ids"); + $type = $this->request->input("test",0); - + + $ids = is_array($ids)?implode(',',$ids):$ids; + + $cps = Coupon::whereIn('id', $ids)->get(); + $now = time(); + $success = []; + $fail = []; + foreach ($cps as $key => $cp) { + + + $crt = CouponUserRecType::where('system_coupon_user_id',$cp->id)->first(); + + //TODO 会有超发情况 + $cr = new CouponRec; + $cr->user_id = $userId; + $cr->system_coupon_user_id = $cp->id; + $cr->order_main_id = 0; + $cr->receive_time = $now; + $cr->number = $crt->one_receive_number; + $cr->nnumber_remain = $crt->one_receive_number; + $cr->status = 0; + $cr->update_time = $now; + $cr->receive_type = $receiveType; + if($cr->save()){ + $success[] = $cp; + }else{ + $fail[] = $cp; + } + } + + return $this->success([ + 'success'=>$success, + 'fail'=>$fail, + ]); }