支付相关
This commit is contained in:
@@ -20,6 +20,7 @@ CREATE TABLE `pay_order`
|
|||||||
`payTypeValue` varchar(500) DEFAULT NULL COMMENT '支付方式Value',
|
`payTypeValue` varchar(500) DEFAULT NULL COMMENT '支付方式Value',
|
||||||
`payType` varchar(500) DEFAULT NULL COMMENT '支付方式key',
|
`payType` varchar(500) DEFAULT NULL COMMENT '支付方式key',
|
||||||
`timeRemarks` int(64) DEFAULT NULL COMMENT '过期时间设置(以分钟为准,例如5分钟,则为5)',
|
`timeRemarks` int(64) DEFAULT NULL COMMENT '过期时间设置(以分钟为准,例如5分钟,则为5)',
|
||||||
|
`returnUrl` varchar(500) DEFAULT NULL COMMENT '业务的回调地址',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `id` (`id`)
|
KEY `id` (`id`)
|
||||||
) ENGINE = InnoDB
|
) ENGINE = InnoDB
|
||||||
@@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dimengzhe
|
* @author dimengzhe
|
||||||
@@ -15,6 +16,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||||||
})
|
})
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@EnableFeignClients(basePackages = {})
|
@EnableFeignClients(basePackages = {})
|
||||||
|
@EnableScheduling
|
||||||
public class PayApplication {
|
public class PayApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -20,4 +20,6 @@ public class PayOrderVo {
|
|||||||
private String price;
|
private String price;
|
||||||
@ApiModelProperty("商品名称")
|
@ApiModelProperty("商品名称")
|
||||||
private String goods;
|
private String goods;
|
||||||
|
@ApiModelProperty("设置的过期时间的值:以分钟为单位")
|
||||||
|
private int timeRemarks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
import com.yxt.pay.api.order.PayOrder;
|
import com.yxt.pay.api.order.PayOrder;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description:
|
* @description:
|
||||||
* @author: dimengzhe
|
* @author: dimengzhe
|
||||||
@@ -12,4 +14,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface OrderMapper extends BaseMapper<PayOrder> {
|
public interface OrderMapper extends BaseMapper<PayOrder> {
|
||||||
PayOrder selectBySn(String out_trade_no);
|
PayOrder selectBySn(String out_trade_no);
|
||||||
|
|
||||||
|
List<PayOrder> selectOrderList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,10 @@
|
|||||||
from pay_order
|
from pay_order
|
||||||
where outTradeNo = #{out_trade_no}
|
where outTradeNo = #{out_trade_no}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectOrderList" resultType="com.yxt.pay.api.order.PayOrder">
|
||||||
|
select *
|
||||||
|
from pay_order
|
||||||
|
where state = 1
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -42,7 +42,7 @@ public class OrderRest extends ApiBaseAction {
|
|||||||
return orderService.pay(query, getClientIp());
|
return orderService.pay(query, getClientIp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("wxPayNotify")
|
@PostMapping("/wxPayNotify")
|
||||||
ResultBean wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
ResultBean wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
return orderService.wxPayNotify(request, response);
|
return orderService.wxPayNotify(request, response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,17 @@ import com.yxt.pay.utils.applet.WechatRefundApiResult;
|
|||||||
import com.yxt.pay.utils.applet.WechatUtil;
|
import com.yxt.pay.utils.applet.WechatUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import javax.servlet.ServletInputStream;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +56,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
payOrderVo.setMainSid(order.getSid());
|
payOrderVo.setMainSid(order.getSid());
|
||||||
payOrderVo.setOutTradeNo(order.getOutTradeNo());
|
payOrderVo.setOutTradeNo(order.getOutTradeNo());
|
||||||
payOrderVo.setPrice(order.getTotalTee());
|
payOrderVo.setPrice(order.getTotalTee());
|
||||||
|
payOrderVo.setTimeRemarks(order.getTimeRemarks());
|
||||||
return rb.success().setData(payOrderVo);
|
return rb.success().setData(payOrderVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +183,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
if (payOrder == null) {
|
if (payOrder == null) {
|
||||||
return rb.setMsg("订单不存在");
|
return rb.setMsg("订单不存在");
|
||||||
}
|
}
|
||||||
payOrder.setState(2);//已支付
|
payOrder.setState(2);//已支付.state:1待支付,2已支付,3已过期
|
||||||
payOrder.setModifyTime(new Date());
|
payOrder.setModifyTime(new Date());
|
||||||
payOrder.setPayTypeValue("微信");
|
payOrder.setPayTypeValue("微信");
|
||||||
if (result_code.equalsIgnoreCase("FAIL")) {
|
if (result_code.equalsIgnoreCase("FAIL")) {
|
||||||
@@ -188,7 +192,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
} else if (result_code.equalsIgnoreCase("SUCCESS")) {
|
} else if (result_code.equalsIgnoreCase("SUCCESS")) {
|
||||||
baseMapper.updateById(payOrder);
|
baseMapper.updateById(payOrder);
|
||||||
//调业务的回调地址接口。mainSid传过去。
|
//调业务的回调地址接口。mainSid传过去。
|
||||||
|
ResponseEntity<ResultBean> postForEntity = new RestTemplate().getForEntity(payOrder.getReturnUrl() + payOrder.getSid(), ResultBean.class);
|
||||||
return rb.success();
|
return rb.success();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -257,6 +261,15 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
if ("SUCCESS".equals(trade_state)) {
|
if ("SUCCESS".equals(trade_state)) {
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
String time_end = MapUtils.getString("time_end", resultUn);
|
String time_end = MapUtils.getString("time_end", resultUn);
|
||||||
|
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
|
Date date = null;
|
||||||
|
try {
|
||||||
|
date = inputFormat.parse(time_end);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String formattedDateTime = outputFormat.format(date);
|
||||||
/*payOrder = fetchBySid(query.getMainSid());
|
/*payOrder = fetchBySid(query.getMainSid());
|
||||||
map.put("createTime", DateUtils.format(payOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
|
map.put("createTime", DateUtils.format(payOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
|
||||||
map.put("payTime", DateUtils.format(payOrder.getModifyTime(), "yyyy-MM-dd HH:mm:ss"));
|
map.put("payTime", DateUtils.format(payOrder.getModifyTime(), "yyyy-MM-dd HH:mm:ss"));
|
||||||
@@ -264,7 +277,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
map.put("mainSid", payOrder.getSid());
|
map.put("mainSid", payOrder.getSid());
|
||||||
map.put("trade_type", payOrder.getPayTypeValue());//交易类型*/
|
map.put("trade_type", payOrder.getPayTypeValue());//交易类型*/
|
||||||
map.put("trade_state", trade_state);
|
map.put("trade_state", trade_state);
|
||||||
map.put("time_end", time_end);
|
map.put("time_end", formattedDateTime);
|
||||||
map.put("createTime", DateUtils.format(payOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
|
map.put("createTime", DateUtils.format(payOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
|
||||||
return rb.success().setData(map);
|
return rb.success().setData(map);
|
||||||
} else {
|
} else {
|
||||||
@@ -272,4 +285,9 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
return rb.setMsg("查询失败,error=" + trade_state);
|
return rb.setMsg("查询失败,error=" + trade_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//查询所有待支付的订单
|
||||||
|
public List<PayOrder> selectOrderList() {
|
||||||
|
return baseMapper.selectOrderList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.yxt.pay.biz.order;
|
||||||
|
|
||||||
|
import com.yxt.pay.api.order.PayOrder;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: dimengzhe
|
||||||
|
* @date: 2024/1/8
|
||||||
|
**/
|
||||||
|
@Component
|
||||||
|
public class ScheduledOrderService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0/10 * * * * ?")
|
||||||
|
public void remindVehicle() {
|
||||||
|
//查询所有待支付的订单
|
||||||
|
List<PayOrder> payOrderList = orderService.selectOrderList();
|
||||||
|
payOrderList.removeAll(Collections.singleton(null));
|
||||||
|
if (!payOrderList.isEmpty()) {
|
||||||
|
for (int i = 0; i < payOrderList.size(); i++) {
|
||||||
|
PayOrder payOrder = payOrderList.get(i);
|
||||||
|
//验证订单是否已过期
|
||||||
|
Date createTime = payOrder.getCreateTime();
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(createTime);
|
||||||
|
calendar.add(Calendar.MINUTE, payOrder.getTimeRemarks());
|
||||||
|
//过期时间
|
||||||
|
long newTimeInMillis = calendar.getTimeInMillis();
|
||||||
|
// 获取当前时间的毫秒表示
|
||||||
|
long currentTimeInMillis = System.currentTimeMillis();
|
||||||
|
if (newTimeInMillis < currentTimeInMillis) {
|
||||||
|
payOrder.setState(3);
|
||||||
|
}
|
||||||
|
orderService.updateById(payOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user