移除优惠劵的使用逻辑
parent
479a05b5d7
commit
488458b631
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,18 +11,12 @@ public interface PromotionErrorCodeConstants {
|
||||||
|
|
||||||
// ========== COUPON TEMPLATE 模块 ==========
|
// ========== COUPON TEMPLATE 模块 ==========
|
||||||
ErrorCode COUPON_TEMPLATE_NOT_EXISTS = new ErrorCode(1006002000, "优惠劵模板(码)不存在");
|
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_STATUS_NOT_ENABLE = new ErrorCode(1006002004, "优惠劵模板(码)未开启");
|
||||||
ErrorCode COUPON_TEMPLATE_TOTAL_NOT_ENOUGH = new ErrorCode(1006002005, "优惠劵(码)模板的发放量不足");
|
ErrorCode COUPON_TEMPLATE_TOTAL_NOT_ENOUGH = new ErrorCode(1006002005, "优惠劵(码)模板的发放量不足");
|
||||||
ErrorCode COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA = new ErrorCode(1006002006, "优惠劵领取到达上限");
|
ErrorCode COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA = new ErrorCode(1006002006, "优惠劵领取到达上限");
|
||||||
|
|
||||||
// ========== COUPON CARD 模块 ==========
|
// ========== COUPON CARD 模块 ==========
|
||||||
ErrorCode COUPON_CARD_NOT_EXISTS = new ErrorCode(1006003000, "优惠劵不存在");
|
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, "优惠劵不处于已使用状态");
|
ErrorCode COUPON_CARD_STATUS_NOT_USED = new ErrorCode( 1006003004, "优惠劵不处于已使用状态");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) ;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
|
@ -9,27 +9,16 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* Title:
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* @author zhuyang
|
|
||||||
* @version 1.0 2021/10/9
|
|
||||||
*/
|
|
||||||
@FeignClient("promotion-service")
|
@FeignClient("promotion-service")
|
||||||
public interface CouponCardFeign {
|
public interface CouponCardFeign {
|
||||||
|
|
||||||
@PostMapping("/coupon/card/pageCouponCard")
|
@PostMapping("/coupon/card/pageCouponCard")
|
||||||
public CommonResult<PageResult<CouponCardRespDTO>> pageCouponCard(@RequestBody CouponCardPageReqDTO pageReqDTO) ;
|
public CommonResult<PageResult<CouponCardRespDTO>> pageCouponCard(@RequestBody CouponCardPageReqDTO pageReqDTO) ;
|
||||||
|
|
||||||
@PostMapping("/coupon/card/createCouponCard")
|
@PostMapping("/coupon/card/createCouponCard")
|
||||||
public CommonResult<Integer> createCouponCard(@RequestBody CouponCardCreateReqDTO createReqDTO);
|
public CommonResult<Integer> createCouponCard(@RequestBody CouponCardCreateReqDTO createReqDTO);
|
||||||
|
|
||||||
@PostMapping("/coupon/card/useCouponCard")
|
|
||||||
public CommonResult<Boolean> useCouponCard(@RequestBody CouponCardUseReqDTO useReqDTO) ;
|
|
||||||
|
|
||||||
@PostMapping("/coupon/card/cancelUseCouponCard")
|
@PostMapping("/coupon/card/cancelUseCouponCard")
|
||||||
public CommonResult<Boolean> cancelUseCouponCard(@RequestBody CouponCardCancelUseReqDTO cancelUseReqDTO) ;
|
public CommonResult<Boolean> cancelUseCouponCard(@RequestBody CouponCardCancelUseReqDTO cancelUseReqDTO) ;
|
||||||
|
|
||||||
@PostMapping("/coupon/card/listAvailableCouponCards")
|
|
||||||
public CommonResult<List<CouponCardAvailableRespDTO>> listAvailableCouponCards(@RequestBody CouponCardAvailableListReqDTO listReqDTO);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
|
@ -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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,16 +19,6 @@ public interface CouponCardMapper extends BaseMapper<CouponCardDO> {
|
||||||
.eq("status", status));
|
.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) {
|
default IPage<CouponCardDO> selectPage(CouponCardPageReqDTO pageReqDTO) {
|
||||||
return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()),
|
return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()),
|
||||||
new QueryWrapperX<CouponCardDO>().eqIfPresent("user_id", pageReqDTO.getUserId())
|
new QueryWrapperX<CouponCardDO>().eqIfPresent("user_id", pageReqDTO.getUserId())
|
||||||
|
|
|
@ -70,11 +70,6 @@ public class PromotionActivityService {
|
||||||
return PromotionActivityConvert.INSTANCE.convertList(activityList);
|
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) {
|
private boolean isSpuMatchTimeLimitDiscount(Integer spuId, PromotionActivityDO activity) {
|
||||||
Assert.isTrue(PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue().equals(activity.getActivityType()),
|
Assert.isTrue(PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue().equals(activity.getActivityType()),
|
||||||
"传入的必须的促销活动必须是限时折扣");
|
"传入的必须的促销活动必须是限时折扣");
|
||||||
|
|
|
@ -37,11 +37,6 @@ import java.util.stream.Collectors;
|
||||||
@Validated
|
@Validated
|
||||||
public class CouponCardService {
|
public class CouponCardService {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CouponCardMapper couponCardMapper;
|
|
||||||
@Autowired
|
|
||||||
private CouponTemplateMapper couponTemplateMapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得用户的优惠劵
|
* 获得用户的优惠劵
|
||||||
*
|
*
|
||||||
|
@ -127,35 +122,6 @@ public class CouponCardService {
|
||||||
return card.getId();
|
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) {
|
if (card == null) {
|
||||||
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_NOT_EXISTS.getCode());
|
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())) {
|
if (!CouponCardStatusEnum.USED.getValue().equals(card.getStatus())) {
|
||||||
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_USED.getCode());
|
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) {
|
private void setCouponCardValidTime(CouponCardDO card, CouponTemplateDO template) {
|
||||||
if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(template.getDateType())) {
|
if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(template.getDateType())) {
|
||||||
card.setValidStartTime(template.getValidStartTime()).setValidEndTime(template.getValidEndTime());
|
card.setValidStartTime(template.getValidStartTime()).setValidEndTime(template.getValidEndTime());
|
||||||
|
|
|
@ -14,9 +14,9 @@ import java.util.Arrays;
|
||||||
@Service
|
@Service
|
||||||
public class TradeOrderClient {
|
public class TradeOrderClient {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TradeOrderFeign tradeOrderFeign;
|
private TradeOrderFeign tradeOrderFeign;
|
||||||
|
|
||||||
public Integer createTradeOrder(TradeOrderCreateReqDTO createReqDTO) {
|
public Integer createTradeOrder(TradeOrderCreateReqDTO createReqDTO) {
|
||||||
CommonResult<Integer> createTradeOrderResult = tradeOrderFeign.createTradeOrder(createReqDTO);
|
CommonResult<Integer> createTradeOrderResult = tradeOrderFeign.createTradeOrder(createReqDTO);
|
||||||
createTradeOrderResult.checkError();
|
createTradeOrderResult.checkError();
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -23,8 +23,10 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/trade/order")
|
@RequestMapping("/trade/order")
|
||||||
public class TradeOrderController {
|
public class TradeOrderController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TradeOrderService tradeOrderService;
|
private TradeOrderService tradeOrderService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建交易订单
|
* 创建交易订单
|
||||||
*
|
*
|
||||||
|
@ -59,8 +61,6 @@ public class TradeOrderController {
|
||||||
return success(tradeOrderService.pageTradeOrder(pageDTO));
|
return success(tradeOrderService.pageTradeOrder(pageDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:需要重构成入参是 DTO,方便后续升级;返回是 CommonResult,用于返回失败的原因
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新交易订单支付成功
|
* 更新交易订单支付成功
|
||||||
*
|
*
|
||||||
|
@ -75,4 +75,5 @@ public class TradeOrderController {
|
||||||
tradeOrderService.updateTradeOrderPaySuccess(Integer.valueOf(tradeOrderId), payAmount);
|
tradeOrderService.updateTradeOrderPaySuccess(Integer.valueOf(tradeOrderId), payAmount);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue