提交 | 用户 | age
|
21488d
|
1 |
package com.hx.phip.service.refund.impl; |
Z |
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
dd8aff
|
5 |
import com.alibaba.fastjson.JSONArray; |
Z |
6 |
import com.alibaba.fastjson.JSONObject; |
df1cf0
|
7 |
import com.hx.common.dao.CommonDao; |
dd8aff
|
8 |
import com.hx.common.service.CommonService; |
Z |
9 |
import com.hx.phiappt.common.*; |
728eb8
|
10 |
import com.hx.phiappt.constants.enums.ApprovalTypeEnum; |
dd8aff
|
11 |
import com.hx.phiappt.constants.tool.JbpmTaskComTool; |
Z |
12 |
import com.hx.phiappt.constants.tool.RefundToolUtil; |
a9353f
|
13 |
import com.hx.phiappt.model.*; |
df1cf0
|
14 |
import com.hx.phiappt.model.refund.*; |
83aac3
|
15 |
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed; |
dd8aff
|
16 |
import com.hx.phiappt.vo.workFlow.JbpmParamVo; |
a751f0
|
17 |
import com.hx.phip.config.CustomParameter; |
dd8aff
|
18 |
import com.hx.phip.dao.mapper.*; |
df1cf0
|
19 |
import com.hx.phip.service.SystemParameterService; |
dd8aff
|
20 |
import com.hx.phip.util.api.ApiOrderUtil; |
1d0fdf
|
21 |
import com.hx.phip.util.api.RefundUtil; |
83aac3
|
22 |
import com.hx.phip.util.api.UserMoneyUtil; |
c3a7be
|
23 |
import com.hx.util.StringUtils; |
f0e01d
|
24 |
import com.hz.his.dto.refund.RefundFundsDto; |
dd8aff
|
25 |
import com.platform.exception.PlatTipsException; |
Z |
26 |
import com.platform.resultTool.PlatformCode; |
a9353f
|
27 |
import org.slf4j.Logger; |
Z |
28 |
import org.slf4j.LoggerFactory; |
21488d
|
29 |
import org.springframework.stereotype.Service; |
Z |
30 |
import org.springframework.transaction.annotation.Transactional; |
|
31 |
|
|
32 |
import com.hx.exception.TipsException; |
|
33 |
import com.hx.phip.service.refund.RefundRecordService; |
|
34 |
import com.hx.mybatisTool.SqlSentence; |
dd8aff
|
35 |
|
Z |
36 |
import java.math.BigDecimal; |
|
37 |
import java.util.*; |
21488d
|
38 |
|
Z |
39 |
@Transactional |
|
40 |
@Service |
|
41 |
public class RefundRecordServiceImpl implements RefundRecordService { |
df1cf0
|
42 |
|
A |
43 |
// log4j日志 |
|
44 |
private static final Logger logger = LoggerFactory.getLogger(RefundRecordServiceImpl.class.getName()); |
21488d
|
45 |
|
Z |
46 |
@Resource |
df1cf0
|
47 |
private CommonDao commonDao; |
a751f0
|
48 |
@Resource |
Z |
49 |
private CustomParameter customParameter; |
df1cf0
|
50 |
@Resource |
A |
51 |
private RefundRecordMapper refundRecordMapper; |
|
52 |
@Resource |
|
53 |
private SystemParameterService systemParameterService; |
21488d
|
54 |
|
Z |
55 |
/**查询列表*/ |
|
56 |
@Override |
|
57 |
public List<RefundRecord> selectList(SqlSentence sqlSentence) { |
|
58 |
return refundRecordMapper.selectList(sqlSentence); |
|
59 |
} |
|
60 |
|
|
61 |
/**查询列表*/ |
|
62 |
@Override |
|
63 |
public List<Map<String,Object>> selectListMap(SqlSentence sqlSentence) { |
|
64 |
return refundRecordMapper.selectListMap(sqlSentence); |
|
65 |
} |
|
66 |
|
|
67 |
/**查询单个*/ |
|
68 |
@Override |
|
69 |
public RefundRecord selectOne(SqlSentence sqlSentence) { |
|
70 |
return refundRecordMapper.selectOne(sqlSentence); |
|
71 |
} |
|
72 |
|
|
73 |
/**查询单个*/ |
|
74 |
@Override |
|
75 |
public Map<String,Object> selectOneMap(SqlSentence sqlSentence) { |
|
76 |
return refundRecordMapper.selectOneMap(sqlSentence); |
|
77 |
} |
|
78 |
|
|
79 |
/**查询单个,大数据不拿取*/ |
|
80 |
@Override |
|
81 |
public RefundRecord selectOneByKey(Object object) { |
|
82 |
return refundRecordMapper.selectOneByKey(object); |
|
83 |
} |
|
84 |
|
|
85 |
/**查询单个,大数据拿取*/ |
|
86 |
@Override |
|
87 |
public RefundRecord selectOneByKeyBlob(Object object) { |
|
88 |
return refundRecordMapper.selectOneByKeyBlob(object); |
|
89 |
} |
|
90 |
|
|
91 |
/**新增*/ |
|
92 |
@Override |
|
93 |
public void insert(RefundRecord refundRecord) { |
|
94 |
int count = refundRecordMapper.insert(refundRecord); |
|
95 |
if(count != 1) { |
|
96 |
throw new TipsException("新增失败!"); |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
/**修改*/ |
|
101 |
@Override |
|
102 |
public void updateAll(RefundRecord refundRecord) { |
|
103 |
int count = refundRecordMapper.updateAll(refundRecord); |
|
104 |
if(count!=1) { |
|
105 |
throw new TipsException("保存失败!"); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
/**修改*/ |
|
110 |
@Override |
|
111 |
public void updateWhere(SqlSentence sqlSentence) { |
|
112 |
int count = refundRecordMapper.updateWhere(sqlSentence); |
|
113 |
if(count!=1) { |
|
114 |
throw new TipsException("保存失败!"); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/**删除一个*/ |
|
119 |
@Override |
|
120 |
public void deleteOne(String delId) { |
|
121 |
int count = refundRecordMapper.deleteById(delId); |
|
122 |
if(count!=1) { |
|
123 |
throw new TipsException("删除失败!"); |
|
124 |
} |
|
125 |
} |
|
126 |
|
ff383a
|
127 |
@Override |
Z |
128 |
public RefundRecord selectOrderId(String orderId) { |
|
129 |
return refundRecordMapper.selectOrderId(orderId); |
|
130 |
} |
|
131 |
|
dd8aff
|
132 |
@Override |
Z |
133 |
public Map<String, Object> refund(JSONArray refundPayMethodList,String remarks, String operatorId, String shopId, String userId, CommonService commonService) { |
|
134 |
Map<String, String> operator = ApiOrderUtil.getOperator(commonService, operatorId);//获取操作人信息 |
|
135 |
SqlSentence sqlSentence = new SqlSentence(); |
|
136 |
Map<String,Object> map=new HashMap<>(); |
|
137 |
sqlSentence.setM(map); |
|
138 |
|
df1cf0
|
139 |
String totalCode = systemParameterService.createRecordNo("R", 16, "yyyyMMddHHmmss"); //总订单编号 |
dd8aff
|
140 |
BigDecimal sumMoney=BigDecimal.ZERO; |
Z |
141 |
RefundRecord refundRecord =null; |
|
142 |
RefundRecordItem refundRecordItem=null; |
|
143 |
RefundRecordMethod refundRecordMethod=null; |
|
144 |
|
|
145 |
Shop shop =commonService.selectOneByKey(ShopMapper.class,shopId); |
|
146 |
if(shop==null){ |
|
147 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到操作人的门店信息"); |
|
148 |
} |
|
149 |
//退款总记录 |
44d306
|
150 |
refundRecord=new RefundRecord(totalCode,shop.getId(),shop.getName(),sumMoney,OrderTotalConstants.STATUS_REFUND_APPLY,1, RefundSoruceConstants.TYPE_SOURCE_ORDER,remarks,null,userId); |
dd8aff
|
151 |
// refundRecordService.insert(refundRecord); |
Z |
152 |
commonService.insert(RefundRecordMapper.class,refundRecord); |
|
153 |
|
|
154 |
List<PaymentMethod> payMethodList=null; |
|
155 |
//记录退回客户的支付方式 |
|
156 |
for(int i=0;i<refundPayMethodList.size();i++){ |
|
157 |
|
|
158 |
JSONObject jsonObject = refundPayMethodList.getJSONObject(i); |
|
159 |
String payMethodNo = jsonObject.getString("payMethodNo");//支付方式编码 |
|
160 |
BigDecimal money = jsonObject.getBigDecimal("money");//实退金额 |
|
161 |
String payee = jsonObject.getString("payee");//收款方 |
|
162 |
String openBank = jsonObject.getString("openBank");//开户行 |
|
163 |
String openBranch = jsonObject.getString("openBranch");//开户支行 |
|
164 |
String account = jsonObject.getString("account");//账号 |
|
165 |
String remark = jsonObject.getString("remarks");//备注 |
|
166 |
map.put("method",payMethodNo); |
|
167 |
sqlSentence.setSqlSentence("select * from payment_method where numberNo=#{m.method} and isDel=0 and isUp=1"); |
|
168 |
PaymentMethod paymentMethod =commonService.selectOne(PaymentMethodMapper.class,sqlSentence); |
|
169 |
if(paymentMethod==null){ |
|
170 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该支付方式编码"+payMethodNo); |
|
171 |
} |
|
172 |
if(money ==null){ |
|
173 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"实退金额为空"); |
|
174 |
} |
|
175 |
sumMoney=sumMoney.add(money); |
|
176 |
refundRecordMethod=new RefundRecordMethod(payMethodNo,paymentMethod.getName(),money, ConsumePayConstants.STATUS_ORDER,null,refundRecord.getId(),paymentMethod.getId()); |
|
177 |
refundRecordMethod.setPayee(payee); |
|
178 |
refundRecordMethod.setOpenBank(openBank); |
|
179 |
refundRecordMethod.setOpenBranch(openBranch); |
|
180 |
refundRecordMethod.setAccount(account); |
|
181 |
refundRecordMethod.setRemarks(remark); |
|
182 |
commonService.insert(RefundRecordMethodMapper.class,refundRecordMethod); |
50cdcb
|
183 |
// if(PayMethodTypeConstants.PAY_STORED.equals(paymentMethod.getNumberNo())){ |
dd8aff
|
184 |
payMethodList=new ArrayList(); |
Z |
185 |
payMethodList.add(paymentMethod); |
50cdcb
|
186 |
// } |
dd8aff
|
187 |
} |
Z |
188 |
//保存退款详情订单 |
a751f0
|
189 |
refundRecordItem = new RefundRecordItem(payMethodList.get(0).getNumberNo(), payMethodList.get(0).getName(), payMethodList.get(0).getId(), 0, sumMoney, "", refundRecord.getId(), "[]", ""); |
dd8aff
|
190 |
refundRecordItem.setType("userMoney"); |
Z |
191 |
commonService.insert(RefundRecordItemMapper.class,refundRecordItem); |
|
192 |
//处理提交审核流程 |
|
193 |
JbpmParamVo jbpmParamVo = new JbpmParamVo(); |
728eb8
|
194 |
jbpmParamVo.setType(ApprovalTypeEnum.CHARGEBACK.getCode()); |
dd8aff
|
195 |
jbpmParamVo.setShopId(refundRecord.getRefundShopId()); |
Z |
196 |
jbpmParamVo.setTotal(sumMoney); |
|
197 |
jbpmParamVo.setAmount(sumMoney); |
|
198 |
jbpmParamVo.setApplyId(refundRecord.getId()); |
|
199 |
jbpmParamVo.setOrderId(refundRecord.getId()); |
|
200 |
Integer integer = JbpmTaskComTool.checkConditions(jbpmParamVo, commonService); |
|
201 |
if(integer==null){ |
|
202 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"预约系统的审核流程接口返回为空"); |
|
203 |
} |
|
204 |
if(integer==0){ |
|
205 |
//没有审批流程走完成退款流程 |
a751f0
|
206 |
RefundToolUtil.completeRefund(commonService,operator.get("operatorId"),operator.get("operatorName"),refundRecord.getId(),customParameter.getAesFixedKey()); |
dd8aff
|
207 |
}else if(integer==1){ |
Z |
208 |
Integer data = JbpmTaskComTool.checkConditionsWithInsert(jbpmParamVo, commonService); |
|
209 |
if(data==0){ |
|
210 |
// logger.info("无退款流程,请添加重试,退款订单:"+refundRecord.getId()); |
|
211 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"审核退款任务生成失败,请重试"); |
|
212 |
} |
|
213 |
}else if(integer==2){ |
|
214 |
//没有审批流程走完成退款流程 |
a751f0
|
215 |
RefundToolUtil.completeRefund(commonService,operator.get("operatorId"),operator.get("operatorName"),refundRecord.getId(),customParameter.getAesFixedKey()); |
dd8aff
|
216 |
} |
Z |
217 |
//返回数据 |
|
218 |
Map<String,Object> data=new HashMap<>(); |
|
219 |
data.put("refundRecordId",refundRecord.getId()); |
|
220 |
data.put("refundRecordCode",refundRecord.getCode()); |
|
221 |
return data; |
|
222 |
} |
|
223 |
|
ff383a
|
224 |
/**查询条数*/ |
21488d
|
225 |
@Override |
Z |
226 |
public int selectCount(SqlSentence sqlSentence) { |
|
227 |
int count = refundRecordMapper.selectCount(sqlSentence); |
|
228 |
return count; |
|
229 |
} |
a9353f
|
230 |
|
Z |
231 |
@Override |
54b8d9
|
232 |
public void refundAduit(CommonService commonService, String operationId,String operationNme, String refundId, CustomParameter customParameter,String appIdCode) { |
Z |
233 |
RefundUtil.refundProcess(commonService, operationId, operationNme, refundId, customParameter, appIdCode,1); |
7c4549
|
234 |
} |
Z |
235 |
|
|
236 |
@Override |
|
237 |
public void reject(RefundRecord refundRecord,String refundId,CommonService commonService) { |
|
238 |
SqlSentence sqlSentence = new SqlSentence(); |
|
239 |
Map<String,Object> map=new HashMap<>(); |
|
240 |
sqlSentence.setM(map); |
|
241 |
map.put("isDel", BaseEntity.NO); |
|
242 |
map.put("refundId", refundId); |
|
243 |
//拒绝退款 |
|
244 |
map.put("refundStatus", RefundStatus.STATUS_FAIL_REFUND); |
|
245 |
map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND); |
a9353f
|
246 |
sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus} where id=#{m.refundId} and isDel=#{m.isDel} and refundStatus=#{m.oldRefundStatus}"); |
0af824
|
247 |
commonService.updateWhere(RefundRecordMapper.class,sqlSentence); |
7c4549
|
248 |
|
Z |
249 |
//更新总订单状态 |
|
250 |
map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_REFUSED); |
|
251 |
map.put("status", OrderTotalConstants.STATUS_DONE); |
|
252 |
map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND); |
|
253 |
map.put("orderId", refundRecord.getOrderId()); |
|
254 |
map.put("isDel", BaseEntity.NO); |
|
255 |
sqlSentence.setSqlSentence(" status=#{m.status},refundStatus=#{m.refundStatus} where id=#{m.orderId} and isDel=#{m.isDel} and refundStatus=#{m.oldRefundStatus}"); |
|
256 |
commonService.updateWhere(OrdersTotalMapper.class,sqlSentence); |
a9353f
|
257 |
} |
Z |
258 |
|
df1cf0
|
259 |
/** |
A |
260 |
* 获取支付方法 |
|
261 |
* @param code 编号 |
|
262 |
* @return 返回 |
|
263 |
*/ |
|
264 |
private PaymentMethod getPaymentMethodByCode(String code){ |
|
265 |
SqlSentence sqlSentence = new SqlSentence(); |
|
266 |
Map<String, Object> sqlValues = new HashMap<>(); |
|
267 |
sqlValues.put("method", code); |
|
268 |
sqlValues.put("isDel", BaseEntity.NO); |
c68a0b
|
269 |
String sql = "select * from payment_method where numberNo=#{m.method} and isDel=#{m.isDel}"; |
df1cf0
|
270 |
sqlSentence.sqlSentence(sql, sqlValues); |
A |
271 |
return commonDao.selectOne(PaymentMethodMapper.class, sqlSentence); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
f0e01d
|
275 |
* 获取退款客户的支付方式 |
c3a7be
|
276 |
* @param refundRecordId 退款总记录标识 |
A |
277 |
* @return 返回 |
|
278 |
*/ |
|
279 |
private RefundRecordMethod getRefundRecordMethodByRefundRecordId(String refundRecordId){ |
|
280 |
SqlSentence sqlSentence = new SqlSentence(); |
|
281 |
Map<String, Object> sqlValues = new HashMap<>(); |
|
282 |
sqlValues.put("refundRecordId", refundRecordId); |
|
283 |
sqlValues.put("isDel", BaseEntity.NO); |
|
284 |
String sql = "select * from refund_record_method where refundRecordId=#{m.refundRecordId} and isDel=#{m.isDel}"; |
|
285 |
sqlSentence.sqlSentence(sql, sqlValues); |
|
286 |
return commonDao.selectOne(RefundRecordMethodMapper.class, sqlSentence); |
f0e01d
|
287 |
} |
A |
288 |
|
|
289 |
/** |
|
290 |
* 获取退款客户的审核记录 |
|
291 |
* @param refundRecordId 退款总记录标识 |
|
292 |
* @return 返回 |
|
293 |
*/ |
|
294 |
private RefundApprove getRefundApproveByRefundRecordId(String refundRecordId){ |
|
295 |
SqlSentence sqlSentence = new SqlSentence(); |
|
296 |
Map<String, Object> sqlValues = new HashMap<>(); |
|
297 |
sqlValues.put("isDel", BaseEntity.NO); |
|
298 |
sqlValues.put("refundRecordId", refundRecordId); |
|
299 |
String sql = "select * from refund_approve where refundRecordId=#{m.refundRecordId} and isDel=#{m.isDel}"; |
|
300 |
sqlSentence.sqlSentence(sql, sqlValues); |
|
301 |
return commonDao.selectOne(RefundApproveMapper.class, sqlSentence); |
c3a7be
|
302 |
} |
A |
303 |
|
|
304 |
/** |
|
305 |
* 操作用户资金 |
|
306 |
* @param refundRecord 资金记录 |
|
307 |
* @param type 是否为提现处理 0 否 1 是 (否就是表示为不通过返回资金) |
|
308 |
*/ |
|
309 |
private void opUserMoneyUnclaimed(RefundRecord refundRecord, Integer type) { |
|
310 |
// 构建操作资金对象 |
|
311 |
UserMoneyUnclaimed userMoneyUnclaimed = new UserMoneyUnclaimed(); |
|
312 |
userMoneyUnclaimed.setUserId(refundRecord.getUserId()); |
|
313 |
userMoneyUnclaimed.setFundType(UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND); |
|
314 |
userMoneyUnclaimed.setOriginChannel(OriginChannelConstants.ORIGIN_CHANNEL_PHIS); |
|
315 |
userMoneyUnclaimed.setOperationReason(OperationReasonConstants.OP_REASON_WITHDRAW); |
|
316 |
userMoneyUnclaimed.setCommonId(refundRecord.getId()); |
|
317 |
// 处理操作人信息 |
|
318 |
if (RefundRecord.OPERATOR_TYPE_EMPLOYEE == refundRecord.getOperatorType()) { |
|
319 |
userMoneyUnclaimed.setOperatorType(UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE); |
|
320 |
userMoneyUnclaimed.setOperatorId(refundRecord.getOperatorId()); |
|
321 |
userMoneyUnclaimed.setOperatorName(refundRecord.getOperatorName()); |
|
322 |
} |
|
323 |
if (RefundRecord.OPERATOR_TYPE_USER == refundRecord.getOperatorType()) { |
|
324 |
userMoneyUnclaimed.setOperatorType(UserMoneyUnclaimed.OPERATOR_TYPE_USER); |
|
325 |
userMoneyUnclaimed.setOperatorId(refundRecord.getOperatorId()); |
|
326 |
userMoneyUnclaimed.setOperatorName(refundRecord.getOperatorName()); |
|
327 |
} |
|
328 |
if (RefundRecord.OPERATOR_TYPE_ADMIN == refundRecord.getOperatorType()) { |
|
329 |
userMoneyUnclaimed.setOperatorType(UserMoneyUnclaimed.OPERATOR_TYPE_ADMIN); |
|
330 |
userMoneyUnclaimed.setOperatorId(refundRecord.getOperatorId()); |
|
331 |
userMoneyUnclaimed.setOperatorName(refundRecord.getOperatorName()); |
|
332 |
} |
|
333 |
String info; |
|
334 |
String title = "客户储值金提现"; |
|
335 |
if (BaseEntity.YES.equals(type)) { |
|
336 |
title += "-提现冻结金额"; |
|
337 |
info = ", 提现冻结金额等待审核出款"; |
|
338 |
userMoneyUnclaimed.setOpNumber(refundRecord.getRefundTotal().negate()); |
|
339 |
} else { |
|
340 |
title += "-回退冻结金额"; |
|
341 |
info = ", 回退冻结金额审核不通过"; |
|
342 |
userMoneyUnclaimed.setOpNumber(refundRecord.getRefundTotal()); |
|
343 |
} |
|
344 |
info = title + info +", 提现金额:" + refundRecord.getRefundTotal(); |
|
345 |
// 标题 |
|
346 |
userMoneyUnclaimed.setOriginSubject(title); |
|
347 |
// 备注 |
|
348 |
userMoneyUnclaimed.setRemarks(info); |
|
349 |
// 调用工具类处理 |
|
350 |
UserMoneyUtil.addUserMoneyUnclaimedData(userMoneyUnclaimed); |
f0e01d
|
351 |
} |
A |
352 |
|
|
353 |
/** |
|
354 |
* 审核处理 |
|
355 |
* @param refundFundsDto 参数 |
|
356 |
* @param refundRecord 退款对象 |
|
357 |
* @param type 状态 0 审核失败 1 审核成功 |
|
358 |
*/ |
|
359 |
private void handlerApprove(RefundFundsDto refundFundsDto, RefundRecord refundRecord, Integer type) { |
|
360 |
RefundApprove refundApprove = this.getRefundApproveByRefundRecordId(refundRecord.getId()); |
|
361 |
if (refundApprove != null) { |
|
362 |
// 营销助手审批标识 |
|
363 |
refundApprove.setApplyId(refundFundsDto.getApplyId()); |
|
364 |
// 审核员 |
|
365 |
Employee employee = commonDao.selectOneByKey(EmployeeMapper.class, refundFundsDto.getExamEmplId()); |
|
366 |
if (employee != null) { |
|
367 |
refundApprove.setExamManId(employee.getId()); |
|
368 |
refundApprove.setExamManName(employee.getCnName()); |
|
369 |
} |
|
370 |
// 是否审核 0 审核失败 1 审核成功 |
|
371 |
if (BaseEntity.YES.equals(type)) { |
|
372 |
refundApprove.setApprovalStatus(RefundApprove.SUCCESS); |
|
373 |
} else { |
|
374 |
refundApprove.setApprovalStatus(RefundApprove.FAIL); |
|
375 |
} |
|
376 |
// 备注 |
|
377 |
if (!StringUtils.isEmpty(refundFundsDto.getRemarks())) { |
|
378 |
refundApprove.setRemarks(refundFundsDto.getRemarks()); |
|
379 |
} |
|
380 |
// 更新时间 |
|
381 |
refundApprove.setEditTime(new Date()); |
|
382 |
// 处理 |
|
383 |
commonDao.updateAll(RefundApproveMapper.class, refundApprove); |
|
384 |
} |
c3a7be
|
385 |
} |
A |
386 |
|
|
387 |
/** |
df1cf0
|
388 |
* 用户资金退款 |
A |
389 |
* @param refundFundsDto 参数 |
|
390 |
*/ |
|
391 |
@Override |
c3a7be
|
392 |
public String refundUserFunds(RefundFundsDto refundFundsDto) { |
df1cf0
|
393 |
// 用户判断 |
A |
394 |
User user = commonDao.selectOneByKey(UserMapper.class, refundFundsDto.getUserId()); |
|
395 |
if (user == null) { |
|
396 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "用户信息不存在!"); |
|
397 |
} |
|
398 |
// 门店判断 |
|
399 |
Shop shop = commonDao.selectOneByKey(ShopMapper.class, refundFundsDto.getShopId()); |
|
400 |
if (shop == null) { |
|
401 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "门店信息不存在!"); |
|
402 |
} |
|
403 |
// 退款总记录 |
|
404 |
RefundRecord refundRecord = new RefundRecord(); |
|
405 |
// 操作人为员工 |
|
406 |
if (RefundRecord.OPERATOR_TYPE_EMPLOYEE == refundFundsDto.getOperatorType()) { |
|
407 |
Employee employee = commonDao.selectOneByKey(EmployeeMapper.class, refundFundsDto.getOperatorId()); |
|
408 |
if (employee == null) { |
|
409 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在"); |
|
410 |
} else { |
|
411 |
refundRecord.setOperatorType(RefundRecord.OPERATOR_TYPE_EMPLOYEE); |
|
412 |
refundRecord.setOperatorId(employee.getId()); |
|
413 |
refundRecord.setOperatorName(employee.getCnName()); |
|
414 |
} |
|
415 |
} |
|
416 |
|
|
417 |
// 操作人为后台用户 |
|
418 |
if (RefundRecord.OPERATOR_TYPE_ADMIN == refundFundsDto.getOperatorType()) { |
|
419 |
SysAdmin sysAdmin = commonDao.selectOneByKey(SysAdminMapper.class, refundFundsDto.getOperatorId()); |
|
420 |
if (sysAdmin == null) { |
|
421 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在"); |
|
422 |
} else { |
|
423 |
refundRecord.setOperatorType(RefundRecord.OPERATOR_TYPE_ADMIN); |
|
424 |
refundRecord.setOperatorId(sysAdmin.getId()); |
|
425 |
refundRecord.setOperatorName(sysAdmin.getName()); |
|
426 |
} |
|
427 |
} |
|
428 |
|
|
429 |
// 操作人为用户 |
|
430 |
if (RefundRecord.OPERATOR_TYPE_USER == refundFundsDto.getOperatorType()) { |
|
431 |
User opUser = commonDao.selectOneByKey(UserMapper.class, refundFundsDto.getOperatorId()); |
|
432 |
if (opUser == null) { |
|
433 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在"); |
|
434 |
} else { |
|
435 |
refundRecord.setOperatorType(RefundRecord.OPERATOR_TYPE_USER); |
|
436 |
refundRecord.setOperatorId(opUser.getId()); |
|
437 |
refundRecord.setOperatorName(opUser.getName()); |
|
438 |
} |
|
439 |
} |
|
440 |
// 退款记录单号 |
|
441 |
String totalCode = systemParameterService.createRecordNo("R", 16, "yyyyMMddHHmmss"); |
|
442 |
refundRecord.setRefundType(1); |
|
443 |
refundRecord.setCode(totalCode); |
|
444 |
refundRecord.setUserId(user.getId()); |
|
445 |
refundRecord.setRefundStatus(OrderTotalConstants.STATUS_REFUND_APPLY); |
|
446 |
refundRecord.setRefundShopId(shop.getId()); |
|
447 |
refundRecord.setRefundShopName(shop.getName()); |
|
448 |
refundRecord.setRefundTotal(refundFundsDto.getRefundTotal()); |
|
449 |
refundRecord.setRealRefundTotal(refundFundsDto.getRefundTotal()); |
|
450 |
refundRecord.setSourceType(RefundSoruceConstants.TYPE_SOURCE_USER); |
|
451 |
refundRecord.setRemarks(refundRecord.getRemarks()); |
|
452 |
// 插入数据 |
|
453 |
int count = refundRecordMapper.insert(refundRecord); |
|
454 |
if (count != 1) { |
|
455 |
throw new TipsException("新增失败!"); |
|
456 |
} else { |
|
457 |
// 获取银行卡退款方式 |
|
458 |
PaymentMethod bank = getPaymentMethodByCode("PM95"); |
|
459 |
if (bank == null){ |
|
460 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "银行卡支付方式不存在"); |
|
461 |
} |
|
462 |
// 获取储值金退款方式 |
|
463 |
PaymentMethod storedValueFund = getPaymentMethodByCode("00000"); |
|
464 |
if (storedValueFund == null){ |
|
465 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "储值金支付方式不存在"); |
|
466 |
} |
|
467 |
|
|
468 |
// 退款方式转换表 |
|
469 |
RefundMethodTransformation refundMethodTransformation = new RefundMethodTransformation(); |
|
470 |
refundMethodTransformation.setRefundRecordId(refundRecord.getId()); |
|
471 |
refundMethodTransformation.setPayMethodNo(storedValueFund.getNumberNo()); |
|
472 |
refundMethodTransformation.setPayMethodName(storedValueFund.getName()); |
|
473 |
refundMethodTransformation.setPayTotal(refundFundsDto.getRefundTotal()); |
|
474 |
refundMethodTransformation.setRefundNumberNo(bank.getNumberNo()); |
|
475 |
refundMethodTransformation.setRefundNumberName(bank.getName()); |
|
476 |
refundMethodTransformation.setRefundTotal(refundFundsDto.getRefundTotal()); |
|
477 |
commonDao.insert(RefundMethodTransformationMapper.class, refundMethodTransformation); |
|
478 |
|
|
479 |
// 退款方式处理 |
|
480 |
RefundRecordMethod refundRecordMethod = new RefundRecordMethod(); |
|
481 |
refundRecordMethod.setNumberNo(storedValueFund.getNumberNo()); |
|
482 |
refundRecordMethod.setRefundNumberNo(bank.getNumberNo()); |
|
483 |
refundRecordMethod.setName(storedValueFund.getName()); |
|
484 |
refundRecordMethod.setPaymentMethodId(storedValueFund.getId()); |
|
485 |
refundRecordMethod.setActualTotal(refundFundsDto.getRefundTotal()); |
|
486 |
refundRecordMethod.setRealRefundTotal(refundFundsDto.getRefundTotal()); |
|
487 |
refundRecordMethod.setIsMoneyPay(BaseEntity.NO); |
|
488 |
refundRecordMethod.setIsExecute(BaseEntity.NO); |
|
489 |
refundRecordMethod.setIsPay(BaseEntity.NO); |
|
490 |
refundRecordMethod.setType(ConsumePayConstants.STATUS_WITHDRAW); |
|
491 |
refundRecordMethod.setRefundRecordId(refundRecord.getId()); |
|
492 |
refundRecordMethod.setPayee(refundFundsDto.getPayee()); |
|
493 |
refundRecordMethod.setOpenBank(refundFundsDto.getOpenBank()); |
|
494 |
refundRecordMethod.setOpenBranch(refundFundsDto.getOpenBranch()); |
|
495 |
refundRecordMethod.setAccount(refundFundsDto.getAccount()); |
|
496 |
refundRecordMethod.setRemarks(refundFundsDto.getRemarks()); |
|
497 |
commonDao.insert(RefundRecordMethodMapper.class, refundRecordMethod); |
|
498 |
|
|
499 |
// 退款审批处理 |
|
500 |
RefundApprove refundApprove = new RefundApprove(); |
|
501 |
refundApprove.setRefundRecordId(refundRecord.getId()); |
|
502 |
refundApprove.setOperatorType(refundRecord.getOperatorType()); |
|
503 |
refundApprove.setOperatorId(refundApprove.getOperatorId()); |
|
504 |
refundApprove.setOperatorName(refundApprove.getOperatorName()); |
|
505 |
Employee opEmployee = commonDao.selectOneByKey(EmployeeMapper.class, refundFundsDto.getOperatorId()); |
|
506 |
if (opEmployee != null) { |
|
507 |
refundApprove.setOperatorType(RefundRecord.OPERATOR_TYPE_EMPLOYEE); |
|
508 |
refundApprove.setOperatorId(opEmployee.getId()); |
|
509 |
refundApprove.setOperatorName(opEmployee.getCnName()); |
|
510 |
refundApprove.setRoleId(opEmployee.getRoleId()); |
|
511 |
refundApprove.setRoleStr(opEmployee.getRoleStr()); |
|
512 |
} |
|
513 |
refundApprove.setShopId(shop.getId()); |
|
514 |
refundApprove.setShopName(shop.getName()); |
|
515 |
refundApprove.setIsApproval(BaseEntity.YES); |
|
516 |
refundApprove.setPlatformSource(refundFundsDto.getPlatformSource()); |
|
517 |
commonDao.insert(RefundApproveMapper.class, refundApprove); |
|
518 |
// 先减扣冻结用户资金处理 |
|
519 |
this.opUserMoneyUnclaimed(refundRecord, BaseEntity.YES); |
|
520 |
} |
c3a7be
|
521 |
return refundRecord.getId(); |
df1cf0
|
522 |
} |
A |
523 |
|
|
524 |
/** |
c3a7be
|
525 |
* 用户资金退款审核 |
A |
526 |
* @param refundFundsDto 参数 |
df1cf0
|
527 |
*/ |
c3a7be
|
528 |
@Override |
A |
529 |
public void refundUserFundsApprove(RefundFundsDto refundFundsDto) { |
|
530 |
RefundRecord refundRecord = refundRecordMapper.selectOneByKey(refundFundsDto.getRefundId()); |
|
531 |
if (refundRecord == null){ |
|
532 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录不存在"); |
df1cf0
|
533 |
} |
c3a7be
|
534 |
if(OrderTotalConstants.STATUS_REFUND_APPLY != refundRecord.getRefundStatus() |
A |
535 |
&& OrderTotalConstants.STATUS_REFUND_WAIT != refundRecord.getRefundStatus()) { |
|
536 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录已被操作请不要重复操作!"); |
df1cf0
|
537 |
} |
c3a7be
|
538 |
RefundRecordMethod refundRecordMethod = getRefundRecordMethodByRefundRecordId(refundRecord.getId()); |
A |
539 |
if (refundRecordMethod == null){ |
|
540 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录的退款方式不存在"); |
df1cf0
|
541 |
} |
c3a7be
|
542 |
if (!ConsumePayConstants.STATUS_WITHDRAW.equals(refundRecordMethod.getType())){ |
A |
543 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录不是提现单!"); |
|
544 |
} |
|
545 |
// 审核通过处理 |
|
546 |
if (BaseEntity.YES.equals(refundFundsDto.getType())){ |
|
547 |
refundRecord.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH); |
df1cf0
|
548 |
} else { |
c3a7be
|
549 |
refundRecord.setRefundStatus(OrderTotalConstants.STATUS_REFUND_REFUSED); |
df1cf0
|
550 |
} |
c3a7be
|
551 |
// 备注处理 |
A |
552 |
if (!StringUtils.isEmpty(refundFundsDto.getRemarks())) { |
|
553 |
refundRecord.setRemarks(refundFundsDto.getRemarks()); |
|
554 |
} |
|
555 |
refundRecord.setEditTime(new Date()); |
|
556 |
int count = refundRecordMapper.updateAll(refundRecord); |
|
557 |
if(count!=1) { |
|
558 |
throw new TipsException("保存失败!"); |
|
559 |
} else { |
|
560 |
// 审核通过处理 |
|
561 |
if (BaseEntity.YES.equals(refundFundsDto.getType())){ |
|
562 |
refundRecordMethod.setIsPay(BaseEntity.YES); |
|
563 |
refundRecordMethod.setEditTime(new Date()); |
00ff55
|
564 |
// 更新数据 |
A |
565 |
commonDao.updateAll(RefundRecordMethodMapper.class, refundRecordMethod); |
f0e01d
|
566 |
// 审核成功 |
A |
567 |
handlerApprove(refundFundsDto, refundRecord, BaseEntity.YES); |
c3a7be
|
568 |
} else { |
f0e01d
|
569 |
// 审核失败 |
A |
570 |
handlerApprove(refundFundsDto, refundRecord, BaseEntity.NO); |
c3a7be
|
571 |
// 审核不通过退回资金 |
A |
572 |
this.opUserMoneyUnclaimed(refundRecord, BaseEntity.NO); |
|
573 |
} |
|
574 |
} |
df1cf0
|
575 |
} |
4ee214
|
576 |
|
A |
577 |
/** |
|
578 |
* 用户资金退款作废 |
|
579 |
* @param refundFundsDto 参数 |
|
580 |
*/ |
|
581 |
@Override |
|
582 |
public void refundUserFundsCancel(RefundFundsDto refundFundsDto) { |
|
583 |
RefundRecord refundRecord = refundRecordMapper.selectOneByKey(refundFundsDto.getRefundId()); |
|
584 |
if (refundRecord == null){ |
|
585 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录不存在"); |
|
586 |
} |
|
587 |
if(OrderTotalConstants.STATUS_REFUND_APPLY != refundRecord.getRefundStatus() |
|
588 |
&& OrderTotalConstants.STATUS_REFUND_WAIT != refundRecord.getRefundStatus()) { |
|
589 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录已被操作请不要重复操作!"); |
|
590 |
} |
|
591 |
RefundRecordMethod refundRecordMethod = getRefundRecordMethodByRefundRecordId(refundRecord.getId()); |
|
592 |
if (refundRecordMethod == null){ |
|
593 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录的退款方式不存在"); |
|
594 |
} |
|
595 |
if (!ConsumePayConstants.STATUS_WITHDRAW.equals(refundRecordMethod.getType())){ |
|
596 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "退款记录不是提现单!"); |
|
597 |
} |
|
598 |
// 作废处理 |
|
599 |
refundRecord.setRefundStatus(OrderTotalConstants.STATUS_REFUND_REVOKE); |
|
600 |
// 备注处理 |
|
601 |
if (!StringUtils.isEmpty(refundFundsDto.getRemarks())) { |
|
602 |
refundRecord.setRemarks(refundFundsDto.getRemarks()); |
|
603 |
} |
|
604 |
refundRecord.setEditTime(new Date()); |
|
605 |
int count = refundRecordMapper.updateAll(refundRecord); |
|
606 |
if(count!=1) { |
|
607 |
throw new TipsException("保存失败!"); |
|
608 |
} else { |
f0e01d
|
609 |
// 审核失败 |
A |
610 |
handlerApprove(refundFundsDto, refundRecord, BaseEntity.NO); |
4ee214
|
611 |
// 审核不通过退回资金 |
A |
612 |
this.opUserMoneyUnclaimed(refundRecord, BaseEntity.NO); |
|
613 |
} |
|
614 |
} |
21488d
|
615 |
} |