Explorar el Código

Merge branch 'pay' into dev

# Conflicts:
#	sp-server/app.pid
qzyReal hace 3 años
padre
commit
dd228cf6d4

+ 7 - 4
app/apis/api.js

@@ -110,12 +110,15 @@ export default {
 	getUnitList() {
 		return ajax.get('/TbUnit/getList')
 	},
-	getPrePay(data) {
-		return ajax.get('/wx/pre-pay', data)
-	},
 	// getPrePay(data) {
-	// 	return ajax.get('/jh/init-pay', data)
+	// 	return ajax.get('/wx/pre-pay', data)
 	// },
+	getPrePay(data) {
+		return ajax.get('/jh/init-pay', data)
+	},
+	checkPayResult(data){
+		return ajax.get('/jh/check-pay-result', data)
+	},
 	getRedirectUrl(data) {
 		return ajax.get('/wx/getRedirectUrl', data)
 	},

+ 1 - 1
app/manifest.json

@@ -85,7 +85,7 @@
     "vueVersion" : "2",
     "h5" : {
         "router" : {
-            "base" : "/h5/",
+            "base" : "/test/",
             "mode" : "history"
         },
         "devServer" : {

+ 20 - 1
app/pages/wx/pay.vue

@@ -196,12 +196,15 @@
 				}
 				let type = this.type;
 				let con = 'A1停车费';
+				let tradeType = 'PORT_PARKING_FEE';
 				if (type == 2) {
 					con = 'A1整车业务';
+					tradeType='PORT_OPERATION_FEE';
 				} else if (type == 1) {
 					con = 'A1车辆消杀'
 				}
 				p.desc = con + '-' + carNos;
+				p.businessType=tradeType;
 				this.$common.showLoading('正在请求...');
 				let that = this;
 				that.$api.getPrePay(that.$common.removeNull(p)).then(resp => {
@@ -220,15 +223,31 @@
 						success: function(res) {
 							if (res.errMsg === "chooseWXPay:ok") {
 								that.$common.toast('支付成功')
+								//that.checkPayResult(data.outTradeNo);
 								that.cars = [];
 								that.item.list = [];
 								that.total = 0
-								// wx.closeWindow();
 							}
+						},
+						complete: function(res) {
+							//that.checkPayResult(data.outTradeNo);
 						}
 					});
 				})
 			},
+			checkPayResult(outTradeNo) {
+				this.$common.showLoading('正在查询结果...')
+				this.$api.checkPayResult({
+					outTradeNo: outTradeNo
+				}).then(resp => {
+					let data = resp.data;
+					if (data.orderStatus == 'SUCCESS' || data.orderStatus == 'FINISH') {
+						this.$common.toast('支付成功')
+					} else {
+						this.$common.toast('支付失败')
+					}
+				})
+			},
 			payTypeChange(value) {
 
 			},

+ 17 - 4
app/pages/wx/payOrder.vue

@@ -176,7 +176,8 @@
 					tradeType: "JSAPI",
 					openid: this.wx.openid
 				}
-				p.desc="A1-业务费用"
+				p.desc = "A1-业务费用";
+				p.businessType='PORT_OPERATION_FEE';
 				this.$api.getPrePay(this.$common.removeNull(p)).then(resp => {
 					let data = resp.data;
 					let that = this;
@@ -189,13 +190,25 @@
 						paySign: data.paySign, // 支付签名
 						success: function(res) {
 							if (res.errMsg === "chooseWXPay:ok") {
-								that.$common.toast('支付成功')
-								// wx.closeWindow();
+								that.checkPayResult(data.outTradeNo);
 							}
 						}
 					});
 				})
-			}
+			},
+			checkPayResult(outTradeNo) {
+				this.$common.showLoading('正在确认结果...')
+				this.$api.checkPayResult({
+					outTradeNo: outTradeNo
+				}).then(resp => {
+					let data = resp.data;
+					if (data.orderStatus == 'SUCCESS' || data.orderStatus == 'FINISH') {
+						this.$common.toast('支付成功')
+					} else {
+						this.$common.toast('支付失败')
+					}
+				})
+			},
 		}
 	}
 </script>

+ 3 - 0
sp-server/src/main/java/com/pj/api/jh/api/JhController.java

@@ -1,6 +1,8 @@
 package com.pj.api.jh.api;
 
 import cn.hutool.core.util.XmlUtil;
+import cn.hutool.json.JSONUtil;
+import cn.hutool.log.StaticLog;
 import com.pj.api.jh.bo.JhNotifyBO;
 import com.pj.api.jh.service.JhService;
 import com.pj.utils.sg.AjaxJson;
@@ -38,6 +40,7 @@ public class JhController {
     }
     @RequestMapping(value = "notify")
     public String notifyResult(JhNotifyBO bo) {
+        StaticLog.info("聚合支付回调:{}", JSONUtil.toJsonStr(bo));
         jhService.notifyResult(bo);
         return "SUCCESS";
     }

+ 2 - 0
sp-server/src/main/java/com/pj/api/jh/bo/JhNotifyBO.java

@@ -1,9 +1,11 @@
 package com.pj.api.jh.bo;
 
 import lombok.Data;
+import lombok.experimental.Accessors;
 
 import java.io.Serializable;
 @Data
+@Accessors(chain = true)
 public class JhNotifyBO implements Serializable {
     private String businessMerchantNo;
     private String orderPrice;

+ 49 - 17
sp-server/src/main/java/com/pj/api/jh/service/JhService.java

@@ -1,5 +1,6 @@
 package com.pj.api.jh.service;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
@@ -7,6 +8,7 @@ import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import cn.hutool.log.StaticLog;
+import com.pj.api.jh.task.CheckPayStatusTask;
 import com.pj.api.jh.utils.JhHttpUtils;
 import com.pj.api.jh.utils.MerchantApiUtil;
 import com.pj.api.jh.bo.JhNotifyBO;
@@ -16,6 +18,9 @@ import com.pj.api.wx.service.WxService;
 import com.pj.current.config.JhConfig;
 import com.pj.current.config.MyConfig;
 import com.pj.current.config.PartConfig;
+import com.pj.current.task.TaskService;
+import com.pj.project.tb_order.TbOrder;
+import com.pj.project.tb_order.TbOrderService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -25,6 +30,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -49,25 +55,34 @@ public class JhService {
 
     @Resource
     JhHttpUtils jhHttpUtils;
+    @Resource
+    private TbOrderService tbOrderService;
+    @Resource
+    private TaskService taskService;
 
-    public JSONObject initPay(HttpServletRequest request) throws Exception {
+    public Map<String, ?> initPay(HttpServletRequest request) throws Exception {
+        if (!jhConfig.isEnable()) {
+            return wxService.prePay(request);
+        }
         String money = request.getParameter("money");
         String openid = request.getParameter("openid");
         String desc = request.getParameter("desc");
         String businessId = request.getParameter("b");
         String c = request.getParameter("c");
         String a = request.getParameter("a");
+        String tradeType = request.getParameter("tradeType");
+        String businessType = request.getParameter("businessType");
         Attach atchMap = new Attach();
         atchMap.setC(c).setB(businessId).setA(a);
-        String out_trade_no = RandomUtil.randomString(30);
-        StaticLog.info("outTradeNo:{}",out_trade_no);
+        String out_trade_no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(6);
+        StaticLog.info("outTradeNo:{}", out_trade_no);
         Map<String, Object> params = new HashMap<>();
         params.put("attach", JSONUtil.toJsonStr(atchMap));
         params.put("productType", jhConfig.getProductType());
         params.put("businessMerchantNo", jhConfig.getBusinessMerchantNo());
         params.put("openId", openid);
         params.put("merchantNo", jhConfig.getBusinessMerchantNo());
-        params.put("tradeType", jhConfig.getTradeType());
+        params.put("tradeType", businessType);
         params.put("subTradeType", "");
         String total_free = partConfig.isTestEnv() ? "0.01" : money + "";
         log.info("order price:{}", total_free);
@@ -85,45 +100,62 @@ public class JhService {
         params.put("sign", sign);
         String jsonParam = JSONUtil.toJsonStr(params);
         String initPayUrl = jhConfig.getServerUrl() + "/uaps-web-gateway/cnpPay/initPay";
-        String result = jhHttpUtils.postJson(initPayUrl,jsonParam);
+        String result = jhHttpUtils.postJson(initPayUrl, jsonParam);
         StaticLog.info("调用聚合支付返回:{}", result);
         JSONObject jsonResult = JSONUtil.parseObj(result);
-        if (StrUtil.equals("0000", jsonResult.get("resultCode").toString())) {
-            JSONObject payMessage = JSONUtil.parseObj(jsonResult.get("payMessage").toString());
+        if (StrUtil.equals("0000", jsonResult.getStr("resultCode"))) {
+            JSONObject payMessage = JSONUtil.parseObj(jsonResult.getStr("payMessage"));
             String p = payMessage.getStr("package");
             Map<String, String> r = wxService.getPayP(payMessage.getStr("timeStamp"), payMessage.getStr("nonceStr"), openid, p);
             StaticLog.info("re:{}", JSONUtil.toJsonStr(r));
             JSONObject object = JSONUtil.parseObj(payMessage);
+
             object.set("outTradeNo", out_trade_no);
-            return object;
+            TbOrder tbOrder = new TbOrder();
+            tbOrder.setAttach(JSONUtil.toJsonStr(atchMap))
+                    .setOpenid(openid)
+                    .setOrderTime(new Date())
+                    .setOutTradeNo(out_trade_no).setPrice(money);
+            tbOrderService.save(tbOrder);
+            taskService.addTask(new CheckPayStatusTask(RandomUtil.randomNumbers(12), 2000, out_trade_no));
+            return BeanUtil.beanToMap(object);
         }
         throw new Exception("支付信息有误");
     }
 
-
-    public JSONObject checkPayResult(String outTradeNo) {
-        String url = jhConfig.getServerUrl() + "/uaps-web-gateway/query/singleOrder";
+    public Map<String, Object> buildCheckParams(String outTradeNo) {
         Map<String, Object> params = new HashMap<>();
         params.put("businessMerchantNo", jhConfig.getBusinessMerchantNo());
         params.put("outTradeNo", outTradeNo);
         String paySecrit = jhConfig.getPaySecret();
         String sign = MerchantApiUtil.getSign(params, paySecrit);
         params.put("sign", sign);
-        String result = jhHttpUtils.postForm(url,params);
-        StaticLog.info("调用聚合支付查询支付接口返回:{}", result);
+        return params;
+    }
+
+    public JSONObject checkPayResult(String outTradeNo) {
+        String url = jhConfig.getServerUrl() + "/uaps-web-gateway/query/singleOrder";
+        Map<String, Object> params = buildCheckParams(outTradeNo);
+        String result = jhHttpUtils.postForm(url, params);
         return JSONUtil.parseObj(result);
     }
+
     @Async
     public void notifyResult(JhNotifyBO bo) {
-        StaticLog.info("聚合支付回调:{}", JSONUtil.toJsonStr(bo));
-        if (!"SUCCESS".equals(bo.getTradeStatus().toUpperCase())){
+        String orderStatus=bo.getTradeStatus();
+        if (!"SUCCESS".equals(orderStatus) && !"FINISH".equals(orderStatus)) {
             return;
         }
-        NotifyBO notifyBO=new NotifyBO();
+        NotifyBO notifyBO = new NotifyBO();
+        String outTradeNo = bo.getOutTradeNo();
         notifyBO.setOutTradeNo(bo.getOutTradeNo())
                 .setAttach(bo.getAttach())
                 .setTransactionId(bo.getBankTrxNo())
-        .setTotalFee(NumberUtil.mul(bo.getOrderPrice(),100+"").toString());
+                .setTotalFee(NumberUtil.mul(bo.getOrderPrice(), 100 + "").toString());
         wxService.WxNotify(notifyBO);
+        TbOrder tbOrder = tbOrderService.findByOutTradeNo(outTradeNo);
+        tbOrder.setOrderStatus(orderStatus)
+                .setTransactionId(bo.getBankTrxNo())
+                .setCompleteDate(bo.getSuccessTime());
     }
 }

+ 80 - 0
sp-server/src/main/java/com/pj/api/jh/task/CheckPayStatusTask.java

@@ -0,0 +1,80 @@
+package com.pj.api.jh.task;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.pj.api.jh.bo.JhNotifyBO;
+import com.pj.api.jh.service.JhService;
+import com.pj.api.jh.utils.JhHttpUtils;
+import com.pj.api.wx.service.WxService;
+import com.pj.current.config.JhConfig;
+import com.pj.current.task.Task;
+import com.pj.project.tb_order.TbOrder;
+import com.pj.project.tb_order.TbOrderService;
+import com.pj.project4sp.global.BusinessException;
+import lombok.extern.slf4j.Slf4j;
+
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
+import java.util.Map;
+
+@Slf4j
+public class CheckPayStatusTask extends Task {
+    private String outTradeNo;
+    private LocalDateTime startTime;
+
+    public CheckPayStatusTask(String id, long delayInMilliseconds, String outTradeNo) {
+        super(id, delayInMilliseconds);
+        this.outTradeNo = outTradeNo;
+        this.startTime = LocalDateTime.now();
+    }
+
+    @Override
+    public void run() {
+        JhConfig jhConfig = SpringUtil.getBean(JhConfig.class);
+        JhService jhService = SpringUtil.getBean(JhService.class);
+        String url = jhConfig.getServerUrl() + "/uaps-web-gateway/query/singleOrder";
+        Map<String, Object> params = jhService.buildCheckParams(outTradeNo);
+        check(url, params);
+    }
+
+    private void check(String url, Map<String, Object> params) {
+        LocalDateTime now = LocalDateTime.now();
+        if (ChronoUnit.MINUTES.between(startTime,now)>5){
+            log.error("超时订单,不再查单:{}",outTradeNo);
+            return;
+        }
+        log.info("开始查单===:{}", JSONUtil.toJsonStr(params));
+        JhHttpUtils jhHttpUtils = SpringUtil.getBean(JhHttpUtils.class);
+        JSONObject result = jhHttpUtils.checkStatus(url, params);
+        String orderStatus = result.getStr("orderStatus");
+        if (StrUtil.equals(orderStatus, "WAITING_PAYMENT")) {
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            this.check(url, params);
+        } else if (StrUtil.equals(orderStatus, "SUCCESS") || StrUtil.equals(orderStatus, "FINISH")) {
+            TbOrderService tbOrderService = SpringUtil.getBean(TbOrderService.class);
+            TbOrder tbOrder = tbOrderService.findByOutTradeNo(outTradeNo);
+            if (StrUtil.equals("WAITING_PAYMENT", tbOrder.getOrderStatus())) {
+                tbOrder.setOrderStatus(orderStatus)
+                        .setTransactionId(result.getStr("bankTrxNo"))
+                        .setCompleteDate(result.getStr("completeDate"));
+                tbOrderService.updateById(tbOrder);
+                JhService jhService = SpringUtil.getBean(JhService.class);
+                JhNotifyBO notifyBO = new JhNotifyBO();
+                notifyBO.setAttach(tbOrder.getAttach()).setBankTrxNo(tbOrder.getTransactionId()).setTradeStatus(orderStatus)
+                        .setOutTradeNo(tbOrder.getOutTradeNo()).setOrderPrice(tbOrder.getPrice());
+                jhService.notifyResult(notifyBO);
+            }
+
+        }
+
+    }
+
+
+}

+ 20 - 0
sp-server/src/main/java/com/pj/api/jh/task/StartUpCheckPayStatusTask.java

@@ -0,0 +1,20 @@
+package com.pj.api.jh.task;
+
+import cn.hutool.extra.spring.SpringUtil;
+import com.pj.current.task.Task;
+import com.pj.project.tb_order.TbOrder;
+import com.pj.project.tb_order.TbOrderService;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class StartUpCheckPayStatusTask extends Task {
+    public StartUpCheckPayStatusTask(String id, long delayInMilliseconds) {
+        super(id, delayInMilliseconds);
+    }
+
+    @Override
+    public void run() {
+        TbOrderService tbOrderService = SpringUtil.getBean(TbOrderService.class);
+        tbOrderService.check();
+    }
+}

+ 22 - 2
sp-server/src/main/java/com/pj/api/jh/utils/JhHttpUtils.java

@@ -1,11 +1,15 @@
 package com.pj.api.jh.utils;
 
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.HttpException;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.pj.project4sp.global.BusinessException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.retry.annotation.Backoff;
 import org.springframework.retry.annotation.Retryable;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import java.util.Map;
@@ -14,7 +18,7 @@ import java.util.Map;
 @Slf4j
 public class JhHttpUtils {
 
-    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000, maxDelay = 1200))
+    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 3000, maxDelay = 6200))
     public String postJson(String url, String body) {
         log.info("开始请求接口:{},{}", url, body);
         String resp = HttpUtil.createPost(url)
@@ -26,7 +30,7 @@ public class JhHttpUtils {
         return resp;
     }
 
-    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000, maxDelay = 1200))
+    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 3000, maxDelay = 4000))
     public String postForm(String url, Map<String, Object> params) {
         log.info("开始请求接口:{},{}", url, JSONUtil.toJsonStr(params));
         String resp = HttpUtil.createPost(url)
@@ -36,4 +40,20 @@ public class JhHttpUtils {
         log.info("接口返回:{},{}", url, resp);
         return resp;
     }
+
+    @Retryable(maxAttempts = 15, backoff = @Backoff(delay = 3000, maxDelay = 10000))
+    public JSONObject checkStatus(String url, Map<String, Object> params) {
+        log.info("检查支付状态:{},{}", url, JSONUtil.toJsonStr(params));
+        String resp = HttpUtil.createPost(url)
+                .setConnectionTimeout(3000)
+                .setReadTimeout(2000)
+                .form(params)
+                .execute().body();
+        log.info("检查支付状态返回:{},{}", url, resp);
+        JSONObject result = JSONUtil.parseObj(resp);
+        if (!StrUtil.equals(result.getStr("resultCode"), "0000")) {
+            throw new BusinessException(result.getStr("errMsg"));
+        }
+        return result;
+    }
 }

+ 6 - 9
sp-server/src/main/java/com/pj/api/wx/service/WxService.java

@@ -2,6 +2,7 @@ package com.pj.api.wx.service;
 
 import cn.hutool.cache.CacheUtil;
 import cn.hutool.cache.impl.TimedCache;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.net.URLDecoder;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.RandomUtil;
@@ -30,6 +31,7 @@ import com.pj.project.tb_costomer.TbCostomer;
 import com.pj.project.tb_costomer.TbCostomerService;
 import com.pj.project.tb_fee_details.TbFeeDetailsService;
 import com.pj.project.tb_fee_statistics.TbFeeStatisticsService;
+import com.pj.project.tb_order.TbOrderService;
 import com.pj.project.tb_pay_record.TbPayRecord;
 import com.pj.project.tb_pay_record.TbPayRecordService;
 import com.pj.utils.cache.RedisUtil;
@@ -64,10 +66,6 @@ public class WxService {
     @Resource
     WxUtils wxUtils;
     @Resource
-    TbPayRecordService tbPayRecordService;
-    @Resource
-    TbCostomerService tbCostomerService;
-    @Resource
     TbBusinessCarService tbBusinessCarService;
     @Resource
     @Lazy
@@ -79,6 +77,7 @@ public class WxService {
     @Resource
     TbFeeDetailsService tbFeeDetailsService;
 
+
     /**
      * 统一下单接口
      */
@@ -181,15 +180,14 @@ public class WxService {
         }
     }
 
-    TimedCache<String, Integer> NotifyCache = CacheUtil.newTimedCache(360000);
 
     @Async
-    public void WxNotify(NotifyBO notifyBO)  {
+    public void WxNotify(NotifyBO notifyBO) {
         String outTradeNo = notifyBO.getOutTradeNo();
-        if (NotifyCache.get(outTradeNo) != null) {
+        if (RedisUtil.get(outTradeNo) != null) {
             return;
         }
-        NotifyCache.put(outTradeNo, 1);
+        RedisUtil.setByHour(outTradeNo, DateUtil.now(), 2);
         String total_fee = notifyBO.getTotalFee();
         BigDecimal money = new BigDecimal(total_fee).divide(new BigDecimal(100), 2, BigDecimal.ROUND_UP);
         String attachStr = notifyBO.getAttach();
@@ -234,7 +232,6 @@ public class WxService {
     }
 
 
-
     public String getRedirectUrl(String path, String state) {
         String redirectUrl = myConfig.getWebDomain() + path;
         String encoderUrl = URLDecoder.decode(redirectUrl, Charset.forName("utf-8"));

+ 7 - 8
sp-server/src/main/java/com/pj/current/SaPlusStartup.java

@@ -1,10 +1,11 @@
 package com.pj.current;
 
-import java.net.InetAddress;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
+import com.pj.api.jh.task.StartUpCheckPayStatusTask;
 import com.pj.current.config.WxConfig;
+import com.pj.current.task.TaskService;
 import com.pj.current.task.TokenTask;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -41,16 +42,14 @@ public class SaPlusStartup implements CommandLineRunner {
     @Resource
     WxConfig wxConfig;
 
+    @Resource
+    TaskService taskService;
+
     @Override
-    public void run(String... args) throws Exception {
+    public void run(String... args){
         tokenTask.run();
         threadPoolTaskScheduler.scheduleAtFixedRate(tokenTask, wxConfig.getFlushSecond() * 1000);
-        String ip = InetAddress.getLocalHost().getHostAddress();
-        String str = "\n------------- " + applicationName + " (" + active + ") 启动成功 --by " + getNow() + " -------------\n" +
-                "\t- Local:   http://localhost:" + port + path + "\n" +
-                "\t- Local2:  http://127.0.0.1:" + port + path + "\n" +
-                "\t- Network: http://" + ip + ":" + port + path + "\n";
-        log.info("启动信息:{}",str);
+        taskService.addTask(new StartUpCheckPayStatusTask("=========检查正在支付订单状态========",2000L));
     }
 
 

+ 1 - 0
sp-server/src/main/java/com/pj/current/config/JhConfig.java

@@ -20,5 +20,6 @@ public class JhConfig {
     private String tradeType;
     private String paySecret;
     private String serverUrl;
+    private boolean enable;
 
 }

+ 85 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrder.java

@@ -0,0 +1,85 @@
+package com.pj.project.tb_order;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.EqualsAndHashCode;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * Model: tb_order -- 临时订单表
+ * @author qzy 
+ */
+@Data
+@Accessors(chain = true)
+@TableName(TbOrder.TABLE_NAME)
+@EqualsAndHashCode(callSuper = false)
+public class TbOrder extends Model<TbOrder> implements Serializable {
+
+	// ---------- 模块常量 ----------
+	/**
+	 * 序列化版本id 
+	 */
+	private static final long serialVersionUID = 1L;	
+	/**
+	 * 此模块对应的表名 
+	 */
+	public static final String TABLE_NAME = "tb_order";	
+	/**
+	 * 此模块对应的权限码 
+	 */
+	public static final String PERMISSION_CODE = "tb-order";	
+
+
+	// ---------- 表中字段 ----------
+	/**
+	 *  
+	 */
+	@TableId(type = IdType.AUTO)
+	private Long id;	
+
+	/**
+	 * 商户订单号 
+	 */
+	private String outTradeNo;	
+
+	/**
+	 * 额外字段 
+	 */
+	private String attach;	
+
+	/**
+	 * 下单时间 
+	 */
+	private Date orderTime;
+
+	/**
+	 * 用户openid 
+	 */
+	private String openid;	
+
+	/**
+	 * SUCCESS 支付成功 FAILED 支付失败 WAITING_PAYMENT等待支付 FINISH 交易完成
+	 */
+	private String orderStatus;	
+
+	/**
+	 * 金额(元) 
+	 */
+	private String price;
+
+	private String transactionId;
+	private String completeDate;
+
+
+
+
+
+	
+
+
+}

+ 72 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrderController.java

@@ -0,0 +1,72 @@
+package com.pj.project.tb_order;
+
+import java.util.List;
+
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+
+import com.pj.utils.sg.*;
+import com.pj.project4sp.SP;
+
+import com.pj.current.satoken.StpUserUtil;
+import cn.dev33.satoken.annotation.SaCheckPermission;
+
+
+/**
+ * Controller: tb_order -- 临时订单表
+ * @author qzy 
+ */
+@RestController
+@RequestMapping("/TbOrder/")
+public class TbOrderController {
+
+	/** 底层 Service 对象 */
+	@Autowired
+	TbOrderService tbOrderService;
+
+
+
+	/** 查 - 根据id */  
+	@RequestMapping("getById")
+	public AjaxJson getById(Long id){
+		TbOrder t = tbOrderService.getById(id);
+		return AjaxJson.getSuccessData(t);
+	}
+
+	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
+	@RequestMapping("getList")
+	public AjaxJson getList() { 
+		SoMap so = SoMap.getRequestSoMap();
+		List<TbOrder> list = tbOrderService.getList(so.startPage());
+		return AjaxJson.getPageData(so.getDataCount(), list);
+	}
+	
+	
+	
+	
+	// ------------------------- 前端接口 -------------------------
+	
+	
+	/** 改 - 不传不改 [G] */
+	@RequestMapping("updateByNotNull")
+	public AjaxJson updateByNotNull(Long id){
+		AjaxError.throwBy(true, "如需正常调用此接口,请删除此行代码");
+		// 鉴别身份,是否为数据创建者 
+		long userId = SP.publicMapper.getColumnByIdToLong(TbOrder.TABLE_NAME, "user_id", id);
+		AjaxError.throwBy(userId != StpUserUtil.getLoginIdAsLong(), "此数据您无权限修改");
+		// 开始修改 (请只保留需要修改的字段)
+		SoMap so = SoMap.getRequestSoMap();
+		so.clearNotIn("id", "outTradeNo", "attach", "orderTime", "openid", "orderStatus", "price").clearNull().humpToLineCase();	
+		int line = SP.publicMapper.updateBySoMapById(TbOrder.TABLE_NAME, so, id);
+		return AjaxJson.getByLine(line);
+	}
+	
+	
+	
+	
+	
+	
+
+}

+ 30 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrderMapper.java

@@ -0,0 +1,30 @@
+package com.pj.project.tb_order;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Mapper;
+
+import com.pj.utils.so.*;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * Mapper: tb_order -- 临时订单表
+ * @author qzy 
+ */
+
+@Mapper
+@Repository
+public interface TbOrderMapper extends BaseMapper <TbOrder> {
+
+
+
+	/**
+	 * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+	 * @param so 参数集合 
+	 * @return 数据列表 
+	 */
+	List<TbOrder> getList(SoMap so);
+
+
+}

+ 60 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrderMapper.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.pj.project.tb_order.TbOrderMapper">
+
+	<!-- ================================== 查询相关 ================================== -->
+	<!-- select id, out_trade_no, attach, order_time, openid, order_status, price from tb_order  -->
+	
+	<!-- 通用映射:手动模式 -->
+	<resultMap id="model" type="com.pj.project.tb_order.TbOrder">
+		<result property="id" column="id" />
+		<result property="outTradeNo" column="out_trade_no" />
+		<result property="attach" column="attach" />
+		<result property="orderTime" column="order_time" />
+		<result property="openid" column="openid" />
+		<result property="orderStatus" column="order_status" />
+		<result property="price" column="price" />
+	</resultMap>
+	
+	<!-- 公共查询sql片段 -->
+	<sql id="select_sql">
+		select * 
+		from tb_order 
+	</sql>
+
+	
+	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
+	<select id="getList" resultMap="model">
+		<include refid="select_sql"></include>
+		<where>
+			<if test=' this.has("id") '> and id = #{id} </if>
+			<if test=' this.has("outTradeNo") '> and out_trade_no = #{outTradeNo} </if>
+			<if test=' this.has("attach") '> and attach = #{attach} </if>
+			<if test=' this.has("orderTime") '> and order_time = #{orderTime} </if>
+			<if test=' this.has("openid") '> and openid = #{openid} </if>
+			<if test=' this.has("orderStatus") '> and order_status = #{orderStatus} </if>
+			<if test=' this.has("price") '> and price = #{price} </if>
+		</where>
+		order by
+		<choose>
+			<when test='sortType == 1'> id desc </when>
+			<when test='sortType == 2'> out_trade_no desc </when>
+			<when test='sortType == 3'> attach desc </when>
+			<when test='sortType == 4'> order_time desc </when>
+			<when test='sortType == 5'> openid desc </when>
+			<when test='sortType == 6'> order_status desc </when>
+			<when test='sortType == 7'> price desc </when>
+			<otherwise> id desc </otherwise>
+		</choose>
+	</select>
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
+</mapper>

+ 89 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrderService.java

@@ -0,0 +1,89 @@
+package com.pj.project.tb_order;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Map;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.pj.api.jh.bo.JhNotifyBO;
+import com.pj.api.jh.service.JhService;
+import com.pj.api.jh.utils.JhHttpUtils;
+import com.pj.api.wx.bo.NotifyBO;
+import com.pj.api.wx.service.WxService;
+import com.pj.current.config.JhConfig;
+import com.pj.project.tb_business.TbBusiness;
+import com.pj.project.tb_business.TbBusinessMapper;
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import com.pj.utils.sg.*;
+
+import javax.annotation.Resource;
+
+/**
+ * Service: tb_order -- 临时订单表
+ *
+ * @author qzy
+ */
+@Service
+public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implements IService<TbOrder> {
+
+    /**
+     * 底层 Mapper 对象
+     */
+    @Autowired
+    TbOrderMapper tbOrderMapper;
+    @Resource
+    JhHttpUtils jhHttpUtils;
+    @Resource
+    JhConfig jhConfig;
+    @Resource
+    @Lazy
+    JhService jhService;
+
+
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     */
+    List<TbOrder> getList(SoMap so) {
+        return tbOrderMapper.getList(so);
+    }
+
+    @Async
+    public void check() {
+        QueryWrapper<TbOrder> ew = new QueryWrapper<>();
+        ew.eq("order_status", "WAITING_PAYMENT");
+        ew.ge("date_format(order_time,'%Y-%m-%d %H:%i:%s')", LocalDateTime.now().minusMinutes(10).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+        List<TbOrder> list = this.list(ew);
+        String url = jhConfig.getServerUrl() + "/uaps-web-gateway/query/singleOrder";
+        list.forEach(tbOrder -> {
+            Map<String, Object> params = jhService.buildCheckParams(tbOrder.getOutTradeNo());
+            JSONObject result = jhHttpUtils.checkStatus(url, params);
+            String orderStatus = result.getStr("orderStatus");
+            if (StrUtil.equals(orderStatus, "SUCCESS") || StrUtil.equals(orderStatus, "FINISH")) {
+                tbOrder.setOrderStatus(orderStatus)
+                        .setTransactionId(result.getStr("bankTrxNo"))
+                        .setCompleteDate(result.getStr("completeDate"));
+                this.updateById(tbOrder);
+                JhNotifyBO notifyBO = new JhNotifyBO();
+                notifyBO.setAttach(tbOrder.getAttach()).setBankTrxNo(tbOrder.getTransactionId()).setTradeStatus(orderStatus)
+                        .setOutTradeNo(tbOrder.getOutTradeNo()).setOrderPrice(tbOrder.getPrice());
+                jhService.notifyResult(notifyBO);
+            }
+        });
+    }
+
+    public TbOrder findByOutTradeNo(String outTradeNo) {
+        QueryWrapper<TbOrder> ew = new QueryWrapper<>();
+        ew.eq("out_trade_no", outTradeNo);
+        return getOne(ew);
+    }
+}

+ 2 - 1
sp-server/src/main/resources/application-dev.yml

@@ -6,7 +6,7 @@ spring:
     # 数据源配置
     datasource:
         type: com.alibaba.druid.pool.DruidDataSource
-        url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
+        url: jdbc:mysql://127.0.0.1:3306/pco_system?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
         username: root
         password: 123456
         # 是否打开sql监控台  (生产环境请务必关闭此选项)
@@ -84,3 +84,4 @@ jh-config:
     trade-type: GAS_PAY
     pay-secret: f0b9d6ea704d4c03a6b44be50d055025
     server-url: http://116.252.74.15:8081
+    enable: true