Browse Source

Merge branch 'coupon_rebate' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into coupon_rebate

master
parent
commit
0a869a507d
  1. 3
      app/Controller/CouponRebateController.php
  2. 43
      app/Service/CouponRebateService.php
  3. 2
      app/Service/CouponRebateServiceInterface.php
  4. 2
      app/Service/CouponService.php
  5. 2
      app/Service/ParamsTokenSsdbService.php

3
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));
}
}

43
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($isAll > 0){
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
];
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 );
return ( $ssdb->exec('hclear', SsdbKeysPrefix::COUPON_REBATE_RECEIVE . $activity . $userId ) === false) ? false : true;
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 ;
}
}
}
}

2
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);
}

2
app/Service/CouponService.php

@ -38,6 +38,8 @@ 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/11/23245eea88db680670df67e77e0d8d7e.png',
'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/background/dangmian_dialog_background.png",
'coupons' => []
]
];

2
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);

Loading…
Cancel
Save