扫码支付回调修改
This commit is contained in:
@@ -7,4 +7,9 @@ import java.math.BigDecimal;
|
|||||||
public interface PayService {
|
public interface PayService {
|
||||||
void returnOrder(Integer shopId, TbOrderInfo orderInfo, TbOrderInfo returnOrderInfo);
|
void returnOrder(Integer shopId, TbOrderInfo orderInfo, TbOrderInfo returnOrderInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付状态校验
|
||||||
|
* @return 是否支付成功
|
||||||
|
*/
|
||||||
|
boolean checkPayState(TbOrderInfo orderInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,52 @@
|
|||||||
package cn.ysk.cashier.service.impl;
|
package cn.ysk.cashier.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import cn.ysk.cashier.cons.RedisConstant;
|
||||||
|
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||||
|
import cn.ysk.cashier.enums.OrderUseTypeEnum;
|
||||||
|
import cn.ysk.cashier.enums.TableStateEnum;
|
||||||
import cn.ysk.cashier.exception.BadRequestException;
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
import cn.ysk.cashier.model.ReturnOrderReq;
|
import cn.ysk.cashier.model.ReturnOrderReq;
|
||||||
import cn.ysk.cashier.mybatis.entity.TbOrderPayment;
|
import cn.ysk.cashier.mybatis.entity.TbOrderPayment;
|
||||||
import cn.ysk.cashier.mybatis.mapper.MpMerchantThirdApplyMapper;
|
import cn.ysk.cashier.mybatis.mapper.*;
|
||||||
import cn.ysk.cashier.mybatis.mapper.MpOrderPaymentMapper;
|
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||||
|
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||||
import cn.ysk.cashier.pojo.shop.TbMerchantThirdApply;
|
import cn.ysk.cashier.pojo.shop.TbMerchantThirdApply;
|
||||||
|
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
||||||
import cn.ysk.cashier.service.PayService;
|
import cn.ysk.cashier.service.PayService;
|
||||||
import cn.ysk.cashier.thirdpay.constants.SignTypeEnum;
|
import cn.ysk.cashier.thirdpay.constants.SignTypeEnum;
|
||||||
import cn.ysk.cashier.thirdpay.req.OrderRefundReq;
|
import cn.ysk.cashier.thirdpay.req.OrderRefundReq;
|
||||||
import cn.ysk.cashier.thirdpay.req.PublicParam;
|
import cn.ysk.cashier.thirdpay.req.PublicParam;
|
||||||
import cn.ysk.cashier.thirdpay.resp.OrderReturnResp;
|
import cn.ysk.cashier.thirdpay.resp.OrderReturnResp;
|
||||||
|
import cn.ysk.cashier.thirdpay.resp.OrderStatusQueryResp;
|
||||||
import cn.ysk.cashier.thirdpay.resp.PublicResp;
|
import cn.ysk.cashier.thirdpay.resp.PublicResp;
|
||||||
import cn.ysk.cashier.thirdpay.service.ThirdPayService;
|
import cn.ysk.cashier.thirdpay.service.ThirdPayService;
|
||||||
import cn.ysk.cashier.utils.DateUtils;
|
|
||||||
import cn.ysk.cashier.utils.MD5Util;
|
import cn.ysk.cashier.utils.MD5Util;
|
||||||
|
import cn.ysk.cashier.utils.RabbitMsgUtils;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.dianguang.cloud.ossservice.model.DateUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -40,6 +55,12 @@ public class PayServiceImpl implements PayService {
|
|||||||
private final MpMerchantThirdApplyMapper mpMerchantThirdApplyMapper;
|
private final MpMerchantThirdApplyMapper mpMerchantThirdApplyMapper;
|
||||||
private final MpOrderPaymentMapper mpOrderPaymentMapper;
|
private final MpOrderPaymentMapper mpOrderPaymentMapper;
|
||||||
private final ThirdPayService thirdPayService;
|
private final ThirdPayService thirdPayService;
|
||||||
|
private final TbCashierCartMapper tbCashierCartMapper;
|
||||||
|
private final TbOrderDetailMapper tbOrderDetailMapper;
|
||||||
|
private final TbOrderInfoMapper tbOrderInfoMapper;
|
||||||
|
private final RabbitMsgUtils rabbitMsgUtils;
|
||||||
|
private final RabbitTemplate rabbitTemplate;
|
||||||
|
private final MpShopTableMapper mpShopTableMapper;
|
||||||
@Value("${thirdPay.payType}")
|
@Value("${thirdPay.payType}")
|
||||||
private String thirdPayType;
|
private String thirdPayType;
|
||||||
@Value("${gateway.url}")
|
@Value("${gateway.url}")
|
||||||
@@ -50,16 +71,26 @@ public class PayServiceImpl implements PayService {
|
|||||||
private String callBack;
|
private String callBack;
|
||||||
|
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
|
private final StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
public PayServiceImpl(MpMerchantThirdApplyMapper mpMerchantThirdApplyMapper, RestTemplate restTemplate, MpOrderPaymentMapper mpOrderPaymentMapper, ThirdPayService thirdPayService) {
|
|
||||||
|
public PayServiceImpl(MpMerchantThirdApplyMapper mpMerchantThirdApplyMapper, RestTemplate restTemplate, MpOrderPaymentMapper mpOrderPaymentMapper, ThirdPayService thirdPayService, TbCashierCartMapper tbCashierCartMapper, TbOrderDetailMapper tbOrderDetailMapper, TbOrderInfoMapper tbOrderInfoMapper, RabbitMsgUtils rabbitMsgUtils, RabbitTemplate rabbitTemplate, MpShopTableMapper mpShopTableMapper, StringRedisTemplate redisTemplate) {
|
||||||
this.mpMerchantThirdApplyMapper = mpMerchantThirdApplyMapper;
|
this.mpMerchantThirdApplyMapper = mpMerchantThirdApplyMapper;
|
||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
this.mpOrderPaymentMapper = mpOrderPaymentMapper;
|
this.mpOrderPaymentMapper = mpOrderPaymentMapper;
|
||||||
this.thirdPayService = thirdPayService;
|
this.thirdPayService = thirdPayService;
|
||||||
|
this.tbCashierCartMapper = tbCashierCartMapper;
|
||||||
|
this.tbOrderDetailMapper = tbOrderDetailMapper;
|
||||||
|
this.tbOrderInfoMapper = tbOrderInfoMapper;
|
||||||
|
this.rabbitMsgUtils = rabbitMsgUtils;
|
||||||
|
this.rabbitTemplate = rabbitTemplate;
|
||||||
|
this.mpShopTableMapper = mpShopTableMapper;
|
||||||
|
this.redisTemplate = redisTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退款
|
* 退款
|
||||||
|
*
|
||||||
* @param shopId 店铺id
|
* @param shopId 店铺id
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -111,6 +142,107 @@ public class PayServiceImpl implements PayService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkPayState(TbOrderInfo orderInfo) {
|
||||||
|
|
||||||
|
if ("paying".equals(orderInfo.getStatus())) {
|
||||||
|
TbOrderPayment payment = mpOrderPaymentMapper.selectOne(new LambdaQueryWrapper<TbOrderPayment>()
|
||||||
|
.eq(TbOrderPayment::getOrderId, orderInfo.getId()));
|
||||||
|
if (ObjectUtil.isNotEmpty(payment) && ObjectUtil.isNotEmpty(payment.getTradeNumber())) {
|
||||||
|
|
||||||
|
TbMerchantThirdApply thirdApply = mpMerchantThirdApplyMapper.selectById(Integer.valueOf(orderInfo.getMerchantId()));
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||||
|
throw new BadRequestException("三方支付信息不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
PublicResp<OrderStatusQueryResp> publicResp = thirdPayService.queryOrder(url, thirdApply.getAppId(),
|
||||||
|
payment.getTradeNumber(), null, thirdApply.getAppToken());
|
||||||
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
||||||
|
if ("000000".equals(publicResp.getCode())) {
|
||||||
|
String cartStatus = "";
|
||||||
|
switch (publicResp.getObjData().getState()) {
|
||||||
|
case "TRADE_SUCCESS":
|
||||||
|
//修改数据库中购物车数据
|
||||||
|
int cartCount = tbCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||||
|
.eq(TbCashierCart::getOrderId, orderInfo.getId())
|
||||||
|
.eq(TbCashierCart::getUseType, orderInfo.getUseType())
|
||||||
|
.in(TbCashierCart::getStatus, "create", "closed")
|
||||||
|
.set(TbCashierCart::getStatus, "final"));
|
||||||
|
log.info("更新购物车:{}", cartCount);
|
||||||
|
|
||||||
|
//更新子单状态
|
||||||
|
tbOrderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>().eq(TbOrderDetail::getId, orderInfo.getId())
|
||||||
|
.eq(TbOrderDetail::getUseType, orderInfo.getUseType())
|
||||||
|
.in(TbOrderDetail::getStatus, "unpaid")
|
||||||
|
.set(TbOrderDetail::getStatus, "closed"));
|
||||||
|
|
||||||
|
//修改主单状态
|
||||||
|
orderInfo.setStatus("closed");
|
||||||
|
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||||
|
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||||
|
orderInfo.setPaidTime(System.currentTimeMillis());
|
||||||
|
tbOrderInfoMapper.updateById(orderInfo);
|
||||||
|
|
||||||
|
|
||||||
|
// 打印消息
|
||||||
|
if (!OrderUseTypeEnum.DINE_IN_AFTER.getValue().equals(orderInfo.getUseType())){
|
||||||
|
List<TbOrderDetail> detailList = tbOrderDetailMapper.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", orderInfo.getId());
|
||||||
|
mqData.put("type", "pc");
|
||||||
|
rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||||
|
|
||||||
|
// 修改台桌状态
|
||||||
|
if (!OrderUseTypeEnum.TAKEOUT.getValue().equals(orderInfo.getUseType())) {
|
||||||
|
TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getShopId, orderInfo.getShopId())
|
||||||
|
.eq(TbShopTable::getQrcode, orderInfo.getTableId()));
|
||||||
|
if (tbShopTable.getAutoClear().equals(1)) {
|
||||||
|
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||||
|
.set(TbShopTable::getEndTime, DateUtil.date())
|
||||||
|
.set(TbShopTable::getUseNum, 0)
|
||||||
|
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||||
|
} else {
|
||||||
|
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||||
|
.set(TbShopTable::getEndTime, DateUtil.date())
|
||||||
|
.set(TbShopTable::getStatus, TableStateEnum.CLEANING.getState()));
|
||||||
|
}
|
||||||
|
|
||||||
|
String day = DateUtils.getDay();
|
||||||
|
String key = "SHOP:CODE:USER:pc" + ":" + orderInfo.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
String currentOrderKey = RedisConstant.CURRENT_TABLE_ORDER + orderInfo.getShopId() + ":" + orderInfo.getTableId();
|
||||||
|
redisTemplate.delete(currentOrderKey);
|
||||||
|
|
||||||
|
// 小程序购物车缓存
|
||||||
|
String tableCartKey = RedisConstant.getTableCartKey(orderInfo.getTableId(), orderInfo.getShopId());
|
||||||
|
redisTemplate.delete(tableCartKey);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
case "REFUND_ING":
|
||||||
|
cartStatus = "refunding";
|
||||||
|
orderInfo.setStatus("refunding");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,6 @@ public class TbPayServiceImpl implements TbPayService {
|
|||||||
throw new BadRequestException("无效码");
|
throw new BadRequestException("无效码");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (merchantId == null) {
|
if (merchantId == null) {
|
||||||
throw new BadRequestException("订单商户id为空");
|
throw new BadRequestException("订单商户id为空");
|
||||||
}
|
}
|
||||||
@@ -280,25 +279,14 @@ public class TbPayServiceImpl implements TbPayService {
|
|||||||
orderPaymentService.updateById(payment);
|
orderPaymentService.updateById(payment);
|
||||||
|
|
||||||
//处理支付成功的订单
|
//处理支付成功的订单
|
||||||
orderInfo.setStatus("closed");
|
orderInfo.setStatus("paying");
|
||||||
orderInfo.setPayOrderNo(mainScanResp.getPayOrderId());
|
orderInfo.setPayOrderNo(mainScanResp.getPayOrderId());
|
||||||
orderInfoMapper.updateById(orderInfo);
|
orderInfoMapper.updateById(orderInfo);
|
||||||
|
|
||||||
//更新购物车状态
|
|
||||||
int cartCount = cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
|
||||||
.eq(TbCashierCart::getOrderId, orderInfo.getId())
|
|
||||||
.set(TbCashierCart::getStatus, "final"));
|
|
||||||
log.info("更新购物车:{}", cartCount);
|
|
||||||
|
|
||||||
//更新子单状态
|
|
||||||
orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
|
||||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
|
||||||
.set(TbOrderDetail::getStatus, "closed"));
|
|
||||||
|
|
||||||
return orderInfo;
|
return orderInfo;
|
||||||
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
||||||
orderInfo.setStatus("paying");
|
orderInfo.setStatus("paying");
|
||||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
orderInfo.setPayOrderNo(mainScanResp.getPayOrderId());
|
||||||
orderInfoMapper.updateById(orderInfo);
|
orderInfoMapper.updateById(orderInfo);
|
||||||
|
|
||||||
payment.setTradeNumber(mainScanResp.getPayOrderId());
|
payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import cn.ysk.cashier.repository.order.TbOrderDetailRepository;
|
|||||||
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
||||||
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
||||||
import cn.ysk.cashier.repository.shop.TbMerchantThirdApplyRepository;
|
import cn.ysk.cashier.repository.shop.TbMerchantThirdApplyRepository;
|
||||||
|
import cn.ysk.cashier.service.PayService;
|
||||||
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
||||||
import cn.ysk.cashier.service.product.TbProductService;
|
import cn.ysk.cashier.service.product.TbProductService;
|
||||||
import cn.ysk.cashier.thirdpay.resp.OrderStatusQueryResp;
|
import cn.ysk.cashier.thirdpay.resp.OrderStatusQueryResp;
|
||||||
@@ -80,6 +81,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||||||
|
|
||||||
private final TbOrderInfoRepository tbOrderInfoRepository;
|
private final TbOrderInfoRepository tbOrderInfoRepository;
|
||||||
private final TbOrderInfoMapper tbOrderInfoMapper;
|
private final TbOrderInfoMapper tbOrderInfoMapper;
|
||||||
|
private final cn.ysk.cashier.mybatis.mapper.TbOrderInfoMapper orderInfoMapper;
|
||||||
|
|
||||||
private final TbOrderDetailRepository tbOrderDetailRepository;
|
private final TbOrderDetailRepository tbOrderDetailRepository;
|
||||||
private final TbShopPayTypeRepository payTypeRepository;
|
private final TbShopPayTypeRepository payTypeRepository;
|
||||||
@@ -100,6 +102,8 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||||||
private final RabbitMsgUtils rabbitMsgUtils;
|
private final RabbitMsgUtils rabbitMsgUtils;
|
||||||
private final TbCashierCartMapper tbCashierCartMapper;
|
private final TbCashierCartMapper tbCashierCartMapper;
|
||||||
|
|
||||||
|
private final PayService payService;
|
||||||
|
|
||||||
@Value("${thirdPay.url}")
|
@Value("${thirdPay.url}")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
@@ -580,8 +584,17 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void successPay(Map<String, String> req) {
|
public void successPay(Map<String, String> req) {
|
||||||
if ("000000".equals(req.get("code"))) {
|
JSONObject bizData = JSONObject.parseObject(req.get("bizData"));
|
||||||
|
if ("000000".equals(req.get("code")) &&
|
||||||
|
"TRADE_SUCCESS".equals(bizData.getString("state"))) {
|
||||||
|
String payOrderId = bizData.get("payOrderId").toString();
|
||||||
|
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
|
||||||
|
.eq(TbOrderInfo::getPayOrderNo, payOrderId));
|
||||||
|
if (orderInfo == null) {
|
||||||
|
log.warn("订单信息不存在: {}", payOrderId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
payService.checkPayState(orderInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1498,6 +1498,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
|
|
||||||
BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.HALF_UP);
|
BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
boolean isOnline = false;
|
||||||
|
|
||||||
switch (payDTO.getPayType()) {
|
switch (payDTO.getPayType()) {
|
||||||
case "vipPay":
|
case "vipPay":
|
||||||
if (payDTO.getVipUserId() != null) {
|
if (payDTO.getVipUserId() != null) {
|
||||||
@@ -1514,6 +1516,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
// orderInfo = tbPayServiceImpl.cashPay(payDTO);
|
// orderInfo = tbPayServiceImpl.cashPay(payDTO);
|
||||||
break;
|
break;
|
||||||
case "scanCode":
|
case "scanCode":
|
||||||
|
isOnline = true;
|
||||||
orderInfo = tbPayServiceImpl.scanPay(payDTO.getShopId(), payDTO.getCode(), Integer.valueOf(orderInfo.getMerchantId()),
|
orderInfo = tbPayServiceImpl.scanPay(payDTO.getShopId(), payDTO.getCode(), Integer.valueOf(orderInfo.getMerchantId()),
|
||||||
StrUtil.isNotBlank(orderInfo.getMemberId()) ? Integer.valueOf(orderInfo.getMemberId()) : null, finalAmount, orderInfo);
|
StrUtil.isNotBlank(orderInfo.getMemberId()) ? Integer.valueOf(orderInfo.getMemberId()) : null, finalAmount, orderInfo);
|
||||||
break;
|
break;
|
||||||
@@ -1524,78 +1527,85 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
throw new BadRequestException("未知支付方式");
|
throw new BadRequestException("未知支付方式");
|
||||||
}
|
}
|
||||||
|
|
||||||
orderInfo.setPayAmount(finalAmount);
|
if (!isOnline) {
|
||||||
orderInfo.setStatus("closed");
|
orderInfo.setPayAmount(finalAmount);
|
||||||
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
|
orderInfo.setStatus("closed");
|
||||||
orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(finalAmount));
|
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
|
||||||
orderInfoMapper.updateById(orderInfo);
|
orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(finalAmount));
|
||||||
|
orderInfoMapper.updateById(orderInfo);
|
||||||
|
|
||||||
//更新购物车状态
|
//更新购物车状态
|
||||||
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
//修改数据库中购物车数据
|
||||||
.eq(TbCashierCart::getOrderId, orderInfo.getId())
|
int cartCount = tbCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||||
.set(TbCashierCart::getStatus, "final"));
|
.eq(TbCashierCart::getOrderId, orderInfo.getId())
|
||||||
|
.eq(TbCashierCart::getUseType, orderInfo.getUseType())
|
||||||
|
.in(TbCashierCart::getStatus, "create", "closed")
|
||||||
|
.set(TbCashierCart::getStatus, "final"));
|
||||||
|
log.info("更新购物车:{}", cartCount);
|
||||||
|
|
||||||
orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
//更新子单状态
|
||||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
tbOrderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>().eq(TbOrderDetail::getId, orderInfo.getId())
|
||||||
.set(TbOrderDetail::getStatus, "closed"));
|
.eq(TbOrderDetail::getUseType, orderInfo.getUseType())
|
||||||
|
.in(TbOrderDetail::getStatus, "unpaid")
|
||||||
|
.set(TbOrderDetail::getStatus, "closed"));
|
||||||
|
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("token", null);
|
||||||
|
jsonObject.put("type", "create");
|
||||||
|
jsonObject.put("orderId", orderInfo.getId());
|
||||||
|
rabbitMsgUtils.sendOrderCollectMsg(jsonObject);
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
// 打印消息
|
||||||
jsonObject.put("token", null);
|
if (!shopEatTypeInfoDTO.isDineInAfter()) {
|
||||||
jsonObject.put("type", "create");
|
List<TbOrderDetail> detailList = orderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||||
jsonObject.put("orderId", orderInfo.getId());
|
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||||
|
.eq(TbOrderDetail::getStatus, "closed"));
|
||||||
// 打印消息
|
rabbitMsgUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
|
||||||
if (!shopEatTypeInfoDTO.isDineInAfter()) {
|
|
||||||
List<TbOrderDetail> detailList = orderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
|
||||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
|
||||||
.eq(TbOrderDetail::getStatus, "closed"));
|
|
||||||
rabbitMsgUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
|
|
||||||
}
|
|
||||||
rabbitMsgUtils.sendOrderCollectMsg(jsonObject);
|
|
||||||
rabbitMsgUtils.printPlaceTicket(orderInfo.getId(), false);
|
|
||||||
|
|
||||||
// 发送库存记录mq消息
|
|
||||||
JSONObject mqData = new JSONObject();
|
|
||||||
mqData.put("orderId", payDTO.getOrderId());
|
|
||||||
mqData.put("type", "pc");
|
|
||||||
rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
|
||||||
|
|
||||||
// 修改台桌状态
|
|
||||||
if (!shopEatTypeInfoDTO.isTakeout()) {
|
|
||||||
TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
|
||||||
.eq(TbShopTable::getShopId, payDTO.getShopId())
|
|
||||||
.eq(TbShopTable::getQrcode, orderInfo.getTableId()));
|
|
||||||
if (tbShopTable.getAutoClear().equals(1)) {
|
|
||||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
|
||||||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
|
||||||
.set(TbShopTable::getEndTime, DateUtil.date())
|
|
||||||
.set(TbShopTable::getUseNum, 0)
|
|
||||||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
|
||||||
} else {
|
|
||||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
|
||||||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
|
||||||
.set(TbShopTable::getEndTime, DateUtil.date())
|
|
||||||
.set(TbShopTable::getStatus, TableStateEnum.CLEANING.getState()));
|
|
||||||
}
|
}
|
||||||
|
rabbitMsgUtils.printPlaceTicket(orderInfo.getId(), false);
|
||||||
|
|
||||||
|
// 发送库存记录mq消息
|
||||||
|
JSONObject mqData = new JSONObject();
|
||||||
|
mqData.put("orderId", payDTO.getOrderId());
|
||||||
|
mqData.put("type", "pc");
|
||||||
|
rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||||
|
|
||||||
|
// 修改台桌状态
|
||||||
|
if (!shopEatTypeInfoDTO.isTakeout()) {
|
||||||
|
TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getShopId, payDTO.getShopId())
|
||||||
|
.eq(TbShopTable::getQrcode, orderInfo.getTableId()));
|
||||||
|
if (tbShopTable.getAutoClear().equals(1)) {
|
||||||
|
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||||
|
.set(TbShopTable::getEndTime, DateUtil.date())
|
||||||
|
.set(TbShopTable::getUseNum, 0)
|
||||||
|
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||||
|
} else {
|
||||||
|
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||||
|
.set(TbShopTable::getEndTime, DateUtil.date())
|
||||||
|
.set(TbShopTable::getStatus, TableStateEnum.CLEANING.getState()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!shopEatTypeInfoDTO.isTakeout()) {
|
||||||
|
String day = DateUtils.getDay();
|
||||||
|
String key = "SHOP:CODE:USER:pc" + ":" + payDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String currentOrderKey = RedisConstant.CURRENT_TABLE_ORDER + payDTO.getShopId() + ":" + orderInfo.getTableId();
|
||||||
|
redisTemplate.delete(currentOrderKey);
|
||||||
|
|
||||||
|
// 小程序购物车缓存
|
||||||
|
String tableCartKey = RedisConstant.getTableCartKey(orderInfo.getTableId(), orderInfo.getShopId());
|
||||||
|
redisTemplate.delete(tableCartKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "success";
|
||||||
if (!shopEatTypeInfoDTO.isTakeout()) {
|
|
||||||
String day = DateUtils.getDay();
|
|
||||||
String key = "SHOP:CODE:USER:pc" + ":" + payDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
|
||||||
redisTemplate.delete(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String currentOrderKey = RedisConstant.CURRENT_TABLE_ORDER + payDTO.getShopId() + ":" + orderInfo.getTableId();
|
|
||||||
redisTemplate.delete(currentOrderKey);
|
|
||||||
|
|
||||||
// 小程序购物车缓存
|
|
||||||
String tableCartKey = RedisConstant.getTableCartKey(orderInfo.getTableId(), orderInfo.getShopId());
|
|
||||||
redisTemplate.delete(tableCartKey);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}, stringRedisTemplate, RedisConstant.getLockKey("", payDTO.getShopId(), payDTO.getOrderId()));
|
}, stringRedisTemplate, RedisConstant.getLockKey("", payDTO.getShopId(), payDTO.getOrderId()));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user