From 117e356d0ae0b226e39afca95e65423268d8d49e Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 16:12:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E5=8D=95=E6=8E=A5=E5=8F=A3=E6=95=B4?= =?UTF-8?q?=E5=90=88=20=E6=9C=89=E5=A4=B1=E6=95=88=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=97=B6=E8=BF=94=E5=9B=9E=E5=A4=B1=E6=95=88=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/CouponUserUse.php | 6 ++++ app/Service/CouponService.php | 43 ++++++++++++++------------ app/Service/CouponServiceInterface.php | 2 +- app/Service/OrderService.php | 6 ++-- app/Service/PurchaseLimitService.php | 2 -- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/Model/CouponUserUse.php b/app/Model/CouponUserUse.php index 0d53a14..76064ca 100644 --- a/app/Model/CouponUserUse.php +++ b/app/Model/CouponUserUse.php @@ -13,5 +13,11 @@ class CouponUserUse extends Model public $timestamps = false; + protected $fillable = [ + 'status', + 'return_time', + 'update_time' + ]; + protected $table = 'ims_system_coupon_user_use'; } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 8363f31..d64b786 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -160,18 +160,6 @@ class CouponService implements CouponServiceInterface { $available = []; $notAvailable = []; - //如果存在特价商品 不给用券 - $carIdsArr = explode(',',$carIds); - $shopCarExists = ShopCar::whereIn('id',$carIdsArr) - ->where('money',0.01) - ->exists(); - if($shopCarExists){ - return [ - 'available' => $available, - 'not_available' => array_values($notAvailable) - ]; - } - $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); if (empty($orderAmount) || empty($userId)) { @@ -218,12 +206,27 @@ class CouponService implements CouponServiceInterface foreach ($data as $key => &$item) { if (in_array($item->id, $couponIds)) { + $item->msg = '今日已使用'; $notAvailable[$item->id] = $item; } else { $available[] = $item; } } + //如果存在特价商品 不给用券 + $carIdsArr = explode(',',$carIds); + $shopCarExists = ShopCar::whereIn('id',$carIdsArr) + ->where('money',0.01) + ->exists(); + if($shopCarExists){ + var_dump(1111); + foreach ($available as $k => $v) { + $v->msg = '特价商品不可使用'; + $notAvailable[$v->id] = $v; + } + $available = []; + } + return [ 'available' => $available, 'not_available' => array_values($notAvailable) @@ -334,7 +337,7 @@ class CouponService implements CouponServiceInterface 'coupon_'.date('Ymd').'_used_'.$order_main->user_id, $coupon->system_coupon_id ); - return $res; + return $remRes; } /* 删除-优惠券今日使用的缓存 @@ -359,19 +362,22 @@ class CouponService implements CouponServiceInterface * 先查询是否正常使用优惠券 * 修改状态,退还领取记录库存,删除ssdb缓存 */ - public function orderRefundCoupon($global_order_id) + public function orderRefundCoupons($global_order_id) { + $order_main = OrderMain::where('global_order_id',$global_order_id) + ->select('id','user_id') + ->first(); $time = time(); Db::beginTransaction(); try { $couponUses = CouponUserUse::query() ->select('id','system_coupon_id','user_id','number','user_receive_id') - ->where('global_order_id',$global_order_id) + ->where('order_main_id',$order_main->id) ->where('status',CouponUserUse::COUPON_USE_STATE_USED) - ->select(); - if(!empty($couponUse)){ + ->get(); + if(!empty($couponUses)){ foreach($couponUses as $use){ - $use->status = CouponUserUse::COUPON_USE_STATE_USED; + $use->status = CouponUserUse::COUPON_USE_STATE_CANCEL; $use->return_time = $time; $use->update_time = $time; $res = $use->save(); @@ -397,6 +403,5 @@ class CouponService implements CouponServiceInterface Db::rollBack(); return false; } - return true; } } \ No newline at end of file diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index 669e086..e7c54b5 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -29,5 +29,5 @@ interface CouponServiceInterface public function refundOrderCoupons($global_order_id); public function clearTodayCouponUsed($userId, $couponId); - public function orderRefundCoupon($global_order_id); + public function orderRefundCoupons($global_order_id); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index fc3c3e0..a1d5734 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -733,10 +733,10 @@ class OrderService implements OrderServiceInterface OrderMain::where('global_order_id',$global_order_id) ->update(['state' => OrderMain::ORDER_STATE_CANCEL]); //撤销redis 用券记录 - $res = $this->couponService->refundOrderCoupons($global_order_id); + $redisRes = $this->couponService->orderRefundCoupons($global_order_id); //撤销特价商品购买记录 - $res = $this->purchaseLimitService->delSsdbPurchaseRecord($global_order_id); - return $res; + $ssdbRes = $this->purchaseLimitService->delSsdbPurchaseRecord($global_order_id); + return $redisRes && $ssdbRes; } /** * @inheritDoc diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 717e45e..8bbd222 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -71,8 +71,6 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface foreach ($goods as $k2 => $v2) { $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id']); - var_dump($v1['user_id']); - var_dump($v1['good_id']); } } return true;