支付记录 状态

This commit is contained in:
2025-11-19 14:02:32 +08:00
parent 8d365b302a
commit 7aa1e4f215
3 changed files with 28 additions and 59 deletions

View File

@@ -2,30 +2,24 @@ package com.czg.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.CzgPayUtils;
import com.czg.entity.CzgBaseRespParams;
import com.czg.market.service.MkDistributionUserService;
import com.czg.market.service.TbMemberConfigService;
import com.czg.mq.PrintMqListener;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.order.service.ShopTableOrderStatisticService;
import com.czg.service.market.service.impl.AppWxServiceImpl;
import com.czg.service.market.service.impl.WxServiceImpl;
import com.czg.task.StatisticTask;
import com.czg.utils.AssertUtil;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
/**
* 回调
@@ -41,32 +35,12 @@ public class NotifyController {
@Resource
private OrderInfoService orderInfoService;
@Resource
private StatisticTask statisticTask;
@Resource
private ShopTableOrderStatisticService shopTableOrderStatisticService;
@Resource
private AppWxServiceImpl wxService;
@Resource
private WxServiceImpl wxService2;
@Resource
private MkDistributionUserService distributionUserService;
@Resource
private OrderPaymentService paymentService;
@Resource
private TbMemberConfigService memberConfigService;
@GetMapping("testOpen")
public JSONObject test1(String code) throws Exception {
JSONObject czg = JSONObject.parseObject("{\"amount\":10,\"cashFee\":0,\"channelSendNo\":\"20251113110113130266202235210653\",\"channelTradeNo\":\"4200002932202511131794511090\",\"currency\":\"cny\",\"drType\":\"00\",\"ifCode\":\"lklspay\",\"mchOrderNo\":\"WX1988788559919120384\",\"mercNo\":\"B251107293903\",\"msgType\":\"sft.trade.notify\",\"note\":\"成功\",\"payOrderId\":\"2025111319887885609440501775VT\",\"payTime\":\"2025-11-13 09:58:44\",\"payType\":\"WECHAT\",\"refundAmt\":0,\"refundState\":0,\"settlementType\":\"D1\",\"state\":\"TRADE_SUCCESS\",\"storeId\":\"S2511077140\",\"subject\":\"万维时光的店铺\",\"tradeFee\":0,\"userId\":\"oVxsc1QNZRRsWdWDmTdwPJGT9BWc\"}");
AssertUtil.isNull(czg, "支付回调数据为空");
log.info("支付回调数据为:{}", czg);
orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg, 0);
return null;
}
@RequestMapping("/payCallBack")
@@ -92,7 +66,7 @@ public class NotifyController {
}catch (Exception e) {
log.warn("转账回调失败", e);
}
return "SUCCESS";
return SUCCESS;
}
@@ -116,21 +90,22 @@ public class NotifyController {
String outTradeNo = plainTextJson.getString("out_trade_no");
String tradeState = plainTextJson.getString("trade_state");
String transactionId = plainTextJson.getString("transaction_id");
OrderPayment payment = paymentService.getOne(new QueryWrapper().eq(OrderPayment::getOrderNo, outTradeNo));
payment.setPayStatus("fail");
if ("SUCCESS".equals(tradeState)) {
try {
OrderPayment payment = paymentService.getOne(new QueryWrapper().eq(OrderPayment::getOrderNo, outTradeNo));
payment.setTradeNumber(transactionId);
payment.setPayTime(DateUtil.date().toLocalDateTime());
payment.setRespJson(plainTextJson.toJSONString());
paymentService.updateById(payment);
payment.setPayStatus("success");
distributionUserService.rechargeCallBack(payment.getShopId(), payment.getAmount(), payment.getId());
}catch (Exception e) {
log.error("充值回调失败", e);
return "SUCCESS";
}
}
return "SUCCESS";
paymentService.updateById(payment);
return SUCCESS;
}
@@ -142,21 +117,4 @@ public class NotifyController {
orderInfoService.refundCallBackOrder(czg.getString("mchOrderNo"), czg);
return SUCCESS;
}
@Resource
private PrintMqListener printMqListener;
@RequestMapping("/test")
public void test(@RequestParam String id) {
shopTableOrderStatisticService.statistic(DateUtil.date());
}
@GetMapping("/anew/statistic/history/data")
public String statistic(@RequestParam String now) {
String format = DateUtil.format(new Date(), "yyyyMMddHHmm");
if (format.equals(now)) {
ThreadUtil.execAsync(() -> statisticTask.statisticHistoryData());
}
return SUCCESS;
}
}

View File

@@ -89,6 +89,10 @@ public class OrderPayment implements Serializable {
* 支付相应结果 json
*/
private String respJson;
/**
* 支付状态success, fail, init
*/
private String payStatus;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@@ -107,6 +111,7 @@ public class OrderPayment implements Serializable {
this.orderNo = orderNo;
this.authCode = authCode;
this.amount = amount;
this.payStatus = "init";
}
public OrderPayment(@NonNull Long shopId,@NonNull Long sourceId, @NotBlank String payType, @NotBlank String orderNo,
@@ -118,5 +123,6 @@ public class OrderPayment implements Serializable {
this.authCode = authCode;
this.amount = amount;
this.relatedId = relatedId;
this.payStatus = "init";
}
}

View File

@@ -1037,9 +1037,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
payment.setTradeNumber(czgCallBackDto.getPayOrderId());
payment.setRespJson(resultJson.toString());
paymentService.updateById(payment);
payment.setPayStatus("fail");
if ("TRADE_SUCCESS".equals(czgCallBackDto.getState())) {
payment.setPayStatus("success");
if ("order".equals(payment.getPayType())) {
OrderInfo orderInfo = getById(payment.getSourceId());
if (orderInfo == null) {
@@ -1154,6 +1154,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
// distributionUserService.distribute(payment.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), payment.getShopId(), "recharge");
// }
} else if ("memberPay".equals(payment.getPayType())) {
//购买会员
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
memberConfigService.joinMember(payment.getShopId(), shopUser.getUserId(), payment.getRelatedId());
// 充值赠送积分
@@ -1164,6 +1165,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
distributionUserService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId());
}
}
paymentService.updateById(payment);
}
@Override
@@ -1174,13 +1176,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
log.info("订单处理过payment id{}", payment.getId());
return;
}
paymentService.updateChain()
.set(OrderPayment::getTradeNumber, czgCallBackDto.getRefundOrderId())
.set(OrderPayment::getRespJson, resultJson.toString())
.set(OrderPayment::getPayTime, czgCallBackDto.getRefundTime())
.where(OrderPayment::getId).eq(payment.getId())
.update();
payment.setPayStatus("success");
if (!"SUCCESS".equals(czgCallBackDto.getState())) {
payment.setPayStatus("fail");
if ("refund".equals(payment.getPayType())) {
//TODO 订单退款失败 暂不考虑回滚 填充退款原因
updateChain()
@@ -1195,6 +1193,13 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
.eq(ShopUserFlow::getId, payment.getSourceId()).update();
}
}
paymentService.updateChain()
.set(OrderPayment::getTradeNumber, czgCallBackDto.getRefundOrderId())
.set(OrderPayment::getRespJson, resultJson.toString())
.set(OrderPayment::getPayTime, czgCallBackDto.getRefundTime())
.set(OrderPayment::getPayStatus, payment.getPayStatus())
.where(OrderPayment::getId).eq(payment.getId())
.update();
}