From 8406b27bca10533077335fa65d190e0f56925bdc Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Wed, 5 Aug 2020 17:22:25 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=90=8E=20=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=A4=9A=E4=BD=99=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebate.php | 15 --------------- app/Service/CouponRebateInterface.php | 12 ------------ 2 files changed, 27 deletions(-) delete mode 100644 app/Service/CouponRebate.php delete mode 100644 app/Service/CouponRebateInterface.php diff --git a/app/Service/CouponRebate.php b/app/Service/CouponRebate.php deleted file mode 100644 index 1afe901..0000000 --- a/app/Service/CouponRebate.php +++ /dev/null @@ -1,15 +0,0 @@ - Date: Thu, 6 Aug 2020 10:24:02 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=BF=94=E5=88=B8=E6=B4=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/couponRebateConsumer.php | 11 + app/Controller/CouponRebateController.php | 16 +- app/Service/CouponRebateService.php | 248 +++++++++++++------ app/Service/CouponRebateServiceInterface.php | 2 + config/routes.php | 1 + 5 files changed, 196 insertions(+), 82 deletions(-) diff --git a/app/Amqp/Consumer/couponRebateConsumer.php b/app/Amqp/Consumer/couponRebateConsumer.php index a4f7e27..475c7b9 100644 --- a/app/Amqp/Consumer/couponRebateConsumer.php +++ b/app/Amqp/Consumer/couponRebateConsumer.php @@ -8,16 +8,27 @@ use Hyperf\Amqp\Result; use Hyperf\Amqp\Annotation\Consumer; use Hyperf\Amqp\Message\ConsumerMessage; use PhpAmqpLib\Message\AMQPMessage; +use App\Service\CouponRebateService; +use App\Service\CouponRebateServiceInterface; +use Hyperf\Di\Annotation\Inject; /** * @Consumer(exchange="couponRebate", routingKey="couponRebate", queue="couponRebate", name ="couponRebateConsumer", nums=1) */ class couponRebateConsumer extends ConsumerMessage { + /** + * @Inject + * @var CouponRebateService + */ + protected $CouponRebateService; + public function consumeMessage($data, AMQPMessage $message): string { var_dump($data); var_dump($message->getBody()); + $res = $this->CouponRebateService->couponRebate($data); + var_dump($res); if (false) { return Result::REQUEUE; } diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index c1b2b93..30cc5bb 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -25,11 +25,11 @@ use App\Service\CouponRebateService; class CouponRebateController extends BaseController { - /** + /** * @Inject * @var CouponRebateService */ - protected $CouponRebateService; + protected $CouponRebateService; /** * 用户是否领取过领取优惠券 @@ -50,13 +50,21 @@ class CouponRebateController extends BaseController return $this->success($res); } - + /** * 用户领取优惠券 * 2020.08.04 只领一张优惠券 - */ + */ public function userReceiveCoupon(CouponRebateReceiveRequest $validator) { return $this->success($this->CouponRebateService->userReceiveCoupon($this->request->all())); } + + public function couponRebate() + { + $order_id = $this->request->input('order_id', 0); + $res = $this->CouponRebateService->couponRebate($order_id); + return $this->success($res); + } + } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 9db3bc9..48d8596 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -13,7 +13,7 @@ use Exception; class CouponRebateService implements CouponRebateServiceInterface { - /** + /** * @Inject * @var Log */ @@ -30,7 +30,7 @@ class CouponRebateService implements CouponRebateServiceInterface $sendUserId = $params["send_user_id"]; $phone = $params["phone"]; $now = time(); - + // status : 0 领取成功 >0 领取失败 $result = [ 'status' => 1, @@ -49,113 +49,119 @@ class CouponRebateService implements CouponRebateServiceInterface Db::transaction( function() use ($id,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData) { - try{ - //读写锁,完全控制,性能低 - $cp = Coupon::where('id', $id)->lockForUpdate() + try{ + //读写锁,完全控制,性能低 + $cp = Coupon::where('id', $id)->lockForUpdate() ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts') ->first(); - - $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$cp->id)->select('one_receive_number'); - if (env('SUB_CHANNEL') == 1) { - $couponReceiveType->where('receive_type',$receiveType); - } - // 查询一次能领取的数量 - $crt = $couponReceiveType->first(); - - $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->number_remain = $crt->one_receive_number; - $cr->status = 0; - $cr->update_time = $now; - $cr->receive_type = $receiveType; - $cr->send_user_id = $sendUserId; - $cr->phone = $phone; - - //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 - if ( - $cp->status != 1 - || - $cp->inventory <= $cp->inventory_use - || - $cp->inventory < ($cp->inventory_use+$cr->number) - || - $cp->start_time > $now - || - $cp->end_time < $now + $couponReceiveType = CouponUserRecType::where('system_coupon_user_id',$cp->id)->select('one_receive_number'); + + if (env('SUB_CHANNEL') == 1) { + $couponReceiveType->where('receive_type',$receiveType); + } + // 查询一次能领取的数量 + $crt = $couponReceiveType->first(); + + $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->number_remain = $crt->one_receive_number; + $cr->status = 0; + $cr->update_time = $now; + $cr->receive_type = $receiveType; + $cr->send_user_id = $sendUserId; + $cr->phone = $phone; + + //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内, 则返回领取失败的优惠券 + if ( + $cp->status != 1 + || + $cp->inventory <= $cp->inventory_use + || + $cp->inventory < ($cp->inventory_use+$cr->number) + || + $cp->start_time > $now + || + $cp->end_time < $now ) - { - $result['status'] = 2; - $result['coupon_text'] = '红包已经领完~'; + { + $result['status'] = 2; + $result['coupon_text'] = '红包已经领完~'; - $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); - }else{ - // 判断是否领取过 存在记录则领取过 - $isReceive = CouponRec::select('id') - ->where('system_coupon_user_id',$id) - ->where('user_id',$userId) - ->exists(); - - if(!$isReceive){ - - $cp->inventory_use += $cr->number;//记录已领取的数量 - - if ( $cr->save() && $cp->save() ) { - $result['status'] = 0; - // $result['data'] = $cp; - $result['coupon_text'] = $cp['discounts'].'元红包'; - } - }else{ - $errorData['msg'] = '用户已经领取了此优惠券'; + $errorData['msg'] = '优惠券已经过期或者被禁用或者已领完'; $this->log->event( LogLabel::COUPON_LOG, $errorData - ); + ); + }else{ + // 判断是否领取过 存在记录则领取过 + $isReceive = CouponRec::select('id') + ->where('system_coupon_user_id',$id) + ->where('user_id',$userId) + ->exists(); + + if(!$isReceive){ + + $cp->inventory_use += $cr->number;//记录已领取的数量 + + if ( $cr->save() && $cp->save() ) { + $result['status'] = 0; + // $result['data'] = $cp; + $result['coupon_text'] = $cp['discounts'].'元红包'; + } + }else{ + $errorData['msg'] = '用户已经领取了此优惠券'; + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } } + } catch (Exception $e){ + $errorData['msg'] = $e->getMessage(); + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); } - } catch (Exception $e){ - $errorData['msg'] = $e->getMessage(); - $this->log->event( - LogLabel::COUPON_LOG, - $errorData - ); - } }); return $result; } + /* + * 判断用户是否已领取过优惠券 + * */ public function isCouponRebate($user_id) { $res = Db::table('ims_system_coupon_user as u') ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') ->where([ - ['r.user_id','=',$user_id], - ['r.receive_type','=',4], - ['u.active_type','=',2], + ['r.user_id' ,'=', $user_id], + ['r.receive_type','=', 4], + ['u.active_type' ,'=', 2], ]) ->select('r.id') ->first(); return $res; } + /* + *获取活动信息 + */ public function getActiveInfo() { $time = time(); $res = Db::table('ims_system_coupon_user') ->where([ - ['status','=',1], - ['active_type','=',2], - ['start_time','<=',$time], - ['end_time','>',$time], + ['status' ,'=', 1], + ['active_type' ,'=', 2], + ['start_time' ,'<=', $time], + ['end_time' ,'>', $time], ]) ->whereRaw('inventory > inventory_use') ->orderBy('addtime','desc') @@ -163,4 +169,90 @@ class CouponRebateService implements CouponRebateServiceInterface return $res; } + /* + * 支付成功 返券 + */ + public function couponRebate($order_id) + { + + /* 判断优惠券类型是否为转发活动优惠券 */ + $coupon = Db::table('ims_system_coupon_user_receive as r') + ->leftjoin('ims_system_coupon_user_use as u', 'u.user_receive_id', '=', 'r.id') + ->where([ + ['u.order_main_id', '=', $order_id], + ['r.send_user_id', '>', 0], + ['r.rebate_type', '=', 1], + ['r.receive_type', '=', 4], + ['u.status', '=', 1], + ]) + ->select('r.id', 'r.send_user_id', 'u.system_coupon_id') + ->first(); + /* 如果使用的优惠券为转发活动优惠券 则给赠送者返一张优惠券*/ + if (isset($coupon->send_user_id) && ($coupon->send_user_id) > 0) { + //判断该优惠券是否有库存 +// $inventory = Db::table('system_coupon_user_receive as r'); +// if($inventory['inventory'] <= 0){ +// return '库存不足'; +// } + //判断用户是否已有该类型优惠券 + $exist_coupon = Db::table('ims_system_coupon_user_receive') + ->where([ + ['system_coupon_user_id', '=', $coupon->system_coupon_id], + ['user_id', '=', $coupon->send_user_id], + ['receive_type', '=', 5], + ['status', '=', 0], + ]) + ->select('id') + ->first(); + //return $exist_coupon; + //开启事务 + try { + /* + * 如果已有该优惠券 则领取数量 和 可用数量 自增1 + * 否则新增一条返券记录 + */ + $nowTime = time(); + $res = Db::table('ims_system_coupon_user_receive')->updateOrInsert( + [ + 'system_coupon_user_id' => $coupon->system_coupon_id, + 'user_id' => $coupon->send_user_id, + 'receive_type' => 5, + 'status' => 0, + ], + [ + 'order_main_id' => $order_id, + 'receive_time' => $nowTime, + 'number' => 1, + 'number_remain' => 1, + 'update_time' => $nowTime, + 'created_at' => $nowTime, + 'updated_at' => $nowTime, + ] + ); +// if ($res) { +// //首次返券更新rebate_type字段 防止重复返券 +// Db::table('system_coupon_user_receive')->where('id', $coupon->id)->update(['rebate_type' => 2]); +// //更新库存操作 +// Db::table('system_coupon_user') +// ->where('id', $coupon->id) +// ->increment('inventory_use'); +// } else { +// Db::rollBack(); +// return '事务失败'; +// } + // 提交 + Db::commit(); + } catch (\Exception $e) { + // 回滚 + Db::rollBack(); + return '返券失败'; + } + } else { +// $str1 = 'order_main_id:'.$this->order_id . ',未查询到用户领取优惠券信息['.$coupon.']'; +// $this->couponErrorLog($str1); + } + + + return $exist_coupon->id; + } } \ No newline at end of file diff --git a/app/Service/CouponRebateServiceInterface.php b/app/Service/CouponRebateServiceInterface.php index cc8c0ef..f7bc3a0 100644 --- a/app/Service/CouponRebateServiceInterface.php +++ b/app/Service/CouponRebateServiceInterface.php @@ -13,4 +13,6 @@ interface CouponRebateServiceInterface public function getActiveInfo(); + public function couponRebate($order_id); + } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 0db0115..0f3633c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -29,4 +29,5 @@ Router::addGroup('/v1/',function (){ Router::post('CouponRebate/isCouponRebate', 'App\Controller\CouponRebateController@isCouponRebate'); Router::post('CouponRebate/userReceiveCoupon', 'App\Controller\CouponRebateController@userReceiveCoupon'); Router::post('CouponRebate/getActiveInfo', 'App\Controller\CouponRebateController@getActiveInfo'); + Router::post('CouponRebate/couponRebate', 'App\Controller\CouponRebateController@couponRebate'); }); \ No newline at end of file From 240f58c43ef79907cd7696efe83d9f20fe4fe782 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Thu, 6 Aug 2020 11:35:42 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=87=AA=E5=A2=9E=E6=88=96=E6=8F=92?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 48d8596..78213ae 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -174,7 +174,6 @@ class CouponRebateService implements CouponRebateServiceInterface */ public function couponRebate($order_id) { - /* 判断优惠券类型是否为转发活动优惠券 */ $coupon = Db::table('ims_system_coupon_user_receive as r') ->leftjoin('ims_system_coupon_user_use as u', 'u.user_receive_id', '=', 'r.id') @@ -212,7 +211,7 @@ class CouponRebateService implements CouponRebateServiceInterface * 否则新增一条返券记录 */ $nowTime = time(); - $res = Db::table('ims_system_coupon_user_receive')->updateOrInsert( + $res = Db::table('ims_system_coupon_user_receive')->updateOrIncrement( [ 'system_coupon_user_id' => $coupon->system_coupon_id, 'user_id' => $coupon->send_user_id, @@ -222,11 +221,13 @@ class CouponRebateService implements CouponRebateServiceInterface [ 'order_main_id' => $order_id, 'receive_time' => $nowTime, - 'number' => 1, - 'number_remain' => 1, 'update_time' => $nowTime, 'created_at' => $nowTime, 'updated_at' => $nowTime, + ], + [ + 'number' => 1, + 'number_remain' => 1, ] ); // if ($res) { From c715d1e81fc02cf99a408b9bed84a0c5bb28ba4b Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Thu, 6 Aug 2020 15:06:58 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=87=AA=E5=A2=9Eor?= =?UTF-8?q?=E6=8F=92=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 78213ae..af734c0 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -193,16 +193,6 @@ class CouponRebateService implements CouponRebateServiceInterface // if($inventory['inventory'] <= 0){ // return '库存不足'; // } - //判断用户是否已有该类型优惠券 - $exist_coupon = Db::table('ims_system_coupon_user_receive') - ->where([ - ['system_coupon_user_id', '=', $coupon->system_coupon_id], - ['user_id', '=', $coupon->send_user_id], - ['receive_type', '=', 5], - ['status', '=', 0], - ]) - ->select('id') - ->first(); //return $exist_coupon; //开启事务 try { @@ -211,7 +201,7 @@ class CouponRebateService implements CouponRebateServiceInterface * 否则新增一条返券记录 */ $nowTime = time(); - $res = Db::table('ims_system_coupon_user_receive')->updateOrIncrement( + $res = Db::table('ims_system_coupon_user_receive')->moreIncrementOrInsert( [ 'system_coupon_user_id' => $coupon->system_coupon_id, 'user_id' => $coupon->send_user_id, @@ -254,6 +244,6 @@ class CouponRebateService implements CouponRebateServiceInterface } - return $exist_coupon->id; + return '返券成功'; } } \ No newline at end of file From 678a2efab576e2738426d15c9f395636b1a2e0ec Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Thu, 6 Aug 2020 15:26:19 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponRebateService.php | 84 ++++++++++++++++------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index dec3b75..da4b6da 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -37,13 +37,13 @@ class CouponRebateService implements CouponRebateServiceInterface $phone = $params["phone"]; $now = time(); $ids = is_array($ids) ? $ids : explode(',',$ids); - + // status: 0领取成功 >0领取失败 $result = [ 'status' => 1, 'coupon_text' => '继续努力~' ]; - + // 错误日志记录 $errorData = [ 'coupon_ids' =>$ids, @@ -54,24 +54,24 @@ class CouponRebateService implements CouponRebateServiceInterface ]; $receiveSsdb = []; - + try{ Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { $success = []; $fail = []; $isr = []; - + //读写锁,完全控制,性能低 $coupons = Coupon::whereIn('id', $ids)->lockForUpdate() - ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') - ->get(); + ->select('id','title','status','inventory','inventory_use','start_time','end_time','full_amount','discounts','active_type') + ->get(); foreach($coupons as $coupon){ $errorData['coupon_id'] = $coupon->id; //如果优惠卷库存小于等于已领取的数量 或者 未在活动时间内可领取, 否则返回领取失败的优惠券 - if ( + if ( $coupon->status == 1 && $coupon->inventory > $coupon->inventory_use @@ -81,7 +81,7 @@ class CouponRebateService implements CouponRebateServiceInterface $coupon->end_time >= $now && $coupon->active_type == 2 - ) + ) { // 查询一次能领取的数量 @@ -90,15 +90,15 @@ class CouponRebateService implements CouponRebateServiceInterface $couponReceiveType->where('receive_type',$receiveType); } $couponReceiveType = $couponReceiveType->first(); - + // 优惠券可领取数量 >= 本次领取数量 if($coupon->inventory - $coupon->inventory_use >= $couponReceiveType->one_receive_number){ // 判断是否领取过 存在记录则领取过 $isReceive = CouponRec::select('id') - ->where('system_coupon_user_id',$coupon->id) - ->where('user_id',$userId) - ->exists(); + ->where('system_coupon_user_id',$coupon->id) + ->where('user_id',$userId) + ->exists(); if(!$isReceive){ //记录已领取的数量 @@ -116,7 +116,7 @@ class CouponRebateService implements CouponRebateServiceInterface $couponReceive->receive_type = $receiveType; $couponReceive->send_user_id = $sendUserId; $couponReceive->phone = $phone; - + // if ( $couponReceive->save() && $coupon->save() ) { // $success[] = $coupon; // $receiveSsdb[] = $coupon->id;; @@ -126,12 +126,12 @@ class CouponRebateService implements CouponRebateServiceInterface $receiveSsdb[] = $coupon->id; $result['status'] = 2; $result['coupon_text'] = '您已领取!赶快去下单吧~'; - + $errorData['msg'] = '用户已经领取了优惠券'; $this->log->event( LogLabel::COUPON_LOG, $errorData - ); + ); } }else{ $fail[] = $coupon; @@ -161,6 +161,13 @@ class CouponRebateService implements CouponRebateServiceInterface $result['coupon_text'] = '恭喜您领取成功!'; } }); + } catch (Exception $e){ + $errorData['msg'] = $e->getMessage(); + $this->log->event( + LogLabel::COUPON_LOG, + $errorData + ); + } if(count($receiveSsdb) > 0){ $saveSsdb = []; foreach($receiveSsdb as $kssdb => $vssdb){ @@ -186,11 +193,11 @@ class CouponRebateService implements CouponRebateServiceInterface public function isCouponRebate($user_id) { $res = Db::table('ims_system_coupon_user as u') - ->leftjoin('ims_system_coupon_user_receive as r','u.id','=','r.system_coupon_user_id') + ->leftjoin('ims_system_coupon_user_receive as r', 'u.id', '=', 'r.system_coupon_user_id') ->where([ - ['r.user_id' ,'=', $user_id], - ['r.receive_type','=', 4], - ['u.active_type' ,'=', 2], + ['r.user_id', '=', $user_id], + ['r.receive_type', '=', 4], + ['u.active_type', '=', 2], ]) ->select('r.id') ->first(); @@ -205,13 +212,13 @@ class CouponRebateService implements CouponRebateServiceInterface $time = time(); $res = Db::table('ims_system_coupon_user') ->where([ - ['status' ,'=', 1], - ['active_type' ,'=', 2], - ['start_time' ,'<=', $time], - ['end_time' ,'>', $time], + ['status', '=', 1], + ['active_type', '=', 2], + ['start_time', '<=', $time], + ['end_time', '>', $time], ]) ->whereRaw('inventory > inventory_use') - ->orderBy('addtime','desc') + ->orderBy('addtime', 'desc') ->get(); return $res; } @@ -220,47 +227,47 @@ class CouponRebateService implements CouponRebateServiceInterface * 将优惠券绑定活动 * 领取优惠券 COUPON_REBATE_FORWARD 可多张 * 返还优惠券 COUPON_REBATE_REPAY 只一张 - */ - public function tieCouponActive($couponActivity,$couponForward,$couponRepay) + */ + public function tieCouponActive($couponActivity, $couponForward, $couponRepay) { $result = [ 'forward' => true, - 'repay' => true, + 'repay' => true, ]; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $rrss1 = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$couponActivity); - $rrss2 = $ssdb->exec('get',SsdbKeysPrefix::COUPON_REBATE_REPAY.$couponActivity); - return [$rrss1,$rrss2]; + $rrss1 = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity); + $rrss2 = $ssdb->exec('get', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity); + return [$rrss1, $rrss2]; // 记录领取类型优惠券 $forwardData = []; - foreach($couponForward as $kForward => $vForward){ + foreach ($couponForward as $kForward => $vForward) { $forwardData[] = $kForward; $forwardData[] = $vForward; } - if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$couponActivity,$forwardData)){ + if (false === $ssdb->exec('multi_hset', SsdbKeysPrefix::COUPON_REBATE_FORWARD . $couponActivity, $forwardData)) { $this->log->event( LogLabel::COUPON_LOG, [ 'coupon_activity' => $couponActivity, - 'coupon_forward' => $forwardData, - 'msg' => '绑定-领取-优惠券到ssdb失败' + 'coupon_forward' => $forwardData, + 'msg' => '绑定-领取-优惠券到ssdb失败' ] ); $result['forward'] = false; }; // 记录返还类型优惠券 - if(false === $ssdb->exec('set',SsdbKeysPrefix::COUPON_REBATE_REPAY.$couponActivity,$couponRepay)){ + if (false === $ssdb->exec('set', SsdbKeysPrefix::COUPON_REBATE_REPAY . $couponActivity, $couponRepay)) { $this->log->event( LogLabel::COUPON_LOG, [ 'coupon_activity' => $couponActivity, - 'coupon_Repay' => $couponRepay, - 'msg' => '绑定-返还-优惠券到ssdb失败' + 'coupon_Repay' => $couponRepay, + 'msg' => '绑定-返还-优惠券到ssdb失败' ] ); $result['repay'] = false; @@ -344,4 +351,5 @@ class CouponRebateService implements CouponRebateServiceInterface return '返券成功'; - }} \ No newline at end of file + } +} \ No newline at end of file