提交 | 用户 | age
|
7192e4
|
1 |
package com.hx.phip.tool.payment; |
C |
2 |
|
|
3 |
import com.hx.common.service.CommonService; |
|
4 |
import com.hx.mybatisTool.SqlSentence; |
|
5 |
import com.hx.phiappt.model.PaymentMethod; |
7a77e3
|
6 |
import com.hx.phiappt.model.consume.ConsumeNotify; |
7192e4
|
7 |
import com.hx.phiappt.model.consume.ConsumePay; |
f3ff4e
|
8 |
import com.hx.phip.dao.mapper.ConsumeNotifyMapper; |
7192e4
|
9 |
import com.hx.phip.dao.mapper.PaymentMethodMapper; |
C |
10 |
import com.hx.util.StringUtils; |
|
11 |
|
|
12 |
import java.math.BigDecimal; |
e3b9cc
|
13 |
import java.util.HashMap; |
C |
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
7192e4
|
16 |
|
1af0b3
|
17 |
/**消费记录工具 |
C |
18 |
* |
|
19 |
* @author CJH |
|
20 |
*/ |
7192e4
|
21 |
public class ConsumeTool { |
C |
22 |
|
1af0b3
|
23 |
/**通过支付编号或者作废流水号获取到支付回调信息 |
C |
24 |
* @param orderId 支付回调信息关联标识,可不传 |
7a77e3
|
25 |
* @param outOrderNo 支付编号 |
C |
26 |
* @param commonService 映射 |
|
27 |
* @return 支付回调信息 |
|
28 |
*/ |
1af0b3
|
29 |
public static ConsumeNotify selectConsumeNotifyByOrderNo(String orderId,String outOrderNo,String platTrxNo, CommonService commonService){ |
7a77e3
|
30 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
31 |
Map<String,Object> values = new HashMap<>(); |
1af0b3
|
32 |
StringBuilder sql = new StringBuilder(); |
C |
33 |
|
4edff3
|
34 |
values.put("outOrderNo",outOrderNo); |
C |
35 |
values.put("platTrxNo",platTrxNo); |
1af0b3
|
36 |
sql.append("SELECT * FROM consume_notify WHERE isDel = 0 AND (outOrderNo = #{m.outOrderNo} OR platTrxNo = #{m.platTrxNo})"); |
C |
37 |
if(StringUtils.noNull(orderId)){ |
|
38 |
values.put("orderId",orderId); |
|
39 |
sql.append(" AND orderId = #{m.orderId}"); |
|
40 |
} |
|
41 |
|
|
42 |
sqlSentence.sqlSentence(sql.toString(),values); |
7a77e3
|
43 |
return commonService.selectOne(ConsumeNotifyMapper.class,sqlSentence); |
C |
44 |
} |
|
45 |
|
1af0b3
|
46 |
/**绑定支付信息,没有绑定的,单个 |
e39e46
|
47 |
* 没有关联到支付记录的支付信息 |
1af0b3
|
48 |
* @param orderId 支付回调信息关联标识 |
e39e46
|
49 |
* @param paymentNo 支付方式编号 |
C |
50 |
* @param payAmount 支付金额 |
|
51 |
* @param consumePayId 支付记录标识 |
|
52 |
* @param commonService 映射 |
|
53 |
* @return 支付回调信息 |
|
54 |
*/ |
1af0b3
|
55 |
public static void bindConsume(String orderId,String paymentNo,BigDecimal payAmount,String consumePayId, CommonService commonService){ |
C |
56 |
ConsumeNotify consumeNotify = selectNoBind(orderId,paymentNo,payAmount,commonService); |
e39e46
|
57 |
if(consumeNotify == null){ |
C |
58 |
return; |
|
59 |
} |
1af0b3
|
60 |
bindConsumeNotify(consumeNotify,consumePayId,commonService); |
C |
61 |
} |
|
62 |
|
|
63 |
/**绑定支付信息集合,没有绑定的 |
|
64 |
* 没有关联到支付记录的支付信息 |
|
65 |
* @param orderId 支付回调信息关联标识 |
|
66 |
* @param consumePayList 支付方式编号 |
|
67 |
* @param commonService 映射 |
|
68 |
* @return 支付回调信息 |
|
69 |
*/ |
|
70 |
public static void bindConsumeList(String orderId,List<ConsumePay> consumePayList, CommonService commonService){ |
|
71 |
|
|
72 |
Map<String,Integer> consumePayCount = new HashMap<>(); |
|
73 |
Integer count; |
|
74 |
for(ConsumePay consumePay:consumePayList){ |
|
75 |
count = consumePayCount.getOrDefault(consumePay.getNumberNo(),0); |
|
76 |
count++; |
|
77 |
consumePayCount.put(consumePay.getNumberNo(),count); |
|
78 |
} |
|
79 |
List<ConsumeNotify> consumeNotifyList; |
|
80 |
for(ConsumePay consumePay:consumePayList){ |
|
81 |
count = consumePayCount.get(consumePay.getNumberNo()); |
|
82 |
if(count == 1){ |
|
83 |
//单条,绑定所有的支付回调信息 |
|
84 |
consumeNotifyList = selectNoBindList(orderId,consumePay.getNumberNo(),null,commonService); |
|
85 |
for(ConsumeNotify consumeNotify:consumeNotifyList){ |
|
86 |
bindConsumeNotify(consumeNotify,consumePay.getId(),commonService); |
|
87 |
} |
|
88 |
}else if(count > 1){ |
|
89 |
//多条,绑定金额一样的回调信息 |
|
90 |
bindConsume(orderId,consumePay.getNumberNo(),consumePay.getActualTotal(),consumePay.getId(),commonService); |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
/**绑定回调记录*/ |
|
96 |
public static void bindConsumeNotify(ConsumeNotify consumeNotify,String consumePayId,CommonService commonService){ |
e39e46
|
97 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
98 |
Map<String,Object> values = new HashMap<>(); |
|
99 |
|
|
100 |
values.put("id",consumeNotify.getId()); |
|
101 |
values.put("consumePayId",consumePayId); |
|
102 |
sqlSentence.sqlUpdate("consumePayId = #{m.consumePayId} WHERE id = #{m.id} AND consumePayId IS NULL",values); |
|
103 |
commonService.updateWhere(ConsumeNotifyMapper.class,sqlSentence); |
|
104 |
} |
|
105 |
|
1af0b3
|
106 |
/**通过支付方式编号和金额获取到支付回调信息,获取单条 |
e39e46
|
107 |
* 没有关联到支付记录的支付信息 |
1af0b3
|
108 |
* @param orderId 支付回调信息关联标识 |
e39e46
|
109 |
* @param paymentNo 支付方式编号 |
C |
110 |
* @param payAmount 支付金额 |
|
111 |
* @param commonService 映射 |
|
112 |
* @return 支付回调信息 |
|
113 |
*/ |
1af0b3
|
114 |
public static ConsumeNotify selectNoBind(String orderId,String paymentNo,BigDecimal payAmount, CommonService commonService){ |
e39e46
|
115 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
116 |
Map<String,Object> values = new HashMap<>(); |
1af0b3
|
117 |
values.put("orderId",orderId); |
e39e46
|
118 |
values.put("paymentNo",paymentNo); |
C |
119 |
values.put("payAmount",payAmount); |
|
120 |
values.put("refundStatus",ConsumeNotify.REFUND_STATUS_NO); |
1af0b3
|
121 |
sqlSentence.sqlSentence("SELECT * FROM consume_notify WHERE isDel = 0 AND paymentNo = #{m.paymentNo} AND orderId = #{m.orderId}" + |
e39e46
|
122 |
" AND payAmount = #{m.payAmount} AND refundStatus = #{m.refundStatus} AND consumePayId IS NULL LIMIT 1",values); |
C |
123 |
return commonService.selectOne(ConsumeNotifyMapper.class,sqlSentence); |
|
124 |
} |
|
125 |
|
1af0b3
|
126 |
/**通过支付方式编号和金额获取到支付回调信息,获取多条 |
C |
127 |
* 没有关联到支付记录的支付信息 |
|
128 |
* @param orderId 支付回调信息关联标识 |
|
129 |
* @param paymentNo 支付方式编号 |
|
130 |
* @param payAmount 支付金额 |
|
131 |
* @param commonService 映射 |
|
132 |
* @return 支付回调信息 |
|
133 |
*/ |
|
134 |
public static List<ConsumeNotify> selectNoBindList(String orderId,String paymentNo,BigDecimal payAmount, CommonService commonService){ |
|
135 |
SqlSentence sqlSentence = new SqlSentence(); |
|
136 |
Map<String,Object> values = new HashMap<>(); |
|
137 |
StringBuilder stringBuilder = new StringBuilder(); |
7192e4
|
138 |
|
1af0b3
|
139 |
values.put("orderId",orderId); |
C |
140 |
values.put("paymentNo",paymentNo); |
|
141 |
values.put("refundStatus",ConsumeNotify.REFUND_STATUS_NO); |
|
142 |
stringBuilder.append("SELECT * FROM consume_notify WHERE isDel = 0 AND paymentNo = #{m.paymentNo} AND orderId = #{m.orderId}"); |
|
143 |
if(payAmount != null){ |
|
144 |
values.put("payAmount",payAmount); |
|
145 |
stringBuilder.append(" AND payAmount = #{m.payAmount}"); |
7192e4
|
146 |
} |
1af0b3
|
147 |
stringBuilder.append(" AND refundStatus = #{m.refundStatus} AND consumePayId IS NULL"); |
C |
148 |
sqlSentence.sqlSentence(stringBuilder.toString(),values); |
260188
|
149 |
return commonService.selectList(ConsumeNotifyMapper.class,sqlSentence); |
7192e4
|
150 |
} |
C |
151 |
|
e3b9cc
|
152 |
/**通过支付方式编号和金额获取到支付回调信息,获取多条,升序排序 |
C |
153 |
* @param orderId 支付回调信息关联标识 |
|
154 |
* @param paymentNo 支付方式编号 |
|
155 |
* @param payAmount 支付金额 |
|
156 |
* @param commonService 映射 |
|
157 |
* @return 支付回调信息 |
|
158 |
*/ |
|
159 |
public static List<ConsumeNotify> selectList(String orderId,String paymentNo,BigDecimal payAmount, CommonService commonService){ |
|
160 |
SqlSentence sqlSentence = new SqlSentence(); |
|
161 |
Map<String,Object> values = new HashMap<>(); |
|
162 |
StringBuilder stringBuilder = new StringBuilder(); |
|
163 |
|
|
164 |
values.put("orderId",orderId); |
f3ff4e
|
165 |
stringBuilder.append("SELECT * FROM consume_notify WHERE isDel = 0 AND orderId = #{m.orderId}"); |
C |
166 |
if(StringUtils.noNull(paymentNo)){ |
|
167 |
values.put("paymentNo",paymentNo); |
|
168 |
stringBuilder.append(" AND paymentNo = #{m.paymentNo}"); |
|
169 |
} |
e3b9cc
|
170 |
if(payAmount != null){ |
C |
171 |
values.put("payAmount",payAmount); |
|
172 |
stringBuilder.append(" AND payAmount = #{m.payAmount}"); |
|
173 |
} |
|
174 |
stringBuilder.append(" ORDER BY payAmount ASC"); |
|
175 |
sqlSentence.sqlSentence(stringBuilder.toString(),values); |
|
176 |
return commonService.selectList(ConsumeNotifyMapper.class,sqlSentence); |
|
177 |
} |
|
178 |
|
|
179 |
/**更新支付回调的退款金额信息*/ |
|
180 |
public static void updateRefundTotal(ConsumeNotify consumeNotify,BigDecimal refundTotal,int refundStatus,CommonService commonService){ |
|
181 |
SqlSentence sqlSentence = new SqlSentence(); |
|
182 |
Map<String,Object> values = new HashMap<>(); |
|
183 |
|
|
184 |
values.put("refundTotal",refundTotal); |
|
185 |
values.put("id",consumeNotify.getId()); |
|
186 |
values.put("refundStatus",refundStatus); |
|
187 |
sqlSentence.sqlUpdate("refundTotal = refundTotal+#{m.refundTotal},refundStatus = #{m.refundStatus} WHERE id = #{m.id}",values); |
f3ff4e
|
188 |
commonService.updateWhere(ConsumeNotifyMapper.class,sqlSentence); |
e3b9cc
|
189 |
} |
C |
190 |
|
|
191 |
|
7192e4
|
192 |
/** |
C |
193 |
* 获取支付方式 |
|
194 |
* @param numberNo 支付编号 |
|
195 |
* @param commonService 映射 |
|
196 |
* @return 支付方式 |
|
197 |
*/ |
|
198 |
public static PaymentMethod getPaymentMethod(String numberNo,CommonService commonService){ |
|
199 |
SqlSentence sqlSentence = new SqlSentence(); |
|
200 |
Map<String,Object> values = new HashMap<>(); |
|
201 |
|
|
202 |
values.put("numberNo",numberNo); |
|
203 |
sqlSentence.sqlSentence("SELECT * FROM payment_method WHERE isDel = 0 AND isUp = 1 AND numberNo = #{m.numberNo}",values); |
|
204 |
return commonService.selectOne(PaymentMethodMapper.class,sqlSentence); |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
} |