Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
736a59eda8
8 files changed
+76
-29
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);
|
||||
|
||||
+3
@@ -258,6 +258,9 @@ public class WalletCodeUseServiceImpl extends ServiceImpl<WalletCodeUseMapper, W
|
||||
.orderByDesc(WalletCodeUseEntity::getId)
|
||||
.last("limit 1")
|
||||
);
|
||||
if (ObjectUtil.isEmpty(detail) || ObjectUtil.isEmpty(detail.getCodeContent())) {
|
||||
return null;
|
||||
}
|
||||
return detail.getCodeContent();
|
||||
}
|
||||
|
||||
|
||||
+2
-7
@@ -231,14 +231,9 @@ public class ActCancelItemServiceImpl extends ServiceImpl<ActCancelItemMapper, A
|
||||
.eq(ActCancelItemEntity::getReceiverUserId, userId)
|
||||
);
|
||||
if (ObjectUtil.isEmpty(detail)) {
|
||||
return ActUserReceiveEnum.USER_LIMIT_REACHED;
|
||||
return ActUserReceiveEnum.USER_CAN_JOIN_ACT;
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(detail.getExpireTime())) {
|
||||
if (detail.getExpireTime().isBefore(LocalDateTime.now())) {
|
||||
return ActUserReceiveEnum.ACT_EXPIRED;
|
||||
}
|
||||
}
|
||||
return ActUserReceiveEnum.USER_CAN_JOIN_ACT;
|
||||
return ActUserReceiveEnum.USER_LIMIT_REACHED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+56
-17
@@ -25,6 +25,7 @@ import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActCouponReceiveDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActCouponRecordDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCouponEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCouponRecordEntity;
|
||||
@@ -42,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;
|
||||
@@ -118,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();
|
||||
}
|
||||
@@ -139,17 +145,22 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
if (ObjectUtil.isEmpty(record)) {
|
||||
throw new ServiceException("优惠券不存在");
|
||||
}
|
||||
// 2. 预处理
|
||||
ActCouponRecordEntity actCouponEntity = actCouponComUtilService.preCancel(record);
|
||||
// 2. 查询活动
|
||||
ActCouponEntity actCouponEntity = actCouponService.getById(record.getCouponId());
|
||||
if (ObjectUtil.isEmpty(actCouponEntity)) {
|
||||
throw new ServiceException("活动不存在");
|
||||
}
|
||||
// 3. 预处理
|
||||
ActCouponRecordEntity actCouponRecordEntity = actCouponComUtilService.preCancel(record);
|
||||
if (ObjectUtil.isEmpty(actCouponRecordEntity)) {
|
||||
throw new ServiceException("优惠券不存在");
|
||||
}
|
||||
// 3. 执行核销逻辑
|
||||
actCouponComUtilService.doCancel(actCouponEntity.getId(), orderId, useAmountPrice);
|
||||
// 4. 优惠券核销成功后,执行生命周期方法
|
||||
actCouponComUtilService.afterCancel(actCouponEntity);
|
||||
// 5. 核销短码
|
||||
walletCodeUseService.cancelCode(actCouponEntity.getId());
|
||||
// 4. 执行核销逻辑
|
||||
actCouponComUtilService.doCancel(actCouponRecordEntity.getId(), orderId, useAmountPrice);
|
||||
// 5. 优惠券核销成功后,执行生命周期方法
|
||||
actCouponComUtilService.afterCancel(actCouponRecordEntity);
|
||||
// 6. 核销短码
|
||||
walletCodeUseService.cancelCode(actCouponRecordEntity.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,6 +171,29 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
return actCouponComUtilService.actIsCanCancel(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 特殊处理领取后
|
||||
*/
|
||||
public void specialReceive(ActCouponEntity act, ActCouponRecordEntity record, SysUser sysUser) {
|
||||
String uniqueCode = act.getUniqueCode();
|
||||
// 食堂生日券
|
||||
if (ObjectUtil.equals(uniqueCode, "1qRgFo")) {
|
||||
LocalDate birthday = sysUser.getBirthday();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 特殊领取规则
|
||||
*/
|
||||
public ActUserReceiveEnum specialCoupon(ActCouponEntity actCouponEntity, SysUser sysUser) {
|
||||
String uniqueCode = actCouponEntity.getUniqueCode();
|
||||
// 食堂生日券
|
||||
@@ -178,25 +212,30 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
dto.setBizTypes(WalletBizEnum.getTopUpCodes());
|
||||
dto.setType(WalletTransactionDto.TYPE_INCOME);
|
||||
dto.setUserId(sysUser.getUserId());
|
||||
dto.setPriceList(List.of(500 * 100, 1500 * 100, 800 * 100, 2400 * 100));
|
||||
dto.setCreateTimeList(new LocalDate[]{
|
||||
LocalDate.now().minusMonths(4),
|
||||
LocalDate.now().minusMonths(3).withDayOfMonth(1),
|
||||
LocalDate.now().plusDays(1)
|
||||
});
|
||||
List<WalletTransactionVo> walletList = walletTransactionMapper.scopeList(dto, null);
|
||||
if (ObjectUtil.isEmpty(walletList)) {
|
||||
log.info("|{}|{}用户参加{}活动失败:用户最近一年充值金额不足500,1500,800,2400", TAG, sysUser.getName(), uniqueCode);
|
||||
log.info("|{}|{}用户参加{}活动失败:用户最近3个月没有充值记录", TAG, sysUser.getName(), uniqueCode);
|
||||
return ActUserReceiveEnum.USER_CANNOT_PARTICIPATE;
|
||||
}
|
||||
// 要在生日当月领取
|
||||
Integer walletTotalPrice = walletList.stream().filter(v -> ObjectUtil.isNotEmpty(v.getPrice())).map(WalletTransactionEntity::getPrice).reduce(Integer::sum).orElse(0);
|
||||
if (walletTotalPrice < 1500 * 100) {
|
||||
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;
|
||||
}
|
||||
if (ObjectUtil.notEqual(LocalDate.now().getMonth().getValue(), birthday.getMonth().getValue())) {
|
||||
log.info("|{}|{}用户参加{}活动成功:在生日当月领取", TAG, sysUser.getName(), uniqueCode);
|
||||
return ActUserReceiveEnum.PLEASE_RECEIVE_IN_BIRTH_MONTH;
|
||||
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;
|
||||
}
|
||||
|
||||
+5
-2
@@ -13,11 +13,13 @@ import com.bsd.pjcloud.wallet.service.ActCouponLifecycleService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author liusiyang_dxm
|
||||
@@ -87,7 +89,7 @@ public class ActCouponComUtilService implements ActCouponLifecycleService {
|
||||
* 领取优惠券后的处理
|
||||
*/
|
||||
@Override
|
||||
public void afterReceive(ActCouponRecordEntity record) {
|
||||
public void afterReceive(ActCouponRecordEntity record, SysUser sysUser) {
|
||||
|
||||
}
|
||||
|
||||
@@ -135,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();
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
</where>
|
||||
order by a.create_time desc , a.id desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user