【代码评审】商城:取消拼团的支付单

This commit is contained in:
YunaiV 2024-08-28 13:19:36 +08:00
parent c4943e97c7
commit cccad2c6c1
7 changed files with 35 additions and 33 deletions

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.promotion.enums.common;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.Objects;
/**
* 营销的商品范围枚举
@ -37,15 +37,15 @@ public enum PromotionProductScopeEnum implements IntArrayValuable {
}
public static boolean isAll(Integer scope) {
return ObjUtil.equal(scope, ALL.scope);
return Objects.equals(scope, ALL.scope);
}
public static boolean isSpu(Integer scope) {
return ObjUtil.equal(scope, SPU.scope);
return Objects.equals(scope, SPU.scope);
}
public static boolean isCategory(Integer scope) {
return ObjUtil.equal(scope, CATEGORY.scope);
return Objects.equals(scope, CATEGORY.scope);
}
}

View File

@ -53,6 +53,7 @@ public class AppActivityController {
private DiscountActivityService discountActivityService;
@Resource
private RewardActivityService rewardActivityService;
@Resource
private ProductSpuApi productSpuApi;
@ -91,7 +92,7 @@ public class AppActivityController {
// 4. 限时折扣活动
getDiscountActivities(spuIds, now, activityList);
// 5. 满减送活动
getRewardActivities(spuIds, now, activityList);
getRewardActivityList(spuIds, now, activityList);
return activityList;
}
@ -148,23 +149,9 @@ public class AppActivityController {
item.getName(), productMap.get(item.getId()), item.getStartTime(), item.getEndTime())));
}
private static void buildAppActivityRespVO(RewardActivityDO rewardActivity, Collection<Long> spuIds,
List<AppActivityRespVO> activityList) {
for (Long spuId : spuIds) {
// 校验商品是否已经加入过活动
if (anyMatch(activityList, appActivity -> ObjUtil.equal(appActivity.getId(), rewardActivity.getId()) &&
ObjUtil.equal(appActivity.getSpuId(), spuId))) {
continue;
}
activityList.add(new AppActivityRespVO(rewardActivity.getId(),
PromotionTypeEnum.REWARD_ACTIVITY.getType(), rewardActivity.getName(), spuId,
rewardActivity.getStartTime(), rewardActivity.getEndTime()));
}
}
private void getRewardActivities(Collection<Long> spuIds, LocalDateTime now, List<AppActivityRespVO> activityList) {
private void getRewardActivityList(Collection<Long> spuIds, LocalDateTime now, List<AppActivityRespVO> activityList) {
// 1.1 获得所有的活动
List<RewardActivityDO> rewardActivityList = rewardActivityService.getRewardActivityByStatusAndDateTimeLt(
List<RewardActivityDO> rewardActivityList = rewardActivityService.getRewardActivityListByStatusAndDateTimeLt(
CommonStatusEnum.ENABLE.getStatus(), now);
if (CollUtil.isEmpty(rewardActivityList)) {
return;
@ -196,4 +183,18 @@ public class AppActivityController {
}
}
private static void buildAppActivityRespVO(RewardActivityDO rewardActivity, Collection<Long> spuIds,
List<AppActivityRespVO> activityList) {
for (Long spuId : spuIds) {
// 校验商品是否已经加入过活动
if (anyMatch(activityList, appActivity -> ObjUtil.equal(appActivity.getId(), rewardActivity.getId()) &&
ObjUtil.equal(appActivity.getSpuId(), spuId))) {
continue;
}
activityList.add(new AppActivityRespVO(rewardActivity.getId(),
PromotionTypeEnum.REWARD_ACTIVITY.getType(), rewardActivity.getName(), spuId,
rewardActivity.getStartTime(), rewardActivity.getEndTime()));
}
}
}

View File

@ -79,6 +79,6 @@ public interface RewardActivityService {
* @param dateTime 当前日期时间
* @return 满减送活动列表
*/
List<RewardActivityDO> getRewardActivityByStatusAndDateTimeLt(Integer status, LocalDateTime dateTime);
List<RewardActivityDO> getRewardActivityListByStatusAndDateTimeLt(Integer status, LocalDateTime dateTime);
}

View File

@ -165,7 +165,7 @@ public class RewardActivityServiceImpl implements RewardActivityService {
}
@Override
public List<RewardActivityDO> getRewardActivityByStatusAndDateTimeLt(Integer status, LocalDateTime dateTime) {
public List<RewardActivityDO> getRewardActivityListByStatusAndDateTimeLt(Integer status, LocalDateTime dateTime) {
return rewardActivityMapper.selectListByStatusAndDateTimeLt(status, dateTime);
}

View File

@ -186,15 +186,14 @@ public interface TradeOrderUpdateService {
*/
void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId);
// TODO 芋艿拼团取消不调这个接口哈
// TODO @puhui999不传递枚举哈因为 rpc 不好支持
/**
* 取消支付订单
*
* @param userId 用户编号
* @param orderId 订单编号
* @param cancelTypeEnum 取消类型
* @param cancelType 取消类型
*/
void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum);
void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelType);
}

View File

@ -858,7 +858,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Override
@Transactional(rollbackFor = Exception.class)
public void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelTypeEnum) {
public void cancelPaidOrder(Long userId, Long orderId, TradeOrderCancelTypeEnum cancelType) {
// TODO @puhui999这里校验下 cancelType 只允许拼团关闭
// 1.1 检验订单存在
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId);
if (order == null) {
@ -875,13 +876,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
}
// 2.1 取消订单
cancelOrder0(order, cancelTypeEnum);
cancelOrder0(order, cancelType);
// 2.2 创建退款单
payRefundApi.createRefund(new PayRefundCreateReqDTO()
.setAppKey(tradeOrderProperties.getPayAppKey()).setUserIp(getClientIP()) // 支付应用
.setMerchantOrderId(String.valueOf(order.getId())) // 支付单号
.setMerchantRefundId(String.valueOf(order.getId()))
.setReason(cancelTypeEnum.getName()).setPrice(order.getPayPrice()));// 价格信息
.setReason(cancelType.getName()).setPrice(order.getPayPrice()));// 价格信息
}
/**

View File

@ -52,7 +52,7 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
private void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result,
RewardActivityMatchRespDTO rewardActivity) {
// 1.1 获得满减送的订单项商品列表
List<TradePriceCalculateRespBO.OrderItem> orderItems = filterMatchCouponOrderItems(result, rewardActivity);
List<TradePriceCalculateRespBO.OrderItem> orderItems = filterMatchActivityOrderItems(result, rewardActivity);
if (CollUtil.isEmpty(orderItems)) {
return;
}
@ -93,8 +93,9 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
* @param rewardActivity 满减送活动
* @return 订单项商品列表
*/
private List<TradePriceCalculateRespBO.OrderItem> filterMatchCouponOrderItems(TradePriceCalculateRespBO result,
RewardActivityMatchRespDTO rewardActivity) {
private List<TradePriceCalculateRespBO.OrderItem> filterMatchActivityOrderItems(TradePriceCalculateRespBO result,
RewardActivityMatchRespDTO rewardActivity) {
// TODO @puhui999是不是得根据类型过滤哈
return filterList(result.getItems(),
orderItem -> CollUtil.contains(rewardActivity.getProductScopeValues(), orderItem.getSpuId()));
}