支付 回调 处理 以及 订单状态 修改
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.czg.service.order.enums;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 订单状态枚举类
|
||||
*/
|
||||
@Getter
|
||||
public enum OrderStatusEnums {
|
||||
|
||||
|
||||
UNPAID("unpaid", "待支付"),
|
||||
IN_PRODUCTION("in_production", "制作中"),
|
||||
WAIT_OUT("wait_out", "待取餐"),
|
||||
DONE("done", "订单完成"),
|
||||
REFUNDING("refunding", "申请退单"),
|
||||
REFUND("refund", "退单"),
|
||||
PART_REFUND("part_refund", "部分退单"),
|
||||
CANCELLED("cancelled", "取消订单");
|
||||
|
||||
|
||||
private final String code;
|
||||
private final String msg;
|
||||
|
||||
OrderStatusEnums(String code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
|
||||
/**
|
||||
* 支付详情 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-15
|
||||
*/
|
||||
public interface OrderPaymentMapper extends BaseMapper<OrderPayment> {
|
||||
|
||||
}
|
||||
@@ -61,19 +61,4 @@ public interface PayService {
|
||||
* @param refundOrderId 平台退款订单号 二选一
|
||||
*/
|
||||
CzgResult<CzgRefundResp> queryRefund(Long shopId, String mchRefundNo, String refundOrderId);
|
||||
|
||||
|
||||
/**
|
||||
* 支付回调数据处理
|
||||
*
|
||||
* @param dataJsonStr 带解析数据
|
||||
*/
|
||||
CzgPayNotifyDTO getPayNotifyData(String dataJsonStr);
|
||||
|
||||
/**
|
||||
* 退款回调数据处理
|
||||
*
|
||||
* @param dataJsonStr 带解析数据
|
||||
*/
|
||||
CzgRefundNotifyDTO getRefundNotifyData(String dataJsonStr);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.entity.notify.CzgPayNotifyDTO;
|
||||
import com.czg.order.dto.OrderInfoQueryDTO;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.order.vo.OrderDetailSmallVO;
|
||||
import com.czg.order.vo.OrderInfoVo;
|
||||
import com.czg.service.order.enums.OrderStatusEnums;
|
||||
import com.czg.service.order.mapper.OrderInfoMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.service.order.mapper.OrderInfoMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -30,6 +38,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
@Resource
|
||||
private OrderDetailService orderDetailService;
|
||||
|
||||
@Resource
|
||||
private OrderPaymentService paymentService;
|
||||
|
||||
@Override
|
||||
public Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param) {
|
||||
String productName = param.getProductName();
|
||||
@@ -59,4 +70,34 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
});
|
||||
return orderInfoVoPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void payCallBackOrder(@NotBlank String orderNo, @NotBlank JSONObject resultJson) {
|
||||
CzgPayNotifyDTO czgCallBackDto = JSONObject.parseObject(resultJson.toString(), CzgPayNotifyDTO.class);
|
||||
OrderPayment payment = paymentService.queryChain().eq(OrderPayment::getOrderNo, orderNo).one();
|
||||
paymentService.updateChain().of(OrderPayment.class)
|
||||
.set(OrderPayment::getTradeNumber, czgCallBackDto.getPayOrderId())
|
||||
.set(OrderPayment::getRespJson, resultJson.toString())
|
||||
.where(OrderPayment::getId).eq(payment.getId())
|
||||
.update();
|
||||
|
||||
if ("TRADE_SUCCESS" .equals(czgCallBackDto.getState())) {
|
||||
if ("order" .equals(payment.getPayType())) {
|
||||
updateChain().of(OrderInfo.class)
|
||||
.set(OrderInfo::getPayAmount, new BigDecimal(czgCallBackDto.getAmount() / 100L))
|
||||
.set(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())
|
||||
.where(OrderInfo::getId).eq(payment.getSourceId())
|
||||
.update();
|
||||
//发送打票信息
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refundCallBackOrder() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.service.order.mapper.OrderPaymentMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 支付详情 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-15
|
||||
*/
|
||||
@Service
|
||||
public class OrderPaymentServiceImpl extends ServiceImpl<OrderPaymentMapper, OrderPayment> implements OrderPaymentService{
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.czg.account.entity.ShopMerchant;
|
||||
import com.czg.account.service.ShopMerchantService;
|
||||
import com.czg.entity.notify.CzgPayNotifyDTO;
|
||||
@@ -7,7 +8,9 @@ import com.czg.entity.notify.CzgRefundNotifyDTO;
|
||||
import com.czg.entity.req.*;
|
||||
import com.czg.entity.resp.*;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.CzgPayService;
|
||||
import com.czg.service.order.dto.OrderPayParamDTO;
|
||||
@@ -37,6 +40,8 @@ public class PayServiceImpl implements PayService {
|
||||
private CzgPayService czgPayService;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private OrderPaymentService paymentService;
|
||||
|
||||
private final BigDecimal MONEY_RATE = new BigDecimal("100");
|
||||
private final String payJsonExtParam = "{\"payType\":\"1\"}";
|
||||
@@ -46,7 +51,9 @@ public class PayServiceImpl implements PayService {
|
||||
public CzgResult<CzgH5PayResp> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
return h5Pay(payParam.getShopId(), new CzgH5PayReq(orderInfo.getOrderNo(), orderInfo.getPayAmount().multiply(MONEY_RATE).longValue(),
|
||||
String payOrderNO = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNO, "", orderInfo.getOrderAmount()));
|
||||
return h5Pay(payParam.getShopId(), new CzgH5PayReq(payOrderNO, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), payJsonExtParam));
|
||||
}
|
||||
|
||||
@@ -55,7 +62,9 @@ public class PayServiceImpl implements PayService {
|
||||
public CzgResult<CzgJsPayResp> jsPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(orderInfo.getOrderNo(), orderInfo.getPayAmount().multiply(MONEY_RATE).longValue(),
|
||||
String payOrderNO = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNO, "", orderInfo.getOrderAmount()));
|
||||
return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNO, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), payJsonExtParam));
|
||||
}
|
||||
|
||||
@@ -63,7 +72,9 @@ public class PayServiceImpl implements PayService {
|
||||
public CzgResult<CzgLtPayResp> ltPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(orderInfo.getOrderNo(), orderInfo.getPayAmount().multiply(MONEY_RATE).longValue(),
|
||||
String payOrderNO = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNO, "", orderInfo.getOrderAmount()));
|
||||
return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNO, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), payJsonExtParam));
|
||||
}
|
||||
|
||||
@@ -71,7 +82,9 @@ public class PayServiceImpl implements PayService {
|
||||
public CzgResult<CzgScanPayResp> scanPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
return scanPay(payParam.getShopId(), new CzgScanPayReq(orderInfo.getOrderNo(), orderInfo.getPayAmount().multiply(MONEY_RATE).longValue(),
|
||||
String payOrderNO = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNO, "", orderInfo.getOrderAmount()));
|
||||
return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNO, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), payJsonExtParam));
|
||||
}
|
||||
|
||||
@@ -79,7 +92,9 @@ public class PayServiceImpl implements PayService {
|
||||
public CzgResult<CzgMicroPayResp> microPayOrder(OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
return microPay(payParam.getShopId(), new CzgMicroPayReq(orderInfo.getOrderNo(), orderInfo.getPayAmount().multiply(MONEY_RATE).longValue(),
|
||||
String payOrderNO = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNO, payParam.getAuthCode(), orderInfo.getOrderAmount()));
|
||||
return microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNO, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getAuthCode(), payParam.getBuyerRemark(), payJsonExtParam));
|
||||
}
|
||||
|
||||
@@ -104,14 +119,9 @@ public class PayServiceImpl implements PayService {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CzgPayNotifyDTO getPayNotifyData(String dataJsonStr) {
|
||||
return czgPayService.getPayNotifyData(dataJsonStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgRefundNotifyDTO getRefundNotifyData(String dataJsonStr) {
|
||||
return czgPayService.getRefundNotifyData(dataJsonStr);
|
||||
private void initOrderPayment(OrderPayment payment) {
|
||||
paymentService.save(payment);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.order.mapper.OrderPaymentMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -84,18 +84,4 @@ public interface CzgPayService {
|
||||
String mchRefundNo, String refundOrderId);
|
||||
|
||||
|
||||
/**
|
||||
* 支付回调数据处理
|
||||
*
|
||||
* @param dataJsonStr 带解析数据
|
||||
*/
|
||||
CzgPayNotifyDTO getPayNotifyData(String dataJsonStr);
|
||||
|
||||
/**
|
||||
* 退款回调数据处理
|
||||
*
|
||||
* @param dataJsonStr 带解析数据
|
||||
*/
|
||||
CzgRefundNotifyDTO getRefundNotifyData(String dataJsonStr);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,17 +60,7 @@ public class CzgPayServiceImpl implements CzgPayService {
|
||||
|
||||
@Override
|
||||
public CzgResult<CzgRefundResp> queryRefundOrder(@NonNull String appId, @NonNull String appSecret, String mchRefundNo, String refundOrderId) {
|
||||
return CzgPayUtils.queryRefundOrder(sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_DOMAIN.getCode()), appId, appSecret, mchRefundNo,refundOrderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgPayNotifyDTO getPayNotifyData(String dataJsonStr) {
|
||||
return CzgPayUtils.getCzg(dataJsonStr,CzgPayNotifyDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgRefundNotifyDTO getRefundNotifyData(String dataJsonStr) {
|
||||
return CzgPayUtils.getCzg(dataJsonStr,CzgRefundNotifyDTO.class);
|
||||
return CzgPayUtils.queryRefundOrder(sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_DOMAIN.getCode()), appId, appSecret, mchRefundNo, refundOrderId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user