张延森 3 anos atrás
pai
commit
25b2df110b
32 arquivos alterados com 973 adições e 53 exclusões
  1. 43
    1
      pom.xml
  2. 5
    0
      src/main/java/com/yunzhi/nanyang/common/Constants.java
  3. 4
    0
      src/main/java/com/yunzhi/nanyang/common/DateUtils.java
  4. 191
    0
      src/main/java/com/yunzhi/nanyang/common/IpUtil.java
  5. 70
    0
      src/main/java/com/yunzhi/nanyang/common/WxPayUtils.java
  6. 39
    1
      src/main/java/com/yunzhi/nanyang/common/WxUtils.java
  7. 23
    7
      src/main/java/com/yunzhi/nanyang/config/WeixinConfig.java
  8. 3
    2
      src/main/java/com/yunzhi/nanyang/controller/TaDispatchController.java
  9. 3
    11
      src/main/java/com/yunzhi/nanyang/controller/TaMachineryController.java
  10. 27
    8
      src/main/java/com/yunzhi/nanyang/controller/TaOrderController.java
  11. 78
    0
      src/main/java/com/yunzhi/nanyang/controller/TaPayController.java
  12. 9
    0
      src/main/java/com/yunzhi/nanyang/controller/TaWorkJobController.java
  13. 48
    0
      src/main/java/com/yunzhi/nanyang/controller/WxPayController.java
  14. 4
    0
      src/main/java/com/yunzhi/nanyang/entity/TaMachinery.java
  15. 3
    0
      src/main/java/com/yunzhi/nanyang/entity/TaOrder.java
  16. 38
    3
      src/main/java/com/yunzhi/nanyang/entity/TaPay.java
  17. 9
    7
      src/main/java/com/yunzhi/nanyang/mapper/TaDispatchMapper.java
  18. 6
    0
      src/main/java/com/yunzhi/nanyang/mapper/TaMachineryMapper.java
  19. 13
    1
      src/main/java/com/yunzhi/nanyang/mapper/TaOrderMapper.java
  20. 9
    0
      src/main/java/com/yunzhi/nanyang/mapper/TaPayMapper.java
  21. 2
    1
      src/main/java/com/yunzhi/nanyang/service/ITaDispatchService.java
  22. 2
    0
      src/main/java/com/yunzhi/nanyang/service/ITaMachineryService.java
  23. 1
    1
      src/main/java/com/yunzhi/nanyang/service/ITaOrderService.java
  24. 22
    0
      src/main/java/com/yunzhi/nanyang/service/ITaPayService.java
  25. 3
    3
      src/main/java/com/yunzhi/nanyang/service/impl/TaDispatchServiceImpl.java
  26. 5
    0
      src/main/java/com/yunzhi/nanyang/service/impl/TaMachineryServiceImpl.java
  27. 2
    2
      src/main/java/com/yunzhi/nanyang/service/impl/TaOrderServiceImpl.java
  28. 231
    0
      src/main/java/com/yunzhi/nanyang/service/impl/TaPayServiceImpl.java
  29. 12
    0
      src/main/resources/application.yml
  30. 5
    2
      src/main/resources/mapper/TaDispatchMapper.xml
  31. 24
    0
      src/main/resources/mapper/TaMachineryMapper.xml
  32. 39
    3
      src/main/resources/mapper/TaOrderMapper.xml

+ 43
- 1
pom.xml Ver arquivo

@@ -93,10 +93,18 @@
93 93
 		<dependency>
94 94
 			<groupId>com.github.binarywang</groupId>
95 95
 			<artifactId>weixin-java-miniapp</artifactId>
96
-			<version>3.8.0</version>
96
+			<version>4.2.0</version>
97 97
 		</dependency>
98 98
 		<!--weixin-miniapp start-->
99 99
 
100
+		<!--weixin-pay start-->
101
+		<dependency>
102
+			<groupId>com.github.binarywang</groupId>
103
+			<artifactId>weixin-java-pay</artifactId>
104
+			<version>4.2.0</version>
105
+		</dependency>
106
+		<!--weixin-pay start-->
107
+
100 108
 		<!--lombok start-->
101 109
 		<dependency>
102 110
 			<groupId>org.projectlombok</groupId>
@@ -155,11 +163,30 @@
155 163
 							</excludes>
156 164
 						</configuration>
157 165
 					</plugin>
166
+					<plugin>
167
+						<groupId>org.apache.maven.plugins</groupId>
168
+						<artifactId>maven-resources-plugin</artifactId>
169
+						<configuration>
170
+							<encoding>UTF-8</encoding>
171
+							<nonFilteredFileExtensions>
172
+								<nonFilteredFileExtension>pem</nonFilteredFileExtension>
173
+								<nonFilteredFileExtension>pfx</nonFilteredFileExtension>
174
+								<nonFilteredFileExtension>p12</nonFilteredFileExtension>
175
+							</nonFilteredFileExtensions>
176
+						</configuration>
177
+					</plugin>
158 178
 				</plugins>
159 179
 				<resources>
160 180
 					<resource>
161 181
 						<directory>src/main/resources</directory>
162 182
 						<filtering>true</filtering>
183
+						<includes>
184
+							<include>**/*.xml</include>
185
+							<include>**/*.p12</include>
186
+							<include>**/*.pem</include>
187
+							<include>application.yml</include>
188
+							<include>application-${profileActive}.yml</include>
189
+						</includes>
163 190
 					</resource>
164 191
 				</resources>
165 192
 			</build>
@@ -190,6 +217,18 @@
190 217
 							<testFailureIgnore>true</testFailureIgnore>
191 218
 						</configuration>
192 219
 					</plugin>
220
+					<plugin>
221
+						<groupId>org.apache.maven.plugins</groupId>
222
+						<artifactId>maven-resources-plugin</artifactId>
223
+						<configuration>
224
+							<encoding>UTF-8</encoding>
225
+							<nonFilteredFileExtensions>
226
+								<nonFilteredFileExtension>pem</nonFilteredFileExtension>
227
+								<nonFilteredFileExtension>pfx</nonFilteredFileExtension>
228
+								<nonFilteredFileExtension>p12</nonFilteredFileExtension>
229
+							</nonFilteredFileExtensions>
230
+						</configuration>
231
+					</plugin>
193 232
 				</plugins>
194 233
 				<resources>
195 234
 					<resource>
@@ -204,6 +243,9 @@
204 243
 						<directory>src/main/resources</directory>
205 244
 						<filtering>true</filtering>
206 245
 						<includes>
246
+							<include>**/*.xml</include>
247
+							<include>**/*.p12</include>
248
+							<include>**/*.pem</include>
207 249
 							<include>application.yml</include>
208 250
 							<include>application-${profileActive}.yml</include>
209 251
 						</includes>

+ 5
- 0
src/main/java/com/yunzhi/nanyang/common/Constants.java Ver arquivo

@@ -15,9 +15,14 @@ public class Constants {
15 15
     public final static String TARGET_MACHINERY = "machinery";  // 农机
16 16
     public final static String TARGET_NEWS = "news";    // 资讯
17 17
 
18
+    // 订单状态
19
+    public final static int ORDER_CANCEL = 9;  // 待支付
20
+
18 21
     // 支付状态
19 22
     public final static int PAY_READY = 0;  // 待支付
20 23
     public final static int PAY_PAID = 1;  // 已支付
24
+    public final static int PAY_FAIL = 2;  // 支付失败
25
+    public final static int PAY_REFUNDING = 3;  // 退款申请中
21 26
     public final static int PAY_REFUND = -1;  // 已退款
22 27
 
23 28
     // 是否调度

+ 4
- 0
src/main/java/com/yunzhi/nanyang/common/DateUtils.java Ver arquivo

@@ -4,6 +4,10 @@ import java.time.*;
4 4
 import java.time.format.DateTimeFormatter;
5 5
 
6 6
 public class DateUtils {
7
+    public static LocalDateTime from(String str, DateTimeFormatter fmt) {
8
+        return LocalDateTime.parse(str, fmt);
9
+    }
10
+
7 11
     public static LocalDateTime from(String str, String formater) {
8 12
         DateTimeFormatter fmt = DateTimeFormatter.ofPattern(formater);
9 13
         return LocalDateTime.parse(str, fmt);

+ 191
- 0
src/main/java/com/yunzhi/nanyang/common/IpUtil.java Ver arquivo

@@ -0,0 +1,191 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import lombok.extern.slf4j.Slf4j;
4
+
5
+import javax.servlet.http.HttpServletRequest;
6
+import java.net.*;
7
+import java.util.Enumeration;
8
+
9
+@Slf4j
10
+public class IpUtil {
11
+    private static final String LOCAL_IP = "127.0.0.1";
12
+    /**
13
+     * 获取IP地址
14
+     *
15
+     * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
16
+     * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
17
+     */
18
+    public static String getIpAddr(HttpServletRequest request) {
19
+        if (request == null) {
20
+            return "unknown";
21
+        }
22
+        String ip = request.getHeader("x-forwarded-for");
23
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
24
+            ip = request.getHeader("Proxy-Client-IP");
25
+        }
26
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
27
+            ip = request.getHeader("X-Forwarded-For");
28
+        }
29
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
30
+            ip = request.getHeader("WL-Proxy-Client-IP");
31
+        }
32
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
33
+            ip = request.getHeader("X-Real-IP");
34
+        }
35
+
36
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
37
+            ip = request.getRemoteAddr();
38
+        }
39
+
40
+        return "0:0:0:0:0:0:0:1".equals(ip) ? LOCAL_IP : ip;
41
+    }
42
+
43
+    public static boolean internalIp(String ip) {
44
+        boolean res = false;
45
+        byte[] addr = textToNumericFormatV4(ip);
46
+        if (addr != null && ip != null) {
47
+            res = internalIp(addr) || LOCAL_IP.equals(ip);
48
+        }
49
+        return res;
50
+    }
51
+
52
+    private static boolean internalIp(byte[] addr) {
53
+        final byte b0 = addr[0];
54
+        final byte b1 = addr[1];
55
+        // 10.x.x.x/8
56
+        final byte SECTION_1 = 0x0A;
57
+        // 172.16.x.x/12
58
+        final byte SECTION_2 = (byte) 0xAC;
59
+        final byte SECTION_3 = (byte) 0x10;
60
+        final byte SECTION_4 = (byte) 0x1F;
61
+        // 192.168.x.x/16
62
+        final byte SECTION_5 = (byte) 0xC0;
63
+        final byte SECTION_6 = (byte) 0xA8;
64
+        boolean flag = false;
65
+        switch (b0) {
66
+            case SECTION_1:
67
+                flag = true;
68
+                break;
69
+            case SECTION_2:
70
+                if (b1 >= SECTION_3 && b1 <= SECTION_4) {
71
+                    flag = true;
72
+                }
73
+                break;
74
+            case SECTION_5:
75
+                if (b1 == SECTION_6) {
76
+                    flag = true;
77
+                }
78
+                break;
79
+            default:
80
+                break;
81
+        }
82
+        return flag;
83
+    }
84
+
85
+    /**
86
+     * 将IPv4地址转换成字节
87
+     *IPv4地址
88
+     * @param text
89
+     * @return byte 字节
90
+     */
91
+    public static byte[] textToNumericFormatV4(String text) {
92
+        if (text.length() == 0) {
93
+            return null;
94
+        }
95
+
96
+        byte[] bytes = new byte[4];
97
+        String[] elements = text.split("\\.", -1);
98
+        try {
99
+            long l;
100
+            int i;
101
+            switch (elements.length) {
102
+                case 1:
103
+                    l = Long.parseLong(elements[0]);
104
+                    if ((l < 0L) || (l > 4294967295L))
105
+                        return null;
106
+                    bytes[0] = (byte) (int) (l >> 24 & 0xFF);
107
+                    bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF);
108
+                    bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
109
+                    bytes[3] = (byte) (int) (l & 0xFF);
110
+                    break;
111
+                case 2:
112
+                    l = Integer.parseInt(elements[0]);
113
+                    if ((l < 0L) || (l > 255L))
114
+                        return null;
115
+                    bytes[0] = (byte) (int) (l & 0xFF);
116
+                    l = Integer.parseInt(elements[1]);
117
+                    if ((l < 0L) || (l > 16777215L))
118
+                        return null;
119
+                    bytes[1] = (byte) (int) (l >> 16 & 0xFF);
120
+                    bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
121
+                    bytes[3] = (byte) (int) (l & 0xFF);
122
+                    break;
123
+                case 3:
124
+                    for (i = 0; i < 2; ++i) {
125
+                        l = Integer.parseInt(elements[i]);
126
+                        if ((l < 0L) || (l > 255L))
127
+                            return null;
128
+                        bytes[i] = (byte) (int) (l & 0xFF);
129
+                    }
130
+                    l = Integer.parseInt(elements[2]);
131
+                    if ((l < 0L) || (l > 65535L))
132
+                        return null;
133
+                    bytes[2] = (byte) (int) (l >> 8 & 0xFF);
134
+                    bytes[3] = (byte) (int) (l & 0xFF);
135
+                    break;
136
+                case 4:
137
+                    for (i = 0; i < 4; ++i) {
138
+                        l = Integer.parseInt(elements[i]);
139
+                        if ((l < 0L) || (l > 255L))
140
+                            return null;
141
+                        bytes[i] = (byte) (int) (l & 0xFF);
142
+                    }
143
+                    break;
144
+                default:
145
+                    return null;
146
+            }
147
+        } catch (NumberFormatException e) {
148
+            log.error("数字格式化异常",e);
149
+            return null;
150
+        }
151
+        return bytes;
152
+    }
153
+
154
+    public static String getLocalIP() {
155
+        String ip = "";
156
+        if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
157
+            InetAddress addr;
158
+            try {
159
+                addr = InetAddress.getLocalHost();
160
+                ip = addr.getHostAddress();
161
+            } catch (UnknownHostException e) {
162
+                log.error("获取失败",e);
163
+            }
164
+            return ip;
165
+        } else {
166
+            try {
167
+                Enumeration<?> e1 = (Enumeration<?>) NetworkInterface
168
+                        .getNetworkInterfaces();
169
+                while (e1.hasMoreElements()) {
170
+                    NetworkInterface ni = (NetworkInterface) e1.nextElement();
171
+                    if (!ni.getName().equals("eth0")) {
172
+                        continue;
173
+                    } else {
174
+                        Enumeration<?> e2 = ni.getInetAddresses();
175
+                        while (e2.hasMoreElements()) {
176
+                            InetAddress ia = (InetAddress) e2.nextElement();
177
+                            if (ia instanceof Inet6Address)
178
+                                continue;
179
+                            ip = ia.getHostAddress();
180
+                            return ip;
181
+                        }
182
+                        break;
183
+                    }
184
+                }
185
+            } catch (SocketException e) {
186
+                log.error("获取失败",e);
187
+            }
188
+        }
189
+        return "";
190
+    }
191
+}

+ 70
- 0
src/main/java/com/yunzhi/nanyang/common/WxPayUtils.java Ver arquivo

@@ -0,0 +1,70 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
4
+import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
5
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
6
+import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result;
7
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
8
+import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
9
+import com.github.binarywang.wxpay.constant.WxPayConstants;
10
+import com.github.binarywang.wxpay.exception.WxPayException;
11
+import com.github.binarywang.wxpay.service.WxPayService;
12
+import com.yunzhi.nanyang.config.WeixinConfig;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.beans.factory.annotation.Value;
15
+import org.springframework.stereotype.Component;
16
+
17
+import java.time.LocalDateTime;
18
+import java.time.ZoneOffset;
19
+
20
+@Component
21
+public class WxPayUtils {
22
+    @Autowired
23
+    WeixinConfig config;
24
+
25
+    @Autowired
26
+    WxUtils wxUtils;
27
+
28
+    @Value("${yz.default.servBase}")
29
+    String servBase;
30
+
31
+    /**
32
+     * 下单
33
+     * @param request
34
+     * @return
35
+     * @throws Exception
36
+     */
37
+    public WxPayUnifiedOrderV3Result.JsapiResult createOrder(WxPayUnifiedOrderV3Request request) throws WxPayException {
38
+        // 北京时间
39
+        LocalDateTime now = LocalDateTime.now(ZoneOffset.ofHours(8));
40
+        WxPayService payService = wxUtils.getPayService();
41
+
42
+        request.setNotifyUrl(servBase + "/wxpay/notify/order");
43
+
44
+        WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = payService.unifiedOrderV3(TradeTypeEnum.JSAPI, request);
45
+        return wxPayUnifiedOrderV3Result.getPayInfo(TradeTypeEnum.JSAPI, request.getAppid(), request.getMchid(), payService.getConfig().getPrivateKey());
46
+    }
47
+
48
+    /**
49
+     * 订单退款
50
+     * @param request
51
+     * @return
52
+     * @throws Exception
53
+     */
54
+    public WxPayRefundV3Result refund(WxPayRefundV3Request request) throws Exception {
55
+        WxPayService payService = wxUtils.getPayService();
56
+
57
+        request.setNotifyUrl(servBase + "/wxpay/notify/refund");
58
+        WxPayRefundV3Result result = payService.refundV3(request);
59
+
60
+        if ("ABNORMAL".equals(result.getStatus())) {
61
+            throw new Exception("退款异常");
62
+        }
63
+        if ("CLOSED".equals(result.getStatus())) {
64
+            throw new Exception("退款关闭");
65
+        }
66
+
67
+        return result;
68
+    }
69
+
70
+}

+ 39
- 1
src/main/java/com/yunzhi/nanyang/common/WxUtils.java Ver arquivo

@@ -3,6 +3,10 @@ package com.yunzhi.nanyang.common;
3 3
 import cn.binarywang.wx.miniapp.api.WxMaService;
4 4
 import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
5 5
 import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
6
+import com.github.binarywang.wxpay.config.WxPayConfig;
7
+import com.github.binarywang.wxpay.constant.WxPayConstants;
8
+import com.github.binarywang.wxpay.service.WxPayService;
9
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
6 10
 import com.yunzhi.nanyang.config.WeixinConfig;
7 11
 import com.yunzhi.nanyang.entity.SysMiniapp;
8 12
 import com.yunzhi.nanyang.service.ISysMiniappService;
@@ -11,21 +15,27 @@ import org.springframework.stereotype.Component;
11 15
 
12 16
 @Component
13 17
 public class WxUtils {
18
+    //
19
+    private final WeixinConfig config;
14 20
     // 农机手小程序
15 21
     private static WxMaService workerService;
16 22
     // 农户小程序
17 23
     private static WxMaService farmerService;
24
+    // 微信支付
25
+    private static WxPayService payService;
18 26
 
19 27
     // 此处不能使用变量注入方式, 否则会是 null
20 28
     ISysMiniappService iSysMiniappService;
21 29
 
22 30
     @Autowired
23
-    public WxUtils(ISysMiniappService iSysMiniappService) {
31
+    public WxUtils(ISysMiniappService iSysMiniappService, WeixinConfig config) {
24 32
         this.iSysMiniappService = iSysMiniappService;
33
+        this.config = config;
25 34
 
26 35
         try {
27 36
             setWorkerService();
28 37
             setFarmerService();
38
+            setPayService();
29 39
         } catch (Exception e) {
30 40
             e.printStackTrace();
31 41
         }
@@ -81,4 +91,32 @@ public class WxUtils {
81 91
         service.setWxMaConfig(conf);
82 92
         return service;
83 93
     }
94
+
95
+    public WxPayService getPayService() {
96
+        if (payService == null) {
97
+            setPayService();
98
+        }
99
+
100
+        return payService;
101
+    }
102
+
103
+    private void setPayService() {
104
+        WxPayConfig payConfig = new WxPayConfig();
105
+        payConfig.setAppId(config.getPay().getAppId());
106
+        payConfig.setMchId(config.getPay().getMchId());
107
+        payConfig.setMchKey(config.getPay().getMchKey());
108
+        payConfig.setSubAppId(config.getPay().getSubAppId());
109
+        payConfig.setSubMchId(config.getPay().getSubMchId());
110
+        payConfig.setKeyPath(config.getPay().getKeyPath());
111
+        payConfig.setApiV3Key(config.getPay().getApiV3Key());
112
+        payConfig.setPrivateKeyPath(config.getPay().getPrivateKeyPath());
113
+        payConfig.setPrivateCertPath(config.getPay().getPrivateCertPath());
114
+        // 固定小程序支付
115
+        payConfig.setTradeType(WxPayConstants.TradeType.JSAPI);
116
+        // 可以指定是否使用沙箱环境
117
+        payConfig.setUseSandboxEnv(false);
118
+
119
+        payService = new WxPayServiceImpl();
120
+        payService.setConfig(payConfig);
121
+    }
84 122
 }

+ 23
- 7
src/main/java/com/yunzhi/nanyang/config/WeixinConfig.java Ver arquivo

@@ -10,15 +10,31 @@ import org.springframework.stereotype.Component;
10 10
 @ConfigurationProperties(prefix = "weixin")
11 11
 public class WeixinConfig {
12 12
 
13
+//    @NestedConfigurationProperty
14
+//    private Miniapp miniapp = new Miniapp();
15
+
13 16
     @NestedConfigurationProperty
14
-    private Miniapp miniapp = new Miniapp();
17
+    private Pay pay = new Pay();
18
+
19
+//    @Data
20
+//    public static class Miniapp {
21
+//        private String appid;
22
+//        private String secret;
23
+//        private String token;
24
+//        private String aesKey;
25
+//        private String msgDataFormat;
26
+//    }
15 27
 
16 28
     @Data
17
-    public static class Miniapp {
18
-        private String appid;
19
-        private String secret;
20
-        private String token;
21
-        private String aesKey;
22
-        private String msgDataFormat;
29
+    public static class Pay {
30
+        private String appId;
31
+        private String mchId;
32
+        private String mchKey;
33
+        private String subAppId;
34
+        private String subMchId;
35
+        private String apiV3Key;
36
+        private String keyPath;
37
+        private String privateKeyPath;
38
+        private String privateCertPath;
23 39
     }
24 40
 }

+ 3
- 2
src/main/java/com/yunzhi/nanyang/controller/TaDispatchController.java Ver arquivo

@@ -75,6 +75,7 @@ public class TaDispatchController extends BaseController {
75 75
                                        @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
76 76
                                        @ApiParam("机构") @RequestParam(value ="orgId", required = false) String orgId,
77 77
                                        @ApiParam("农机") @RequestParam(value ="machineryId", required = false) String machineryId,
78
+                                       @ApiParam("农机类型") @RequestParam(value ="typeId", required = false) String typeId,
78 79
                                        @ApiParam(value = "预约开始", example = "2022-03-01") @RequestParam(value ="startDate",required = false) String startDate,
79 80
                                        @ApiParam(value = "预约结束", example = "2022-03-31") @RequestParam(value ="endDate",required = false) String endDate,
80 81
                                        @ApiParam("手机号") @RequestParam(value ="phone",required = false) String phone,
@@ -87,12 +88,12 @@ public class TaDispatchController extends BaseController {
87 88
             }
88 89
         }
89 90
 
90
-        IPage<TaDispatch> pg = new Page<>(pageNum, pageSize);
91
+        IPage<TaOrder> pg = new Page<>(pageNum, pageSize);
91 92
 
92 93
         LocalDateTime start = DateUtils.getDayStart(startDate);
93 94
         LocalDateTime end = DateUtils.getDayEnd(endDate);
94 95
 
95
-        IPage<TaDispatch> result = iTaDispatchService.getPageBy(pg, orgId, machineryId, start, end, phone, status);
96
+        IPage<TaOrder> result = iTaDispatchService.getPageBy(pg, orgId, typeId, machineryId, start, end, phone, status);
96 97
         return ResponseBean.success(result);
97 98
     }
98 99
 

+ 3
- 11
src/main/java/com/yunzhi/nanyang/controller/TaMachineryController.java Ver arquivo

@@ -74,23 +74,15 @@ public class TaMachineryController extends BaseController {
74 74
         SysUser sysUser = currentUser();
75 75
         boolean isAdmin = Constants.ADMIN_ID.equals(sysUser.getUserId());
76 76
 
77
-        if (!StringUtils.isEmpty(orgId)) {
77
+        if (!StringUtils.isEmpty(orgId) && !isAdmin) {
78 78
             if (!checkOrgAccess(orgId, sysUser.getUserId())) {
79 79
                 return ResponseBean.error("无权限操作");
80 80
             }
81 81
         }
82 82
 
83 83
         IPage<TaMachinery> pg = new Page<>(pageNum, pageSize);
84
-        QueryWrapper<TaMachinery> queryWrapper = new QueryWrapper<>();
85
-        queryWrapper.like(!StringUtils.isEmpty(name), "name", "%" + name + "%");
86
-        queryWrapper.eq(!StringUtils.isEmpty(typeId), "type_id", typeId);
87
-        queryWrapper.in(!isAdmin, "org_id", getAccessOrgs(sysUser.getUserId()));
88
-        queryWrapper.eq(!StringUtils.isEmpty(orgId), "org_id", orgId);
89
-        queryWrapper.gt("status", Constants.STATUS_DELETE);
90
-        queryWrapper.eq(null != status, "status", status);
91
-        queryWrapper.orderByDesc("create_date");
92
-
93
-        IPage<TaMachinery> result = iTaMachineryService.page(pg, queryWrapper);
84
+
85
+        IPage<TaMachinery> result = iTaMachineryService.getPageBy(pg, name, typeId, orgId, status);
94 86
         return ResponseBean.success(result);
95 87
     }
96 88
 

+ 27
- 8
src/main/java/com/yunzhi/nanyang/controller/TaOrderController.java Ver arquivo

@@ -3,10 +3,8 @@ package com.yunzhi.nanyang.controller;
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
-import com.yunzhi.nanyang.common.BaseController;
7
-import com.yunzhi.nanyang.common.Constants;
8
-import com.yunzhi.nanyang.common.ResponseBean;
9
-import com.yunzhi.nanyang.common.StringUtils;
6
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
7
+import com.yunzhi.nanyang.common.*;
10 8
 import com.yunzhi.nanyang.entity.*;
11 9
 import com.yunzhi.nanyang.service.*;
12 10
 import io.swagger.annotations.Api;
@@ -22,6 +20,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
22 20
 import org.springframework.web.bind.annotation.RequestParam;
23 21
 import org.springframework.web.bind.annotation.RestController;
24 22
 
23
+import javax.servlet.http.HttpServletRequest;
24
+
25 25
 /**
26 26
  * <p>
27 27
     * 订单表 前端控制器
@@ -53,6 +53,9 @@ public class TaOrderController extends BaseController {
53 53
     @Autowired
54 54
     public ITaMachineryService iTaMachineryService;
55 55
 
56
+    @Autowired
57
+    public ITaPayService iTaPayService;
58
+
56 59
     /**
57 60
      * 分页查询列表
58 61
      * @param pageNum
@@ -62,12 +65,27 @@ public class TaOrderController extends BaseController {
62 65
     @RequestMapping(value="/admin/order",method= RequestMethod.GET)
63 66
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
64 67
     public ResponseBean getList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
65
-                                @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
68
+                                @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
69
+                                @ApiParam("机构") @RequestParam(value ="orgId", required = false) String orgId,
70
+                                @ApiParam("农机") @RequestParam(value ="machineryId", required = false) String machineryId,
71
+                                @ApiParam("类型") @RequestParam(value ="typeId", required = false) String typeId,
72
+                                @ApiParam("下单人") @RequestParam(value ="personName", required = false) String personName,
73
+                                @ApiParam("手机号") @RequestParam(value ="phone", required = false) String phone,
74
+                                @ApiParam("付款状态") @RequestParam(value ="payStatus", required = false) Integer payStatus,
75
+                                @ApiParam("调度状态") @RequestParam(value ="dispatchStatus", required = false) Integer dispatchStatus,
76
+                                @ApiParam("作业状态") @RequestParam(value ="workStatus", required = false) Integer workStatus,
77
+                                @ApiParam("评价状态") @RequestParam(value ="isEvaluated", required = false) Integer isEvaluated) throws Exception{
66 78
         SysUser current = currentUser();
67 79
         boolean isAdmin = Constants.ADMIN_ID.equals(current.getUserId());
68
-        IPage<TaOrder> pg = new Page<>(pageNum, pageSize);
69 80
 
70
-        IPage<TaOrder> result = iTaOrderService.getAdminPage(pg, isAdmin ? null : current);
81
+        if (!isAdmin && !StringUtils.isEmpty(orgId)) {
82
+            if (!checkOrgAccess(orgId, current.getUserId())) {
83
+                return ResponseBean.error("无机构查询权限");
84
+            }
85
+        }
86
+
87
+        IPage<TaOrder> pg = new Page<>(pageNum, pageSize);
88
+        IPage<TaOrder> result = iTaOrderService.getAdminPage(pg, isAdmin ? null : current, orgId, machineryId, typeId, personName, phone, payStatus, dispatchStatus, workStatus, isEvaluated);
71 89
         return ResponseBean.success(result);
72 90
     }
73 91
 
@@ -118,7 +136,8 @@ public class TaOrderController extends BaseController {
118 136
     @ApiOperation(value="生成订单", notes = "生成订单", httpMethod = "POST", response = ResponseBean.class)
119 137
     public ResponseBean taOrderAdd(@ApiParam("客户端") @PathVariable String client,
120 138
                                    @ApiParam("客户端ID") @PathVariable String clientId,
121
-                                   @ApiParam("保存内容") @RequestBody TaOrder taOrder) throws Exception{
139
+                                   @ApiParam("保存内容") @RequestBody TaOrder taOrder,
140
+                                   HttpServletRequest request) throws Exception{
122 141
         TaPerson taPerson = currentPerson();
123 142
 
124 143
         String orderNo = iTaOrderService.getNextOrderNO();

+ 78
- 0
src/main/java/com/yunzhi/nanyang/controller/TaPayController.java Ver arquivo

@@ -0,0 +1,78 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
4
+import com.yunzhi.nanyang.common.BaseController;
5
+import com.yunzhi.nanyang.common.Constants;
6
+import com.yunzhi.nanyang.common.ResponseBean;
7
+import com.yunzhi.nanyang.common.StringUtils;
8
+import com.yunzhi.nanyang.entity.TaOrder;
9
+import com.yunzhi.nanyang.service.ITaOrderService;
10
+import com.yunzhi.nanyang.service.ITaPayService;
11
+import io.swagger.annotations.Api;
12
+import io.swagger.annotations.ApiOperation;
13
+import io.swagger.annotations.ApiParam;
14
+import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.web.bind.annotation.*;
16
+
17
+import java.util.HashMap;
18
+import java.util.Map;
19
+
20
+@Api(tags = "支付")
21
+@RestController
22
+@RequestMapping("/")
23
+public class TaPayController extends BaseController {
24
+
25
+    @Autowired
26
+    ITaPayService iTaPayService;
27
+
28
+    @Autowired
29
+    public ITaOrderService iTaOrderService;
30
+
31
+    @RequestMapping(value="/{client}/{clientId}/order/{id}/prepay",method= RequestMethod.POST)
32
+    @ApiOperation(value="预支付", notes = "预支付", httpMethod = "POST", response = ResponseBean.class)
33
+    public ResponseBean prepay(@ApiParam("客户端") @PathVariable String client,
34
+                               @ApiParam("客户端ID") @PathVariable String clientId,
35
+                               @ApiParam("订单ID") @PathVariable String id,
36
+                               @ApiParam("支付相关") @RequestBody TaOrder payOrder) throws Exception{
37
+        if (null == payOrder || StringUtils.isEmpty(payOrder.getPayType())) {
38
+            return ResponseBean.error("请选择支付方式");
39
+        }
40
+
41
+        TaOrder taOrder = iTaOrderService.getExistBy("order_id", id, false, true);
42
+        if (null == taOrder) {
43
+            return ResponseBean.error("未找到订单信息");
44
+        }
45
+
46
+        // 设置支付方式
47
+        taOrder.setPayType(payOrder.getPayType());
48
+
49
+        if (taOrder.getPayStatus() != Constants.PAY_READY) {
50
+            return ResponseBean.error("订单已支付");
51
+        }
52
+
53
+        WxPayUnifiedOrderV3Result.JsapiResult result = iTaPayService.createPay(client, clientId, taOrder);
54
+        return ResponseBean.success(result);
55
+    }
56
+
57
+
58
+    @RequestMapping(value="/{client}/{clientId}/order/{id}/refund",method= RequestMethod.PUT)
59
+    @ApiOperation(value="申请退款", notes = "申请退款", httpMethod = "PUT", response = ResponseBean.class)
60
+    public ResponseBean refund(@ApiParam("客户端") @PathVariable String client,
61
+                               @ApiParam("客户端ID") @PathVariable String clientId,
62
+                               @ApiParam("订单ID") @PathVariable String id) throws Exception{
63
+        TaOrder taOrder = iTaOrderService.getExistBy("order_id", id, false, true);
64
+        if (null == taOrder) {
65
+            return ResponseBean.error("未找到订单信息");
66
+        }
67
+
68
+        if (taOrder.getPayStatus() != Constants.PAY_PAID) {
69
+            return ResponseBean.error("订单未支付");
70
+        }
71
+        if (taOrder.getWorkStatus() != Constants.WORK_READY) {
72
+            return ResponseBean.error("订单已作业, 不能退款");
73
+        }
74
+
75
+        iTaPayService.refund(client, clientId, taOrder);
76
+        return ResponseBean.success("success");
77
+    }
78
+}

+ 9
- 0
src/main/java/com/yunzhi/nanyang/controller/TaWorkJobController.java Ver arquivo

@@ -107,6 +107,15 @@ public class TaWorkJobController extends BaseController {
107 107
             return ResponseBean.error("非工作状态, 不能操作");
108 108
         }
109 109
 
110
+        TaOrder taOrder = iTaOrderService.getExistBy("order_id", taWorkJob.getOrderId(), false, true);
111
+        if (taOrder == null) {
112
+            return ResponseBean.error("校验订单失败");
113
+        }
114
+
115
+        if (Constants.PAY_PAID != taOrder.getPayStatus()) {
116
+            return ResponseBean.error("订单未支付或者已退款");
117
+        }
118
+
110 119
 //        int status = mode ? Constants.WORK_DOING : Constants.WORK_PAUSE;
111 120
         int status = Constants.WORK_DOING;
112 121
 

+ 48
- 0
src/main/java/com/yunzhi/nanyang/controller/WxPayController.java Ver arquivo

@@ -0,0 +1,48 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.github.binarywang.wxpay.bean.notify.*;
4
+import com.github.binarywang.wxpay.service.WxPayService;
5
+import com.yunzhi.nanyang.common.BaseController;
6
+import com.yunzhi.nanyang.common.WxUtils;
7
+import com.yunzhi.nanyang.service.ITaPayService;
8
+import io.swagger.annotations.Api;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.web.bind.annotation.RequestBody;
11
+import org.springframework.web.bind.annotation.RequestMapping;
12
+import org.springframework.web.bind.annotation.ResponseBody;
13
+import org.springframework.web.bind.annotation.RestController;
14
+
15
+@Api(tags = "微信小程序")
16
+@RestController
17
+@RequestMapping("/wxpay")
18
+public class WxPayController extends BaseController {
19
+
20
+    @Autowired
21
+    WxUtils wxUtils;
22
+
23
+    @Autowired
24
+    ITaPayService orderPayService;
25
+
26
+    @ResponseBody
27
+    @RequestMapping("/notify/order")
28
+    public String payNotify(@RequestBody String jsonData) throws Exception {
29
+        WxPayService payService = wxUtils.getPayService();
30
+        WxPayOrderNotifyV3Result result = payService.parseOrderNotifyV3Result(jsonData, null);
31
+
32
+        orderPayService.notifyOrder(result.getResult());
33
+
34
+        return WxPayNotifyResponse.success("OK");
35
+    }
36
+
37
+    @ResponseBody
38
+    @RequestMapping("/notify/refund")
39
+    public String refundNotify(@RequestBody String jsonData) throws Exception {
40
+        WxPayService payService = wxUtils.getPayService();
41
+        WxPayRefundNotifyV3Result result = payService.parseRefundNotifyV3Result(jsonData, null);
42
+
43
+        orderPayService.refundNotifyOrder(result.getResult());
44
+
45
+        return WxPayNotifyResponse.success("OK");
46
+    }
47
+
48
+}

+ 4
- 0
src/main/java/com/yunzhi/nanyang/entity/TaMachinery.java Ver arquivo

@@ -73,6 +73,10 @@ public class TaMachinery implements Serializable {
73 73
     @ApiModelProperty(value = "机构ID")
74 74
     private String orgId;
75 75
 
76
+    @TableField(exist = false)
77
+    @ApiModelProperty(value = "机构名称")
78
+    private String orgName;
79
+
76 80
     @ApiModelProperty(value = "工作状态")
77 81
     private String jobStatus;
78 82
 

+ 3
- 0
src/main/java/com/yunzhi/nanyang/entity/TaOrder.java Ver arquivo

@@ -90,6 +90,9 @@ public class TaOrder implements Serializable {
90 90
     @ApiModelProperty(value = "是否评价")
91 91
     private Integer isEvaluated;
92 92
 
93
+    @ApiModelProperty(value = "支付端")
94
+    private String payType;
95
+
93 96
     @ApiModelProperty(value = "是否退单")
94 97
     private Integer isRefund;
95 98
 

+ 38
- 3
src/main/java/com/yunzhi/nanyang/entity/TaPay.java Ver arquivo

@@ -3,6 +3,8 @@ package com.yunzhi.nanyang.entity;
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import com.baomidou.mybatisplus.annotation.TableId;
5 5
 import java.io.Serializable;
6
+import java.time.LocalDateTime;
7
+
6 8
 import io.swagger.annotations.ApiModel;
7 9
 import io.swagger.annotations.ApiModelProperty;
8 10
 import lombok.Data;
@@ -25,8 +27,41 @@ public class TaPay implements Serializable {
25 27
 
26 28
 	private static final long serialVersionUID = 1L;
27 29
 
28
-	@ApiModelProperty(value = "轮播图Id")
29
-	@TableId(value = "id", type = IdType.INPUT)
30
-	private String id;
30
+	@ApiModelProperty(value = "支付ID")
31
+	@TableId(value = "pay_id", type = IdType.INPUT)
32
+	private String payId;
33
+
34
+	@ApiModelProperty(value = "订单ID")
35
+	private String orderId;
36
+
37
+	@ApiModelProperty(value = "订单号")
38
+	private String orderNo;
39
+
40
+	@ApiModelProperty(value = "支付人")
41
+	private String personId;
42
+
43
+	@ApiModelProperty(value = "支付类型")
44
+	private String payType;
45
+
46
+	@ApiModelProperty(value = "是否退款")
47
+	private Boolean isRefund;
48
+
49
+	@ApiModelProperty(value = "支付结果描述")
50
+	private String message;
51
+
52
+	@ApiModelProperty(value = "支付金额;单位分")
53
+	private Integer charges;
54
+
55
+	@ApiModelProperty(value = "商品描述")
56
+	private String description;
57
+
58
+	@ApiModelProperty(value = "状态")
59
+	private Integer status;
60
+
61
+	@ApiModelProperty(value = "创建时间")
62
+	private LocalDateTime createDate;
63
+
64
+	@ApiModelProperty(value = "支付时间")
65
+	private LocalDateTime payDate;
31 66
 
32 67
 }

+ 9
- 7
src/main/java/com/yunzhi/nanyang/mapper/TaDispatchMapper.java Ver arquivo

@@ -3,6 +3,7 @@ package com.yunzhi.nanyang.mapper;
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.yunzhi.nanyang.entity.TaDispatch;
5 5
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.yunzhi.nanyang.entity.TaOrder;
6 7
 import org.apache.ibatis.annotations.Mapper;
7 8
 import org.apache.ibatis.annotations.Param;
8 9
 
@@ -19,11 +20,12 @@ import java.time.LocalDateTime;
19 20
 @Mapper
20 21
 public interface TaDispatchMapper extends BaseMapper<TaDispatch> {
21 22
 
22
-    IPage<TaDispatch> getPageBy(IPage<TaDispatch> pg,
23
-                                @Param("orgId") String orgId,
24
-                                @Param("machineryId") String machineryId,
25
-                                @Param("start") LocalDateTime start,
26
-                                @Param("end") LocalDateTime end,
27
-                                @Param("phone") String phone,
28
-                                @Param("status") String status);
23
+    IPage<TaOrder> getPageBy(IPage<TaOrder> pg,
24
+                             @Param("orgId") String orgId,
25
+                             @Param("typeId") String typeId,
26
+                             @Param("machineryId") String machineryId,
27
+                             @Param("start") LocalDateTime start,
28
+                             @Param("end") LocalDateTime end,
29
+                             @Param("phone") String phone,
30
+                             @Param("status") String status);
29 31
 }

+ 6
- 0
src/main/java/com/yunzhi/nanyang/mapper/TaMachineryMapper.java Ver arquivo

@@ -36,4 +36,10 @@ public interface TaMachineryMapper extends BaseMapper<TaMachinery> {
36 36
                                         @Param("location") String location,
37 37
                                         @Param("typeId") String typeId,
38 38
                                         @Param("q") String q);
39
+
40
+    IPage<TaMachinery> getPageBy(IPage<TaMachinery> pg,
41
+                                 @Param("name") String name,
42
+                                 @Param("typeId") String typeId,
43
+                                 @Param("orgId") String orgId,
44
+                                 @Param("status") Integer status);
39 45
 }

+ 13
- 1
src/main/java/com/yunzhi/nanyang/mapper/TaOrderMapper.java Ver arquivo

@@ -23,7 +23,17 @@ public interface TaOrderMapper extends BaseMapper<TaOrder> {
23 23
     @Select("SELECT fn_nextval(#{name})")
24 24
     int getNextOrderNO(@Param("name") String name);
25 25
 
26
-    IPage<TaOrder> getAdminPage(IPage<TaOrder> pg, @Param("userId") String userId);
26
+    IPage<TaOrder> getAdminPage(IPage<TaOrder> pg,
27
+                                @Param("userId") String userId,
28
+                                @Param("orgId") String orgId,
29
+                                @Param("machineryId") String machineryId,
30
+                                @Param("typeId") String typeId,
31
+                                @Param("personName") String personName,
32
+                                @Param("phone") String phone,
33
+                                @Param("payStatus") Integer payStatus,
34
+                                @Param("dispatchStatus") Integer dispatchStatus,
35
+                                @Param("workStatus") Integer workStatus,
36
+                                @Param("isEvaluated") Integer isEvaluated);
27 37
 
28 38
     IPage<TaOrder> getClientPage(IPage<TaOrder> pg,
29 39
                                  @Param("personId") String personId,
@@ -35,4 +45,6 @@ public interface TaOrderMapper extends BaseMapper<TaOrder> {
35 45
                                       @Param("q") String q);
36 46
 
37 47
     List<TaOrder> checkMachineryDuty(@Param("machineryId") String machineryId,@Param("appointmentDate") String appointmentDate);
48
+
49
+    int updatePayStatus(@Param("orderId") String orderId, @Param("payStatus") int payStatus);
38 50
 }

+ 9
- 0
src/main/java/com/yunzhi/nanyang/mapper/TaPayMapper.java Ver arquivo

@@ -0,0 +1,9 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.nanyang.entity.TaPay;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+@Mapper
8
+public interface TaPayMapper extends BaseMapper<TaPay> {
9
+}

+ 2
- 1
src/main/java/com/yunzhi/nanyang/service/ITaDispatchService.java Ver arquivo

@@ -3,6 +3,7 @@ package com.yunzhi.nanyang.service;
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.yunzhi.nanyang.entity.TaDispatch;
5 5
 import com.baomidou.mybatisplus.extension.service.IService;
6
+import com.yunzhi.nanyang.entity.TaOrder;
6 7
 
7 8
 import java.time.LocalDateTime;
8 9
 
@@ -16,5 +17,5 @@ import java.time.LocalDateTime;
16 17
  */
17 18
 public interface ITaDispatchService extends IBaseService<TaDispatch> {
18 19
 
19
-    IPage<TaDispatch> getPageBy(IPage<TaDispatch> pg, String orgId, String machineryId, LocalDateTime start, LocalDateTime end, String phone, String status);
20
+    IPage<TaOrder> getPageBy(IPage<TaOrder> pg, String orgId, String typeId, String machineryId, LocalDateTime start, LocalDateTime end, String phone, String status);
20 21
 }

+ 2
- 0
src/main/java/com/yunzhi/nanyang/service/ITaMachineryService.java Ver arquivo

@@ -29,4 +29,6 @@ public interface ITaMachineryService extends IBaseService<TaMachinery> {
29 29
     MachineSummary getSummaryDetail(String machineryId, String location, Boolean attached);
30 30
 
31 31
     boolean updateStatus(String machineryId, String statusColumn, int statusValue);
32
+
33
+    IPage<TaMachinery> getPageBy(IPage<TaMachinery> pg, String name, String typeId, String orgId, Integer status);
32 34
 }

+ 1
- 1
src/main/java/com/yunzhi/nanyang/service/ITaOrderService.java Ver arquivo

@@ -19,7 +19,7 @@ public interface ITaOrderService extends IBaseService<TaOrder> {
19 19
 
20 20
     String getNextOrderNO();
21 21
 
22
-    IPage<TaOrder> getAdminPage(IPage<TaOrder> pg, SysUser sysUser);
22
+    IPage<TaOrder> getAdminPage(IPage<TaOrder> pg, SysUser sysUser, String orgId, String machineryId, String typeId, String personName, String phone, Integer payStatus, Integer dispatchStatus, Integer workStatus, Integer isEvaluated);
23 23
 
24 24
     IPage<TaOrder> getClientPage(IPage<TaOrder> pg, TaPerson taPerson, SysUser sysUser, Integer workStatus, String q);
25 25
 

+ 22
- 0
src/main/java/com/yunzhi/nanyang/service/ITaPayService.java Ver arquivo

@@ -0,0 +1,22 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
4
+import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyV3Result;
5
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
6
+import com.yunzhi.nanyang.entity.TaOrder;
7
+import com.yunzhi.nanyang.entity.TaPay;
8
+
9
+public interface ITaPayService extends IBaseService<TaPay> {
10
+
11
+    WxPayUnifiedOrderV3Result.JsapiResult createPay(String client, String clientId, TaOrder taOrder) throws Exception;
12
+
13
+    WxPayUnifiedOrderV3Result.JsapiResult prePay(TaPay taPay) throws Exception;
14
+
15
+    TaPay getByOrderNo(String orderNo);
16
+
17
+    void notifyOrder(WxPayOrderNotifyV3Result.DecryptNotifyResult result);
18
+
19
+    void refund(String client, String clientId, TaOrder taOrder) throws Exception;
20
+
21
+    void refundNotifyOrder(WxPayRefundNotifyV3Result.DecryptNotifyResult result);
22
+}

+ 3
- 3
src/main/java/com/yunzhi/nanyang/service/impl/TaDispatchServiceImpl.java Ver arquivo

@@ -2,9 +2,9 @@ package com.yunzhi.nanyang.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.yunzhi.nanyang.entity.TaDispatch;
5
+import com.yunzhi.nanyang.entity.TaOrder;
5 6
 import com.yunzhi.nanyang.mapper.TaDispatchMapper;
6 7
 import com.yunzhi.nanyang.service.ITaDispatchService;
7
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8 8
 import org.springframework.stereotype.Service;
9 9
 
10 10
 import java.time.LocalDateTime;
@@ -21,7 +21,7 @@ import java.time.LocalDateTime;
21 21
 public class TaDispatchServiceImpl extends BaseServiceImpl<TaDispatchMapper, TaDispatch> implements ITaDispatchService {
22 22
 
23 23
     @Override
24
-    public IPage<TaDispatch> getPageBy(IPage<TaDispatch> pg, String orgId, String machineryId, LocalDateTime start, LocalDateTime end, String phone, String status) {
25
-        return baseMapper.getPageBy(pg, orgId, machineryId, start, end, phone, status);
24
+    public IPage<TaOrder> getPageBy(IPage<TaOrder> pg, String orgId, String typeId, String machineryId, LocalDateTime start, LocalDateTime end, String phone, String status) {
25
+        return baseMapper.getPageBy(pg, orgId, typeId, machineryId, start, end, phone, status);
26 26
     }
27 27
 }

+ 5
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TaMachineryServiceImpl.java Ver arquivo

@@ -134,6 +134,11 @@ public class TaMachineryServiceImpl extends BaseServiceImpl<TaMachineryMapper, T
134 134
         return update(updateWrapper);
135 135
     }
136 136
 
137
+    @Override
138
+    public IPage<TaMachinery> getPageBy(IPage<TaMachinery> pg, String name, String typeId, String orgId, Integer status) {
139
+        return baseMapper.getPageBy(pg, name, typeId, orgId, status);
140
+    }
141
+
137 142
     private void saveImages(TaMachinery taMachinery) {
138 143
         String machineryId = taMachinery.getMachineryId();
139 144
         // 先删除所有

+ 2
- 2
src/main/java/com/yunzhi/nanyang/service/impl/TaOrderServiceImpl.java Ver arquivo

@@ -35,9 +35,9 @@ public class TaOrderServiceImpl extends BaseServiceImpl<TaOrderMapper, TaOrder>
35 35
     }
36 36
 
37 37
     @Override
38
-    public IPage<TaOrder> getAdminPage(IPage<TaOrder> pg, SysUser sysUser) {
38
+    public IPage<TaOrder> getAdminPage(IPage<TaOrder> pg, SysUser sysUser, String orgId, String machineryId, String typeId, String personName, String phone, Integer payStatus, Integer dispatchStatus, Integer workStatus, Integer isEvaluated) {
39 39
 
40
-        return baseMapper.getAdminPage(pg, null == sysUser ? null : sysUser.getUserId());
40
+        return baseMapper.getAdminPage(pg, null == sysUser ? null : sysUser.getUserId(), orgId, machineryId, typeId, personName, phone, payStatus, dispatchStatus, workStatus, isEvaluated);
41 41
     }
42 42
 
43 43
     @Override

+ 231
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TaPayServiceImpl.java Ver arquivo

@@ -0,0 +1,231 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
5
+import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyV3Result;
6
+import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
7
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
8
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
9
+import com.github.binarywang.wxpay.constant.WxPayConstants;
10
+import com.github.binarywang.wxpay.constant.WxPayErrorCode;
11
+import com.github.binarywang.wxpay.exception.WxPayException;
12
+import com.yunzhi.nanyang.common.Constants;
13
+import com.yunzhi.nanyang.common.DateUtils;
14
+import com.yunzhi.nanyang.common.StringUtils;
15
+import com.yunzhi.nanyang.common.WxPayUtils;
16
+import com.yunzhi.nanyang.entity.TaOrder;
17
+import com.yunzhi.nanyang.entity.TaPay;
18
+import com.yunzhi.nanyang.mapper.TaOrderMapper;
19
+import com.yunzhi.nanyang.mapper.TaPayMapper;
20
+import com.yunzhi.nanyang.mapper.TaPersonMapper;
21
+import com.yunzhi.nanyang.service.ITaPayService;
22
+import lombok.extern.slf4j.Slf4j;
23
+import org.springframework.beans.factory.annotation.Autowired;
24
+import org.springframework.stereotype.Service;
25
+
26
+import java.time.LocalDateTime;
27
+import java.time.format.DateTimeFormatter;
28
+
29
+@Slf4j
30
+@Service
31
+public class TaPayServiceImpl extends BaseServiceImpl<TaPayMapper, TaPay> implements ITaPayService {
32
+
33
+
34
+    @Autowired
35
+    TaPersonMapper taPersonMapper;
36
+
37
+    @Autowired
38
+    TaOrderMapper taOrderMapper;
39
+
40
+    @Autowired
41
+    WxPayUtils wxPayUtils;
42
+
43
+    @Override
44
+    public WxPayUnifiedOrderV3Result.JsapiResult createPay(String client, String clientId, TaOrder taOrder) throws Exception {
45
+        TaPay taPay = getByOrderNo(taOrder.getOrderNo());
46
+        if (null == taPay) {
47
+            taPay = new TaPay();
48
+            taPay.setOrderId(taOrder.getOrderId());
49
+            taPay.setOrderNo(taOrder.getOrderNo());
50
+            taPay.setPersonId(taOrder.getPersonId());
51
+            taPay.setCharges(taOrder.getCharges());
52
+
53
+            if (taOrder.getTypeName().length() > 127) {
54
+                taPay.setDescription(taOrder.getTypeName().substring(0, 127));
55
+            } else {
56
+                taPay.setDescription(taOrder.getTypeName());
57
+            }
58
+
59
+            taPay.setPayType(taOrder.getPayType());
60
+            taPay.setStatus(Constants.PAY_READY);
61
+        }
62
+
63
+        try {
64
+            WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = prePay(taPay);
65
+            if (StringUtils.isEmpty(taPay.getPayId())) {
66
+                taPay.setPayId(StringUtils.uuid());
67
+                if (!save(taPay)) {
68
+                    throw new Exception("系统出错请重试");
69
+                }
70
+            }
71
+            return jsapiResult;
72
+        } catch (WxPayException e) {
73
+            e.printStackTrace();
74
+
75
+            boolean isPaid = WxPayErrorCode.UnifiedOrder.ORDERPAID.equals(e.getErrCode());
76
+            if (isPaid) {
77
+                // 如果订单已支付
78
+                taPay.setStatus(Constants.PAY_PAID);
79
+                taPay.setPayDate(LocalDateTime.now());
80
+                if (StringUtils.isEmpty(taPay.getPayId())) {
81
+                    taPay.setPayId(StringUtils.uuid());
82
+                    if (!save(taPay)) {
83
+                        throw new Exception("系统出错请重试");
84
+                    }
85
+                } else {
86
+                    updateById(taPay);
87
+                }
88
+                taOrderMapper.updatePayStatus(taPay.getOrderId(), Constants.PAY_PAID);
89
+            }
90
+
91
+            throw e;
92
+        }
93
+    }
94
+
95
+    @Override
96
+    public WxPayUnifiedOrderV3Result.JsapiResult prePay(TaPay taPay) throws WxPayException {
97
+        // 生成订单
98
+        if ("wx".equals(taPay.getPayType())) {
99
+            WxPayUnifiedOrderV3Request.Amount amount = new  WxPayUnifiedOrderV3Request.Amount();
100
+            amount.setTotal(taPay.getCharges());
101
+
102
+            WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
103
+            payer.setOpenid(taPersonMapper.selectById(taPay.getPersonId()).getOpenid());
104
+
105
+            WxPayUnifiedOrderV3Request req = new WxPayUnifiedOrderV3Request();
106
+            req.setDescription(taPay.getDescription());
107
+            req.setOutTradeNo(taPay.getOrderNo());
108
+            req.setAmount(amount);
109
+            req.setPayer(payer);
110
+
111
+            return wxPayUtils.createOrder(req);
112
+        }
113
+
114
+        return null;
115
+    }
116
+
117
+    @Override
118
+    public TaPay getByOrderNo(String orderNo) {
119
+        QueryWrapper<TaPay> queryWrapper = new QueryWrapper<>();
120
+        queryWrapper.eq("order_no", orderNo);
121
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
122
+
123
+        return getOne(queryWrapper);
124
+    }
125
+
126
+    @Override
127
+    public void notifyOrder(WxPayOrderNotifyV3Result.DecryptNotifyResult result) {
128
+        TaPay orderPay = getByOrderNo(result.getOutTradeNo());
129
+        if (orderPay.getStatus() != Constants.PAY_READY) {
130
+            return;
131
+        }
132
+
133
+        boolean isSuccess = WxPayConstants.ResultCode.SUCCESS.equals(result.getTradeState());
134
+
135
+        orderPay.setPayDate(DateUtils.from(result.getSuccessTime(), DateTimeFormatter.ISO_DATE_TIME));
136
+        orderPay.setStatus(isSuccess ? Constants.PAY_PAID : Constants.PAY_FAIL);
137
+        orderPay.setMessage(isSuccess ? null : result.getTradeStateDesc());
138
+        baseMapper.updateById(orderPay);
139
+
140
+        // 更新订单状态
141
+        if (isSuccess) {
142
+            taOrderMapper.updatePayStatus(orderPay.getOrderId(), Constants.PAY_PAID);
143
+        }
144
+
145
+        // 插入账户流水
146
+        // 暂无
147
+    }
148
+
149
+    @Override
150
+    public void refund(String client, String clientId, TaOrder taOrder) throws Exception {
151
+        TaPay origin = getByOrderNo(taOrder.getOrderNo());
152
+        if (null == origin) {
153
+            throw new Exception("未找到支付信息");
154
+        }
155
+
156
+        if (origin.getStatus() != Constants.PAY_PAID) {
157
+            throw new Exception("订单支付校验失败");
158
+        }
159
+
160
+        String refundNo = "R-"+origin.getOrderNo();
161
+        TaPay taPay = getByOrderNo(refundNo);
162
+        if (null == taPay) {
163
+            taPay = new TaPay();
164
+            taPay.setOrderId(taOrder.getOrderId());
165
+            taPay.setOrderNo(refundNo);
166
+            taPay.setPersonId(taOrder.getPersonId());
167
+            taPay.setCharges(taOrder.getCharges());
168
+            taPay.setIsRefund(true);
169
+            taPay.setDescription("退款");
170
+            taPay.setPayType(taOrder.getPayType());
171
+            taPay.setStatus(Constants.PAY_READY);
172
+        }
173
+
174
+        WxPayRefundV3Request request = new WxPayRefundV3Request();
175
+        request.setOutTradeNo(origin.getOrderNo()); // 原单号
176
+        request.setOutRefundNo(taPay.getOrderNo()); // 退款单号
177
+        WxPayRefundV3Request.Amount amount = new  WxPayRefundV3Request.Amount();
178
+        amount.setTotal(taPay.getCharges());
179
+        amount.setRefund(taPay.getCharges());
180
+        amount.setCurrency("CNY");
181
+        request.setAmount(amount);
182
+
183
+        wxPayUtils.refund(request);
184
+        if (StringUtils.isEmpty(taPay.getPayId())) {
185
+            // 退款申请中 ...
186
+            taOrder.setPayStatus(Constants.PAY_REFUNDING);
187
+            taOrderMapper.updateById(taOrder);
188
+
189
+            taPay.setPayId(StringUtils.uuid());
190
+            if (!save(taPay)) {
191
+                throw new Exception("内部错误, 请重新操作");
192
+            }
193
+        }
194
+    }
195
+
196
+    @Override
197
+    public void refundNotifyOrder(WxPayRefundNotifyV3Result.DecryptNotifyResult result) {
198
+        TaPay taPay = getByOrderNo(result.getOutRefundNo());
199
+        if (null == taPay) {
200
+            log.error("退款通知处理失败: 单号 " + result.getOutRefundNo());
201
+            log.error(result.toString());
202
+            return;
203
+        }
204
+
205
+        if (taPay.getStatus() != Constants.PAY_READY) {
206
+            return;
207
+        }
208
+
209
+        boolean isSuccess = WxPayConstants.RefundStatus.SUCCESS.equals(result.getRefundStatus());
210
+
211
+        taPay.setPayDate(DateUtils.from(result.getSuccessTime(), DateTimeFormatter.ISO_DATE_TIME));
212
+        taPay.setStatus(isSuccess ? Constants.PAY_PAID : Constants.PAY_FAIL);
213
+        taPay.setMessage(isSuccess ? null : result.getRefundStatus());
214
+        baseMapper.updateById(taPay);
215
+
216
+        // 更新订单状态
217
+        if (isSuccess) {
218
+            TaOrder taOrder = taOrderMapper.selectById(taPay.getOrderId());
219
+            taOrder.setPayStatus(Constants.PAY_REFUND);
220
+            taOrder.setIsRefund(1);
221
+            taOrder.setStatus(Constants.ORDER_CANCEL);
222
+            taOrderMapper.updateById(taOrder);
223
+        }
224
+
225
+        // 插入账户流水
226
+        // 暂无
227
+
228
+    }
229
+
230
+
231
+}

+ 12
- 0
src/main/resources/application.yml Ver arquivo

@@ -9,6 +9,7 @@ shiro:
9 9
   enabled: true
10 10
   unauthorizedUrl: /api/401
11 11
   filterRuleMap: '{
12
+    "/wxpay/notify/**": "anon",
12 13
     "/**/sms-captcha": "anon",
13 14
     "/admin/login": "anon",
14 15
     "/admin/**": "manager",
@@ -35,6 +36,7 @@ sms:
35 36
 yz:
36 37
   default:
37 38
     password: 888888
39
+    servBase: https://machine.njyunzhi.com/api
38 40
   sms:
39 41
     ## 可以任意名称
40 42
     appid: state-grid-training
@@ -71,6 +73,16 @@ weixin:
71 73
     token:
72 74
     aesKey:
73 75
     msgDataFormat: JSON
76
+  pay:
77
+    appId: wx94f23e5b285c046d
78
+    mchId: 1621038483
79
+    mchKey: #商户密钥
80
+    subAppId: #服务商模式下的子商户公众账号ID
81
+    subMchId: #服务商模式下的子商户号
82
+    apiV3Key: bRygxYHU7hTzNPixgnKbElhmYQDw1C7r
83
+    keyPath:
84
+    privateKeyPath: classpath:cert/apiclient_key.pem
85
+    privateCertPath: classpath:cert/apiclient_cert.pem
74 86
 
75 87
 ###
76 88
 spring:

+ 5
- 2
src/main/resources/mapper/TaDispatchMapper.xml Ver arquivo

@@ -42,10 +42,13 @@
42 42
         <if test="end != null">
43 43
             AND t.appointment_date &lt;= #{end}
44 44
         </if>
45
+        <if test="typeId != null and typeId != ''">
46
+            AND s.type_id = #{typeId}
47
+        </if>
45 48
         <if test="machineryId != null and machineryId != ''">
46
-            AND m.machinery_id = #{machineryId}
49
+            AND s.machinery_id = #{machineryId}
47 50
         </if>
48
-        <if test="machineryId != null and phone != ''">
51
+        <if test="phone != null and phone != ''">
49 52
             AND m.phone LIKE CONCAT( '%', #{phone}, '%' )
50 53
         </if>
51 54
         ORDER BY

+ 24
- 0
src/main/resources/mapper/TaMachineryMapper.xml Ver arquivo

@@ -65,4 +65,28 @@
65 65
         ORDER BY
66 66
             distance ASC
67 67
     </select>
68
+    <select id="getPageBy" resultType="com.yunzhi.nanyang.entity.TaMachinery">
69
+        SELECT
70
+            t.*,
71
+            m.`name` as org_name
72
+        FROM
73
+            ta_machinery t
74
+            INNER JOIN ta_org m ON m.org_id = t.org_id
75
+        WHERE
76
+            t.`status` &gt; -1
77
+        <if test="name != null and name != ''">
78
+            AND t.`name` LIKE CONCAT('%', #{name}, '%')
79
+        </if>
80
+        <if test="typeId != null and typeId != ''">
81
+            AND t.type_id = #{typeId}
82
+        </if>
83
+        <if test="orgId != null and orgId != ''">
84
+            AND t.org_id = #{orgId}
85
+        </if>
86
+        <if test="status != null">
87
+            AND t.status = #{status}
88
+        </if>
89
+        ORDER BY
90
+            t.create_date DESC
91
+    </select>
68 92
 </mapper>

+ 39
- 3
src/main/resources/mapper/TaOrderMapper.xml Ver arquivo

@@ -1,11 +1,19 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.yunzhi.nanyang.mapper.TaOrderMapper">
4
+    <update id="updatePayStatus">
5
+        UPDATE ta_order
6
+        SET pay_status = #{payStatus}
7
+        WHERE
8
+            order_id = #{orderId}
9
+    </update>
4 10
 
5 11
     <select id="getAdminPage" resultType="com.yunzhi.nanyang.entity.TaOrder">
6 12
         SELECT DISTINCT
7 13
             t.*,
8
-            m.`name` as org_name
14
+            m.`name` as org_name,
15
+            n.nick_name as person_name,
16
+            n.phone as phone
9 17
         FROM
10 18
             ta_order t
11 19
             <if test="userId != null and userId != ''">
@@ -13,8 +21,36 @@
13 21
                 AND s.user_id = #{userId}
14 22
             </if>
15 23
             INNER JOIN ta_org m ON m.org_id = t.org_id
24
+            INNER JOIN ta_person n ON n.person_id = t.person_id
16 25
         WHERE
17
-            t.`status` = 1
26
+            t.`status` &gt; 0
27
+        <if test="orgId != null and orgId != ''">
28
+            AND t.org_id = #{orgId}
29
+        </if>
30
+        <if test="machineryId != null and machineryId != ''">
31
+            AND t.machinery_id = #{machineryId}
32
+        </if>
33
+        <if test="typeId != null and typeId != ''">
34
+            AND t.machinery_type = #{typeId}
35
+        </if>
36
+        <if test="payStatus != null">
37
+            AND t.pay_status = #{payStatus}
38
+        </if>
39
+        <if test="dispatchStatus != null">
40
+            AND t.dispatch_status = #{dispatchStatus}
41
+        </if>
42
+        <if test="workStatus != null">
43
+            AND t.work_status = #{workStatus}
44
+        </if>
45
+        <if test="isEvaluated != null">
46
+            AND t.is_evaluated = #{isEvaluated}
47
+        </if>
48
+        <if test="personName != null and personName != ''">
49
+            AND n.nick_name LIKE CONCAT( '%', #{personName}, '%' )
50
+        </if>
51
+        <if test="phone != null and phone != ''">
52
+            AND n.phone LIKE CONCAT( '%', #{phone}, '%' )
53
+        </if>
18 54
         ORDER BY
19 55
             t.create_date DESC
20 56
     </select>
@@ -29,7 +65,7 @@
29 65
             INNER JOIN ta_org m ON m.org_id = t.org_id
30 66
             INNER JOIN ta_person n ON n.person_id = t.person_id
31 67
         WHERE
32
-            t.`status` = 1
68
+            t.`status` &gt; 0
33 69
         <if test="personId != null and personId != ''">
34 70
             AND t.person_id = #{personId}
35 71
         </if>