feat:优化
This commit is contained in:
1 parent
2d39bbe3c2
commit
f29cc83be7
5 files changed
+40
-24
No files matched your search
+1
-1
@@ -1230,7 +1230,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
cancelDto.setOrderId(orderObj.getId());
|
||||
cancelDto.setUseAmountPrice(useAmountPrice);
|
||||
Boolean isCancelSuccess = remoteComActService.remoteDoCancel(cancelDto).getData();
|
||||
if (!isCancelSuccess) {
|
||||
if (ObjectUtil.isEmpty(isCancelSuccess) || !isCancelSuccess) {
|
||||
throw new RuntimeException("核销失败");
|
||||
}
|
||||
// 钱包扣款
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ public enum ActUserReceiveEnum {
|
||||
// 特殊
|
||||
PLEASE_RECEIVE_IN_BIRTH_MONTH("-100", "请在生日当月领取"),
|
||||
PLEASE_FILL_BIRTH_DATE("-101", "请填写出生日期"),
|
||||
BIRTHDAY_PERIOD_ENDED("-102", "生日已结束"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
+7
-2
@@ -1,5 +1,6 @@
|
||||
package com.bsd.pjcloud.wallet.service;
|
||||
|
||||
import com.bsd.pjcloud.admin.api.entity.SysUser;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCouponEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCouponRecordEntity;
|
||||
|
||||
@@ -7,20 +8,23 @@ public interface ActCouponLifecycleService {
|
||||
|
||||
/**
|
||||
* 领取优惠券前的校验
|
||||
*
|
||||
* @param couponId 优惠券ID
|
||||
* @param userId 用户ID
|
||||
* @param userId 用户ID
|
||||
* @return 优惠券实体
|
||||
*/
|
||||
ActCouponEntity preReceive(Long couponId, Long userId);
|
||||
|
||||
/**
|
||||
* 领取优惠券后的处理
|
||||
*
|
||||
* @param record 优惠券记录实体
|
||||
*/
|
||||
void afterReceive(ActCouponRecordEntity record);
|
||||
void afterReceive(ActCouponRecordEntity record, SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 核销前的校验
|
||||
*
|
||||
* @param record 优惠券记录实体
|
||||
* @return 优惠券实体
|
||||
*/
|
||||
@@ -28,6 +32,7 @@ public interface ActCouponLifecycleService {
|
||||
|
||||
/**
|
||||
* 核销后的处理
|
||||
*
|
||||
* @param record 优惠券记录实体
|
||||
*/
|
||||
void afterCancel(ActCouponRecordEntity record);
|
||||
|
||||
+28
-19
@@ -43,6 +43,9 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -119,8 +122,10 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
// 4. 执行领取逻辑
|
||||
ActCouponRecordEntity record = actCouponComUtilService.doReceive(actCouponEntity, sysUser);
|
||||
// 5. 优惠券领取成功后,执行生命周期方法
|
||||
actCouponComUtilService.afterReceive(record);
|
||||
// 6. 生成核销二维码
|
||||
actCouponComUtilService.afterReceive(record, sysUser);
|
||||
// 6. 领取后特殊处理
|
||||
specialReceive(actCouponEntity, record, sysUser);
|
||||
// 7. 生成核销二维码
|
||||
walletCodeUseService.generate(record.getId(), record.getUserId(), WalletCodeBizEnum.ACT, 1);
|
||||
return record.getId();
|
||||
}
|
||||
@@ -150,13 +155,11 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
if (ObjectUtil.isEmpty(actCouponRecordEntity)) {
|
||||
throw new ServiceException("优惠券不存在");
|
||||
}
|
||||
// 4. 特殊核销
|
||||
specialCancelCoupon(actCouponEntity, actCouponRecordEntity, sysUser);
|
||||
// 5. 执行核销逻辑
|
||||
// 4. 执行核销逻辑
|
||||
actCouponComUtilService.doCancel(actCouponRecordEntity.getId(), orderId, useAmountPrice);
|
||||
// 6. 优惠券核销成功后,执行生命周期方法
|
||||
// 5. 优惠券核销成功后,执行生命周期方法
|
||||
actCouponComUtilService.afterCancel(actCouponRecordEntity);
|
||||
// 7. 核销短码
|
||||
// 6. 核销短码
|
||||
walletCodeUseService.cancelCode(actCouponRecordEntity.getId());
|
||||
}
|
||||
|
||||
@@ -169,20 +172,21 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
}
|
||||
|
||||
/**
|
||||
* 特殊核销规则
|
||||
* 特殊处理领取后
|
||||
*/
|
||||
public void specialCancelCoupon(ActCouponEntity actCouponEntity, ActCouponRecordEntity actCouponRecordEntity, SysUser sysUser) {
|
||||
String uniqueCode = actCouponEntity.getUniqueCode();
|
||||
public void specialReceive(ActCouponEntity act, ActCouponRecordEntity record, SysUser sysUser) {
|
||||
String uniqueCode = act.getUniqueCode();
|
||||
// 食堂生日券
|
||||
if (ObjectUtil.equals(uniqueCode, "1qRgFo")) {
|
||||
// 只能本月核销
|
||||
LocalDate birthday = sysUser.getBirthday();
|
||||
if (ObjectUtil.isEmpty(birthday)) {
|
||||
log.info("|{}|{}用户核销{}活动失败:请填写生日", TAG, sysUser.getName(), uniqueCode);
|
||||
throw new ServiceException("请填写生日");
|
||||
}
|
||||
if (ObjectUtil.notEqual(LocalDate.now().getMonth().getValue(), birthday.getMonth().getValue())) {
|
||||
log.info("|{}|{}用户核销{}活动成功:在生日当月核销", TAG, sysUser.getName(), uniqueCode);
|
||||
throw new ServiceException("只能在生日当月核销");
|
||||
if (ObjectUtil.isNotEmpty(birthday)) {
|
||||
LocalDate now = LocalDate.now().withMonth(birthday.getMonthValue());
|
||||
// 使用时间是生日当月
|
||||
ActCouponRecordEntity updateObj = new ActCouponRecordEntity();
|
||||
updateObj.setId(record.getId());
|
||||
updateObj.setStartTime(now.with(TemporalAdjusters.firstDayOfMonth()).atTime(LocalTime.MIN));
|
||||
updateObj.setEndTime(now.with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59));
|
||||
baseMapper.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,12 +226,17 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
log.info("|{}|{}用户参加{}活动失败:用户最近3个月没有充值{}分", TAG, sysUser.getName(), uniqueCode, walletTotalPrice);
|
||||
return ActUserReceiveEnum.USER_CANNOT_PARTICIPATE;
|
||||
}
|
||||
// 要在本年领取
|
||||
// 领取时间要大于生日
|
||||
LocalDate birthday = sysUser.getBirthday();
|
||||
if (ObjectUtil.isEmpty(birthday)) {
|
||||
log.info("|{}|{}用户参加{}活动失败:请填写生日", TAG, sysUser.getName(), uniqueCode);
|
||||
return ActUserReceiveEnum.PLEASE_FILL_BIRTH_DATE;
|
||||
}
|
||||
LocalDate currentYearBirthday = birthday.withYear(LocalDate.now().getYear());
|
||||
if (currentYearBirthday.isBefore(LocalDate.now())) {
|
||||
log.info("|{}|{}用户参加{}活动失败:生日已结束", TAG, sysUser.getName(), uniqueCode);
|
||||
return ActUserReceiveEnum.BIRTHDAY_PERIOD_ENDED;
|
||||
}
|
||||
return ActUserReceiveEnum.USER_CAN_JOIN_ACT;
|
||||
}
|
||||
return null;
|
||||
|
||||
+3
-2
@@ -89,7 +89,7 @@ public class ActCouponComUtilService implements ActCouponLifecycleService {
|
||||
* 领取优惠券后的处理
|
||||
*/
|
||||
@Override
|
||||
public void afterReceive(ActCouponRecordEntity record) {
|
||||
public void afterReceive(ActCouponRecordEntity record, SysUser sysUser) {
|
||||
|
||||
}
|
||||
|
||||
@@ -137,7 +137,8 @@ public class ActCouponComUtilService implements ActCouponLifecycleService {
|
||||
}
|
||||
// 基本校验:状态是否可用
|
||||
if (ObjectUtil.notEqual(ActCouponRecordStatusEnum.UNUSED.getCode(), couponRecord.getStatus())) {
|
||||
return "优惠券不可用";
|
||||
ActCouponRecordStatusEnum type = ActCouponRecordStatusEnum.valueOfByType(couponRecord.getStatus());
|
||||
return "该优惠券" + type.getDesc();
|
||||
}
|
||||
// 校验有效期
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
Reference in new issue
Block a user