| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; |
| | | import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.config.C3mRedisConfig; |
| | | import com.sandu.ximon.admin.pay.OrderStatusEnums; |
| | | import com.sandu.ximon.admin.pay.wx.WxFastPayService; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.security.order.OrderQueryListener; |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author liuhaonan |
| | |
| | | ); |
| | | // 推送到自动查询模块,进行扫描启动 |
| | | orderQueryListener.startScan(OrderScanType.C3M.getType()); |
| | | if(b){ |
| | | save(c3mOrderEntity); |
| | | } |
| | | return b ? c3mOrderEntity : null; |
| | | } |
| | | |
| | | /** |
| | | * 微信支付回调 |
| | | */ |
| | | public Object payWechatNotify(String xmlData) { |
| | | WxPayOrderNotifyResult wxPayOrderNotifyResult = fastPayService.parseOrderNotifyResult(xmlData); |
| | | String orderSn = wxPayOrderNotifyResult.getOutTradeNo(); |
| | | String transactionId = wxPayOrderNotifyResult.getOutTradeNo(); |
| | | C3mOrder userOrder = getByOrderSn(orderSn); |
| | | if (userOrder == null) { |
| | | return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn); |
| | | } |
| | | |
| | | // 检查这个订单是否已经处理过 |
| | | if (!OrderStatusEnums.UNPAID.getCode().equals(userOrder.getOrderStatus())) { |
| | | return WxPayNotifyResponse.success("订单已经处理成功!"); |
| | | } |
| | | userOrder.setOutTradeNo(transactionId); |
| | | userOrder.setPayTimestamp(new Date().getTime()); |
| | | userOrder.setOrderStatus(OrderStatusEnums.PAID.getCode()); |
| | | if (!updateById(userOrder)) { |
| | | return WxPayNotifyResponse.fail("更新数据已失效"); |
| | | } |
| | | |
| | | // UserPayRecord userPayRecord = new UserPayRecord(); |
| | | // userPayRecord.setOrderId(userOrder.getId()); |
| | | // userPayRecord.setPayAmount(userOrder.getTotalPrice()); |
| | | // userPayRecord.setPayType(PayTypeEnums.WECHAT.getCode()); |
| | | // userPayRecord.setPayDate(userOrder.getPayTime()); |
| | | // userPayRecord.setUserId(userOrder.getUserId()); |
| | | // userPayRecordService.save(userPayRecord); |
| | | |
| | | return WxPayNotifyResponse.success("更新数据成功"); |
| | | } |
| | | |
| | | |
| | | public C3mOrder getByOrderSn(String orderSn) { |
| | | LambdaQueryWrapper<C3mOrder> wrapper = Wrappers.lambdaQuery(C3mOrder.class).eq(C3mOrder::getOutTradeNo, orderSn).last("limit 1"); |
| | | return getOne(wrapper); |
| | | } |
| | | |
| | | } |