|
@@ -1,15 +1,5 @@
|
1
|
1
|
package com.huiju.estateagents.redpack.service.impl;
|
2
|
2
|
|
3
|
|
-import java.time.LocalDate;
|
4
|
|
-import java.time.LocalDateTime;
|
5
|
|
-import java.util.ArrayList;
|
6
|
|
-import java.util.List;
|
7
|
|
-
|
8
|
|
-import org.apache.commons.collections.CollectionUtils;
|
9
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
10
|
|
-import org.springframework.stereotype.Service;
|
11
|
|
-import org.springframework.transaction.annotation.Transactional;
|
12
|
|
-
|
13
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
14
|
4
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
15
|
5
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -18,21 +8,31 @@ import com.huiju.estateagents.center.taUser.entity.TaUser;
|
18
|
8
|
import com.huiju.estateagents.center.taUser.mapper.TaUserMapper;
|
19
|
9
|
import com.huiju.estateagents.common.CommConstant;
|
20
|
10
|
import com.huiju.estateagents.common.CommonUtils;
|
21
|
|
-import com.huiju.estateagents.redpack.entity.TaOrgAccount;
|
22
|
|
-import com.huiju.estateagents.redpack.entity.TaOrgAccountBlocked;
|
23
|
|
-import com.huiju.estateagents.redpack.entity.TaOrgAccountCertificate;
|
24
|
|
-import com.huiju.estateagents.redpack.entity.TaOrgAccountDetailedList;
|
25
|
|
-import com.huiju.estateagents.redpack.entity.TaOrgOrder;
|
26
|
|
-import com.huiju.estateagents.redpack.entity.TaOrgOrderDetail;
|
27
|
|
-import com.huiju.estateagents.redpack.entity.TaOrgRefundApplication;
|
28
|
|
-import com.huiju.estateagents.redpack.mapper.TaOrgAccountBlockedMapper;
|
29
|
|
-import com.huiju.estateagents.redpack.mapper.TaOrgAccountCertificateMapper;
|
30
|
|
-import com.huiju.estateagents.redpack.mapper.TaOrgAccountDetailedListMapper;
|
31
|
|
-import com.huiju.estateagents.redpack.mapper.TaOrgAccountMapper;
|
32
|
|
-import com.huiju.estateagents.redpack.mapper.TaOrgOrderDetailMapper;
|
33
|
|
-import com.huiju.estateagents.redpack.mapper.TaOrgOrderMapper;
|
34
|
|
-import com.huiju.estateagents.redpack.mapper.TaOrgRefundApplicationMapper;
|
|
11
|
+import com.huiju.estateagents.common.wxpay.WXPay;
|
|
12
|
+import com.huiju.estateagents.common.wxpay.WXPayConstants;
|
|
13
|
+import com.huiju.estateagents.common.wxpay.WxConfig;
|
|
14
|
+import com.huiju.estateagents.entity.TaWxPayConfig;
|
|
15
|
+import com.huiju.estateagents.mapper.TaWxPayConfigMapper;
|
|
16
|
+import com.huiju.estateagents.redpack.entity.*;
|
|
17
|
+import com.huiju.estateagents.redpack.mapper.*;
|
35
|
18
|
import com.huiju.estateagents.redpack.service.ITaOrgOrderService;
|
|
19
|
+import lombok.extern.slf4j.Slf4j;
|
|
20
|
+import org.apache.commons.collections.CollectionUtils;
|
|
21
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
22
|
+import org.springframework.beans.factory.annotation.Value;
|
|
23
|
+import org.springframework.stereotype.Service;
|
|
24
|
+import org.springframework.transaction.annotation.Transactional;
|
|
25
|
+
|
|
26
|
+import java.io.ByteArrayOutputStream;
|
|
27
|
+import java.io.InputStream;
|
|
28
|
+import java.net.HttpURLConnection;
|
|
29
|
+import java.net.URL;
|
|
30
|
+import java.time.LocalDate;
|
|
31
|
+import java.time.LocalDateTime;
|
|
32
|
+import java.util.ArrayList;
|
|
33
|
+import java.util.HashMap;
|
|
34
|
+import java.util.List;
|
|
35
|
+import java.util.Map;
|
36
|
36
|
|
37
|
37
|
/**
|
38
|
38
|
* <p>
|
|
@@ -42,9 +42,13 @@ import com.huiju.estateagents.redpack.service.ITaOrgOrderService;
|
42
|
42
|
* @author fxf
|
43
|
43
|
* @since 2020-06-03
|
44
|
44
|
*/
|
|
45
|
+@Slf4j
|
45
|
46
|
@Service
|
46
|
47
|
public class TaOrgOrderServiceImpl extends ServiceImpl<TaOrgOrderMapper, TaOrgOrder> implements ITaOrgOrderService {
|
47
|
48
|
|
|
49
|
+ @Value("${pay-notify}")
|
|
50
|
+ private String payNotify;
|
|
51
|
+
|
48
|
52
|
@Autowired
|
49
|
53
|
private TaOrgAccountMapper taOrgAccountMapper;
|
50
|
54
|
|
|
@@ -69,6 +73,9 @@ public class TaOrgOrderServiceImpl extends ServiceImpl<TaOrgOrderMapper, TaOrgOr
|
69
|
73
|
@Autowired
|
70
|
74
|
private TaUserMapper taUserMapper;
|
71
|
75
|
|
|
76
|
+ @Autowired
|
|
77
|
+ private TaWxPayConfigMapper taWxPayConfigMapper;
|
|
78
|
+
|
72
|
79
|
@Override
|
73
|
80
|
public IPage<TaOrgOrder> listByCondition(IPage<TaOrgOrder> pg, String orderType, Integer orgId, String tradeNo, Integer isOffline, String tradingStatus, String receivePhone, String itemType, LocalDate startDate, LocalDate endDate) {
|
74
|
81
|
IPage<TaOrgOrder> result = null;
|
|
@@ -84,6 +91,87 @@ public class TaOrgOrderServiceImpl extends ServiceImpl<TaOrgOrderMapper, TaOrgOr
|
84
|
91
|
}
|
85
|
92
|
}
|
86
|
93
|
|
|
94
|
+ /**
|
|
95
|
+ * 微信支付
|
|
96
|
+ *
|
|
97
|
+ * @param taOrgOrder
|
|
98
|
+ * @param clientIp
|
|
99
|
+ * @return
|
|
100
|
+ */
|
|
101
|
+ @Override
|
|
102
|
+ public ResponseBean payUnifiedOrder(TaOrgOrder taOrgOrder, String clientIp) throws Exception {
|
|
103
|
+ taOrgOrder = taOrgOrderMapper.selectById(taOrgOrder.getOrderId());
|
|
104
|
+ //构建微信配置
|
|
105
|
+ WxConfig config = getWxConfig(0);
|
|
106
|
+ WXPay wxpay = new WXPay(config);
|
|
107
|
+
|
|
108
|
+ //获取支付的钱数并且判断是自动锁房还是手动锁房,自动锁房需要锁定房源,手动锁房跳过
|
|
109
|
+ String payPrice = String.valueOf(taOrgOrder.getAmount());
|
|
110
|
+
|
|
111
|
+ //生成商户订单
|
|
112
|
+// String tradeNo = CommonUtils.generateTradeNo("CJ");
|
|
113
|
+// taOrgOrder.setTradeNo(tradeNo);
|
|
114
|
+
|
|
115
|
+ //下单
|
|
116
|
+ Map<String, String> data = new HashMap<String, String>();
|
|
117
|
+ data.put("body", "微信支付");
|
|
118
|
+ //商品号唯一
|
|
119
|
+ data.put("out_trade_no", taOrgOrder.getTradeNo());
|
|
120
|
+ data.put("device_info", "");
|
|
121
|
+ data.put("fee_type", "CNY");
|
|
122
|
+ //金额 后台计算
|
|
123
|
+ data.put("total_fee", payPrice);
|
|
124
|
+ //终端IP
|
|
125
|
+ data.put("spbill_create_ip", clientIp);
|
|
126
|
+ //回调地址
|
|
127
|
+ data.put("notify_url", payNotify+CommConstant.ITEM_TYPE_RECHARGE);
|
|
128
|
+ // 此处指定为APP支付
|
|
129
|
+ data.put("trade_type", "NATIVE");
|
|
130
|
+ Map<String, String> resp = wxpay.unifiedOrder(data);
|
|
131
|
+ log.info("下单成功:{}", resp);
|
|
132
|
+ if (resp.get("result_code").equalsIgnoreCase(WXPayConstants.FAIL)){
|
|
133
|
+ throw new Exception(resp.get("err_code_des"));
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ return ResponseBean.success(resp.get("code_url"));
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ /**
|
|
140
|
+ * 获取每个小程序独立的微信账户
|
|
141
|
+ * @param orgId
|
|
142
|
+ * @return
|
|
143
|
+ */
|
|
144
|
+ private WxConfig getWxConfig(Integer orgId) throws Exception {
|
|
145
|
+ //根据orgId获取支付配置
|
|
146
|
+ QueryWrapper<TaWxPayConfig> taWxPayConfigQueryWrapper = new QueryWrapper<>();
|
|
147
|
+ taWxPayConfigQueryWrapper.eq("org_id",orgId);
|
|
148
|
+ TaWxPayConfig taWxPayConfig = taWxPayConfigMapper.selectOne(taWxPayConfigQueryWrapper);
|
|
149
|
+ if (null == taWxPayConfig){
|
|
150
|
+ throw new Exception("请先完善支付信息");
|
|
151
|
+ }
|
|
152
|
+ log.info("正在配置orgId为{}的微信支付参数,商户号为{}",orgId,taWxPayConfig.getMchId());
|
|
153
|
+ //把库里的值赋值给微信
|
|
154
|
+ URL urlConet = new URL(taWxPayConfig.getApiPath());
|
|
155
|
+ HttpURLConnection con = (HttpURLConnection)urlConet.openConnection();
|
|
156
|
+ con.setRequestMethod("GET");
|
|
157
|
+ con.setConnectTimeout(4 * 1000);
|
|
158
|
+ InputStream inStream = con .getInputStream();
|
|
159
|
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
|
160
|
+ byte[] buffer = new byte[2048];
|
|
161
|
+ int len = 0;
|
|
162
|
+ while( (len=inStream.read(buffer)) != -1 ){
|
|
163
|
+ outStream.write(buffer, 0, len);
|
|
164
|
+ }
|
|
165
|
+ inStream.close();
|
|
166
|
+
|
|
167
|
+ WxConfig config = new WxConfig();
|
|
168
|
+ config.setAppid(taWxPayConfig.getAppid());
|
|
169
|
+ config.setMachId(taWxPayConfig.getMchId());
|
|
170
|
+ config.setCertData(outStream.toByteArray());
|
|
171
|
+ config.setKey(taWxPayConfig.getMchKey());
|
|
172
|
+ return config;
|
|
173
|
+ }
|
|
174
|
+
|
87
|
175
|
@Override
|
88
|
176
|
@Transactional(rollbackFor = {RuntimeException.class})
|
89
|
177
|
public ResponseBean refundOrder(String id, TaOrgRefundApplication refundApplication, Integer userId) {
|