移除优惠劵的使用逻辑

pull/12/head
YunaiV 2022-11-10 13:02:50 +08:00
parent 479a05b5d7
commit 488458b631
17 changed files with 5 additions and 508 deletions

View File

@ -1,45 +0,0 @@
package cn.iocoder.mall.order.biz.service;
import cn.iocoder.mall.order.api.OrderCommentService;
import cn.iocoder.mall.order.api.bo.OrderCommentTimeOutBO;
import cn.iocoder.mall.order.api.dto.OrderCommentTimeOutPageDTO;
import cn.iocoder.mall.order.biz.OrderApplicationTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import java.util.stream.Collectors;
/**
*
*
* @author wtz
* @time 2019-06-17 19:09
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = OrderApplicationTest.class)
@ActiveProfiles("dev")
public class OrderCommentJobTest {
@Autowired
private OrderCommentService orderCommentService;
@Test
public void createOrderCommentJob(){
OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO=new OrderCommentTimeOutPageDTO();
orderCommentTimeOutPageDTO.setCommentState(0);
orderCommentTimeOutPageDTO.setPageNo(0);
orderCommentTimeOutPageDTO.setPageSize(10);
orderCommentTimeOutPageDTO.setOverDay(7);
List<OrderCommentTimeOutBO> orderCommentTimeOutBOList = orderCommentService.getOrderCommentTimeOutPage(orderCommentTimeOutPageDTO);
orderCommentService.updateBatchOrderCommentState(orderCommentTimeOutBOList);
}
}

View File

@ -1,29 +0,0 @@
package cn.iocoder.mall.pay.biz.service;
import cn.iocoder.mall.pay.api.PayRefundService;
import cn.iocoder.mall.pay.api.dto.refund.PayRefundSubmitDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class PayRefundServiceImplTest {
@Autowired
private PayRefundService payRefundService;
@Test
public void testSubmitRefund() {
PayRefundSubmitDTO payRefundSubmitDTO = new PayRefundSubmitDTO()
.setAppId("POd4RC6a")
.setCreateIp("127.0.0.1")
.setOrderId("13500000")
.setOrderDescription("测试下退款")
.setPrice(1);
payRefundService.submitRefund(payRefundSubmitDTO);
}
}

View File

@ -11,18 +11,12 @@ public interface PromotionErrorCodeConstants {
// ========== COUPON TEMPLATE 模块 ==========
ErrorCode COUPON_TEMPLATE_NOT_EXISTS = new ErrorCode(1006002000, "优惠劵模板(码)不存在");
ErrorCode COUPON_TEMPLATE_NOT_CARD = new ErrorCode(1006002001, "不是优惠劵模板");
ErrorCode COUPON_TEMPLATE_NOT_CODE = new ErrorCode(1006002002, "不是优惠码模板");
ErrorCode COUPON_TEMPLATE_TOTAL_CAN_NOT_REDUCE = new ErrorCode(1006002003, "优惠劵(码)模板的发放数量不能减小");
ErrorCode COUPON_TEMPLATE_STATUS_NOT_ENABLE = new ErrorCode(1006002004, "优惠劵模板(码)未开启");
ErrorCode COUPON_TEMPLATE_TOTAL_NOT_ENOUGH = new ErrorCode(1006002005, "优惠劵(码)模板的发放量不足");
ErrorCode COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA = new ErrorCode(1006002006, "优惠劵领取到达上限");
// ========== COUPON CARD 模块 ==========
ErrorCode COUPON_CARD_NOT_EXISTS = new ErrorCode(1006003000, "优惠劵不存在");
ErrorCode COUPON_CARD_ERROR_USER = new ErrorCode(1006003001, "优惠劵不属于当前用户");
ErrorCode COUPON_CARD_NOT_MATCH = new ErrorCode(1006003002, "优惠劵不匹配,无法使用");
ErrorCode COUPON_CARD_STATUS_NOT_UNUSED = new ErrorCode(1006003003, "优惠劵不处于待使用状态");
ErrorCode COUPON_CARD_STATUS_NOT_USED = new ErrorCode( 1006003004, "优惠劵不处于已使用状态");
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.activity;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* Title:
* Description:
*
* @author zhuyang
* @version 1.0 2021/10/9
*/
@FeignClient("promotion-service")
public interface PromotionActivityFeign {
@PostMapping("/promotion/activity/pagePromotionActivity")
CommonResult<PageResult<PromotionActivityRespDTO>> pagePromotionActivity(@RequestBody PromotionActivityPageReqDTO pageReqDTO) ;
@PostMapping("/promotion/activity/listPromotionActivities")
CommonResult<List<PromotionActivityRespDTO>> listPromotionActivities(@RequestBody PromotionActivityListReqDTO listReqDTO) ;
}

View File

@ -1,21 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.activity.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Collection;
/**
* Request DTO
*/
@Data
@Accessors(chain = true)
public class PromotionActivityListReqDTO implements Serializable {
/**
*
*/
private Collection<Integer> activeIds;
}

View File

@ -9,27 +9,16 @@ import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* Title:
* Description:
*
* @author zhuyang
* @version 1.0 2021/10/9
*/
@FeignClient("promotion-service")
public interface CouponCardFeign {
@PostMapping("/coupon/card/pageCouponCard")
public CommonResult<PageResult<CouponCardRespDTO>> pageCouponCard(@RequestBody CouponCardPageReqDTO pageReqDTO) ;
@PostMapping("/coupon/card/createCouponCard")
public CommonResult<Integer> createCouponCard(@RequestBody CouponCardCreateReqDTO createReqDTO);
@PostMapping("/coupon/card/useCouponCard")
public CommonResult<Boolean> useCouponCard(@RequestBody CouponCardUseReqDTO useReqDTO) ;
@PostMapping("/coupon/card/cancelUseCouponCard")
public CommonResult<Boolean> cancelUseCouponCard(@RequestBody CouponCardCancelUseReqDTO cancelUseReqDTO) ;
@PostMapping("/coupon/card/listAvailableCouponCards")
public CommonResult<List<CouponCardAvailableRespDTO>> listAvailableCouponCards(@RequestBody CouponCardAvailableListReqDTO listReqDTO);
}

View File

@ -1,68 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* Request DTO
*/
@Data
@Accessors(chain = true)
public class CouponCardAvailableListReqDTO implements Serializable {
/**
*
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
*
*/
@NotEmpty(message = "商品数组不能为空")
private List<Item> items;
/**
*
*/
@Data
@Accessors(chain = true)
public static class Item implements Serializable {
/**
* SPU
*/
@NotNull(message = "商品 SPU 编号不能为空")
private Integer spuId;
/**
* SKU
*/
@NotNull(message = "商品 SKU 编号不能为空")
private Integer skuId;
/**
* SKU
*/
@NotNull(message = "商品 Category 编号不能为空")
private Integer cid;
/**
*
*/
@NotNull(message = "商品数量不能为空")
@Min(value = 1L, message = "最小商品数量 1")
private Integer quantity;
/**
*
*
*
*/
@NotNull(message = "商品价格不能为空")
private Integer price;
}
}

View File

@ -1,26 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* BO
*
* available = false unavailableReason
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class CouponCardAvailableRespDTO extends CouponCardRespDTO {
/**
*
*/
private Boolean available;
/**
*
*/
private String unavailableReason;
}

View File

@ -1,27 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* Request DTO
*/
@Data
@Accessors(chain = true)
public class CouponCardCreateReqDTO implements Serializable {
/**
*
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
*
*/
@NotNull(message = "优惠劵模板编号不能为空")
private Integer couponTemplateId;
}

View File

@ -1,27 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 使 Request DTO
*/
@Data
@Accessors(chain = true)
public class CouponCardUseReqDTO implements Serializable {
/**
*
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
*
*/
@NotNull(message = "优惠劵编号不能为空")
private Integer couponCardId;
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.activity;
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
@Repository
public interface PromotionActivityMapper extends BaseMapper<PromotionActivityDO> {
default List<PromotionActivityDO> selectListByStatus(Collection<Integer> statuses) {
return selectList(new QueryWrapper<PromotionActivityDO>().in("status", statuses));
}
default IPage<PromotionActivityDO> selectPage(PromotionActivityPageReqDTO pageReqDTO) {
return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()),
new QueryWrapperX<PromotionActivityDO>().likeIfPresent("title", pageReqDTO.getTitle())
.eqIfPresent("activity_type", pageReqDTO.getActivityType())
.inIfPresent("status", pageReqDTO.getStatuses()));
}
default List<PromotionActivityDO> selectList(PromotionActivityListReqDTO listReqDTO) {
return selectList(new QueryWrapperX<PromotionActivityDO>().inIfPresent("id", listReqDTO.getActiveIds()));
}
}

View File

@ -19,16 +19,6 @@ public interface CouponCardMapper extends BaseMapper<CouponCardDO> {
.eq("status", status));
}
default int selectCountByUserIdAndTemplateId(Integer userId, Integer templateId) {
return selectCount(new QueryWrapper<CouponCardDO>().eq("user_id", userId)
.eq("template_id", templateId));
}
default int updateByIdAndStatus(Integer id, Integer status, CouponCardDO updateObj) {
return update(updateObj, new QueryWrapper<CouponCardDO>().eq("id", id)
.eq("status", status));
}
default IPage<CouponCardDO> selectPage(CouponCardPageReqDTO pageReqDTO) {
return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()),
new QueryWrapperX<CouponCardDO>().eqIfPresent("user_id", pageReqDTO.getUserId())

View File

@ -70,11 +70,6 @@ public class PromotionActivityService {
return PromotionActivityConvert.INSTANCE.convertList(activityList);
}
public PageResult<PromotionActivityRespDTO> pagePromotionActivity(PromotionActivityPageReqDTO pageReqDTO) {
IPage<PromotionActivityDO> promotionActivityPage = promotionActivityMapper.selectPage(pageReqDTO);
return PromotionActivityConvert.INSTANCE.convertPage(promotionActivityPage);
}
private boolean isSpuMatchTimeLimitDiscount(Integer spuId, PromotionActivityDO activity) {
Assert.isTrue(PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue().equals(activity.getActivityType()),
"传入的必须的促销活动必须是限时折扣");

View File

@ -37,11 +37,6 @@ import java.util.stream.Collectors;
@Validated
public class CouponCardService {
@Autowired
private CouponCardMapper couponCardMapper;
@Autowired
private CouponTemplateMapper couponTemplateMapper;
/**
*
*
@ -127,35 +122,6 @@ public class CouponCardService {
return card.getId();
}
/**
* 使
*
* @param userId
* @param couponCardId
*/
public void useCouponCard(Integer userId, Integer couponCardId) {
// 查询优惠劵
CouponCardDO card = couponCardMapper.selectById(couponCardId);
if (card == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_NOT_EXISTS.getCode());
}
if (!userId.equals(card.getUserId())) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_ERROR_USER.getCode());
}
if (!CouponCardStatusEnum.UNUSED.getValue().equals(card.getStatus())) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode());
}
if (DateUtil.isBetween(card.getValidStartTime(), card.getValidEndTime())) { // 为避免定时器没跑,实际优惠劵已经过期
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode());
}
// 更新优惠劵已使用
int updateCount = couponCardMapper.updateByIdAndStatus(card.getId(), CouponCardStatusEnum.UNUSED.getValue(),
new CouponCardDO().setStatus(CouponCardStatusEnum.USED.getValue()).setUsedTime(new Date()));
if (updateCount == 0) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode());
}
}
/**
* 使
*
@ -168,9 +134,6 @@ public class CouponCardService {
if (card == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_NOT_EXISTS.getCode());
}
if (!userId.equals(card.getUserId())) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_ERROR_USER.getCode());
}
if (!CouponCardStatusEnum.USED.getValue().equals(card.getStatus())) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_USED.getCode());
}
@ -183,67 +146,6 @@ public class CouponCardService {
// 有一点要注意,更新会未使用时,优惠劵可能已经过期了,直接让定时器跑过期,这里不做处理。
}
/**
*
*
* @param listReqDTO
* @return
*/
public List<CouponCardAvailableRespDTO> listAvailableCouponCards(CouponCardAvailableListReqDTO listReqDTO) {
// 查询用户未使用的优惠劵列表
List<CouponCardDO> cards = couponCardMapper.selectListByUserIdAndStatus(listReqDTO.getUserId(), CouponCardStatusEnum.UNUSED.getValue());
if (cards.isEmpty()) {
return Collections.emptyList();
}
// 查询优惠劵模板集合
Map<Integer, CouponTemplateDO> templates = CollectionUtils.convertMap(
couponTemplateMapper.selectBatchIds(CollectionUtils.convertSet(cards, CouponCardDO::getTemplateId)),
CouponTemplateDO::getId);
// 逐个判断是否可用
return cards.stream().map(card -> {
CouponCardAvailableRespDTO availableCard = CouponCardConvert.INSTANCE.convert01(card);
availableCard.setUnavailableReason(isMatch(card, templates.get(card.getTemplateId()), listReqDTO.getItems()));
availableCard.setAvailable(availableCard.getUnavailableReason() == null);
return availableCard;
}).collect(Collectors.toList());
}
/**
* 使
*
* @param card
* @param template
* @param items SKU
* @return
*/
private String isMatch(CouponCardDO card, CouponTemplateDO template, List<CouponCardAvailableListReqDTO.Item> items) {
int totalPrice = 0;
if (RangeTypeEnum.ALL.getValue().equals(template.getRangeType())) {
totalPrice = items.stream().mapToInt(spu -> spu.getPrice() * spu.getQuantity()).sum();
} else if (RangeTypeEnum.PRODUCT_INCLUDE_PART.getValue().equals(template.getRangeType())) {
List<Integer> spuIds = StringUtils.splitToInt(template.getRangeValues(), ",");
totalPrice = items.stream().mapToInt(spu -> spuIds.contains(spu.getSpuId()) ? spu.getPrice() * spu.getQuantity() : 0).sum();
} else if (RangeTypeEnum.PRODUCT_EXCLUDE_PART.getValue().equals(template.getRangeType())) {
List<Integer> spuIds = StringUtils.splitToInt(template.getRangeValues(), ",");
totalPrice = items.stream().mapToInt(spu -> !spuIds.contains(spu.getSpuId()) ? spu.getPrice() * spu.getQuantity() : 0).sum();
} else if (RangeTypeEnum.CATEGORY_INCLUDE_PART.getValue().equals(template.getRangeType())) {
List<Integer> spuIds = StringUtils.splitToInt(template.getRangeValues(), ",");
totalPrice = items.stream().mapToInt(spu -> spuIds.contains(spu.getCid()) ? spu.getPrice() * spu.getQuantity() : 0).sum();
} else if (RangeTypeEnum.CATEGORY_EXCLUDE_PART.getValue().equals(template.getRangeType())) {
List<Integer> spuIds = StringUtils.splitToInt(template.getRangeValues(), ",");
totalPrice = items.stream().mapToInt(spu -> !spuIds.contains(spu.getCid()) ? spu.getPrice() * spu.getQuantity() : 0).sum();
}
// 总价为 0 时,说明优惠劵丫根不匹配
if (totalPrice == 0) {
return "优惠劵不匹配";
}
// 如果不满足金额
if (totalPrice < card.getPriceAvailable()) {
return String.format("差 %1$,.2f 元可用优惠劵", (card.getPriceAvailable() - totalPrice) / 100D);
}
return null;
}
private void setCouponCardValidTime(CouponCardDO card, CouponTemplateDO template) {
if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(template.getDateType())) {
card.setValidStartTime(template.getValidStartTime()).setValidEndTime(template.getValidEndTime());

View File

@ -14,9 +14,9 @@ import java.util.Arrays;
@Service
public class TradeOrderClient {
@Autowired
private TradeOrderFeign tradeOrderFeign;
public Integer createTradeOrder(TradeOrderCreateReqDTO createReqDTO) {
CommonResult<Integer> createTradeOrderResult = tradeOrderFeign.createTradeOrder(createReqDTO);
createTradeOrderResult.checkError();

View File

@ -1,69 +0,0 @@
package cn.iocoder.mall.tradeservice.rpc.order.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* Request DTO
*
* @author Sin
* @time 2019-03-16 14:42
*/
@Data
@Accessors(chain = true)
public class TradeOrderCreateReqDTO implements Serializable {
/**
*
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* IP
*/
@NotNull(message = "用户 IP 不能为空")
private String ip;
/**
*
*/
@NotNull(message = "用户地址不能为空")
private Integer userAddressId;
/**
*
*/
private Integer couponCardId;
/**
*
*/
private String remark;
/**
*
*/
@NotNull(message = "必须选择购买的商品")
private List<OrderItem> orderItems;
@Data
@Accessors(chain = true)
public static class OrderItem implements Serializable {
/**
*
*/
@NotNull(message = "商品 SKU 编号不能为空")
private Integer skuId;
/**
*
*/
@NotNull(message = "商品 SKU 购买数量不能为空")
@Min(value = 1, message = "商品 SKU 购买数量必须大于 0")
private Integer quantity;
}
}

View File

@ -23,8 +23,10 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("/trade/order")
public class TradeOrderController {
@Autowired
private TradeOrderService tradeOrderService;
/**
*
*
@ -59,8 +61,6 @@ public class TradeOrderController {
return success(tradeOrderService.pageTradeOrder(pageDTO));
}
// TODO 芋艿:需要重构成入参是 DTO方便后续升级返回是 CommonResult用于返回失败的原因
/**
*
*
@ -75,4 +75,5 @@ public class TradeOrderController {
tradeOrderService.updateTradeOrderPaySuccess(Integer.valueOf(tradeOrderId), payAmount);
return success(true);
}
}