|
@@ -0,0 +1,667 @@
|
|
1
|
+package com.huiju.estateagents.property.service.impl;
|
|
2
|
+
|
|
3
|
+import com.alibaba.fastjson.JSONObject;
|
|
4
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
5
|
+import com.google.common.collect.Lists;
|
|
6
|
+import com.google.common.collect.Maps;
|
|
7
|
+import com.huiju.estateagents.base.ResponseBean;
|
|
8
|
+import com.huiju.estateagents.center.taUser.entity.TaUser;
|
|
9
|
+import com.huiju.estateagents.center.taUser.mapper.TaUserMapper;
|
|
10
|
+import com.huiju.estateagents.common.wxpay.WXPay;
|
|
11
|
+import com.huiju.estateagents.common.wxpay.WXPayConstants;
|
|
12
|
+import com.huiju.estateagents.common.wxpay.WXPayUtil;
|
|
13
|
+import com.huiju.estateagents.common.wxpay.WxConfig;
|
|
14
|
+import com.huiju.estateagents.entity.TaPerson;
|
|
15
|
+import com.huiju.estateagents.entity.TaWxPayConfig;
|
|
16
|
+import com.huiju.estateagents.mapper.TaPersonMapper;
|
|
17
|
+import com.huiju.estateagents.mapper.TaWxPayConfigMapper;
|
|
18
|
+import com.huiju.estateagents.property.common.Constant;
|
|
19
|
+import com.huiju.estateagents.property.common.UserElement;
|
|
20
|
+import com.huiju.estateagents.property.dao.*;
|
|
21
|
+import com.huiju.estateagents.property.exception.WisdomException;
|
|
22
|
+import com.huiju.estateagents.property.model.*;
|
|
23
|
+import com.huiju.estateagents.property.perproties.PayNotifyPerproties;
|
|
24
|
+import com.huiju.estateagents.property.service.WxPayServiceI;
|
|
25
|
+import org.apache.commons.collections.CollectionUtils;
|
|
26
|
+import org.apache.commons.lang3.StringUtils;
|
|
27
|
+import org.slf4j.Logger;
|
|
28
|
+import org.slf4j.LoggerFactory;
|
|
29
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
30
|
+import org.springframework.context.ApplicationContext;
|
|
31
|
+import org.springframework.stereotype.Service;
|
|
32
|
+import org.springframework.transaction.annotation.Transactional;
|
|
33
|
+
|
|
34
|
+import java.io.ByteArrayOutputStream;
|
|
35
|
+import java.io.InputStream;
|
|
36
|
+import java.math.BigDecimal;
|
|
37
|
+import java.net.HttpURLConnection;
|
|
38
|
+import java.net.URL;
|
|
39
|
+import java.time.Instant;
|
|
40
|
+import java.time.LocalDateTime;
|
|
41
|
+import java.time.ZoneId;
|
|
42
|
+import java.time.ZoneOffset;
|
|
43
|
+import java.util.*;
|
|
44
|
+import java.util.stream.Collectors;
|
|
45
|
+
|
|
46
|
+/**
|
|
47
|
+ * @author FXF
|
|
48
|
+ * @date 2018-10-25
|
|
49
|
+ */
|
|
50
|
+@Service("wxPayService")
|
|
51
|
+@Transactional(rollbackFor = Exception.class)
|
|
52
|
+public class WxPayServiceImpl implements WxPayServiceI {
|
|
53
|
+ private Logger log = LoggerFactory.getLogger(WxPayServiceImpl.class);
|
|
54
|
+
|
|
55
|
+ @Autowired
|
|
56
|
+ private BillInvoiceMapper tpBillInvoiceMapper;
|
|
57
|
+
|
|
58
|
+ @Autowired
|
|
59
|
+ private BillStatementMapper tpBillStatementMapper;
|
|
60
|
+
|
|
61
|
+ @Autowired
|
|
62
|
+ private BillMapper tpBillMapper;
|
|
63
|
+
|
|
64
|
+ @Autowired
|
|
65
|
+ private TaPersonMapper taPersonMapper;
|
|
66
|
+
|
|
67
|
+ @Autowired
|
|
68
|
+ private TaSysRoleMapper taSysRoleMapper;
|
|
69
|
+
|
|
70
|
+ @Autowired
|
|
71
|
+ private MessageMapper tpMessageMapper;
|
|
72
|
+
|
|
73
|
+ @Autowired
|
|
74
|
+ private TpBillOrderMapper tpBillOrderMapper;
|
|
75
|
+
|
|
76
|
+ @Autowired
|
|
77
|
+ private TaUserVerifyMapper taUserVerifyMapper;
|
|
78
|
+
|
|
79
|
+ @Autowired
|
|
80
|
+ private TpBuildingOwnerInfoMapper tpBuildingOwnerInfoMapper;
|
|
81
|
+
|
|
82
|
+ @Autowired
|
|
83
|
+ private PayNotifyPerproties payNotifyPerproties;
|
|
84
|
+
|
|
85
|
+// @Autowired
|
|
86
|
+// private TaUserLicenseOrderMapper taUserLicenseOrderMapper;
|
|
87
|
+
|
|
88
|
+ @Autowired
|
|
89
|
+ private ApplicationContext applicationContext;
|
|
90
|
+
|
|
91
|
+ @Autowired
|
|
92
|
+ private TaWxPayConfigMapper taWxPayConfigMapper;
|
|
93
|
+
|
|
94
|
+// @Autowired
|
|
95
|
+// private IFuShiService iFuShiService;
|
|
96
|
+
|
|
97
|
+// @Autowired
|
|
98
|
+// private TaUserLicenseMapper taUserLicenseMapper;
|
|
99
|
+//
|
|
100
|
+// @Autowired
|
|
101
|
+// private ITaUserLicenseService iTaUserLicenseService;
|
|
102
|
+
|
|
103
|
+// private IdGen idGen = IdGen.get();
|
|
104
|
+
|
|
105
|
+ /**
|
|
106
|
+ * 微信支付统一下单
|
|
107
|
+ *
|
|
108
|
+ * @return
|
|
109
|
+ * @param orderNo
|
|
110
|
+ * @param
|
|
111
|
+ */
|
|
112
|
+ @Override
|
|
113
|
+ @Transactional(rollbackFor = Exception.class)
|
|
114
|
+ public Map<String, String> wxUnifiedOrder(String orderNo, String type, String personId) throws Exception {
|
|
115
|
+ //构建微信配置
|
|
116
|
+ WxConfig config = getWxConfig(1);
|
|
117
|
+ WXPay wxpay = new WXPay(config);
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+ Map<String, Object> orderPriceAndNotifyUrl = getOrderPriceAndNotifyUrl(type, orderNo, "wx");
|
|
121
|
+
|
|
122
|
+ String typeName = Constant.PAY_TYPE_BILL.equals(type) ? "物业缴费" : Constant.PAY_TYPE_CAR.equals(type) ? "车缴费" : "缴费";
|
|
123
|
+
|
|
124
|
+ //下单
|
|
125
|
+ Map<String, String> data = new HashMap<String, String>();
|
|
126
|
+ data.put("body", typeName);
|
|
127
|
+ //商品号唯一
|
|
128
|
+ data.put("out_trade_no", orderNo);
|
|
129
|
+ data.put("device_info", "");
|
|
130
|
+ data.put("fee_type", "CNY");
|
|
131
|
+ //金额 后台计算
|
|
132
|
+ data.put("total_fee", String.valueOf(orderPriceAndNotifyUrl.get("payPrice")));
|
|
133
|
+ //终端IP
|
|
134
|
+ data.put("spbill_create_ip", "123.12.12.123");
|
|
135
|
+ //回调地址
|
|
136
|
+ data.put("notify_url", String.valueOf(orderPriceAndNotifyUrl.get("notifyUrl")));
|
|
137
|
+ // 此处指定为APP支付
|
|
138
|
+ data.put("trade_type", "APP");
|
|
139
|
+ Map<String, String> resp = wxpay.unifiedOrder(data);
|
|
140
|
+ log.info("下单成功:{}", resp);
|
|
141
|
+ if (resp.get("result_code").equalsIgnoreCase(WXPayConstants.FAIL)){
|
|
142
|
+ throw new Exception(resp.get("err_code_des"));
|
|
143
|
+ }
|
|
144
|
+ //插入下单记录表
|
|
145
|
+
|
|
146
|
+ //第二次重新生成签名
|
|
147
|
+ Map<String, String> secondSignData = new HashMap<String, String>();
|
|
148
|
+ long timestamp = Instant.now().getEpochSecond();
|
|
149
|
+ secondSignData.put("appid", config.getAppID());
|
|
150
|
+ secondSignData.put("partnerid", config.getMchID());
|
|
151
|
+ secondSignData.put("prepayid", resp.get("prepay_id"));
|
|
152
|
+ secondSignData.put("noncestr", resp.get("nonce_str"));
|
|
153
|
+ secondSignData.put("timestamp", String.valueOf(timestamp));
|
|
154
|
+ secondSignData.put("package", "Sign=WXPay");
|
|
155
|
+ secondSignData.put("sign", WXPayUtil.generateSignature(secondSignData, config.getKey(), WXPayConstants.SignType.MD5));
|
|
156
|
+
|
|
157
|
+ log.info("订单: {},订单类型: {}, 状态变更为正在支付", orderNo, type);
|
|
158
|
+
|
|
159
|
+ // 更改订单状态 为正在支付
|
|
160
|
+ updateOrderStatus(orderNo, type, "2");
|
|
161
|
+ return secondSignData;
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ /**
|
|
165
|
+ * 根据订单类型获取 金额 和 回调地址
|
|
166
|
+ * @param type
|
|
167
|
+ * @param orderNo
|
|
168
|
+ * @param notifyType wx 微信, ali 支付宝
|
|
169
|
+ * @return
|
|
170
|
+ * @throws Exception
|
|
171
|
+ */
|
|
172
|
+ @Override
|
|
173
|
+ public Map<String,Object> getOrderPriceAndNotifyUrl(String type, String orderNo, String notifyType) throws Exception {
|
|
174
|
+ Map<String,Object> orderMap = Maps.newHashMap();
|
|
175
|
+
|
|
176
|
+ // 物业缴费
|
|
177
|
+ if (Constant.PAY_TYPE_BILL.equals(type)) {
|
|
178
|
+ //获取支付金额
|
|
179
|
+ List<TpBillOrder> billOrderList = tpBillOrderMapper.selectByOrderBumber(orderNo);
|
|
180
|
+ if (CollectionUtils.isEmpty(billOrderList)){
|
|
181
|
+ throw new Exception("订单不存在");
|
|
182
|
+ }
|
|
183
|
+ // 检测订单是否 已关闭
|
|
184
|
+ billOrderList.forEach(e-> {
|
|
185
|
+ if ("3".equals(e.getOrderStatus())) {
|
|
186
|
+ throw new WisdomException("无法支付已关闭的订单!");
|
|
187
|
+ }
|
|
188
|
+ });
|
|
189
|
+ // 计算金额
|
|
190
|
+ Long payPrice = billOrderList.stream().mapToLong(e -> tpBillInvoiceMapper.selectById(e.getTpBillInvoiceId()).getPayPrice()).sum();
|
|
191
|
+ orderMap.put("orderNo", orderNo);
|
|
192
|
+ orderMap.put("payPrice", String.valueOf(payPrice));
|
|
193
|
+ orderMap.put("notifyUrl", "wx".equals(notifyType) ? payNotifyPerproties.getWxBillNotify() : payNotifyPerproties.getAliBillNotify());
|
|
194
|
+
|
|
195
|
+ } else if (Constant.PAY_TYPE_CAR.equals(type)) { // 车缴费
|
|
196
|
+// List<TaUserLicenseOrder> userLicenseOrders = taUserLicenseOrderMapper.selectByOrderNumber(orderNo);
|
|
197
|
+// if (CollectionUtils.isEmpty(userLicenseOrders)) {
|
|
198
|
+// throw new Exception("订单不存在");
|
|
199
|
+// }
|
|
200
|
+// // 检测订单是否 已关闭
|
|
201
|
+// userLicenseOrders.forEach(e-> {
|
|
202
|
+// if ("3".equals(e.getOrderStatus())) {
|
|
203
|
+// throw new WisdomException("无法支付已关闭的订单!");
|
|
204
|
+// }
|
|
205
|
+// });
|
|
206
|
+//
|
|
207
|
+// // 总额
|
|
208
|
+// Long payPrice = userLicenseOrders.stream().map(e -> Long.parseLong(e.getExtensionPrice())).count();
|
|
209
|
+// orderMap.put("orderNo", orderNo);
|
|
210
|
+// orderMap.put("payPrice", String.valueOf(payPrice));
|
|
211
|
+// orderMap.put("notifyUrl", "wx".equals(notifyType) ? payNotifyPerproties.getWxCarNotify() : payNotifyPerproties.getAliCarNotify());
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ return orderMap;
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+ /**
|
|
221
|
+ * 支付成功的回调
|
|
222
|
+ *
|
|
223
|
+ * @return
|
|
224
|
+ * @param resultMap
|
|
225
|
+ */
|
|
226
|
+ @Override
|
|
227
|
+ @Transactional(rollbackFor = Exception.class)
|
|
228
|
+ public String wxBillNotify(Map<String, String> resultMap) throws Exception {
|
|
229
|
+ String outTradeNo = resultMap.get("out_trade_no");
|
|
230
|
+ List<TpBillOrder> billOrderList = tpBillOrderMapper.selectByOrderBumber(outTradeNo);
|
|
231
|
+ if (CollectionUtils.isEmpty(billOrderList)){
|
|
232
|
+ return "不存在的订单";
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ // 缴费人在准备支付状态下更新, 这里是微信的回调所有没有 token
|
|
236
|
+
|
|
237
|
+ for ( TpBillOrder billOrder : billOrderList){
|
|
238
|
+ BillInvoice tpBillInvoice = tpBillInvoiceMapper.selectById(billOrder.getTpBillInvoiceId());
|
|
239
|
+
|
|
240
|
+ // 更新为正在支付状态
|
|
241
|
+ // 更改收费单的 缴费时间, 修改人, 修改时间
|
|
242
|
+ tpBillInvoice.setBillStatus("1");
|
|
243
|
+ tpBillInvoice.setPayDate(new Date());
|
|
244
|
+ tpBillInvoice.setUpdateDate(new Date());
|
|
245
|
+ // 缴费方式 0:微信支付 1:线下缴费 2.支付宝支付
|
|
246
|
+ tpBillInvoice.setPayType(resultMap.get("pay_type"));
|
|
247
|
+ tpBillInvoiceMapper.updateById(tpBillInvoice);
|
|
248
|
+
|
|
249
|
+ //插入流水账单表
|
|
250
|
+ BillStatement tpBillStatement = new BillStatement();
|
|
251
|
+ tpBillStatement.setBillInvoiceId(tpBillInvoice.getId());
|
|
252
|
+ tpBillStatement.setOrgId(1);
|
|
253
|
+ tpBillStatement.setTaUserId(tpBillInvoice.getTaUserId());
|
|
254
|
+ tpBillStatement.setPayPrice(tpBillInvoice.getPayPrice());
|
|
255
|
+ tpBillStatement.setPayName(tpBillInvoice.getPayName());
|
|
256
|
+ tpBillStatement.setPayRemark(tpBillInvoice.getBillInvoiceExplain());
|
|
257
|
+ tpBillStatement.setPayType(resultMap.get("pay_type"));
|
|
258
|
+ tpBillStatement.setCreateTime(new Date());
|
|
259
|
+ tpBillStatementMapper.insert(tpBillStatement);
|
|
260
|
+
|
|
261
|
+ // 更新 收费单流水id
|
|
262
|
+ tpBillInvoice.setBillStatementId(tpBillStatement.getId());
|
|
263
|
+ tpBillInvoiceMapper.updateById(tpBillInvoice);
|
|
264
|
+
|
|
265
|
+ // 更新收费组的 未交费用户数 和 已缴费用户数
|
|
266
|
+ Bill tpBill = tpBillMapper.selectById(tpBillInvoice.getBillId());
|
|
267
|
+ tpBill.setPayedNum(tpBill.getPayedNum() + 1);
|
|
268
|
+ tpBill.setUnpayedNum(tpBill.getUnpayedNum() - 1);
|
|
269
|
+ // 如果为零, 表示这个收费组收费完成
|
|
270
|
+ if (tpBill.getUnpayedNum() <= 0) {
|
|
271
|
+ tpBill.setBillStatus("1");
|
|
272
|
+ tpBill.setUnpayedNum(0);
|
|
273
|
+ }
|
|
274
|
+ tpBillMapper.updateById(tpBill);
|
|
275
|
+
|
|
276
|
+ // 把相对应的APP端, 代办消息设置为无效
|
|
277
|
+// Map<String, Object> map = Maps.newHashMap();
|
|
278
|
+// map.put("communityId", tpBillInvoice.getCommunityId());
|
|
279
|
+// map.put("billInvoiceId", tpBillInvoice.getId());
|
|
280
|
+// map.put("userId", tpBillInvoice.getTaUserId());
|
|
281
|
+// TpMessage tpMessage = tpMessageMapper.selectBillinvoiceMessage(map);
|
|
282
|
+// tpMessage.setStatus("0");
|
|
283
|
+// tpMessageMapper.updateByPrimaryKeySelective(tpMessage);
|
|
284
|
+ }
|
|
285
|
+
|
|
286
|
+ log.info("订单: {},订单类型: {}, 状态变更为支付成功", outTradeNo, Constant.PAY_TYPE_BILL);
|
|
287
|
+
|
|
288
|
+ // 更改订单状态 为支付成功
|
|
289
|
+ updateOrderStatus(outTradeNo, Constant.PAY_TYPE_BILL, "1");
|
|
290
|
+
|
|
291
|
+ // 只取第一条根据订单号去匹配列表
|
|
292
|
+ TpBillOrder tpBillOrder = billOrderList.get(0);
|
|
293
|
+ BillInvoice tpBillInvoice = tpBillInvoiceMapper.selectById(tpBillOrder.getTpBillInvoiceId());
|
|
294
|
+// List<TpUser> tpUserList= tpUserMapper.selectCommunityId(tpBillOrder.getCommunityId());
|
|
295
|
+//
|
|
296
|
+// // 推物业端,推这个小区下的所有管理员
|
|
297
|
+// TaUser taUser= taUserMapper.selectByPrimaryKey(tpBillOrder.getCreateUser());
|
|
298
|
+// for (TpUser tpUser:tpUserList) {
|
|
299
|
+// Map<String, Object> mapProp = new HashMap<>();
|
|
300
|
+// mapProp.put("communityId", tpBillOrder.getCommunityId());
|
|
301
|
+// mapProp.put("tpUserId", tpUser.getId());
|
|
302
|
+// mapProp.put("createUserId", tpBillOrder.getCreateUser());
|
|
303
|
+// mapProp.put("billInvoiceId", tpBillOrder.getId());
|
|
304
|
+// mapProp.put("name", taUser.getUserName());
|
|
305
|
+// applicationContext.publishEvent(new MessageEvent(mapProp, Constant.PAY_TYPE_SUCCEED, mapProp));
|
|
306
|
+// }
|
|
307
|
+ return "success";
|
|
308
|
+ }
|
|
309
|
+
|
|
310
|
+ /**
|
|
311
|
+ * 订单查询
|
|
312
|
+ *
|
|
313
|
+ * @return
|
|
314
|
+ */
|
|
315
|
+ @Override
|
|
316
|
+ public Map<String, String> wxOrderQuery(String outTradeNo) throws Exception {
|
|
317
|
+ WxConfig config = getWxConfig(1);
|
|
318
|
+ WXPay wxpay = new WXPay(config);
|
|
319
|
+
|
|
320
|
+ Map<String, String> data = new HashMap<String, String>();
|
|
321
|
+ data.put("out_trade_no", outTradeNo);
|
|
322
|
+ return wxpay.orderQuery(data);
|
|
323
|
+ }
|
|
324
|
+
|
|
325
|
+ @Override
|
|
326
|
+ @Transactional(rollbackFor = Exception.class)
|
|
327
|
+ public String wxStartPay(List<Integer> idArray, String type, Integer extensionMonth, String personId) throws Exception {
|
|
328
|
+ if (StringUtils.isBlank(type)) {
|
|
329
|
+ throw new WisdomException("type 不能为空!");
|
|
330
|
+ }
|
|
331
|
+
|
|
332
|
+ // 缴费的用户
|
|
333
|
+ TaPerson taPerson = taPersonMapper.selectById(personId);
|
|
334
|
+
|
|
335
|
+ Random random = new Random();
|
|
336
|
+ String orderNo = String.valueOf(System.currentTimeMillis()) + random.nextInt();
|
|
337
|
+
|
|
338
|
+ // 创建订单
|
|
339
|
+ createOrder(idArray, type, taPerson, personId, orderNo, extensionMonth, null);
|
|
340
|
+
|
|
341
|
+ return orderNo;
|
|
342
|
+ }
|
|
343
|
+
|
|
344
|
+ /**
|
|
345
|
+ * 创建订单
|
|
346
|
+ * @param idArray
|
|
347
|
+ * @param type
|
|
348
|
+ * @param orderNo
|
|
349
|
+ * @param extensionMonth 延期月份,也就是延期几个月!
|
|
350
|
+ * 只有在 车缴费的时候才有效
|
|
351
|
+ * @param paymentType 缴费方式 1是支付宝 2是微信支付
|
|
352
|
+ * @throws Exception
|
|
353
|
+ */
|
|
354
|
+ private void createOrder(List<Integer> idArray, String type, TaPerson taPerson, String personId, String orderNo, Integer extensionMonth, String paymentType) throws Exception {
|
|
355
|
+ // 物业缴费
|
|
356
|
+ if (Constant.PAY_TYPE_BILL.equals(type)) {
|
|
357
|
+ //获取支付金额
|
|
358
|
+ for (Integer billInvoiceId : idArray) {
|
|
359
|
+ BillInvoice tpBillInvoice = tpBillInvoiceMapper.selectById(billInvoiceId);
|
|
360
|
+ if (null == tpBillInvoice){
|
|
361
|
+ throw new Exception("订单不存在");
|
|
362
|
+ }else if (!tpBillInvoice.getBillStatus().equals("0")){
|
|
363
|
+ throw new Exception("正在支付的订单");
|
|
364
|
+ }
|
|
365
|
+
|
|
366
|
+ TpBillOrder tpBillOrder = new TpBillOrder();
|
|
367
|
+ tpBillOrder.setOrgId(1);
|
|
368
|
+ tpBillOrder.setTpBillId(tpBillInvoice.getBillId());
|
|
369
|
+ tpBillOrder.setTpBillInvoiceId(tpBillInvoice.getId());
|
|
370
|
+ tpBillOrder.setCreateDate(LocalDateTime.now());
|
|
371
|
+ tpBillOrder.setCreateUser(personId);
|
|
372
|
+ tpBillOrder.setUpdateDate(LocalDateTime.now());
|
|
373
|
+ tpBillOrder.setUpdateUser(personId);
|
|
374
|
+ tpBillOrder.setOrderBumber(orderNo);
|
|
375
|
+ tpBillOrder.setPayPhone(taPerson.getPhone());
|
|
376
|
+ tpBillOrder.setOrderStatus("0");
|
|
377
|
+
|
|
378
|
+ tpBillOrderMapper.insert(tpBillOrder);
|
|
379
|
+
|
|
380
|
+ }
|
|
381
|
+ // 修改缴费人, 修改为正在缴费
|
|
382
|
+ updateBillInvoiceBillStatus(idArray, taPerson.getName(), "3");
|
|
383
|
+
|
|
384
|
+ // 车缴费
|
|
385
|
+ } else if (Constant.PAY_TYPE_CAR.equals(type)) {
|
|
386
|
+// if (null == extensionMonth || extensionMonth <= 0) {
|
|
387
|
+// throw new Exception("延期月份不能为空,并且要大于0!");
|
|
388
|
+// }
|
|
389
|
+//
|
|
390
|
+// for (Integer clicenseId : idArray) {
|
|
391
|
+// // 根据车牌id,查询车牌
|
|
392
|
+// TaUserLicense taUserLicense = taUserLicenseMapper.selectByPrimaryKey(clicenseId);
|
|
393
|
+// // 获取车牌最新信息
|
|
394
|
+// ResponseBean responseLicense = iTaUserLicenseService.getLicense(userElement, taUserLicense.getLicensePlate());
|
|
395
|
+// Object licenseData = responseLicense.getData();
|
|
396
|
+// if (null != licenseData && licenseData instanceof TaUserLicense) {
|
|
397
|
+// taUserLicense = (TaUserLicense) licenseData;
|
|
398
|
+// }
|
|
399
|
+//
|
|
400
|
+// // 校验车状态
|
|
401
|
+// if (taUserLicense.getLicenseType().intValue() != 1) {
|
|
402
|
+// throw new WisdomException("异常状态,不能缴月租费!");
|
|
403
|
+// }
|
|
404
|
+//
|
|
405
|
+// // 校验是否,超出缴费有效期时间
|
|
406
|
+// LocalDateTime expireDateLocalDateTime = LocalDateTime.ofInstant(taUserLicense.getExpireDate().toInstant(), ZoneId.systemDefault());
|
|
407
|
+// expireDateLocalDateTime.plusDays(taUserLicense.getRenewTime());
|
|
408
|
+// if (taUserLicense.getRenewTime().intValue() > 0 && System.currentTimeMillis() > expireDateLocalDateTime.toEpochSecond(ZoneOffset.of("+8"))) {
|
|
409
|
+// throw new WisdomException("已超出续费时间,请找物业处理!");
|
|
410
|
+// }
|
|
411
|
+//
|
|
412
|
+// TaUserLicenseOrder taUserLicenseOrder = new TaUserLicenseOrder();
|
|
413
|
+// taUserLicenseOrder.setCommunityId(userElement.getCommunityId());
|
|
414
|
+// taUserLicenseOrder.setTaUserId(userElement.getId());
|
|
415
|
+// taUserLicenseOrder.setOrderNumber(orderNo);
|
|
416
|
+// taUserLicenseOrder.setOrderStatus("0");
|
|
417
|
+// taUserLicenseOrder.setCreateDate(new Date());
|
|
418
|
+// taUserLicenseOrder.setCreateUser(userElement.getId());
|
|
419
|
+// taUserLicenseOrder.setExtensionMonth(extensionMonth);
|
|
420
|
+//
|
|
421
|
+// // 费用
|
|
422
|
+// String extensionPrice = BigDecimal.valueOf(Double.valueOf(taUserLicense.getUnitPrice()) / 100).multiply(BigDecimal.valueOf(extensionMonth)).toString();
|
|
423
|
+// String price = String.valueOf(Double.valueOf(extensionPrice) * 100);
|
|
424
|
+// taUserLicenseOrder.setExtensionPrice(price.substring(0, price.lastIndexOf(".")));
|
|
425
|
+//
|
|
426
|
+// taUserLicenseOrder.setPaymentTel(taUser.getLoginName());
|
|
427
|
+// taUserLicenseOrder.setPaymentName(taUser.getUserName());
|
|
428
|
+// taUserLicenseOrder.setPaymentType(paymentType);
|
|
429
|
+//
|
|
430
|
+// // 到期时间 (具体的到期时候,在支付回调里面以车辆管理系统为准)
|
|
431
|
+// LocalDateTime localDateTime = LocalDateTime.ofInstant(taUserLicense.getExpireDate().toInstant(), ZoneId.systemDefault());
|
|
432
|
+// localDateTime.plusMonths(extensionMonth);
|
|
433
|
+// taUserLicenseOrder.setExpireDate(Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()));
|
|
434
|
+// taUserLicenseOrder.setUnitPrice(taUserLicense.getUnitPrice());
|
|
435
|
+// taUserLicenseOrder.setParkingLot(taUserLicense.getParkingLot());
|
|
436
|
+// taUserLicenseOrder.setLicensePlate(taUserLicense.getLicensePlate());
|
|
437
|
+//
|
|
438
|
+// // 插入数据
|
|
439
|
+// taUserLicenseOrderMapper.insertSelective(taUserLicenseOrder);
|
|
440
|
+
|
|
441
|
+// }
|
|
442
|
+
|
|
443
|
+ }
|
|
444
|
+ }
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+ /**
|
|
449
|
+ * 取消支付
|
|
450
|
+ *
|
|
451
|
+ * @param outTradeNo
|
|
452
|
+ * @param
|
|
453
|
+ */
|
|
454
|
+ @Override
|
|
455
|
+ @Transactional(rollbackFor = Exception.class)
|
|
456
|
+ public void wxCancelPay(String outTradeNo, String type, String personId) throws Exception {
|
|
457
|
+
|
|
458
|
+ /**
|
|
459
|
+ * 如果是车缴费订单,就只直接更新 订单状态为关闭
|
|
460
|
+ */
|
|
461
|
+ // 如果是车缴费
|
|
462
|
+// if (Constant.PAY_TYPE_CAR.equals(type)) {
|
|
463
|
+// // 更改订单状态 为订单已关闭
|
|
464
|
+// updateOrderStatus(outTradeNo, type, "3");
|
|
465
|
+// return;
|
|
466
|
+// }
|
|
467
|
+
|
|
468
|
+ // --------------------------- 物业缴费 --------------------------------
|
|
469
|
+
|
|
470
|
+ //获取支付金额
|
|
471
|
+ List<TpBillOrder> billOrderList = tpBillOrderMapper.selectByOrderBumber(outTradeNo);
|
|
472
|
+ if (CollectionUtils.isEmpty(billOrderList)){
|
|
473
|
+ throw new Exception("订单不存在");
|
|
474
|
+ }
|
|
475
|
+
|
|
476
|
+ List<BillInvoice> billInvoiceList = Lists.newArrayList();
|
|
477
|
+ for (TpBillOrder tpBillOrder : billOrderList) {
|
|
478
|
+ BillInvoice billInvoice = tpBillInvoiceMapper.selectById(tpBillOrder.getTpBillInvoiceId());
|
|
479
|
+ if (!billInvoice.getBillStatus().equals("3")){
|
|
480
|
+ throw new Exception("不是正在支付的订单");
|
|
481
|
+ }
|
|
482
|
+ billInvoiceList.add(billInvoice);
|
|
483
|
+ }
|
|
484
|
+
|
|
485
|
+ // 缴费单id集合
|
|
486
|
+ List<Integer> billInvoiceIdList = billInvoiceList.stream().map(e -> e.getId()).collect(Collectors.toList());
|
|
487
|
+
|
|
488
|
+ //更新为 未支付状态
|
|
489
|
+ updateBillInvoiceBillStatus(billInvoiceIdList, "","0");
|
|
490
|
+ log.info("订单: {}, 订单类型: {}, 状态变更为取消支付", outTradeNo, type);
|
|
491
|
+
|
|
492
|
+ // 更改订单状态 为订单已关闭
|
|
493
|
+ updateOrderStatus(outTradeNo, type, "3");
|
|
494
|
+
|
|
495
|
+ }
|
|
496
|
+
|
|
497
|
+ @Override
|
|
498
|
+ public String wxCarNotify(Map<String, String> resultMap) {
|
|
499
|
+//
|
|
500
|
+// String outTradeNo = resultMap.get("out_trade_no");
|
|
501
|
+// String pay_type = resultMap.get("pay_type");
|
|
502
|
+// String payTypeName = pay_type.equals("0") ? "微信支付" : pay_type.equals("2") ? "支付宝" : "未知";
|
|
503
|
+//
|
|
504
|
+// List<TaUserLicenseOrder> userLicenseOrderList = taUserLicenseOrderMapper.selectByOrderNumber(outTradeNo);
|
|
505
|
+// if (CollectionUtils.isEmpty(userLicenseOrderList)){
|
|
506
|
+// return "不存在的订单";
|
|
507
|
+// }
|
|
508
|
+//
|
|
509
|
+// log.info("订单:{},订单类型: {} 开始推送到 车辆管理系统 ", outTradeNo, Constant.PAY_TYPE_CAR);
|
|
510
|
+//
|
|
511
|
+// TaUserLicenseOrder taUserLicenseOrder = userLicenseOrderList.get(0);
|
|
512
|
+// TaUser taUser = taUserMapper.selectByPrimaryKey(taUserLicenseOrder.getTaUserId());
|
|
513
|
+//
|
|
514
|
+// ApiThirdPartyMonthCardPay apiThirdPartyMonthCardPay = new ApiThirdPartyMonthCardPay();
|
|
515
|
+// apiThirdPartyMonthCardPay.setPhone(taUser.getLoginName());
|
|
516
|
+// apiThirdPartyMonthCardPay.setRenewDayType("2");
|
|
517
|
+// apiThirdPartyMonthCardPay.setRenewDay(String.valueOf(taUserLicenseOrder.getExtensionMonth()));
|
|
518
|
+// apiThirdPartyMonthCardPay.setPayStyle(payTypeName);
|
|
519
|
+// apiThirdPartyMonthCardPay.setCarNo(taUserLicenseOrder.getLicensePlate());
|
|
520
|
+// apiThirdPartyMonthCardPay.setCardNo(null);
|
|
521
|
+// apiThirdPartyMonthCardPay.setRechargeAmt(String.valueOf(Double.valueOf(taUserLicenseOrder.getExtensionPrice()) / 100));
|
|
522
|
+// apiThirdPartyMonthCardPay.setDealNo(outTradeNo);
|
|
523
|
+//
|
|
524
|
+// // 推送到车辆管理系统
|
|
525
|
+// iFuShiServer.apiThirdPartyMonthCardPay(JSONObject.toJSONString(apiThirdPartyMonthCardPay));
|
|
526
|
+//
|
|
527
|
+// // 推送到车辆管理系统
|
|
528
|
+//// iFuShiService.apiThirdPartyMonthCardPay(taUser.getLoginName(), "2",
|
|
529
|
+//// String.valueOf(taUserLicenseOrder.getExtensionMonth()),
|
|
530
|
+//// payTypeName, taUserLicenseOrder.getLicensePlate(),
|
|
531
|
+//// null, String.valueOf(Double.valueOf(taUserLicenseOrder.getExtensionPrice()) / 100));
|
|
532
|
+//
|
|
533
|
+//
|
|
534
|
+//// userLicenseOrderList.forEach(e-> {
|
|
535
|
+//// UserElement userElement = new UserElement();
|
|
536
|
+//// userElement.setCommunityId(e.getCommunityId());
|
|
537
|
+//// userElement.setId(e.getTaUserId());
|
|
538
|
+//// ResponseBean responseLicense = iTaUserLicenseService.getLicense(userElement, e.getLicensePlate());
|
|
539
|
+//// Object licenseData = responseLicense.getData();
|
|
540
|
+//// TaUserLicense taUserLicense = null;
|
|
541
|
+//// if (null != licenseData && licenseData instanceof TaUserLicense) {
|
|
542
|
+//// taUserLicense = (TaUserLicense) licenseData;
|
|
543
|
+//// e.setExpireDate(taUserLicense.getExpireDate());
|
|
544
|
+//// }
|
|
545
|
+//// e.setPaymentType(pay_type);
|
|
546
|
+//// e.setUpdateUser(e.getCreateUser());
|
|
547
|
+//// e.setUpdateDate(new Date());
|
|
548
|
+//// taUserLicenseOrderMapper.updateByPrimaryKeySelective(e);
|
|
549
|
+////
|
|
550
|
+//// });
|
|
551
|
+//
|
|
552
|
+//
|
|
553
|
+// log.info("订单: {},订单类型: {}, 状态变更为支付成功", outTradeNo, Constant.PAY_TYPE_CAR);
|
|
554
|
+//
|
|
555
|
+// // 更改订单状态 为支付成功
|
|
556
|
+// updateOrderStatus(outTradeNo, Constant.PAY_TYPE_CAR, "1");
|
|
557
|
+//
|
|
558
|
+// // 推物业端,推这个小区下的所有管理员
|
|
559
|
+//
|
|
560
|
+// List<TpUser> tpUserList = tpUserMapper.selectCommunityId(taUserLicenseOrder.getCommunityId());
|
|
561
|
+// for (TpUser tpUser : tpUserList) {
|
|
562
|
+// Map<String, Object> mapProp = new HashMap<>();
|
|
563
|
+// mapProp.put("communityId", taUserLicenseOrder.getCommunityId());
|
|
564
|
+// mapProp.put("tpUserId", tpUser.getId());
|
|
565
|
+// mapProp.put("createUserId", taUserLicenseOrder.getTaUserId());
|
|
566
|
+// mapProp.put("licenseOrderId", taUserLicenseOrder.getId());
|
|
567
|
+// mapProp.put("name", taUserLicenseOrder.getPaymentName());
|
|
568
|
+// mapProp.put("number", taUserLicenseOrder.getLicensePlate());
|
|
569
|
+// applicationContext.publishEvent(new MessageEvent(mapProp, Constant.PAY_MONTH_Bill_SUCCEED, mapProp));
|
|
570
|
+// }
|
|
571
|
+
|
|
572
|
+ return "success";
|
|
573
|
+ }
|
|
574
|
+
|
|
575
|
+ /**
|
|
576
|
+ * 更新支付状态
|
|
577
|
+ * @param billInvoiceIdList
|
|
578
|
+ * @param status
|
|
579
|
+ */
|
|
580
|
+ private void updateBillInvoiceBillStatus(List<Integer> billInvoiceIdList, String status) {
|
|
581
|
+ billInvoiceIdList.forEach(e -> {
|
|
582
|
+ BillInvoice tpBillInvoiceUpdate = new BillInvoice();
|
|
583
|
+ tpBillInvoiceUpdate.setBillStatus(status);
|
|
584
|
+ tpBillInvoiceUpdate.setId(e);
|
|
585
|
+ tpBillInvoiceMapper.updateById(tpBillInvoiceUpdate);
|
|
586
|
+ });
|
|
587
|
+
|
|
588
|
+ }
|
|
589
|
+
|
|
590
|
+ /**
|
|
591
|
+ * 更新支付状态
|
|
592
|
+ * @param billInvoiceIdList
|
|
593
|
+ * @param userName 缴费人
|
|
594
|
+ * @param status
|
|
595
|
+ */
|
|
596
|
+ private void updateBillInvoiceBillStatus(List<Integer> billInvoiceIdList, String userName, String status) {
|
|
597
|
+ billInvoiceIdList.forEach(e -> {
|
|
598
|
+ BillInvoice tpBillInvoiceUpdate = new BillInvoice();
|
|
599
|
+ tpBillInvoiceUpdate.setBillStatus(status);
|
|
600
|
+ tpBillInvoiceUpdate.setId(e);
|
|
601
|
+ tpBillInvoiceUpdate.setPayName(userName);
|
|
602
|
+ tpBillInvoiceMapper.updateById(tpBillInvoiceUpdate);
|
|
603
|
+ });
|
|
604
|
+ }
|
|
605
|
+
|
|
606
|
+ /**
|
|
607
|
+ * 更改订单状态
|
|
608
|
+ * @param orderNumber
|
|
609
|
+ * @param type
|
|
610
|
+ * @param status
|
|
611
|
+ */
|
|
612
|
+ private void updateOrderStatus(String orderNumber, String type, String status){
|
|
613
|
+ // 物业缴费
|
|
614
|
+ if (Constant.PAY_TYPE_BILL.equals(type)) {
|
|
615
|
+ List<TpBillOrder> billOrders = tpBillOrderMapper.selectByOrderBumber(orderNumber);
|
|
616
|
+ billOrders.forEach(e-> {
|
|
617
|
+ e.setOrderStatus(status);
|
|
618
|
+ tpBillOrderMapper.updateById(e);
|
|
619
|
+ });
|
|
620
|
+
|
|
621
|
+ // 车缴费
|
|
622
|
+ } else if (Constant.PAY_TYPE_CAR.equals(type)) {
|
|
623
|
+// List<TaUserLicenseOrder> taUserLicenseOrders = taUserLicenseOrderMapper.selectByOrderNumber(orderNumber);
|
|
624
|
+// taUserLicenseOrders.forEach(e-> {
|
|
625
|
+// e.setOrderStatus(status);
|
|
626
|
+// taUserLicenseOrderMapper.updateByPrimaryKeySelective(e);
|
|
627
|
+// });
|
|
628
|
+ }
|
|
629
|
+ }
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+ /**
|
|
633
|
+ * 获取每个小程序独立的微信账户
|
|
634
|
+ * @param orgId
|
|
635
|
+ * @return
|
|
636
|
+ */
|
|
637
|
+ private WxConfig getWxConfig(Integer orgId) throws Exception {
|
|
638
|
+ //根据orgId获取支付配置
|
|
639
|
+ QueryWrapper<TaWxPayConfig> taWxPayConfigQueryWrapper = new QueryWrapper<>();
|
|
640
|
+ taWxPayConfigQueryWrapper.eq("org_id",orgId);
|
|
641
|
+ TaWxPayConfig taWxPayConfig = taWxPayConfigMapper.selectOne(taWxPayConfigQueryWrapper);
|
|
642
|
+ if (null == taWxPayConfig){
|
|
643
|
+ throw new Exception("请先完善支付信息");
|
|
644
|
+ }
|
|
645
|
+ log.info("正在配置orgId为{}的微信支付参数,商户号为{}",orgId,taWxPayConfig.getMchId());
|
|
646
|
+ //把库里的值赋值给微信
|
|
647
|
+ URL urlConet = new URL(taWxPayConfig.getApiPath());
|
|
648
|
+ HttpURLConnection con = (HttpURLConnection)urlConet.openConnection();
|
|
649
|
+ con.setRequestMethod("GET");
|
|
650
|
+ con.setConnectTimeout(4 * 1000);
|
|
651
|
+ InputStream inStream = con .getInputStream();
|
|
652
|
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
|
653
|
+ byte[] buffer = new byte[2048];
|
|
654
|
+ int len = 0;
|
|
655
|
+ while( (len=inStream.read(buffer)) != -1 ){
|
|
656
|
+ outStream.write(buffer, 0, len);
|
|
657
|
+ }
|
|
658
|
+ inStream.close();
|
|
659
|
+
|
|
660
|
+ WxConfig config = new WxConfig();
|
|
661
|
+ config.setAppid(taWxPayConfig.getAppid());
|
|
662
|
+ config.setMachId(taWxPayConfig.getMchId());
|
|
663
|
+ config.setCertData(outStream.toByteArray());
|
|
664
|
+ config.setKey(taWxPayConfig.getMchKey());
|
|
665
|
+ return config;
|
|
666
|
+ }
|
|
667
|
+}
|