diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index dd9ed65..3f4064b 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -87,6 +87,7 @@ class CouponRebateController extends BaseController $activity = $this->request->input('activity_type',0); $userId = $this->request->input('user_id',0); $get = $this->request->input('get',0); - return $this->success($this->CouponRebateService->clearSsdbCouponReceiveByName($activity,$userId, $get)); + $isAll = $this->request->input('is_all',0);; + return $this->success($this->CouponRebateService->clearSsdbCouponReceiveByName($activity,$userId, $get, $isAll)); } } diff --git a/app/Service/CouponRebateService.php b/app/Service/CouponRebateService.php index 138b7a9..8d27c16 100644 --- a/app/Service/CouponRebateService.php +++ b/app/Service/CouponRebateService.php @@ -56,14 +56,16 @@ class CouponRebateService implements CouponRebateServiceInterface $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $activity = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY ,'activity'); + // ssdb 键值 + $ssdbKey = 'activity_'.$activity.'_user_'.$userId; $receiveSsdb = []; // 判断是否已全部领取过 - $userReceive = $ssdb->exec('hgetall', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId); + $userReceive = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_RECEIVE,$ssdbKey); if($userReceive === false){ $ids = $idsData; }else{ - $userReceiveCouponIds = empty($userReceive) ? [] : $userReceive ; + $userReceiveCouponIds = empty($userReceive) ? [] : explode(',',$userReceive) ; $ids = array_diff($idsData, $userReceiveCouponIds); $receiveSsdb = $userReceiveCouponIds; } @@ -148,13 +150,12 @@ class CouponRebateService implements CouponRebateServiceInterface } if(count($receiveSsdb) > 0){ - $saveSsdb = []; - foreach($receiveSsdb as $kssdb => $vssdb){ - $saveSsdb[] = $kssdb; - $saveSsdb[] = $vssdb; - } - // 记录到ssdb - if(false === $ssdb->exec('multi_hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId, $saveSsdb)){ +; + $saveSsdb = [ + $ssdbKey, + implode(',',$receiveSsdb) + ]; + if(false === $ssdb->exec('hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE, $saveSsdb)){ $errorData['msg'] = '记录领取优惠券到ssdb失败'; $this->log->event( LogLabel::COUPON_LOG, @@ -372,16 +373,24 @@ class CouponRebateService implements CouponRebateServiceInterface /** * 清优惠券领取记录(SSDB) */ - public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0){ - + public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0, $isAll = 0){ + $key = 'activity_'.$activity.'_user_'.$userId; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - if($get > 0){ - return [ - $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ) - ]; + if($isAll > 0){ + if($get > 0){ + return $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE); + }else{ + return ( $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE) === false) ? false : true ; + } + }else { + $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ); + + if($get > 0){ + return $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_RECEIVE, $key); + }else{ + return ( $ssdb->exec('hdel', SsdbKeysPrefix::COUPON_REBATE_RECEIVE, $key) === false) ? false : true ; + } } - - return ( $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ) === false) ? false : true; } } \ No newline at end of file diff --git a/app/Service/CouponRebateServiceInterface.php b/app/Service/CouponRebateServiceInterface.php index 6b6edf9..df8fc5d 100644 --- a/app/Service/CouponRebateServiceInterface.php +++ b/app/Service/CouponRebateServiceInterface.php @@ -17,6 +17,6 @@ interface CouponRebateServiceInterface public function couponRebate($order_id); - public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0); + public function clearSsdbCouponReceiveByName($activity, $userId, $get = 0, $isAll = 0); } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 7c365f0..8ee46a2 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -38,7 +38,7 @@ class CouponService implements CouponServiceInterface 'jump_data' => [ 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'share_bg' => env('OSS_IMG_HOST')."/attachment/images/png/2020/08/10/23245eea88db680670df67e77e0d8d7e.png", + 'share_bg' => env('OSS_IMG_HOST').'/attachment/images/png/2020/08/11/23245eea88db680670df67e77e0d8d7e.png', 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png", 'coupons' => [] ]