支付相关
This commit is contained in:
@@ -20,6 +20,7 @@ CREATE TABLE `pay_order`
|
||||
`payTypeValue` varchar(500) DEFAULT NULL COMMENT '支付方式Value',
|
||||
`payType` varchar(500) DEFAULT NULL COMMENT '支付方式key',
|
||||
`timeRemarks` int(64) DEFAULT NULL COMMENT '过期时间设置(以分钟为准,例如5分钟,则为5)',
|
||||
`returnUrl` varchar(500) DEFAULT NULL COMMENT '业务的回调地址',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `id` (`id`)
|
||||
) ENGINE = InnoDB
|
||||
@@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* @author dimengzhe
|
||||
@@ -15,6 +16,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
})
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackages = {})
|
||||
@EnableScheduling
|
||||
public class PayApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -20,4 +20,6 @@ public class PayOrderVo {
|
||||
private String price;
|
||||
@ApiModelProperty("商品名称")
|
||||
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 org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: dimengzhe
|
||||
@@ -12,4 +14,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface OrderMapper extends BaseMapper<PayOrder> {
|
||||
PayOrder selectBySn(String out_trade_no);
|
||||
|
||||
List<PayOrder> selectOrderList();
|
||||
}
|
||||
|
||||
@@ -6,4 +6,10 @@
|
||||
from pay_order
|
||||
where outTradeNo = #{out_trade_no}
|
||||
</select>
|
||||
|
||||
<select id="selectOrderList" resultType="com.yxt.pay.api.order.PayOrder">
|
||||
select *
|
||||
from pay_order
|
||||
where state = 1
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -42,7 +42,7 @@ public class OrderRest extends ApiBaseAction {
|
||||
return orderService.pay(query, getClientIp());
|
||||
}
|
||||
|
||||
@PostMapping("wxPayNotify")
|
||||
@PostMapping("/wxPayNotify")
|
||||
ResultBean wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
return orderService.wxPayNotify(request, response);
|
||||
}
|
||||
|
||||
@@ -9,14 +9,17 @@ import com.yxt.pay.utils.applet.WechatRefundApiResult;
|
||||
import com.yxt.pay.utils.applet.WechatUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -53,6 +56,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
||||
payOrderVo.setMainSid(order.getSid());
|
||||
payOrderVo.setOutTradeNo(order.getOutTradeNo());
|
||||
payOrderVo.setPrice(order.getTotalTee());
|
||||
payOrderVo.setTimeRemarks(order.getTimeRemarks());
|
||||
return rb.success().setData(payOrderVo);
|
||||
}
|
||||
|
||||
@@ -179,7 +183,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
||||
if (payOrder == null) {
|
||||
return rb.setMsg("订单不存在");
|
||||
}
|
||||
payOrder.setState(2);//已支付
|
||||
payOrder.setState(2);//已支付.state:1待支付,2已支付,3已过期
|
||||
payOrder.setModifyTime(new Date());
|
||||
payOrder.setPayTypeValue("微信");
|
||||
if (result_code.equalsIgnoreCase("FAIL")) {
|
||||
@@ -188,7 +192,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
||||
} else if (result_code.equalsIgnoreCase("SUCCESS")) {
|
||||
baseMapper.updateById(payOrder);
|
||||
//调业务的回调地址接口。mainSid传过去。
|
||||
|
||||
ResponseEntity<ResultBean> postForEntity = new RestTemplate().getForEntity(payOrder.getReturnUrl() + payOrder.getSid(), ResultBean.class);
|
||||
return rb.success();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -257,6 +261,15 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
||||
if ("SUCCESS".equals(trade_state)) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
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());
|
||||
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"));
|
||||
@@ -264,7 +277,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
||||
map.put("mainSid", payOrder.getSid());
|
||||
map.put("trade_type", payOrder.getPayTypeValue());//交易类型*/
|
||||
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"));
|
||||
return rb.success().setData(map);
|
||||
} else {
|
||||
@@ -272,4 +285,9 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
||||
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