虚拟商品订单创建核验码
This commit is contained in:
parent
969437fc34
commit
e5d4207839
@ -15,6 +15,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 分销订单入库
|
||||
*
|
||||
@ -28,7 +30,7 @@ public class DistributionOrderExecute implements OrderStatusChangeEvent, EveryDa
|
||||
@Autowired
|
||||
private DistributionOrderService distributionOrderService;
|
||||
//分销订单持久层
|
||||
@Autowired
|
||||
@Resource
|
||||
private DistributionOrderMapper distributionOrderMapper;
|
||||
|
||||
|
||||
|
@ -10,8 +10,6 @@ import cn.lili.modules.order.order.service.OrderService;
|
||||
import cn.lili.modules.payment.entity.RefundLog;
|
||||
import cn.lili.modules.payment.kit.Payment;
|
||||
import cn.lili.modules.payment.kit.enums.PaymentMethodEnum;
|
||||
import cn.lili.modules.payment.service.PaymentService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -24,9 +22,6 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class PaymentExecute implements OrderStatusChangeEvent {
|
||||
|
||||
//支付日志
|
||||
@Autowired
|
||||
private PaymentService paymentService;
|
||||
//订单
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
@ -52,7 +52,6 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
|
||||
|
||||
switch (orderMessage.getNewStatus()) {
|
||||
case PAID: {
|
||||
|
||||
OrderDetailVO order = orderService.queryDetail(orderMessage.getOrderSn());
|
||||
//库存key 和 扣减数量
|
||||
List<String> keys = new ArrayList<>();
|
||||
@ -78,7 +77,6 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
|
||||
break;
|
||||
}
|
||||
case CANCELLED: {
|
||||
|
||||
OrderDetailVO order = orderService.queryDetail(orderMessage.getOrderSn());
|
||||
if (order.getOrder().getPayStatus().equals(PayStatusEnum.PAID.name())) {
|
||||
for (OrderItem orderItem : order.getOrderItems()) {
|
||||
|
@ -0,0 +1,34 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
import cn.lili.common.utils.CommonUtil;
|
||||
import cn.lili.event.OrderStatusChangeEvent;
|
||||
import cn.lili.modules.order.order.entity.dos.Order;
|
||||
import cn.lili.modules.order.order.entity.dto.OrderMessage;
|
||||
import cn.lili.modules.order.order.entity.enums.OrderStatusEnum;
|
||||
import cn.lili.modules.order.order.service.OrderService;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 虚拟商品
|
||||
* @author Bulbasaur
|
||||
* @date: 2021/5/29 9:17 上午
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class VerificationOrderExecute implements OrderStatusChangeEvent {
|
||||
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
@Override
|
||||
public void orderChange(OrderMessage orderMessage) {
|
||||
//订单状态为待核验,添加订单添加核验码
|
||||
if(orderMessage.getNewStatus().equals(OrderStatusEnum.TAKE)) {
|
||||
String code = CommonUtil.getRandomNum();
|
||||
orderService.update(new LambdaUpdateWrapper<Order>()
|
||||
.set(Order::getVerificationCode, code)
|
||||
.eq(Order::getSn, orderMessage.getOrderSn()));
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ import java.io.Serializable;
|
||||
public class StoreRemarkDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6793274046513576434L;
|
||||
@ApiModelProperty(value = "商家id")
|
||||
@ApiModelProperty(value = "店铺id")
|
||||
private String storeId;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
|
@ -65,14 +65,12 @@ public class TradeDTO implements Serializable {
|
||||
/**
|
||||
* key 为商家id
|
||||
* value 为商家优惠券
|
||||
* 商家优惠券
|
||||
* 店铺优惠券
|
||||
*/
|
||||
private Map<String, MemberCouponDTO> storeCoupons;
|
||||
|
||||
/**
|
||||
* key 为商家id
|
||||
* value 为商家优惠券
|
||||
* 商家优惠券
|
||||
* 店铺备注
|
||||
*/
|
||||
private List<StoreRemarkDTO> storeRemark;
|
||||
|
||||
|
@ -24,5 +24,9 @@ public enum CartTypeEnum {
|
||||
* 积分
|
||||
*/
|
||||
POINTS,
|
||||
/**
|
||||
* 虚拟商品
|
||||
*/
|
||||
FICTITIOUS;
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import cn.lili.modules.promotion.entity.dos.MemberCoupon;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -19,6 +20,7 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(description = "购物车")
|
||||
@NoArgsConstructor
|
||||
public class CartVO extends CartBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5651775413457562422L;
|
||||
@ -44,7 +46,6 @@ public class CartVO extends CartBase implements Serializable {
|
||||
@ApiModelProperty(value = "使用的优惠券列表")
|
||||
private List<MemberCoupon> couponList;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "赠品列表")
|
||||
private List<String> giftList;
|
||||
|
||||
@ -72,9 +73,6 @@ public class CartVO extends CartBase implements Serializable {
|
||||
@ApiModelProperty(value = "已参与的的促销活动提示,直接展示给客户")
|
||||
private String promotionNotice;
|
||||
|
||||
public CartVO() {
|
||||
}
|
||||
|
||||
public CartVO(CartSkuVO cartSkuVO) {
|
||||
this.setStoreId(cartSkuVO.getStoreId());
|
||||
this.setStoreName(cartSkuVO.getStoreName());
|
||||
|
@ -4,27 +4,23 @@ import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.base.BaseEntity;
|
||||
import cn.lili.common.utils.BeanUtil;
|
||||
import cn.lili.modules.base.entity.enums.ClientTypeEnum;
|
||||
import cn.lili.modules.order.cart.entity.enums.DeliveryMethodEnum;
|
||||
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
|
||||
import cn.lili.modules.order.order.entity.enums.DeliverStatusEnum;
|
||||
import cn.lili.modules.order.order.entity.enums.OrderStatusEnum;
|
||||
import cn.lili.modules.order.order.entity.enums.OrderTypeEnum;
|
||||
import cn.lili.modules.order.order.entity.enums.PayStatusEnum;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.enums.PromotionTypeEnum;
|
||||
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
||||
import cn.lili.modules.order.cart.entity.enums.CartTypeEnum;
|
||||
import cn.lili.modules.order.cart.entity.enums.DeliveryMethodEnum;
|
||||
import cn.lili.modules.order.cart.entity.vo.CartVO;
|
||||
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
|
||||
import cn.lili.modules.order.order.entity.enums.*;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 订单
|
||||
@ -37,6 +33,7 @@ import java.util.Optional;
|
||||
@Table(name = "li_order")
|
||||
@TableName("li_order")
|
||||
@ApiModel(value = "订单")
|
||||
@NoArgsConstructor
|
||||
public class Order extends BaseEntity {
|
||||
|
||||
|
||||
@ -176,6 +173,12 @@ public class Order extends BaseEntity {
|
||||
@ApiModelProperty(value = "订单类型")
|
||||
private String orderType;
|
||||
|
||||
/**
|
||||
* @see OrderPromotionTypeEnum
|
||||
*/
|
||||
@ApiModelProperty(value = "订单促销类型")
|
||||
private String orderPromotionType;
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
@ApiModelProperty(value = "价格详情")
|
||||
private String priceDetail;
|
||||
@ -195,62 +198,38 @@ public class Order extends BaseEntity {
|
||||
@ApiModelProperty(value = "使用的平台会员优惠券id")
|
||||
private String usePlatformMemberCouponId;
|
||||
|
||||
public Order() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建订单
|
||||
*
|
||||
* @param cartVO 购物车VO
|
||||
* @param tradeDTO 交易DTO
|
||||
*/
|
||||
public Order(CartVO cartVO, TradeDTO tradeDTO) {
|
||||
String oldId = this.getId();
|
||||
String orderId = this.getId();
|
||||
BeanUtil.copyProperties(tradeDTO, this);
|
||||
BeanUtil.copyProperties(cartVO.getPriceDetailDTO(), this);
|
||||
BeanUtil.copyProperties(cartVO, this);
|
||||
this.setId(oldId);
|
||||
//循环购物车列表判断是否为促销订单
|
||||
this.setOrderType(OrderTypeEnum.NORMAL.name());
|
||||
//促销信息填充
|
||||
if (cartVO.getSkuList().get(0).getPromotions() != null) {
|
||||
//判断是否为拼团订单
|
||||
Optional<String> pintuanId = cartVO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst();
|
||||
if (pintuanId.isPresent()) {
|
||||
this.setOrderType(OrderTypeEnum.PINTUAN.name());
|
||||
if (tradeDTO.getParentOrderSn() == null) {
|
||||
this.setParentOrderSn("");
|
||||
}
|
||||
}
|
||||
//判断是否为积分订单
|
||||
Optional<String> pointGoodsId = cartVO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.POINTS_GOODS.name())).map(PromotionGoods::getPromotionId).findFirst();
|
||||
if (pointGoodsId.isPresent()) {
|
||||
this.setOrderType(OrderTypeEnum.POINT.name());
|
||||
if (tradeDTO.getParentOrderSn() == null) {
|
||||
this.setParentOrderSn("");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
||||
//订单类型判断--普通订单,活动订单。
|
||||
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.CART) || tradeDTO.getCartTypeEnum().equals(CartTypeEnum.BUY_NOW)) {
|
||||
this.setOrderType(OrderTypeEnum.NORMAL.name());
|
||||
} else {
|
||||
this.setOrderType(tradeDTO.getCartTypeEnum().name());
|
||||
}
|
||||
//设定订单默认状态
|
||||
this.setId(orderId);
|
||||
this.setOrderStatus(OrderStatusEnum.UNPAID.name());
|
||||
this.setPayStatus(PayStatusEnum.UNPAID.name());
|
||||
this.setDeliverStatus(DeliverStatusEnum.UNDELIVERED.name());
|
||||
//填充订单收件人信息
|
||||
this.setTradeSn(tradeDTO.getSn());
|
||||
this.setRemark(cartVO.getRemark());
|
||||
this.setFreightPrice(tradeDTO.getPriceDetailDTO().getFreightPrice());
|
||||
//会员收件信息
|
||||
this.setConsigneeAddressIdPath(tradeDTO.getMemberAddress().getConsigneeAddressIdPath());
|
||||
this.setConsigneeAddressPath(tradeDTO.getMemberAddress().getConsigneeAddressPath());
|
||||
this.setConsigneeDetail(tradeDTO.getMemberAddress().getDetail());
|
||||
this.setConsigneeMobile(tradeDTO.getMemberAddress().getMobile());
|
||||
this.setConsigneeName(tradeDTO.getMemberAddress().getName());
|
||||
//判断是否使用平台优惠券
|
||||
if (tradeDTO.getPlatformCoupon() != null) {
|
||||
this.setUsePlatformMemberCouponId(tradeDTO.getPlatformCoupon().getMemberCoupon().getId());
|
||||
}
|
||||
//判断是否使用店铺优惠券
|
||||
//如果有收货地址,才记录收货地址
|
||||
if (tradeDTO.getMemberAddress() != null) {
|
||||
this.setConsigneeAddressIdPath(tradeDTO.getMemberAddress().getConsigneeAddressIdPath());
|
||||
this.setConsigneeAddressPath(tradeDTO.getMemberAddress().getConsigneeAddressPath());
|
||||
this.setConsigneeDetail(tradeDTO.getMemberAddress().getDetail());
|
||||
this.setConsigneeMobile(tradeDTO.getMemberAddress().getMobile());
|
||||
this.setConsigneeName(tradeDTO.getMemberAddress().getName());
|
||||
}
|
||||
//平台优惠券判定
|
||||
if (tradeDTO.getPlatformCoupon() != null) {
|
||||
this.setUsePlatformMemberCouponId(tradeDTO.getPlatformCoupon().getMemberCoupon().getId());
|
||||
@ -263,18 +242,10 @@ public class Order extends BaseEntity {
|
||||
}
|
||||
this.setUseStoreMemberCouponIds(storeCouponIds.toString());
|
||||
}
|
||||
this.setTradeSn(tradeDTO.getSn());
|
||||
this.setRemark(cartVO.getRemark());
|
||||
this.setFreightPrice(tradeDTO.getPriceDetailDTO().getFreightPrice());
|
||||
}
|
||||
|
||||
public PriceDetailDTO getPriceDetailDTO() {
|
||||
|
||||
try {
|
||||
return JSONUtil.toBean(priceDetail, PriceDetailDTO.class);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPriceDetailDTO(PriceDetailDTO priceDetail) {
|
||||
|
@ -0,0 +1,24 @@
|
||||
package cn.lili.modules.order.order.entity.enums;
|
||||
|
||||
/**
|
||||
* 订单促销类型枚举
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/17 7:28 下午
|
||||
*/
|
||||
public enum OrderPromotionTypeEnum {
|
||||
|
||||
/**
|
||||
* 赠品订单
|
||||
*/
|
||||
GIFT,
|
||||
/**
|
||||
* 拼团订单
|
||||
*/
|
||||
PINTUAN,
|
||||
/**
|
||||
* 积分订单
|
||||
*/
|
||||
POINT
|
||||
|
||||
}
|
@ -21,7 +21,7 @@ public enum OrderTypeEnum {
|
||||
/**
|
||||
* 虚拟订单
|
||||
*/
|
||||
FICTITIOUS,
|
||||
VIRTUAL,
|
||||
/**
|
||||
* 拼团订单
|
||||
*/
|
||||
|
@ -81,7 +81,7 @@ public class AllowOperation implements Serializable {
|
||||
//是否允许查看物流信息
|
||||
this.showLogistics = order.getDeliverStatus().equals(DeliverStatusEnum.DELIVERED.name()) && status.equals(OrderStatusEnum.DELIVERED.name());
|
||||
|
||||
this.take = order.getOrderType().equals(OrderTypeEnum.FICTITIOUS.name()) && order.getOrderStatus().equals(OrderStatusEnum.TAKE.name());
|
||||
this.take = order.getOrderType().equals(OrderTypeEnum.VIRTUAL.name()) && order.getOrderStatus().equals(OrderStatusEnum.TAKE.name());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,7 +119,7 @@ public class AllowOperation implements Serializable {
|
||||
//是否允许查看物流信息
|
||||
this.showLogistics = order.getDeliverStatus().equals(DeliverStatusEnum.DELIVERED.name()) && status.equals(OrderStatusEnum.DELIVERED.name());
|
||||
|
||||
this.take = order.getOrderType().equals(OrderTypeEnum.FICTITIOUS.name()) && order.getOrderStatus().equals(OrderStatusEnum.TAKE.name());
|
||||
this.take = order.getOrderType().equals(OrderTypeEnum.VIRTUAL.name()) && order.getOrderStatus().equals(OrderStatusEnum.TAKE.name());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package cn.lili.modules.order.order.entity.vo;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.lili.modules.order.order.entity.dos.Order;
|
||||
import cn.lili.modules.order.order.entity.dos.OrderItem;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -14,6 +16,7 @@ import java.util.List;
|
||||
* @date 2020/11/28 11:38
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class OrderVO extends Order {
|
||||
|
||||
|
||||
@ -23,4 +26,8 @@ public class OrderVO extends Order {
|
||||
private List<OrderItem> orderItems;
|
||||
|
||||
|
||||
public OrderVO (Order order,List<OrderItem> orderItems){
|
||||
BeanUtil.copyProperties(order, this);
|
||||
this.setOrderItems(orderItems);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,10 @@ import cn.lili.common.security.enums.UserEnums;
|
||||
import cn.lili.common.trigger.interfaces.TimeTrigger;
|
||||
import cn.lili.common.trigger.model.TimeExecuteConstant;
|
||||
import cn.lili.common.trigger.model.TimeTriggerMsg;
|
||||
import cn.lili.common.utils.*;
|
||||
import cn.lili.common.utils.OperationalJudgment;
|
||||
import cn.lili.common.utils.PageUtil;
|
||||
import cn.lili.common.utils.SnowFlake;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.config.rocketmq.RocketmqCustomProperties;
|
||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||
@ -126,38 +129,40 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
|
||||
@Override
|
||||
public void intoDB(TradeDTO tradeDTO) {
|
||||
//检查TradeDTO信息
|
||||
checkTradeDTO(tradeDTO);
|
||||
//订单列表
|
||||
List<Order> orders = new ArrayList<>(tradeDTO.getCartList().size());
|
||||
//订单日志
|
||||
List<OrderLog> orderLogs = new ArrayList<>(tradeDTO.getCartList().size());
|
||||
//订单VO列表
|
||||
List<OrderVO> OrderVOList = new ArrayList<>(tradeDTO.getCartList().size());
|
||||
//订单货物列表
|
||||
List<OrderItem> orderItems = new ArrayList<>();
|
||||
List<OrderLog> orderLogs = new ArrayList<>();
|
||||
if (tradeDTO.getParentOrderSn() != null) {
|
||||
Order parentOrder = this.getBySn(tradeDTO.getParentOrderSn());
|
||||
if (parentOrder.getMemberId().equals(UserContext.getCurrentUser().getId())) {
|
||||
throw new ServiceException("不能参与自己发起的拼团活动!");
|
||||
}
|
||||
}
|
||||
List<OrderVO> list = new ArrayList<>();
|
||||
//循环交易货物列表,新增订单
|
||||
tradeDTO.getCartList().forEach(item -> {
|
||||
//构建订单
|
||||
Order order = new Order(item, tradeDTO);
|
||||
if (OrderTypeEnum.PINTUAN.name().equals(order.getOrderType())) {
|
||||
Pintuan pintuan = pintuanService.getPintuanById(order.getPromotionId());
|
||||
Integer limitNum = pintuan.getLimitNum();
|
||||
if (limitNum != 0 && order.getGoodsNum() > limitNum) {
|
||||
throw new ServiceException("购买数量超过拼团活动限制数量");
|
||||
}
|
||||
}
|
||||
//构建orderVO对象
|
||||
OrderVO orderVO = new OrderVO();
|
||||
BeanUtil.copyProperties(order, orderVO);
|
||||
//检查订单信息
|
||||
checkOrder(order);
|
||||
//新建订单
|
||||
orders.add(order);
|
||||
String message = "订单[" + item.getSn() + "]创建";
|
||||
orderLogs.add(new OrderLog(item.getSn(), UserContext.getCurrentUser().getId(), UserContext.getCurrentUser().getRole().getRole(), UserContext.getCurrentUser().getUsername(), message));
|
||||
//记录订单日志
|
||||
orderLogs.add(new OrderLog(item.getSn(),
|
||||
UserContext.getCurrentUser().getId(),
|
||||
UserContext.getCurrentUser().getRole().getRole(),
|
||||
UserContext.getCurrentUser().getUsername(), "订单[" + item.getSn() + "]创建"));
|
||||
|
||||
//添加订单货物
|
||||
item.getSkuList().forEach(
|
||||
sku -> orderItems.add(new OrderItem(sku, item, tradeDTO))
|
||||
);
|
||||
orderVO.setOrderItems(orderItems);
|
||||
list.add(orderVO);
|
||||
|
||||
//构建orderVO对象
|
||||
OrderVO orderVO = new OrderVO(order, orderItems);
|
||||
OrderVOList.add(orderVO);
|
||||
});
|
||||
tradeDTO.setOrderVO(list);
|
||||
tradeDTO.setOrderVO(OrderVOList);
|
||||
//批量保存订单
|
||||
this.saveBatch(orders);
|
||||
//批量保存 子订单
|
||||
@ -165,6 +170,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
// 批量记录订单操作日志
|
||||
orderLogService.saveBatch(orderLogs);
|
||||
// 赠品根据店铺单独生成订单
|
||||
//todo 优化赠品订单代码逻辑
|
||||
this.generatorGiftOrder(tradeDTO);
|
||||
}
|
||||
|
||||
@ -275,62 +281,18 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
@OrderLogPoint(description = "'库存确认'", orderSn = "#orderSn")
|
||||
public void afterOrderConfirm(String orderSn) {
|
||||
Order order = this.getBySn(orderSn);
|
||||
LambdaUpdateWrapper<Order> orderLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
|
||||
//如果为虚拟订单-修改订单状态为待核验
|
||||
if (order.getOrderType().equals(OrderTypeEnum.FICTITIOUS.name())) {
|
||||
//填写提货码
|
||||
String code = CommonUtil.getRandomNum();
|
||||
orderLambdaUpdateWrapper.eq(Order::getSn, orderSn);
|
||||
orderLambdaUpdateWrapper.set(Order::getVerificationCode, code);
|
||||
orderLambdaUpdateWrapper.set(Order::getOrderStatus, OrderStatusEnum.TAKE.name());
|
||||
orderLambdaUpdateWrapper.set(Order::getCanReturn, !PaymentMethodEnum.BANK_TRANSFER.name().equals(order.getPaymentMethod()));
|
||||
|
||||
this.update(orderLambdaUpdateWrapper);
|
||||
|
||||
OrderMessage orderMessage = new OrderMessage();
|
||||
orderMessage.setNewStatus(OrderStatusEnum.TAKE);
|
||||
orderMessage.setOrderSn(order.getSn());
|
||||
this.sendUpdateStatusMessage(orderMessage);
|
||||
}
|
||||
//如果为商品订单-修改订单状态为待发货
|
||||
else {
|
||||
orderLambdaUpdateWrapper.eq(Order::getSn, orderSn);
|
||||
//拼团订单
|
||||
if (order.getOrderType().equals(OrderTypeEnum.PINTUAN.name()) && order.getPromotionId() != null) {
|
||||
//校验拼团是否成团 对拼团结果进行处理
|
||||
//判断是否为拼团订单,进行特殊处理
|
||||
//判断订单类型进行不同的订单确认操作
|
||||
if (order.getOrderPromotionType().equals(OrderPromotionTypeEnum.PINTUAN.name())) {
|
||||
this.checkPintuanOrder(order.getPromotionId(), order.getParentOrderSn());
|
||||
} else {
|
||||
//普通订单直接修改为代发货状态
|
||||
orderLambdaUpdateWrapper.set(Order::getOrderStatus, OrderStatusEnum.UNDELIVERED.name());
|
||||
orderLambdaUpdateWrapper.set(Order::getCanReturn, !PaymentMethodEnum.BANK_TRANSFER.name().equals(order.getPaymentMethod()));
|
||||
this.update(orderLambdaUpdateWrapper);
|
||||
|
||||
OrderMessage orderMessage = new OrderMessage();
|
||||
orderMessage.setNewStatus(OrderStatusEnum.UNDELIVERED);
|
||||
orderMessage.setOrderSn(order.getSn());
|
||||
this.sendUpdateStatusMessage(orderMessage);
|
||||
//判断订单类型
|
||||
if (order.getOrderType().equals(OrderTypeEnum.NORMAL.name())) {
|
||||
normalOrderConfirm(orderSn);
|
||||
} else {
|
||||
virtualOrderConfirm(orderSn);
|
||||
}
|
||||
}
|
||||
|
||||
// 发送当前商品购买完成的信息(用于更新商品数据)
|
||||
List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn);
|
||||
List<GoodsCompleteMessage> goodsCompleteMessageList = new ArrayList<>();
|
||||
for (OrderItem orderItem : orderItems) {
|
||||
GoodsCompleteMessage goodsCompleteMessage = new GoodsCompleteMessage();
|
||||
goodsCompleteMessage.setGoodsId(orderItem.getGoodsId());
|
||||
goodsCompleteMessage.setSkuId(orderItem.getSkuId());
|
||||
goodsCompleteMessage.setBuyNum(orderItem.getNum());
|
||||
goodsCompleteMessage.setMemberId(order.getMemberId());
|
||||
goodsCompleteMessageList.add(goodsCompleteMessage);
|
||||
}
|
||||
if (!goodsCompleteMessageList.isEmpty()) {
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.BUY_GOODS_COMPLETE.name();
|
||||
//发送订单变更mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsCompleteMessageList), RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -400,7 +362,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
//是否可以查询到订单
|
||||
Order order = OperationalJudgment.judgment(this.getBySn(orderSn));
|
||||
//判断是否为虚拟订单
|
||||
if (!order.getOrderType().equals(OrderTypeEnum.FICTITIOUS.name())) {
|
||||
if (!order.getOrderType().equals(OrderTypeEnum.VIRTUAL.name())) {
|
||||
throw new ServiceException(ResultCode.ORDER_TAKE_ERROR);
|
||||
}
|
||||
//判断虚拟订单状态
|
||||
@ -438,6 +400,25 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
orderMessage.setNewStatus(OrderStatusEnum.COMPLETED);
|
||||
orderMessage.setOrderSn(order.getSn());
|
||||
this.sendUpdateStatusMessage(orderMessage);
|
||||
|
||||
// 发送当前商品购买完成的信息(用于更新商品数据)
|
||||
List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn);
|
||||
List<GoodsCompleteMessage> goodsCompleteMessageList = new ArrayList<>();
|
||||
for (OrderItem orderItem : orderItems) {
|
||||
GoodsCompleteMessage goodsCompleteMessage = new GoodsCompleteMessage();
|
||||
goodsCompleteMessage.setGoodsId(orderItem.getGoodsId());
|
||||
goodsCompleteMessage.setSkuId(orderItem.getSkuId());
|
||||
goodsCompleteMessage.setBuyNum(orderItem.getNum());
|
||||
goodsCompleteMessage.setMemberId(order.getMemberId());
|
||||
goodsCompleteMessageList.add(goodsCompleteMessage);
|
||||
}
|
||||
//发送商品购买消息
|
||||
if (!goodsCompleteMessageList.isEmpty()) {
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.BUY_GOODS_COMPLETE.name();
|
||||
//发送订单变更mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsCompleteMessageList), RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -609,6 +590,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
this.baseMapper.updateStatus(orderStatus.name(), orderSn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测拼团订单内容
|
||||
* 此方法用与订单确认
|
||||
* 判断拼团是否达到人数进行下一步处理
|
||||
*
|
||||
* @param pintuanId 拼团活动ID
|
||||
* @param parentOrderSn 拼团父订单编号
|
||||
*/
|
||||
private void checkPintuanOrder(String pintuanId, String parentOrderSn) {
|
||||
//拼团有效参数判定
|
||||
if (CharSequenceUtil.isEmpty(parentOrderSn)) {
|
||||
@ -630,9 +619,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
DelayQueueTools.wrapperUniqueKey(DelayQueueType.PINTUAN_ORDER, (pintuanId + parentOrderSn)),
|
||||
rocketmqCustomProperties.getPromotionTopic());
|
||||
this.timeTrigger.addDelay(timeTriggerMsg, cn.lili.common.utils.DateUtil.getDelayTime(startTime));
|
||||
}
|
||||
} else if (pintuan.getRequiredNum() <= count) {
|
||||
//拼团所需人数,小于等于 参团后的人数,则说明成团,所有订单成团
|
||||
if (pintuan.getRequiredNum() <= count) {
|
||||
this.pintuanOrderSuccess(list);
|
||||
}
|
||||
}
|
||||
@ -659,17 +647,18 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
|
||||
/**
|
||||
* 根据提供的拼团订单列表更新拼团状态为拼团成功
|
||||
* 循环订单列表根据不同的订单类型进行确认订单
|
||||
*
|
||||
* @param list 需要更新拼团状态为成功的拼团订单列表
|
||||
*/
|
||||
private void pintuanOrderSuccess(List<Order> list) {
|
||||
for (Order order : list) {
|
||||
LambdaUpdateWrapper<Order> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(Order::getId, order.getId());
|
||||
updateWrapper.set(Order::getOrderStatus, OrderStatusEnum.UNDELIVERED.name());
|
||||
updateWrapper.set(Order::getCanReturn, !PaymentMethodEnum.BANK_TRANSFER.name().equals(order.getPaymentMethod()));
|
||||
this.update(updateWrapper);
|
||||
list.stream().forEach(order -> {
|
||||
if (order.getOrderType().equals(OrderTypeEnum.VIRTUAL)) {
|
||||
this.virtualOrderConfirm(order.getSn());
|
||||
} else if (order.getOrderType().equals(OrderTypeEnum.NORMAL)) {
|
||||
this.normalOrderConfirm(order.getSn());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -761,4 +750,72 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查交易信息
|
||||
*
|
||||
* @param tradeDTO 交易DTO
|
||||
*/
|
||||
private void checkTradeDTO(TradeDTO tradeDTO) {
|
||||
//检测是否为拼团订单
|
||||
if (tradeDTO.getParentOrderSn() != null) {
|
||||
//判断用户不能参与自己发起的拼团活动
|
||||
Order parentOrder = this.getBySn(tradeDTO.getParentOrderSn());
|
||||
if (parentOrder.getMemberId().equals(UserContext.getCurrentUser().getId())) {
|
||||
throw new ServiceException("不能参与自己发起的拼团活动!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查交易信息
|
||||
*
|
||||
* @param order 订单
|
||||
*/
|
||||
private void checkOrder(Order order) {
|
||||
//订单类型为拼团订单,检测购买数量是否超过了限购数量
|
||||
if (OrderTypeEnum.PINTUAN.name().equals(order.getOrderType())) {
|
||||
Pintuan pintuan = pintuanService.getPintuanById(order.getPromotionId());
|
||||
Integer limitNum = pintuan.getLimitNum();
|
||||
if (limitNum != 0 && order.getGoodsNum() > limitNum) {
|
||||
throw new ServiceException("购买数量超过拼团活动限制数量");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通商品订单确认
|
||||
* 修改订单状态为待发货
|
||||
* 发送订单状态变更消息
|
||||
*
|
||||
* @param orderSn 订单编号
|
||||
*/
|
||||
private void normalOrderConfirm(String orderSn) {
|
||||
//修改订单
|
||||
this.update(new LambdaUpdateWrapper<Order>()
|
||||
.eq(Order::getSn, orderSn)
|
||||
.set(Order::getOrderStatus, OrderStatusEnum.UNDELIVERED.name()));
|
||||
//修改订单
|
||||
OrderMessage orderMessage = new OrderMessage();
|
||||
orderMessage.setNewStatus(OrderStatusEnum.UNDELIVERED);
|
||||
orderMessage.setOrderSn(orderSn);
|
||||
this.sendUpdateStatusMessage(orderMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 虚拟商品订单确认
|
||||
* 修改订单状态为待核验
|
||||
* 发送订单状态变更消息
|
||||
*
|
||||
* @param orderSn 订单编号
|
||||
*/
|
||||
private void virtualOrderConfirm(String orderSn) {
|
||||
//修改订单
|
||||
this.update(new LambdaUpdateWrapper<Order>()
|
||||
.eq(Order::getSn, orderSn)
|
||||
.set(Order::getOrderStatus, OrderStatusEnum.TAKE.name()));
|
||||
OrderMessage orderMessage = new OrderMessage();
|
||||
orderMessage.setNewStatus(OrderStatusEnum.TAKE);
|
||||
orderMessage.setOrderSn(orderSn);
|
||||
this.sendUpdateStatusMessage(orderMessage);
|
||||
}
|
||||
}
|
@ -74,7 +74,9 @@ public class TradeServiceImpl extends ServiceImpl<TradeMapper, Trade> implements
|
||||
pointPretreatment(tradeDTO);
|
||||
//优惠券预处理
|
||||
couponPretreatment(tradeDTO);
|
||||
//添加交易
|
||||
this.save(trade);
|
||||
//添加订单
|
||||
orderService.intoDB(tradeDTO);
|
||||
//写入缓存,给消费者调用
|
||||
cache.put(key, tradeDTO);
|
||||
|
Loading…
x
Reference in New Issue
Block a user