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 245ab7c..0af991f 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; } @@ -106,7 +108,7 @@ class CouponRebateService implements CouponRebateServiceInterface if(!$isReceive){ //记录已领取的数量 - $coupon->inventory_use += $couponReceiveType->number; + $coupon->inventory_use += $couponReceiveType->one_receive_number; $couponReceive = new CouponRec; $couponReceive->user_id = $userId; @@ -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, @@ -373,18 +374,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 ), - $ssdb->exec('hgetAll', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $userId ), - 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 915dc6e..8ee46a2 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -36,9 +36,11 @@ class CouponService implements CouponServiceInterface 'active_type' => 1, 'not_receive' => [], 'jump_data' => [ - 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, + 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'coupons' => [] + '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' => [] ] ]; $nowTime = time(); diff --git a/app/Service/ParamsTokenSsdbService.php b/app/Service/ParamsTokenSsdbService.php index 65bd113..8aa60e2 100644 --- a/app/Service/ParamsTokenSsdbService.php +++ b/app/Service/ParamsTokenSsdbService.php @@ -26,7 +26,7 @@ class ParamsTokenSsdbService implements ParamsTokenServiceInterface */ public function generate($params) { - $token = md5(json_encode($params)); + $token = $params['token_name'] ?? md5(json_encode($params)); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);