fix: 挂账支付实现
This commit is contained in:
@@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
|||||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.dto.CreditDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnOrderDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnOrderDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.VipPayDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.VipPayDTO;
|
||||||
@@ -25,6 +26,7 @@ import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
|||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
import com.chaozhanggui.system.cashierservice.util.IpUtil;
|
import com.chaozhanggui.system.cashierservice.util.IpUtil;
|
||||||
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
|
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
|
||||||
|
import com.chaozhanggui.system.cashierservice.util.Utils;
|
||||||
import com.chaozhanggui.system.cashierservice.util.WechatUtil;
|
import com.chaozhanggui.system.cashierservice.util.WechatUtil;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -214,12 +216,20 @@ public class PayController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((vipPayDTO.getPayAmount() != null && vipPayDTO.getPayAmount().compareTo(BigDecimal.ZERO) <= 0) ||
|
if ((vipPayDTO.getPayAmount() != null && vipPayDTO.getPayAmount().compareTo(BigDecimal.ZERO) <= 0) ||
|
||||||
(vipPayDTO.getDiscountAmount() != null && vipPayDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0)) {
|
(vipPayDTO.getDiscountAmount() != null && vipPayDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0)) {
|
||||||
return Result.fail("折扣金额必须大于0");
|
return Result.fail("折扣金额必须大于0");
|
||||||
}
|
}
|
||||||
return payService.vipPay(vipPayDTO.getOrderId(), token, vipPayDTO.getVipUserId(), vipPayDTO.getPayAmount(), vipPayDTO.getDiscountAmount());
|
return payService.vipPay(vipPayDTO.getOrderId(), token, vipPayDTO.getVipUserId(), vipPayDTO.getPayAmount(), vipPayDTO.getDiscountAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 挂账支付
|
||||||
|
*/
|
||||||
|
@PostMapping("creditPay")
|
||||||
|
public Result creditPay(@RequestHeader("token") String token, @RequestBody CreditDTO creditDTO) {
|
||||||
|
return payService.creditPay(creditDTO, token);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 银行卡支付
|
* 银行卡支付
|
||||||
*
|
*
|
||||||
@@ -315,11 +325,11 @@ public class PayController {
|
|||||||
|
|
||||||
@GetMapping("/noToken/queryOrderInfo")
|
@GetMapping("/noToken/queryOrderInfo")
|
||||||
public Result noTokenQueryOrderInfo(String orderId) {
|
public Result noTokenQueryOrderInfo(String orderId) {
|
||||||
if(StrUtil.isBlank(orderId)){
|
if (StrUtil.isBlank(orderId)) {
|
||||||
return Result.fail("订单id不能为空");
|
return Result.fail("订单id不能为空");
|
||||||
}
|
}
|
||||||
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||||
if(orderInfo == null){
|
if (orderInfo == null) {
|
||||||
return Result.fail("订单不存在");
|
return Result.fail("订单不存在");
|
||||||
}
|
}
|
||||||
Map<String, Object> data = new HashMap<>(4);
|
Map<String, Object> data = new HashMap<>(4);
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ public class TbOrderInfo implements Serializable {
|
|||||||
private BigDecimal pointsDiscountAmount;
|
private BigDecimal pointsDiscountAmount;
|
||||||
private String refundRemark;
|
private String refundRemark;
|
||||||
private Integer pointsNum;
|
private Integer pointsNum;
|
||||||
|
private String creditBuyerId;
|
||||||
|
|
||||||
public TbOrderInfo(){
|
public TbOrderInfo(){
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.DecimalMin;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreditDTO {
|
||||||
|
@NotNull
|
||||||
|
private Integer orderId;
|
||||||
|
@NotEmpty
|
||||||
|
private String creditBuyerId;
|
||||||
|
@DecimalMin("0.00")
|
||||||
|
private BigDecimal payAmount;
|
||||||
|
@DecimalMin("0.00")
|
||||||
|
private BigDecimal discountAmount;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.bean.TableStateEnum;
|
|||||||
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
|
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.dto.CreditDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.OrderInfoCouponInfoDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.OrderInfoCouponInfoDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnOrderDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnOrderDTO;
|
||||||
@@ -146,14 +147,14 @@ public class PayService {
|
|||||||
private final MpProductStockDetailMapper mpProductStockDetailMapper;
|
private final MpProductStockDetailMapper mpProductStockDetailMapper;
|
||||||
private final MpOrderInfoService mpOrderInfoService;
|
private final MpOrderInfoService mpOrderInfoService;
|
||||||
private final TbMemberPointsService memberPointsService;
|
private final TbMemberPointsService memberPointsService;
|
||||||
|
private final TbCreditBuyerOrderService creditBuyerOrderService;
|
||||||
|
|
||||||
|
|
||||||
private final Utils utils;
|
private final Utils utils;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MPOrderInfoMapper mPOrderInfoMapper;
|
private MPOrderInfoMapper mPOrderInfoMapper;
|
||||||
|
|
||||||
public PayService(RedisTemplate<String, Object> redisTemplate, MpCashierCartService mpCashierCartService, TbShopCouponService shopCouponService, MpOrderDetailService mpOrderDetailService, MpShopUnitMapper mpShopUnitMapper, MpProductStockDetailMapper mpProductStockDetailMapper, MpOrderInfoService mpOrderInfoService, Utils utils) {
|
public PayService(RedisTemplate<String, Object> redisTemplate, MpCashierCartService mpCashierCartService, TbShopCouponService shopCouponService, MpOrderDetailService mpOrderDetailService, MpShopUnitMapper mpShopUnitMapper, MpProductStockDetailMapper mpProductStockDetailMapper, MpOrderInfoService mpOrderInfoService, TbMemberPointsService memberPointsService, TbCreditBuyerOrderService creditBuyerOrderService, Utils utils) {
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.mpCashierCartService = mpCashierCartService;
|
this.mpCashierCartService = mpCashierCartService;
|
||||||
this.shopCouponService = shopCouponService;
|
this.shopCouponService = shopCouponService;
|
||||||
@@ -161,8 +162,9 @@ public class PayService {
|
|||||||
this.mpShopUnitMapper = mpShopUnitMapper;
|
this.mpShopUnitMapper = mpShopUnitMapper;
|
||||||
this.mpProductStockDetailMapper = mpProductStockDetailMapper;
|
this.mpProductStockDetailMapper = mpProductStockDetailMapper;
|
||||||
this.mpOrderInfoService = mpOrderInfoService;
|
this.mpOrderInfoService = mpOrderInfoService;
|
||||||
|
this.memberPointsService = memberPointsService;
|
||||||
|
this.creditBuyerOrderService = creditBuyerOrderService;
|
||||||
this.utils = utils;
|
this.utils = utils;
|
||||||
memberPointsService = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -286,7 +288,7 @@ public class PayService {
|
|||||||
return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.runFunAndTransactional(() -> {
|
utils.runFunAndTransactional(() -> {
|
||||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
||||||
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
||||||
payment = new TbOrderPayment();
|
payment = new TbOrderPayment();
|
||||||
@@ -875,6 +877,90 @@ public class PayService {
|
|||||||
return Result.success(SUCCESS);
|
return Result.success(SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result creditPay(CreditDTO creditDTO, String token) {
|
||||||
|
|
||||||
|
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(creditDTO.getOrderId());
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(orderInfo)) {
|
||||||
|
return Result.fail(CodeEnum.ORDERNOEXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||||
|
return Result.fail(CodeEnum.ORDERSTATUSERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "cash");
|
||||||
|
if (count < 1) {
|
||||||
|
return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (creditDTO.getPayAmount().add(creditDTO.getDiscountAmount()).compareTo(orderInfo.getOrderAmount()) != 0) {
|
||||||
|
return Result.fail("优惠金额 + 支付金额不等于订单金额");
|
||||||
|
}
|
||||||
|
|
||||||
|
creditBuyerOrderService.save(creditDTO.getCreditBuyerId(), Long.valueOf(orderInfo.getId()));
|
||||||
|
|
||||||
|
utils.runFunAndTransactional(() -> {
|
||||||
|
|
||||||
|
|
||||||
|
if (creditDTO.getPayAmount() != null && creditDTO.getDiscountAmount() != null) {
|
||||||
|
orderInfo.setPayAmount(creditDTO.getPayAmount());
|
||||||
|
orderInfo.setDiscountAmount(creditDTO.getDiscountAmount());
|
||||||
|
orderInfo.setDiscountRatio(ObjectUtil.isNotEmpty(creditDTO.getPayAmount()) ? creditDTO.getPayAmount()
|
||||||
|
.divide(orderInfo.getOrderAmount(), 2, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_DOWN) : null);
|
||||||
|
} else {
|
||||||
|
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||||
|
}
|
||||||
|
orderInfo.setCreditBuyerId(creditDTO.getCreditBuyerId());
|
||||||
|
orderInfo.setPayType("creditBuyer");
|
||||||
|
orderInfo.setStatus("closed");
|
||||||
|
orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||||
|
//更新购物车状态
|
||||||
|
mpCashierCartService.updateStateByOrderId(TableConstant.OrderInfo.Status.CLOSED, orderInfo.getId());
|
||||||
|
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
||||||
|
tbOrderDetailMapper.updateStatusByOrderId(creditDTO.getOrderId(), "closed", orderInfo.getDiscountRatio());
|
||||||
|
} else {
|
||||||
|
tbOrderDetailMapper.updateStatusByOrderId(creditDTO.getOrderId(), "closed", null);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("token", token);
|
||||||
|
jsonObject.put("type", "create");
|
||||||
|
jsonObject.put("orderId", creditDTO.getOrderId());
|
||||||
|
|
||||||
|
producer.putOrderCollect(jsonObject.toJSONString());
|
||||||
|
|
||||||
|
// 打印消息
|
||||||
|
if (!OrderUseTypeEnum.DINE_IN_AFTER.getValue().equals(orderInfo.getUseType())) {
|
||||||
|
List<TbOrderDetail> detailList = mPOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||||
|
.eq(TbOrderDetail::getStatus, "closed"));
|
||||||
|
rabbitMsgUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
|
||||||
|
}
|
||||||
|
rabbitMsgUtils.printPlaceTicket(orderInfo.getId(), false);
|
||||||
|
|
||||||
|
// 发送库存记录mq消息
|
||||||
|
JSONObject mqData = new JSONObject();
|
||||||
|
mqData.put("orderId", creditDTO.getOrderId());
|
||||||
|
mqData.put("type", "pc");
|
||||||
|
producer.sendStockSaleMsg(mqData);
|
||||||
|
|
||||||
|
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||||
|
orderInfo.getShopId());
|
||||||
|
redisUtil.del(tableCartKey);
|
||||||
|
clearTableInfoCache(orderInfo);
|
||||||
|
|
||||||
|
return Result.success(SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
public Result vipPay(Integer orderId, String token, Integer vipUserId, BigDecimal payAmount, BigDecimal discountAmount) {
|
public Result vipPay(Integer orderId, String token, Integer vipUserId, BigDecimal payAmount, BigDecimal discountAmount) {
|
||||||
if (ObjectUtil.isEmpty(orderId)) {
|
if (ObjectUtil.isEmpty(orderId)) {
|
||||||
return Result.fail(CodeEnum.PARAM);
|
return Result.fail(CodeEnum.PARAM);
|
||||||
@@ -1307,24 +1393,24 @@ public class PayService {
|
|||||||
|
|
||||||
// TbOrderInfo returnOrder = mpOrderInfoService.selectReturnOrderByOrderId(returnOrderDTO.getOrderId());
|
// TbOrderInfo returnOrder = mpOrderInfoService.selectReturnOrderByOrderId(returnOrderDTO.getOrderId());
|
||||||
TbOrderInfo returnOrder = new TbOrderInfo();
|
TbOrderInfo returnOrder = new TbOrderInfo();
|
||||||
String orderNo = generateOrderNumber();
|
String orderNo = generateOrderNumber();
|
||||||
cn.hutool.core.bean.BeanUtil.copyProperties(oldOrderInfo, returnOrder);
|
cn.hutool.core.bean.BeanUtil.copyProperties(oldOrderInfo, returnOrder);
|
||||||
returnOrder.setId(null);
|
returnOrder.setId(null);
|
||||||
returnOrder.setOrderNo(orderNo);
|
returnOrder.setOrderNo(orderNo);
|
||||||
returnOrder.setRefundAmount(returnAmount);
|
returnOrder.setRefundAmount(returnAmount);
|
||||||
returnOrder.setOrderType("return");
|
returnOrder.setOrderType("return");
|
||||||
returnOrder.setStatus(isOnline ? "refunding" : "refund");
|
returnOrder.setStatus(isOnline ? "refunding" : "refund");
|
||||||
returnOrder.setUpdatedAt(null);
|
returnOrder.setUpdatedAt(null);
|
||||||
returnOrder.setSystemTime(DateUtil.date().getTime());
|
returnOrder.setSystemTime(DateUtil.date().getTime());
|
||||||
returnOrder.setCreatedAt(DateUtil.date().getTime());
|
returnOrder.setCreatedAt(DateUtil.date().getTime());
|
||||||
returnOrder.setPayOrderNo(null);
|
returnOrder.setPayOrderNo(null);
|
||||||
returnOrder.setSource(oldOrderInfo.getId());
|
returnOrder.setSource(oldOrderInfo.getId());
|
||||||
returnOrder.setRefundRemark(returnOrderDTO.getNote());
|
returnOrder.setRefundRemark(returnOrderDTO.getNote());
|
||||||
returnOrder.setOrderAmount(returnAmount);
|
returnOrder.setOrderAmount(returnAmount);
|
||||||
returnOrder.setAmount(returnAmount);
|
returnOrder.setAmount(returnAmount);
|
||||||
returnOrder.setSettlementAmount(returnAmount);
|
returnOrder.setSettlementAmount(returnAmount);
|
||||||
returnOrder.setPayAmount(returnAmount);
|
returnOrder.setPayAmount(returnAmount);
|
||||||
mPOrderInfoMapper.insert(returnOrder);
|
mPOrderInfoMapper.insert(returnOrder);
|
||||||
|
|
||||||
for (TbOrderDetail orderDetail : detailList) {
|
for (TbOrderDetail orderDetail : detailList) {
|
||||||
orderDetail.setOrderId(returnOrder.getId());
|
orderDetail.setOrderId(returnOrder.getId());
|
||||||
@@ -1434,11 +1520,11 @@ public class PayService {
|
|||||||
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(returnOrderInfo.getRefundAmount()));
|
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(returnOrderInfo.getRefundAmount()));
|
||||||
orderInfo.setRefundRemark(returnOrderDTO.getNote());
|
orderInfo.setRefundRemark(returnOrderDTO.getNote());
|
||||||
if (hasNormalReturn && ("scanCode".equals(payType) || "wx_lite".equals(payType))) {
|
if (hasNormalReturn && ("scanCode".equals(payType) || "wx_lite".equals(payType))) {
|
||||||
if (returnOrderDTO.getIsOnline() != null && !returnOrderDTO.getIsOnline()) {
|
if (returnOrderDTO.getIsOnline() != null && !returnOrderDTO.getIsOnline()) {
|
||||||
mpOrderDetailService.updateStatusByOrderIdAndIds(TableConstant.OrderInfo.Status.REFUNDING, TableConstant.OrderInfo.Status.REFUND,
|
mpOrderDetailService.updateStatusByOrderIdAndIds(TableConstant.OrderInfo.Status.REFUNDING, TableConstant.OrderInfo.Status.REFUND,
|
||||||
returnOrderDTO.getOrderId(), returnOrderDTO.getOrderDetails().stream().map(ReturnOrderDTO.OrderDetail::getId).collect(Collectors.toList()));
|
returnOrderDTO.getOrderId(), returnOrderDTO.getOrderDetails().stream().map(ReturnOrderDTO.OrderDetail::getId).collect(Collectors.toList()));
|
||||||
|
|
||||||
}else {
|
} else {
|
||||||
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
|
||||||
MsgException.checkNull(thirdApply, "支付参数配置错误");
|
MsgException.checkNull(thirdApply, "支付参数配置错误");
|
||||||
|
|
||||||
@@ -2489,4 +2575,5 @@ public class PayService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user