package com.ruoyi.other.controller;
|
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.web.page.PageInfo;
|
import com.ruoyi.common.security.service.TokenService;
|
import com.ruoyi.other.api.domain.IntegralPay;
|
import com.ruoyi.other.api.domain.IntegralRecord;
|
import com.ruoyi.other.api.domain.ServicePay;
|
import com.ruoyi.other.query.ServiceListQuery;
|
import com.ruoyi.other.service.TIntegralPayService;
|
import com.ruoyi.other.service.TIntegralRecordService;
|
import com.ruoyi.other.service.TIntegralRuleService;
|
import com.ruoyi.other.service.TServicePayService;
|
import com.ruoyi.other.util.UUIDUtil;
|
import com.ruoyi.other.util.payment.wx.PayResult;
|
import com.ruoyi.other.util.payment.wx.WechatPayService;
|
import com.ruoyi.other.vo.ServiceListVO;
|
import com.ruoyi.other.vo.ServiceVO;
|
import com.ruoyi.system.api.domain.SysUser;
|
import com.ruoyi.system.api.feignClient.SysUserClient;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.io.PrintWriter;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDateTime;
|
import java.util.Date;
|
import java.util.Map;
|
|
/**
|
* <p>
|
* 微信回调
|
* </p>
|
*
|
* @author 无关风月
|
* @since 2024-08-06
|
*/
|
@RestController
|
@RequestMapping("/wx")
|
public class WXCallBackController {
|
|
@Autowired
|
private TIntegralRuleService integralRuleService;
|
@Autowired
|
private TIntegralRecordService integralRecordService;
|
@Autowired
|
private TIntegralPayService integralPayService;
|
|
@Autowired
|
private TokenService tokenService;
|
@Resource
|
private SysUserClient sysUserClient;
|
@Resource
|
private WechatPayService wechatPayService;
|
@Resource
|
private TServicePayService servicePayService;
|
|
@ResponseBody
|
@PostMapping("/integralCallback")
|
public R integralCallback(HttpServletRequest request, String r2_OrderNo) {
|
// System.err.println("积分充值回调");
|
// PayResult payResult= null;
|
// try {
|
// payResult = wechatPayService.processNotify(request);
|
// } catch (Exception e) {
|
// throw new RuntimeException(e);
|
// }
|
System.err.println("======积分充值回调");
|
System.err.println("======积分充值回调单号" + r2_OrderNo);
|
System.err.println("请求" + request.getParameterMap());
|
Map<String, String[]> parameterMap = request.getParameterMap();
|
String r6Status = request.getParameter("r6_Status");
|
if (org.springframework.util.StringUtils.hasLength(r6Status)) {
|
if (r6Status.equals("101")) {
|
return R.fail("支付失败");
|
}
|
}
|
// 循环打印
|
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
String key = entry.getKey();
|
String[] values = entry.getValue();
|
for (String value : values) {
|
System.err.println("======回调开始" + key + ":" + value);
|
}
|
}
|
IntegralPay integralPay = integralPayService.lambdaQuery().eq(IntegralPay::getCode, r2_OrderNo).one();
|
if (integralPay != null && integralPay.getPayStatus() == 1) {
|
SysUser data = sysUserClient.getSysUser(integralPay.getUserId()).getData();
|
integralPay.setPayStatus(2);
|
integralPay.setPayTime(LocalDateTime.now());
|
// integralPay.setOrderNumber(payResult.getTransactionId());
|
integralPayService.updateById(integralPay);
|
IntegralRecord integralRecord = new IntegralRecord();
|
integralRecord.setPayId(integralPay.getId());
|
integralRecord.setSiteId(data.getSiteId());
|
integralRecord.setAppUserId(integralPay.getUserId());
|
integralRecord.setIntegralType(1);
|
integralRecord.setIntegralCount(integralPay.getIntegralCount());
|
integralRecord.setDelFlag(0);
|
integralRecord.setCreateTime(LocalDateTime.now());
|
integralRecordService.save(integralRecord);
|
data.setIntegral(data.getIntegral() + integralPay.getIntegralCount());
|
sysUserClient.updateSysUser(data);
|
return R.ok(null, "success");
|
}
|
return R.ok(null, "error");
|
|
}
|
|
@ResponseBody
|
@PostMapping("/serviceCallback")
|
public void serviceCallback(HttpServletRequest request, HttpServletResponse response) {
|
System.err.println("服务费缴纳回调");
|
PayResult payResult = null;
|
try {
|
payResult = wechatPayService.processNotify(request);
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
ServicePay servicePay = servicePayService.lambdaQuery().eq(ServicePay::getCode, payResult.getOrderNumber()).one();
|
if (servicePay != null && servicePay.getPayStatus() == 1) {
|
servicePay.setPayStatus(2);
|
ServicePay servicePayBefore = servicePayService.lambdaQuery()
|
.eq(ServicePay::getUserId, servicePay.getUserId())
|
.eq(ServicePay::getPayStatus, 2)
|
.orderByDesc(ServicePay::getCreateTime)
|
.last("limit 1")
|
.one();
|
if (servicePayBefore != null) {
|
servicePay.setEndTime(servicePayBefore.getEndTime().plusDays(365));
|
} else {
|
servicePay.setEndTime(LocalDateTime.now().plusDays(365));
|
|
}
|
|
servicePay.setPayType(1);
|
servicePay.setPayTime(LocalDateTime.now());
|
servicePay.setOrderNumber(payResult.getTransactionId());
|
servicePayService.updateById(servicePay);
|
}
|
response.setStatus(200);
|
PrintWriter out = null;
|
try {
|
out = response.getWriter();
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
out.println("success");
|
out.flush();
|
out.close();
|
}
|
|
|
}
|