commit message
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package cn.lili.event;
|
||||
|
||||
|
||||
import cn.lili.modules.order.order.entity.dos.AfterSale;
|
||||
|
||||
/**
|
||||
* 售后单改变状态
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/17 7:13 下午
|
||||
*/
|
||||
public interface AfterSaleStatusChangeEvent {
|
||||
|
||||
/**
|
||||
* 售后单改变
|
||||
*
|
||||
* @param afterSale 售后
|
||||
*/
|
||||
void afterSaleStatusChange(AfterSale afterSale);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.lili.event;
|
||||
|
||||
import cn.lili.modules.member.entity.dos.MemberEvaluation;
|
||||
|
||||
/**
|
||||
* 订单状态改变事件
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/17 7:13 下午
|
||||
*/
|
||||
public interface GoodsCommentCompleteEvent {
|
||||
|
||||
/**
|
||||
* 商品评价
|
||||
* @param memberEvaluation 会员评价
|
||||
*/
|
||||
void goodsComment(MemberEvaluation memberEvaluation);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lili.event;
|
||||
|
||||
import cn.lili.modules.member.entity.dto.MemberPointMessage;
|
||||
|
||||
/**
|
||||
* 会员积分改变消息
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/17 7:13 下午
|
||||
*/
|
||||
public interface MemberPointChangeEvent {
|
||||
|
||||
/**
|
||||
* 会员积分改变消息
|
||||
*
|
||||
* @param memberPointMessage 会员积分消息
|
||||
*/
|
||||
void memberPointChange(MemberPointMessage memberPointMessage);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lili.event;
|
||||
|
||||
import cn.lili.modules.member.entity.dos.Member;
|
||||
|
||||
/**
|
||||
* 会员注册消息
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/17 7:13 下午
|
||||
*/
|
||||
public interface MemberRegisterEvent {
|
||||
|
||||
/**
|
||||
* 会员登录
|
||||
*
|
||||
* @param member 会员
|
||||
*/
|
||||
void memberRegister(Member member);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lili.event;
|
||||
|
||||
import cn.lili.modules.member.entity.dto.MemberWithdrawalMessage;
|
||||
|
||||
/**
|
||||
* 会员提现消息
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/17 7:13 下午
|
||||
*/
|
||||
public interface MemberWithdrawalEvent {
|
||||
|
||||
/**
|
||||
* 会员提现
|
||||
*
|
||||
* @param memberWithdrawalMessage 提现对象
|
||||
*/
|
||||
void memberWithdrawal(MemberWithdrawalMessage memberWithdrawalMessage);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.lili.event;
|
||||
|
||||
import cn.lili.modules.order.order.entity.dto.OrderMessage;
|
||||
|
||||
/**
|
||||
* 订单状态改变事件
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/17 7:13 下午
|
||||
*/
|
||||
public interface OrderStatusChangeEvent {
|
||||
|
||||
/**
|
||||
* 订单改变
|
||||
* @param orderMessage 订单消息
|
||||
*/
|
||||
void orderChange(OrderMessage orderMessage);
|
||||
}
|
||||
20
consumer/src/main/java/cn/lili/event/TradeEvent.java
Normal file
20
consumer/src/main/java/cn/lili/event/TradeEvent.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package cn.lili.event;
|
||||
|
||||
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
||||
|
||||
/**
|
||||
* 订单创建消息
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2021/2/2 15:15
|
||||
*/
|
||||
public interface TradeEvent {
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
*
|
||||
* @param tradeDTO 交易
|
||||
*/
|
||||
void orderCreate(TradeDTO tradeDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.lili.event.AfterSaleStatusChangeEvent;
|
||||
import cn.lili.event.OrderStatusChangeEvent;
|
||||
import cn.lili.modules.distribution.entity.dos.DistributionOrder;
|
||||
import cn.lili.modules.distribution.entity.enums.DistributionOrderStatusEnum;
|
||||
import cn.lili.modules.distribution.mapper.DistributionOrderMapper;
|
||||
import cn.lili.modules.distribution.service.DistributionOrderService;
|
||||
import cn.lili.modules.order.order.entity.dos.AfterSale;
|
||||
import cn.lili.modules.order.order.entity.dto.OrderMessage;
|
||||
import cn.lili.modules.order.trade.entity.enums.AfterSaleStatusEnum;
|
||||
import cn.lili.timetask.handler.EveryDayExecute;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 分销订单入库
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020-07-03 11:20
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class DistributionOrderExecute implements OrderStatusChangeEvent, EveryDayExecute, AfterSaleStatusChangeEvent {
|
||||
|
||||
//分销订单
|
||||
private final DistributionOrderService distributionOrderService;
|
||||
//分销订单持久层
|
||||
private final DistributionOrderMapper distributionOrderMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public void orderChange(OrderMessage orderMessage) {
|
||||
|
||||
switch (orderMessage.getNewStatus()) {
|
||||
case PAID: {
|
||||
//记录分销订单
|
||||
distributionOrderService.payOrder(orderMessage.getOrderSn());
|
||||
break;
|
||||
}
|
||||
case CANCELLED: {
|
||||
//修改分销订单状态
|
||||
distributionOrderService.cancelOrder(orderMessage.getOrderSn());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
//计算分销提佣
|
||||
distributionOrderMapper.rebate(DistributionOrderStatusEnum.WAIT_BILL.name(), new DateTime());
|
||||
|
||||
//修改分销订单状态
|
||||
distributionOrderService.update(new LambdaUpdateWrapper<DistributionOrder>()
|
||||
.eq(DistributionOrder::getDistributionOrderStatus, DistributionOrderStatusEnum.WAIT_BILL.name())
|
||||
.le(DistributionOrder::getSettleCycle, new DateTime())
|
||||
.set(DistributionOrder::getDistributionOrderStatus, DistributionOrderStatusEnum.WAIT_CASH.name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSaleStatusChange(AfterSale afterSale) {
|
||||
if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.COMPLETE.name())) {
|
||||
distributionOrderService.refundOrder(afterSale.getSn());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
|
||||
import cn.lili.event.GoodsCommentCompleteEvent;
|
||||
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||
import cn.lili.modules.member.entity.dos.MemberEvaluation;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 商品SKU变化
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020-07-03 11:20
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class GoodsSkuExecute implements GoodsCommentCompleteEvent {
|
||||
|
||||
//商品
|
||||
private final GoodsSkuService goodsSkuService;
|
||||
|
||||
|
||||
@Override
|
||||
public void goodsComment(MemberEvaluation memberEvaluation) {
|
||||
goodsSkuService.updateGoodsSkuCommentNum(memberEvaluation.getSkuId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
|
||||
import cn.lili.event.GoodsCommentCompleteEvent;
|
||||
import cn.lili.event.MemberRegisterEvent;
|
||||
import cn.lili.modules.member.entity.dos.Member;
|
||||
import cn.lili.modules.member.entity.dos.MemberEvaluation;
|
||||
import cn.lili.modules.member.service.MemberService;
|
||||
import cn.lili.modules.member.service.MemberWalletService;
|
||||
import cn.lili.modules.system.entity.dos.Setting;
|
||||
import cn.lili.modules.system.entity.dto.PointSetting;
|
||||
import cn.lili.modules.system.entity.enums.SettingEnum;
|
||||
import cn.lili.modules.system.service.SettingService;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 会员积分
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020-07-03 11:20
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class MemberPointExecute implements MemberRegisterEvent, GoodsCommentCompleteEvent {
|
||||
|
||||
//配置
|
||||
private final SettingService settingService;
|
||||
//会员
|
||||
private final MemberService memberService;
|
||||
|
||||
@Override
|
||||
public void memberRegister(Member member) {
|
||||
//获取签到积分赠送设置
|
||||
Setting setting = settingService.get(SettingEnum.POINT_SETTING.name());
|
||||
PointSetting pointSetting = new Gson().fromJson(setting.getSettingValue(), PointSetting.class);
|
||||
//赠送会员积分
|
||||
memberService.updateMemberPoint(Long.valueOf(pointSetting.getRegister().longValue()), 1, member.getId(), "会员注册,赠送积分" + pointSetting.getRegister() + "分");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goodsComment(MemberEvaluation memberEvaluation) {
|
||||
//获取签到积分赠送设置
|
||||
Setting setting = settingService.get(SettingEnum.POINT_SETTING.name());
|
||||
PointSetting pointSetting = new Gson().fromJson(setting.getSettingValue(), PointSetting.class);
|
||||
//赠送会员积分
|
||||
memberService.updateMemberPoint(Long.valueOf(pointSetting.getComment().longValue()), 1, memberEvaluation.getMemberId(), "会员评价,赠送积分" + pointSetting.getComment() + "分");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
|
||||
import cn.lili.event.MemberRegisterEvent;
|
||||
import cn.lili.modules.member.entity.dos.Member;
|
||||
import cn.lili.modules.member.service.MemberWalletService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 会员钱包创建
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020-07-03 11:20
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class MemberWalletExecute implements MemberRegisterEvent {
|
||||
|
||||
private final MemberWalletService memberWalletService;
|
||||
|
||||
@Override
|
||||
public void memberRegister(Member member) {
|
||||
memberWalletService.save(member.getId(),member.getUsername());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
import cn.lili.event.*;
|
||||
import cn.lili.modules.member.entity.dto.MemberPointMessage;
|
||||
import cn.lili.modules.member.entity.dto.MemberWithdrawalMessage;
|
||||
import cn.lili.modules.member.entity.enums.MemberWithdrawalDestinationEnum;
|
||||
import cn.lili.modules.message.entity.dto.NoticeMessageDTO;
|
||||
import cn.lili.modules.message.entity.enums.NoticeMessageNodeEnum;
|
||||
import cn.lili.modules.message.entity.enums.NoticeMessageParameterEnum;
|
||||
import cn.lili.modules.message.service.NoticeMessageService;
|
||||
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
||||
import cn.lili.modules.order.order.entity.dos.AfterSale;
|
||||
import cn.lili.modules.order.order.entity.dto.OrderMessage;
|
||||
import cn.lili.modules.order.order.entity.enums.OrderTypeEnum;
|
||||
import cn.lili.modules.order.order.entity.vo.OrderDetailVO;
|
||||
import cn.lili.modules.order.order.service.OrderService;
|
||||
import cn.lili.modules.order.trade.entity.enums.AfterSaleStatusEnum;
|
||||
import cn.lili.modules.order.trade.entity.enums.AfterSaleTypeEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 通知类消息实现
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020-07-03 11:20
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class NoticeMessageExecute implements TradeEvent, OrderStatusChangeEvent, AfterSaleStatusChangeEvent, MemberPointChangeEvent, MemberWithdrawalEvent {
|
||||
|
||||
private final NoticeMessageService noticeMessageService;
|
||||
|
||||
private final OrderService orderService;
|
||||
|
||||
|
||||
@Override
|
||||
public void orderCreate(TradeDTO tradeDTO) {
|
||||
//订单创建发送订单创建站内信息
|
||||
NoticeMessageDTO noticeMessageDTO = new NoticeMessageDTO();
|
||||
noticeMessageDTO.setMemberId(tradeDTO.getMemberId());
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.ORDER_CREATE_SUCCESS);
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("goods", tradeDTO.getSkuList().get(0).getGoodsSku().getGoodsName());
|
||||
noticeMessageDTO.setParameter(params);
|
||||
//保存站内信
|
||||
noticeMessageService.noticeMessage(noticeMessageDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void orderChange(OrderMessage orderMessage) {
|
||||
//查询订单信息
|
||||
OrderDetailVO orderDetailVO = orderService.queryDetail(orderMessage.getOrderSn());
|
||||
NoticeMessageDTO noticeMessageDTO = new NoticeMessageDTO();
|
||||
//如果订单状态不为空
|
||||
if (orderDetailVO != null) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
switch (orderMessage.getNewStatus()){
|
||||
//如果订单新的状态为已取消 则发送取消订单站内信
|
||||
case CANCELLED:
|
||||
params.put(NoticeMessageParameterEnum.CANCEL_REASON.getType(), orderDetailVO.getOrder().getCancelReason());
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.ORDER_CANCEL_SUCCESS);
|
||||
break;
|
||||
//如果订单新的状态为已经支付,则发送支付成功站内信
|
||||
case PAID:
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.ORDER_PAY_SUCCESS);
|
||||
break;
|
||||
//如果订单新的状态为已发货,则发送已发货站内信
|
||||
case DELIVERED:
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.ORDER_DELIVER);
|
||||
break;
|
||||
//如果订单新的状态为已完成,则发送已完成站内信
|
||||
case COMPLETED:
|
||||
//订单完成消息
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.ORDER_COMPLETE);
|
||||
//订单完成也可以进行评价,所以要有评价消息
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.ORDER_EVALUATION);
|
||||
break;
|
||||
//如果是拼团订单,发送拼团成功消息
|
||||
case UNDELIVERED:
|
||||
if(orderDetailVO.getOrder().getOrderType().equals(OrderTypeEnum.PINTUAN.name())){
|
||||
//拼团成功消息
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.PINTUAN_SUCCESS);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
noticeMessageDTO.setMemberId(orderDetailVO.getOrder().getMemberId());
|
||||
//添加站内信参数
|
||||
params.put(NoticeMessageParameterEnum.GOODS.getType(), orderDetailVO.getOrderItems().get(0).getGoodsName());
|
||||
noticeMessageDTO.setParameter(params);
|
||||
//保存站内信
|
||||
noticeMessageService.noticeMessage(noticeMessageDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSaleStatusChange(AfterSale afterSale) {
|
||||
NoticeMessageDTO noticeMessageDTO = new NoticeMessageDTO();
|
||||
noticeMessageDTO.setMemberId(afterSale.getMemberId());
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("goods", afterSale.getGoodsName());
|
||||
params.put("refuse", afterSale.getAuditRemark());
|
||||
noticeMessageDTO.setParameter(params);
|
||||
//如果售后单是申请中 则发送申请中站内信
|
||||
if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.APPLY.name())) {
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.AFTER_SALE_CREATE_SUCCESS);
|
||||
}
|
||||
//售后审核同意切退货站内信通知
|
||||
else if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.PASS.name()) && afterSale.getServiceType().equals(AfterSaleTypeEnum.RETURN_GOODS.name())) {
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.RETURN_GOODS_PASS);
|
||||
}
|
||||
//售后审核拒绝且退货站内信通知
|
||||
else if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.REFUSE.name()) && afterSale.getServiceType().equals(AfterSaleTypeEnum.RETURN_GOODS.name())) {
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.RETURN_GOODS_REFUSE);
|
||||
}
|
||||
//售后审核同意切退款站内信通知
|
||||
else if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.PASS.name()) && afterSale.getServiceType().equals(AfterSaleTypeEnum.RETURN_MONEY.name())) {
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.RETURN_MONEY_PASS);
|
||||
}
|
||||
//售后审核拒绝且退款站内信通知
|
||||
else if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.REFUSE.name()) && afterSale.getServiceType().equals(AfterSaleTypeEnum.RETURN_MONEY.name())) {
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.RETURN_MONEY_REFUSE);
|
||||
}
|
||||
//售后商家确认收货站内信通知
|
||||
else if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.SELLER_CONFIRM.name())) {
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.AFTER_SALE_ROG_PASS);
|
||||
}
|
||||
//退货物品拒收站内信通知
|
||||
else if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.SELLER_TERMINATION.name())) {
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.AFTER_SALE_ROG_REFUSE);
|
||||
}
|
||||
//售后完成通知
|
||||
else if (afterSale.getServiceStatus().equals(AfterSaleStatusEnum.COMPLETE.name())) {
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.AFTER_SALE_COMPLETE);
|
||||
}
|
||||
//保存站内信
|
||||
if (noticeMessageDTO.getNoticeMessageNodeEnum() != null) {
|
||||
noticeMessageService.noticeMessage(noticeMessageDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberPointChange(MemberPointMessage memberPointMessage) {
|
||||
//组织站内信参数
|
||||
NoticeMessageDTO noticeMessageDTO = new NoticeMessageDTO();
|
||||
noticeMessageDTO.setMemberId(memberPointMessage.getMemberId());
|
||||
Map<String, String> params = new HashMap<>();
|
||||
if (memberPointMessage.getType().equals(1)) {
|
||||
params.put("expenditure_points", "0");
|
||||
params.put("income_points", memberPointMessage.getPoint().toString());
|
||||
} else {
|
||||
params.put("expenditure_points", memberPointMessage.getPoint().toString());
|
||||
params.put("income_points", "0");
|
||||
}
|
||||
noticeMessageDTO.setParameter(params);
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.POINT_CHANGE);
|
||||
//发送站内通知信息
|
||||
noticeMessageService.noticeMessage(noticeMessageDTO);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void memberWithdrawal(MemberWithdrawalMessage memberWithdrawalMessage) {
|
||||
|
||||
//如果提现到余额
|
||||
if (memberWithdrawalMessage.getDestination().equals(MemberWithdrawalDestinationEnum.WALLET.name())) {
|
||||
|
||||
//组织参数
|
||||
NoticeMessageDTO noticeMessageDTO = new NoticeMessageDTO();
|
||||
noticeMessageDTO.setMemberId(memberWithdrawalMessage.getMemberId());
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("income", memberWithdrawalMessage.getPrice().toString());
|
||||
noticeMessageDTO.setParameter(params);
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.WALLET_WITHDRAWAL_SUCCESS);
|
||||
//发送提现申请成功消息
|
||||
noticeMessageService.noticeMessage(noticeMessageDTO);
|
||||
|
||||
params.put("income", memberWithdrawalMessage.getPrice().toString());
|
||||
params.put("expenditure", "0");
|
||||
noticeMessageDTO.setNoticeMessageNodeEnum(NoticeMessageNodeEnum.WALLET_CHANGE);
|
||||
noticeMessageDTO.setParameter(params);
|
||||
//发送余额变动消息
|
||||
noticeMessageService.noticeMessage(noticeMessageDTO);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.common.utils.BeanUtil;
|
||||
import cn.lili.event.TradeEvent;
|
||||
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
||||
import cn.lili.modules.order.order.entity.dos.Receipt;
|
||||
import cn.lili.modules.order.order.entity.vo.OrderVO;
|
||||
import cn.lili.modules.order.order.entity.vo.ReceiptVO;
|
||||
import cn.lili.modules.order.order.service.ReceiptService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单创建发票相关处理
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020-07-03 11:20
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class OrderCreateReceiptExecute implements TradeEvent {
|
||||
|
||||
private final ReceiptService receiptService;
|
||||
|
||||
@Override
|
||||
public void orderCreate(TradeDTO tradeDTO) {
|
||||
//根据交易sn查询订单信息
|
||||
List<OrderVO> orderList = tradeDTO.getOrderVO();
|
||||
//获取发票信息
|
||||
ReceiptVO receiptVO = tradeDTO.getReceiptVO();
|
||||
//如果需要获取发票则保存发票信息
|
||||
if (tradeDTO.getNeedReceipt()) {
|
||||
if (orderList.size() > 0) {
|
||||
List<Receipt> receipts = new ArrayList<>();
|
||||
for (OrderVO orderVO : orderList) {
|
||||
Receipt receipt = new Receipt();
|
||||
BeanUtil.copyProperties(receiptVO, receipt);
|
||||
receipt.setMemberId(orderVO.getMemberId());
|
||||
receipt.setMemberName(orderVO.getMemberName());
|
||||
receipt.setStoreId(orderVO.getStoreId());
|
||||
receipt.setStoreName(orderVO.getStoreName());
|
||||
receipt.setOrderSn(orderVO.getSn());
|
||||
receipt.setReceiptDetail(JSONUtil.toJsonStr(orderVO.getOrderItems()));
|
||||
receipt.setReceiptPrice(orderVO.getFlowPrice());
|
||||
receipt.setReceiptStatus(0);
|
||||
receipts.add(receipt);
|
||||
}
|
||||
//保存发票
|
||||
receiptService.saveBatch(receipts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
import cn.lili.common.utils.SnowFlake;
|
||||
import cn.lili.common.utils.SpringContextUtil;
|
||||
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.PayStatusEnum;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 支付
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2021-03-13 16:58
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class PaymentExecute implements OrderStatusChangeEvent {
|
||||
|
||||
//支付日志
|
||||
private final PaymentService paymentService;
|
||||
//订单
|
||||
private final OrderService orderService;
|
||||
|
||||
@Override
|
||||
public void orderChange(OrderMessage orderMessage) {
|
||||
|
||||
switch (orderMessage.getNewStatus()) {
|
||||
case CANCELLED:
|
||||
Order order = orderService.getBySn(orderMessage.getOrderSn());
|
||||
//未付款不做处理 直接返回
|
||||
if (order.getPayStatus() == PayStatusEnum.UNPAID.name()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PaymentMethodEnum paymentMethodEnum = PaymentMethodEnum.valueOf(order.getPaymentMethod());
|
||||
//进行退款操作
|
||||
switch (paymentMethodEnum) {
|
||||
case WALLET:
|
||||
case ALIPAY:
|
||||
case WECHAT:
|
||||
//获取支付方式
|
||||
Payment payment =
|
||||
(Payment) SpringContextUtil.getBean(paymentMethodEnum.getPlugin());
|
||||
|
||||
RefundLog refundLog = RefundLog.builder()
|
||||
.isRefund(false)
|
||||
.totalAmount(order.getFlowPrice())
|
||||
.payPrice(order.getFlowPrice())
|
||||
.memberId(order.getMemberId())
|
||||
.paymentName(order.getPaymentMethod())
|
||||
.afterSaleNo("订单取消")
|
||||
.orderSn(order.getSn())
|
||||
.paymentReceivableNo(order.getReceivableNo())
|
||||
.outOrderNo("AF" + SnowFlake.getIdStr())
|
||||
.outOrderNo("AF" + SnowFlake.getIdStr())
|
||||
.refundReason("订单取消")
|
||||
.build();
|
||||
payment.cancel(refundLog);
|
||||
break;
|
||||
case BANK_TRANSFER:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
import cn.lili.common.cache.Cache;
|
||||
import cn.lili.event.OrderStatusChangeEvent;
|
||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||
import cn.lili.modules.order.order.entity.dos.OrderItem;
|
||||
import cn.lili.modules.order.order.entity.dto.OrderMessage;
|
||||
import cn.lili.modules.order.order.entity.enums.PayStatusEnum;
|
||||
import cn.lili.modules.order.order.entity.vo.OrderDetailVO;
|
||||
import cn.lili.modules.order.order.service.OrderService;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.enums.PromotionTypeEnum;
|
||||
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 库存扣减,他表示了订单状态是否出库成功
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020-07-03 11:20
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class StockUpdateExecute implements OrderStatusChangeEvent {
|
||||
|
||||
//Redis
|
||||
private final StringRedisTemplate stringRedisTemplate;
|
||||
private final DefaultRedisScript<Boolean> quantityScript;
|
||||
//订单
|
||||
private final OrderService orderService;
|
||||
//规格商品
|
||||
private final GoodsSkuService goodsSkuService;
|
||||
//促销商品
|
||||
private final PromotionGoodsService promotionGoodsService;
|
||||
//缓存
|
||||
private final Cache cache;
|
||||
|
||||
@Override
|
||||
public void orderChange(OrderMessage orderMessage) {
|
||||
|
||||
switch (orderMessage.getNewStatus()) {
|
||||
case PAID: {
|
||||
|
||||
OrderDetailVO order = orderService.queryDetail(orderMessage.getOrderSn());
|
||||
//库存key 和 扣减数量
|
||||
List<String> keys = new ArrayList<>();
|
||||
List<String> values = new ArrayList<>();
|
||||
for (OrderItem orderItem : order.getOrderItems()) {
|
||||
keys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId()));
|
||||
int i = -orderItem.getNum();
|
||||
values.add(Integer.toString(i));
|
||||
setPromotionStock(keys, values, orderItem);
|
||||
}
|
||||
//库存扣除结果
|
||||
Boolean skuResult = stringRedisTemplate.execute(quantityScript, keys, values.toArray());
|
||||
//如果库存扣减都成功,则记录成交订单
|
||||
if (Boolean.TRUE.equals(skuResult)) {
|
||||
//库存确认之后对结构处理
|
||||
orderService.afterOrderConfirm(orderMessage.getOrderSn());
|
||||
//成功之后,同步库存
|
||||
synchroDB(order);
|
||||
} else {
|
||||
//失败之后取消订单
|
||||
this.errorOrder(orderMessage.getOrderSn());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CANCELLED: {
|
||||
|
||||
OrderDetailVO order = orderService.queryDetail(orderMessage.getOrderSn());
|
||||
if (order.getOrder().getPayStatus().equals(PayStatusEnum.PAID.name())) {
|
||||
for (OrderItem orderItem : order.getOrderItems()) {
|
||||
if (PromotionTypeEnum.haveStock(orderItem.getPromotionType())) {
|
||||
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(orderItem.getPromotionType());
|
||||
Integer goodsPromotionOriginStock = promotionGoodsService.getPromotionGoodsStock(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId());
|
||||
int goodsPromotionStock = goodsPromotionOriginStock + orderItem.getNum();
|
||||
String promotionGoodsStockCacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId());
|
||||
stringRedisTemplate.opsForValue().set(promotionGoodsStockCacheKey, Integer.toString(goodsPromotionStock));
|
||||
}
|
||||
String stockCacheKey = GoodsSkuService.getStockCacheKey(orderItem.getSkuId());
|
||||
Integer goodsOriginStock = goodsSkuService.getStock(orderItem.getSkuId());
|
||||
int goodsStock = goodsOriginStock + orderItem.getNum();
|
||||
stringRedisTemplate.opsForValue().set(stockCacheKey, Integer.toString(goodsStock));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单出库失败
|
||||
*
|
||||
* @param orderSn 失败入库订单信息
|
||||
*/
|
||||
private void errorOrder(String orderSn) {
|
||||
orderService.systemCancel(orderSn, "库存不足,出库失败");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 写入需要更改促销库存的商品
|
||||
*
|
||||
* @param keys 缓存key值
|
||||
* @param values 缓存value值
|
||||
* @param sku 购物车信息
|
||||
*/
|
||||
private void setPromotionStock(List<String> keys, List<String> values, OrderItem sku) {
|
||||
if (sku.getPromotionType() != null) {
|
||||
//如果此促销有库存概念,则计入
|
||||
if (!PromotionTypeEnum.haveStock(sku.getPromotionType())) {
|
||||
return;
|
||||
}
|
||||
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(sku.getPromotionType());
|
||||
keys.add(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, sku.getPromotionId(), sku.getSkuId()));
|
||||
int i = -sku.getNum();
|
||||
values.add(Integer.toString(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入需要更改促销库存的商品
|
||||
*
|
||||
* @param order 订单
|
||||
*/
|
||||
private void synchroDB(OrderDetailVO order) {
|
||||
|
||||
//sku商品
|
||||
List<GoodsSku> goodsSkus = new ArrayList<>();
|
||||
//促销商品
|
||||
List<PromotionGoods> promotionGoods = new ArrayList<>();
|
||||
//sku库存key 集合
|
||||
List<String> skuKeys = new ArrayList<>();
|
||||
//促销库存key 集合
|
||||
List<String> promotionKey = new ArrayList<>();
|
||||
|
||||
// 循环订单
|
||||
for (OrderItem orderItem : order.getOrderItems()) {
|
||||
skuKeys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId()));
|
||||
GoodsSku goodsSku = new GoodsSku();
|
||||
goodsSku.setId(orderItem.getSkuId());
|
||||
//如果有促销信息
|
||||
if (null != orderItem.getPromotionType() && null != orderItem.getPromotionId()) {
|
||||
//如果促销有库存信息
|
||||
if (PromotionTypeEnum.haveStock(orderItem.getPromotionType())) {
|
||||
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(orderItem.getPromotionType());
|
||||
PromotionGoods pGoods = promotionGoodsService.getPromotionGoods(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId());
|
||||
promotionKey.add(
|
||||
PromotionGoodsService.getPromotionGoodsStockCacheKey(
|
||||
promotionTypeEnum,
|
||||
orderItem.getPromotionId(), orderItem.getSkuId())
|
||||
);
|
||||
promotionGoods.add(pGoods);
|
||||
}
|
||||
}
|
||||
goodsSkus.add(goodsSku);
|
||||
}
|
||||
|
||||
List skuStocks = cache.multiGet(skuKeys);
|
||||
//循环写入商品库存
|
||||
for (int i = 0; i < skuStocks.size(); i++) {
|
||||
goodsSkus.get(i).setQuantity(Integer.parseInt(skuStocks.get(i).toString()));
|
||||
}
|
||||
//批量修改商品库存
|
||||
goodsSkuService.updateBatchById(goodsSkus);
|
||||
|
||||
//促销库存处理
|
||||
if (!promotionKey.isEmpty()) {
|
||||
List promotionStocks = cache.multiGet(promotionKey);
|
||||
for (int i = 0; i < promotionKey.size(); i++) {
|
||||
promotionGoods.get(i).setQuantity(Integer.parseInt(promotionStocks.get(i).toString()));
|
||||
Integer num = promotionGoods.get(i).getNum();
|
||||
promotionGoods.get(i).setNum((num != null ? num : 0) + order.getOrder().getGoodsNum());
|
||||
}
|
||||
promotionGoodsService.updateBatchById(promotionGoods);
|
||||
}
|
||||
goodsSkuService.updateGoodsStuck(goodsSkus);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package cn.lili.event.impl;
|
||||
|
||||
import cn.lili.event.OrderStatusChangeEvent;
|
||||
import cn.lili.event.TradeEvent;
|
||||
import cn.lili.modules.message.util.WechatMessageUtil;
|
||||
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
||||
import cn.lili.modules.order.order.entity.dto.OrderMessage;
|
||||
import cn.lili.modules.order.order.entity.vo.OrderVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 微信消息执行器
|
||||
*
|
||||
* @author Chopper
|
||||
* @version v1.0
|
||||
* 2021-04-19 14:25
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class WechatMessageExecute implements OrderStatusChangeEvent, TradeEvent {
|
||||
|
||||
@Autowired
|
||||
private WechatMessageUtil wechatMessageUtil;
|
||||
|
||||
@Override
|
||||
public void orderCreate(TradeDTO tradeDTO) {
|
||||
for (OrderVO orderVO : tradeDTO.getOrderVO()) {
|
||||
try {
|
||||
wechatMessageUtil.sendWechatMessage(orderVO.getSn());
|
||||
} catch (Exception e) {
|
||||
log.error("微信消息发送失败:" + orderVO.getSn(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void orderChange(OrderMessage orderMessage) {
|
||||
|
||||
switch (orderMessage.getNewStatus()) {
|
||||
case PAID:
|
||||
case UNDELIVERED:
|
||||
case DELIVERED:
|
||||
case COMPLETED:
|
||||
try {
|
||||
wechatMessageUtil.sendWechatMessage(orderMessage.getOrderSn());
|
||||
} catch (Exception e) {
|
||||
log.error("微信消息发送失败", e);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user