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.TbOrderInfo;
|
||||
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.ReturnOrderDTO;
|
||||
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.util.IpUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.Utils;
|
||||
import com.chaozhanggui.system.cashierservice.util.WechatUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -220,6 +222,14 @@ public class PayController {
|
||||
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")
|
||||
public Result noTokenQueryOrderInfo(String orderId) {
|
||||
if(StrUtil.isBlank(orderId)){
|
||||
if (StrUtil.isBlank(orderId)) {
|
||||
return Result.fail("订单id不能为空");
|
||||
}
|
||||
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||
if(orderInfo == null){
|
||||
if (orderInfo == null) {
|
||||
return Result.fail("订单不存在");
|
||||
}
|
||||
Map<String, Object> data = new HashMap<>(4);
|
||||
|
||||
@@ -122,6 +122,7 @@ public class TbOrderInfo implements Serializable {
|
||||
private BigDecimal pointsDiscountAmount;
|
||||
private String refundRemark;
|
||||
private Integer pointsNum;
|
||||
private String creditBuyerId;
|
||||
|
||||
public TbOrderInfo(){
|
||||
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.dao.*;
|
||||
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.ReturnGroupOrderDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnOrderDTO;
|
||||
@@ -146,14 +147,14 @@ public class PayService {
|
||||
private final MpProductStockDetailMapper mpProductStockDetailMapper;
|
||||
private final MpOrderInfoService mpOrderInfoService;
|
||||
private final TbMemberPointsService memberPointsService;
|
||||
|
||||
private final TbCreditBuyerOrderService creditBuyerOrderService;
|
||||
|
||||
|
||||
private final Utils utils;
|
||||
@Autowired
|
||||
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.mpCashierCartService = mpCashierCartService;
|
||||
this.shopCouponService = shopCouponService;
|
||||
@@ -161,8 +162,9 @@ public class PayService {
|
||||
this.mpShopUnitMapper = mpShopUnitMapper;
|
||||
this.mpProductStockDetailMapper = mpProductStockDetailMapper;
|
||||
this.mpOrderInfoService = mpOrderInfoService;
|
||||
this.memberPointsService = memberPointsService;
|
||||
this.creditBuyerOrderService = creditBuyerOrderService;
|
||||
this.utils = utils;
|
||||
memberPointsService = null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -875,6 +877,90 @@ public class PayService {
|
||||
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) {
|
||||
if (ObjectUtil.isEmpty(orderId)) {
|
||||
return Result.fail(CodeEnum.PARAM);
|
||||
@@ -1438,7 +1524,7 @@ public class PayService {
|
||||
mpOrderDetailService.updateStatusByOrderIdAndIds(TableConstant.OrderInfo.Status.REFUNDING, TableConstant.OrderInfo.Status.REFUND,
|
||||
returnOrderDTO.getOrderId(), returnOrderDTO.getOrderDetails().stream().map(ReturnOrderDTO.OrderDetail::getId).collect(Collectors.toList()));
|
||||
|
||||
}else {
|
||||
} else {
|
||||
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
|
||||
MsgException.checkNull(thirdApply, "支付参数配置错误");
|
||||
|
||||
@@ -2489,4 +2575,5 @@ public class PayService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user