提交 | 用户 | age
|
a1c527
|
1 |
package com.hx.phip.tool.refund; |
ae6ff7
|
2 |
|
C |
3 |
import com.hx.common.service.CommonService; |
|
4 |
import com.hx.exception.TipsException; |
|
5 |
import com.hx.mybatisTool.SqlSentence; |
|
6 |
import com.hx.phiappt.common.*; |
|
7 |
import com.hx.phiappt.constants.enums.GroupTypeEnum; |
|
8 |
import com.hx.phiappt.constants.tool.RefundToolUtil; |
|
9 |
import com.hx.phiappt.model.BaseEntity; |
|
10 |
import com.hx.phiappt.model.UserMoney; |
|
11 |
import com.hx.phiappt.model.activity.ActivityAction; |
|
12 |
import com.hx.phiappt.model.activity.ActivityRule; |
a1c527
|
13 |
import com.hx.phiappt.model.cardItem.CardEquity; |
C |
14 |
import com.hx.phiappt.model.cardItem.CardItemInfo; |
ae6ff7
|
15 |
import com.hx.phiappt.model.consume.ConsumePay; |
C |
16 |
import com.hx.phiappt.model.consume.ConsumePayItem; |
2a45d4
|
17 |
import com.hx.phiappt.model.consume.ConsumePayItemSon; |
ae6ff7
|
18 |
import com.hx.phiappt.model.coupon.CouponNumber; |
C |
19 |
import com.hx.phiappt.model.coupon.CouponOrderDiscountLog; |
|
20 |
import com.hx.phiappt.model.order.*; |
|
21 |
import com.hx.phiappt.model.refund.*; |
|
22 |
import com.hx.phiappt.model.user.UserCard; |
|
23 |
import com.hx.phiappt.model.user.UserCardUsed; |
|
24 |
import com.hx.phiappt.model.user.UserProjectItem; |
|
25 |
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed; |
|
26 |
import com.hx.phip.dao.mapper.*; |
|
27 |
import com.hx.phip.tool.user.UserProjectTool; |
a1c527
|
28 |
import com.hx.phip.util.api.UserMoneyUtil; |
1869f3
|
29 |
import com.hx.phip.vo.order.refund.RefundCarryVo; |
C |
30 |
import com.hx.phip.vo.user.UserProjectDeductionVo; |
ae6ff7
|
31 |
import com.hx.util.StringUtils; |
C |
32 |
import com.platform.exception.PlatTipsException; |
|
33 |
import com.platform.resultTool.PlatformCode; |
2a45d4
|
34 |
import org.springframework.beans.BeanUtils; |
ae6ff7
|
35 |
|
C |
36 |
import java.math.BigDecimal; |
|
37 |
import java.math.RoundingMode; |
|
38 |
import java.util.*; |
|
39 |
import java.util.stream.Collectors; |
|
40 |
|
|
41 |
/** |
|
42 |
* @Author |
|
43 |
*/ |
|
44 |
public class PartialRefundUtil { |
|
45 |
|
2a45d4
|
46 |
/**有子项退款的类型*/ |
C |
47 |
public static Set<String> CONTAIN_SON_TYPE_SET; |
|
48 |
|
ae6ff7
|
49 |
/**领建优惠券标识*/ |
C |
50 |
public static final String HIS_COUPON_CODE = "his_coupon_code"; |
2a45d4
|
51 |
|
C |
52 |
static { |
|
53 |
CONTAIN_SON_TYPE_SET = new HashSet<>(); |
|
54 |
CONTAIN_SON_TYPE_SET.add(OrderItemConstants.TYPE_PROMOTION); |
|
55 |
CONTAIN_SON_TYPE_SET.add(OrderItemConstants.CARD_BAG); |
|
56 |
} |
ae6ff7
|
57 |
|
C |
58 |
/** |
|
59 |
* 退款总流程工具 |
a1c527
|
60 |
* @param commonService 映射 |
C |
61 |
* @param operationId 操作人标识 |
|
62 |
* @param operationNme 操作人名称 |
|
63 |
* @param refundId 退款总单标识 |
ae6ff7
|
64 |
*/ |
a1c527
|
65 |
public static OrdersTotal refundProcess(CommonService commonService, String operationId, String operationNme, String refundId) { |
ae6ff7
|
66 |
|
C |
67 |
RefundRecord refundRecord = commonService.selectOneByKeyBlob(RefundRecordMapper.class,refundId); |
|
68 |
if(refundRecord ==null){ |
|
69 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到该退款信息!"); |
|
70 |
} |
|
71 |
|
|
72 |
SqlSentence sqlSentence = new SqlSentence(); |
|
73 |
Map<String,Object> values = new HashMap<>(); |
|
74 |
|
|
75 |
//退款总订单状态变更 |
|
76 |
values.put("refundStatus", RefundStatus.STATUS_SUCC_REFUND); |
|
77 |
values.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND); |
2a45d4
|
78 |
values.put("refundTotal", refundRecord.getRefundTotal()); |
ae6ff7
|
79 |
values.put("isDel", BaseEntity.NO); |
C |
80 |
values.put("id",refundRecord.getId()); |
2a45d4
|
81 |
sqlSentence.sqlSentence(" refundTotal = #{m.refundTotal},refundStatus=#{m.refundStatus} WHERE id = #{m.id} AND isDel=#{m.isDel} AND refundStatus = #{m.oldRefundStatus}",values); |
ae6ff7
|
82 |
if(commonService.updateWhere(RefundRecordMapper.class,sqlSentence) != 1){ |
C |
83 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作失败,退款单状态已改变!"); |
|
84 |
} |
|
85 |
|
510678
|
86 |
//获取订单信息 |
ae6ff7
|
87 |
OrdersTotal ordersTotal = commonService.selectOneByKeyBlob(OrdersTotalMapper.class,refundRecord.getOrderId()); |
C |
88 |
if(ordersTotal == null ){ |
|
89 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到订单信息!"); |
|
90 |
} |
|
91 |
|
|
92 |
//查询用户是否有账户信息,退款需要处理资金 |
a1c527
|
93 |
values.clear(); |
ae6ff7
|
94 |
values.put("userId",refundRecord.getUserId()); |
e9e32c
|
95 |
sqlSentence.sqlSentence("SELECT * FROM user_money WHERE userId=#{m.userId} AND isDel=0",values); |
ae6ff7
|
96 |
UserMoney userMoney=commonService.selectOne(UserMoneyMapper.class,sqlSentence); |
C |
97 |
if(userMoney==null){ |
|
98 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该用户的资金信息"); |
|
99 |
} |
1869f3
|
100 |
|
C |
101 |
//获取总退款方式 |
|
102 |
values.put("refundRecordId",refundRecord.getId()); |
|
103 |
sqlSentence.sqlSentence("SELECT * FROM refund_record_method WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",values); |
|
104 |
List<RefundRecordMethod> refundRecordMethodList = commonService.selectList(RefundRecordMethodMapper.class,sqlSentence); |
|
105 |
|
|
106 |
//全程使用携带参数对象 |
|
107 |
RefundCarryVo refundCarryVo = new RefundCarryVo(); |
|
108 |
refundCarryVo.setRefundRecordMethodList(refundRecordMethodList); |
ae6ff7
|
109 |
|
C |
110 |
if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){ |
|
111 |
//充值订单需要把充值的储值金 拿回来 因为储值金需要开单来处理,所以不需要增加日志 |
|
112 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
113 |
if(ordersTotal.getActualTotal().compareTo(BigDecimal.ZERO)!=0){ |
|
114 |
//交给审批前操作 |
|
115 |
/* UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式储值金额退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),new BigDecimal(String.valueOf(ordersTotal.getTotal())).negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
|
116 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, "储值金客户退回金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND); |
|
117 |
commonService.insert(OrderLogMapper.class,orderLog);*/ |
|
118 |
//活动规则退款处理 |
|
119 |
// handActivityRule(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,orderInfo); |
|
120 |
} |
a1c527
|
121 |
//处理支付方式和退款方式关联 |
C |
122 |
refundCarryVo = rechargeRefundMothedHandle(refundCarryVo,refundRecord,commonService); |
|
123 |
}else{ |
|
124 |
//子单退款项处理 |
|
125 |
refundCarryVo = numberOfRefunds(refundCarryVo,operationId, refundRecord,ordersTotal,commonService); |
ae6ff7
|
126 |
} |
a1c527
|
127 |
//处理优惠券 |
C |
128 |
handCoupon(refundRecord,commonService); |
|
129 |
//处理总退款方式数据 |
|
130 |
refundCarryVo = refundRecordMotnedHandle(refundCarryVo,operationId,operationNme,refundRecord,ordersTotal,commonService); |
ae6ff7
|
131 |
|
C |
132 |
//更改总订单退款状态 |
|
133 |
values.clear(); |
|
134 |
values.put("orderId",ordersTotal.getId()); |
e9e32c
|
135 |
sqlSentence.sqlSentence("select * from order_item WHERE orderId=#{m.orderId} and isDel=0",values); |
ae6ff7
|
136 |
List<OrderItem> orderItemList=commonService.selectList(OrderItemMapper.class,sqlSentence); |
C |
137 |
|
f72f73
|
138 |
values.clear(); |
C |
139 |
values.put("oldStatus",ordersTotal.getStatus()); |
|
140 |
values.put("oldRefundStatus",ordersTotal.getRefundStatus()); |
|
141 |
|
a1c527
|
142 |
List<Integer> collect = orderItemList.stream().map(OrderItem::getRefundStatus).collect(Collectors.toList()); |
ae6ff7
|
143 |
if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){ |
C |
144 |
ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); |
|
145 |
ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
|
146 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
|
147 |
ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); |
|
148 |
ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
|
149 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ |
|
150 |
ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
|
151 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
|
152 |
ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH); |
|
153 |
ordersTotal.setStatus(OrderTotalConstants.STATUS_CANCEL); |
|
154 |
ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
|
155 |
}else { |
|
156 |
if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){ |
|
157 |
if(ordersTotal.getActualTotal().compareTo(refundRecord.getRefundTotal()) <= 0){ |
|
158 |
ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH); |
f72f73
|
159 |
ordersTotal.setStatus(OrderTotalConstants.STATUS_CANCEL); |
C |
160 |
ordersTotal.setReTotal(ordersTotal.getReTotal().add(refundRecord.getRefundTotal())); |
ae6ff7
|
161 |
}else{ |
C |
162 |
ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); |
f72f73
|
163 |
ordersTotal.setReTotal(ordersTotal.getReTotal().add(refundRecord.getRefundTotal())); |
ae6ff7
|
164 |
} |
C |
165 |
}else{ |
|
166 |
ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
|
167 |
} |
|
168 |
} |
|
169 |
ordersTotal.setIsSyncOrder(BaseEntity.NO); |
f72f73
|
170 |
|
C |
171 |
values.put("isSyncOrder",BaseEntity.NO); |
|
172 |
values.put("status",ordersTotal.getStatus()); |
|
173 |
values.put("refundStatus",ordersTotal.getRefundStatus()); |
|
174 |
values.put("reTotal",ordersTotal.getReTotal()); |
|
175 |
values.put("id",ordersTotal.getId()); |
|
176 |
sqlSentence.sqlUpdate("isSyncOrder = #{m.isSyncOrder},status = #{m.status},refundStatus = #{m.refundStatus},reTotal = #{m.reTotal}" + |
|
177 |
" WHERE id = #{m.id} AND status = #{m.oldStatus} AND refundStatus = #{m.oldRefundStatus}",values); |
|
178 |
if(commonService.updateWhere(OrdersTotalMapper.class,sqlSentence) != 1){ |
|
179 |
throw new TipsException("操作失败,订单状态已发生改变!"); |
|
180 |
} |
ae6ff7
|
181 |
return ordersTotal; |
C |
182 |
} |
|
183 |
|
|
184 |
/**处理总退款方式数据*/ |
a1c527
|
185 |
public static RefundCarryVo refundRecordMotnedHandle(RefundCarryVo refundCarryVo,String operationId,String operationNme |
C |
186 |
,RefundRecord refundRecord,OrdersTotal ordersTotal,CommonService commonService){ |
ae6ff7
|
187 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
188 |
Map<String,Object> map = new HashMap<>(); |
|
189 |
|
|
190 |
//获取总退款方式 |
a1c527
|
191 |
List<RefundRecordMethod> refundRecordMethodList = refundCarryVo.getRefundRecordMethodList(); |
2a45d4
|
192 |
//退款的支付方式记录数据 |
a1c527
|
193 |
List<RefundRecordConsumePay> refundConsumePayList = refundCarryVo.getRefundConsumePayList(); |
2a45d4
|
194 |
//通过支付编号,装载分组好支付方式记录,key值:支付方式编号,value:支付方式记录集合 |
a1c527
|
195 |
Map<String,List<RefundRecordConsumePay>> refundConsumePayMap= new HashMap<>(); |
C |
196 |
List<RefundRecordConsumePay> refundRecordConsumePays; |
|
197 |
for(RefundRecordConsumePay refundRecordConsumePay:refundConsumePayList){ |
|
198 |
refundRecordConsumePays = refundConsumePayMap.computeIfAbsent(refundRecordConsumePay.getNumberNo(),k->new ArrayList<>()); |
|
199 |
refundRecordConsumePays.add(refundRecordConsumePay); |
|
200 |
} |
ae6ff7
|
201 |
|
a1c527
|
202 |
List<RefundRecordConsumePay> refundRecordConsumePayList = new ArrayList<>(); |
C |
203 |
RefundRecordConsumePay refundRecordConsumePay1; |
ae6ff7
|
204 |
|
C |
205 |
for(RefundRecordMethod refundRecordMethod:refundRecordMethodList){ |
8b5222
|
206 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO) < 1){ |
C |
207 |
continue; |
|
208 |
} |
2a45d4
|
209 |
//判断是否已经被分配完 |
a1c527
|
210 |
if(refundRecordMethod.getpTotal().compareTo(BigDecimal.ZERO) > 0){ |
C |
211 |
throw new TipsException("退款错误[20]!"); |
|
212 |
} |
|
213 |
refundRecordConsumePays = refundConsumePayMap.get(refundRecordMethod.getNumberNo()); |
|
214 |
if(refundRecordConsumePays == null){ |
|
215 |
throw new TipsException("退款错误[21]!"); |
|
216 |
} |
|
217 |
for(RefundRecordConsumePay refundRecordConsumePay:refundRecordConsumePays){ |
|
218 |
//更新支付记录退款信息 |
|
219 |
map.clear(); |
|
220 |
map.put("refundTotal",refundRecordConsumePay.getRefundTotal()); |
|
221 |
map.put("id",refundRecordConsumePay.getConsumePayId()); |
|
222 |
sqlSentence.sqlUpdate("refundTotal = refundTotal + #{m.refundTotal} WHERE id = #{m.id} AND actualTotal >= refundTotal + #{m.refundTotal}",map); |
|
223 |
if(commonService.updateWhere(ConsumePayMapper.class,sqlSentence) != 1){ |
|
224 |
throw new TipsException("退款金额错误[33]!"); |
|
225 |
} |
|
226 |
|
|
227 |
//生成关联记录 |
|
228 |
refundRecordConsumePay1 = insertRefundRecordConsumePay(refundRecordConsumePay.getRefundTotal(),null,null,refundRecord.getOrderId(),refundRecordConsumePay.getNumberNo() |
2a45d4
|
229 |
,refundRecordConsumePay.getName(),refundRecordConsumePay.getIsMoneyPay(),refundRecordConsumePay.getIsExecute(),refundRecordConsumePay.getConsumePayId(),refundRecordMethod.getId(),null,refundRecord.getId(),commonService); |
a1c527
|
230 |
refundRecordConsumePayList.add(refundRecordConsumePay1); |
C |
231 |
} |
|
232 |
//修改实际退款金额 |
|
233 |
map.put("realRefundTotal",refundRecordMethod.getActualTotal()); |
|
234 |
map.put("id",refundRecordMethod.getId()); |
|
235 |
sqlSentence.sqlUpdate(" realRefundTotal = realRefundTotal + #{m.realRefundTotal} where id = #{m.id}",map); |
|
236 |
if(commonService.updateWhere(RefundRecordMethodMapper.class,sqlSentence) != 1){ |
|
237 |
throw new TipsException("更新退款方式信息错误[001]"); |
|
238 |
} |
|
239 |
|
|
240 |
} |
|
241 |
refundCarryVo.setRefundConsumePayList(refundRecordConsumePayList); |
|
242 |
|
|
243 |
//处理回退到账 |
|
244 |
for(RefundRecordMethod refundRecordMethod:refundRecordMethodList){ |
ae6ff7
|
245 |
if(PayMethodTypeConstants.PAY_STORED.equals(refundRecordMethod.getRefundNumberNo())){ |
C |
246 |
//储值金额 |
|
247 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
248 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)>0){ |
|
249 |
UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式储值金额退回",operationId,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundRecord.getId(),refundRecordMethod.getActualTotal(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
|
250 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, refundRecordMethod.getName()+"退款金额:"+refundRecordMethod.getActualTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND); |
|
251 |
commonService.insert(OrderLogMapper.class,orderLog); |
|
252 |
} |
|
253 |
}else if(PayMethodTypeConstants.PAY_ADD_FUND.equals(refundRecordMethod.getRefundNumberNo())){ |
|
254 |
//增值金 |
|
255 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
256 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)!=0){ |
|
257 |
UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式增值金退回",operationId,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundRecord.getId(),refundRecordMethod.getActualTotal(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
258 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,refundRecordMethod.getName(),0, OrderLogConstants.LOG_TYPE_REFUND); |
|
259 |
commonService.insert(OrderLogMapper.class,orderLog); |
|
260 |
} |
|
261 |
}else if(PayMethodTypeConstants.PAY_INTEGRAL.equals(refundRecordMethod.getRefundNumberNo())){ |
|
262 |
//积分 |
|
263 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
264 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)!=0){ |
|
265 |
UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式积分退回",operationId,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundRecord.getId(),refundRecordMethod.getActualTotal(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
266 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,refundRecordMethod.getName()+"退款金额:"+refundRecordMethod.getActualTotal(),0, OrderLogConstants.LOG_TYPE_REFUND); |
|
267 |
commonService.insert(OrderLogMapper.class,orderLog); |
|
268 |
} |
|
269 |
}else { |
|
270 |
//现金支付 |
|
271 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)<1){ |
|
272 |
continue; |
|
273 |
} |
|
274 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,refundRecordMethod.getName()+"退款金额:"+refundRecordMethod.getActualTotal(),0, OrderLogConstants.LOG_TYPE_REFUND); |
|
275 |
orderLog.setOrderId(ordersTotal.getId()); |
|
276 |
commonService.insert(OrderLogMapper.class,orderLog); |
|
277 |
|
|
278 |
//现金支付需要创建创建退款单进行退款 |
|
279 |
RefundNote refundNote = new RefundNote(refundRecordMethod.getActualTotal(), refundRecordMethod.getNumberNo(),refundRecordMethod.getName(),ordersTotal.getId(),refundRecord.getUserId()); |
|
280 |
refundNote.setRefundRecordId(refundRecord.getId()); |
|
281 |
commonService.insert(RefundNoteMapper.class,refundNote); |
|
282 |
} |
a1c527
|
283 |
} |
C |
284 |
return refundCarryVo; |
|
285 |
} |
|
286 |
|
|
287 |
/**充值订单退款方式的支付方式记录处理*/ |
|
288 |
public static RefundCarryVo rechargeRefundMothedHandle(RefundCarryVo refundCarryVo,RefundRecord refundRecord,CommonService commonService){ |
|
289 |
|
|
290 |
SqlSentence sqlSentence = new SqlSentence(); |
|
291 |
Map<String,Object> map = new HashMap<>(); |
|
292 |
|
|
293 |
List<RefundRecordMethod> refundRecordMethodList = refundCarryVo.getRefundRecordMethodList(); |
|
294 |
|
510678
|
295 |
//装载分配好的支付方式记录的金额数据 |
a1c527
|
296 |
List<RefundRecordConsumePay> refundConsumePayList = new ArrayList<>(); |
C |
297 |
RefundRecordConsumePay refundRecordConsumePay; |
|
298 |
|
510678
|
299 |
///////获取订单支付方式记录 |
C |
300 |
map.put("orderId",refundRecord.getOrderId()); |
|
301 |
sqlSentence.sqlSentence("SELECT *,ROUND(actualTotal-refundTotal,2) AS pTotal FROM consume_pay WHERE isDel = 0 AND orderId = #{m.orderId} ORDER BY pTotal ASC",map); |
|
302 |
List<ConsumePay> consumePayList = commonService.selectList(ConsumePayMapper.class,sqlSentence); |
|
303 |
//根据支付编号进行区分,key值:支付编号 |
|
304 |
Map<String,List<ConsumePay>> consumePayMap = new HashMap<>(); |
|
305 |
List<ConsumePay> consumePays; |
|
306 |
for(ConsumePay consumePay:consumePayList){ |
|
307 |
consumePays = consumePayMap.computeIfAbsent(consumePay.getNumberNo(),k->new ArrayList<>()); |
|
308 |
consumePays.add(consumePay); |
|
309 |
} |
|
310 |
|
|
311 |
////引用对象 |
|
312 |
//退款方式的金额 |
a1c527
|
313 |
BigDecimal mothedTotal; |
510678
|
314 |
//分配支付方式金额 |
a1c527
|
315 |
BigDecimal mothedCutTotal; |
C |
316 |
for(RefundRecordMethod refundRecordMethod:refundRecordMethodList){ |
510678
|
317 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO) < 1){ |
C |
318 |
continue; |
|
319 |
} |
a1c527
|
320 |
mothedTotal = refundRecordMethod.getActualTotal(); |
510678
|
321 |
consumePays = consumePayMap.get(refundRecordMethod.getNumberNo()); |
C |
322 |
if(consumePays == null){ |
|
323 |
throw new TipsException("没有找到该支付记录:"+refundRecordMethod.getName()+"["+refundRecordMethod.getNumberNo()+"]"); |
|
324 |
} |
|
325 |
for(ConsumePay consumePay:consumePays){ |
ae6ff7
|
326 |
if(consumePay.getpTotal().compareTo(BigDecimal.ZERO) < 1){ |
C |
327 |
continue; |
|
328 |
} |
|
329 |
//计算扣减金额 |
|
330 |
if(consumePay.getpTotal().compareTo(mothedTotal) > 0){ |
|
331 |
mothedCutTotal = mothedTotal; |
|
332 |
}else{ |
|
333 |
mothedCutTotal = consumePay.getpTotal(); |
|
334 |
} |
a1c527
|
335 |
//减去已经分配的金额 |
ae6ff7
|
336 |
mothedTotal = mothedTotal.subtract(mothedCutTotal).setScale(2, RoundingMode.HALF_UP); |
a1c527
|
337 |
|
C |
338 |
refundRecordConsumePay = new RefundRecordConsumePay(); |
|
339 |
refundRecordConsumePay.setNumberNo(consumePay.getNumberNo()); |
|
340 |
refundRecordConsumePay.setName(consumePay.getName()); |
|
341 |
refundRecordConsumePay.setRefundTotal(mothedCutTotal); |
|
342 |
refundRecordConsumePay.setConsumePayId(consumePay.getId()); |
8b5222
|
343 |
refundRecordConsumePay.setIsMoneyPay(consumePay.getIsMoneyPay()); |
C |
344 |
refundRecordConsumePay.setIsExecute(consumePay.getIsPay()); |
a1c527
|
345 |
refundConsumePayList.add(refundRecordConsumePay); |
C |
346 |
|
ae6ff7
|
347 |
//已经分配完成,跳出循环 |
C |
348 |
if(mothedTotal.compareTo(BigDecimal.ZERO) < 1){ |
|
349 |
//跳出循环 |
|
350 |
break; |
|
351 |
} |
|
352 |
} |
|
353 |
//判断退款金额是否已经全部分配 |
|
354 |
if(mothedTotal.compareTo(BigDecimal.ZERO) > 0){ |
|
355 |
throw new TipsException("退款金额错误[426]!"); |
|
356 |
} |
a1c527
|
357 |
refundRecordMethod.setpTotal(BigDecimal.ZERO); |
ae6ff7
|
358 |
} |
a1c527
|
359 |
refundCarryVo.setRefundConsumePayList(refundConsumePayList); |
C |
360 |
return refundCarryVo; |
ae6ff7
|
361 |
} |
C |
362 |
|
1869f3
|
363 |
/**处理一级子退款方式数据 |
C |
364 |
* @param deductionTotalUser 用户项目被扣减的划扣金额,可空 |
|
365 |
* @param refundRecord 退款记录总表 |
|
366 |
* @param refundRecordItem 退款记录子表 |
|
367 |
* @param refundCarryVo 总携带参数结构 |
|
368 |
* @param commonService 映射 |
|
369 |
* @return 总携带参数结构 |
|
370 |
*/ |
|
371 |
public static RefundCarryVo refundRecordMotnedItemHandle(BigDecimal deductionTotalUser,RefundRecord refundRecord,RefundRecordItem refundRecordItem |
|
372 |
,RefundCarryVo refundCarryVo,CommonService commonService){ |
|
373 |
|
510678
|
374 |
//没有退款方式,跳过当前处理,因为这里是处理退款方式金额的,如果没有退款金额,那么可以跳过该环节 |
1869f3
|
375 |
if(refundCarryVo.getRefundRecordMethodList().size() == 0){ |
C |
376 |
return refundCarryVo; |
|
377 |
} |
|
378 |
//支付方式占比 |
|
379 |
BigDecimal payMothedPercentage; |
|
380 |
//计算退款方式的占比 |
|
381 |
if(refundRecord.getRefundTotal().compareTo(BigDecimal.ZERO) > 0){ |
|
382 |
payMothedPercentage = refundRecordItem.getRefundMoney().divide(refundRecord.getRefundTotal(),15,RoundingMode.HALF_UP); |
|
383 |
}else{ |
|
384 |
payMothedPercentage = BigDecimal.ZERO; |
ae6ff7
|
385 |
} |
C |
386 |
|
1869f3
|
387 |
//处理退款方式 |
C |
388 |
refundCarryVo = insertRefundItemMothed(refundRecordItem.getId(),refundRecordItem.getRefundMoney(),payMothedPercentage,OrderSourceConstans.TYPE_PROJECT |
|
389 |
,refundRecordItem.getOrderItemId(),refundCarryVo,refundRecord,commonService); |
a1c527
|
390 |
|
2a45d4
|
391 |
//更新退款子单 |
C |
392 |
updateRefundItem(refundCarryVo.getDeductionTotal(),refundCarryVo.getCashTotal(),deductionTotalUser |
|
393 |
,refundRecordItem.getId(),commonService); |
|
394 |
|
|
395 |
return refundCarryVo; |
|
396 |
} |
|
397 |
|
|
398 |
/**更新退款一级子单的信息 |
|
399 |
* @param deductionTotal 退款方式的划扣金额 |
|
400 |
* @param cashTotal 退款方式的现金金额 |
|
401 |
* @param deductionTotalUser 用户项目的划扣金额 |
|
402 |
* @param refundItemId 退款记录一级子单标识 |
|
403 |
* @param commonService 映射 |
|
404 |
*/ |
|
405 |
public static void updateRefundItem(BigDecimal deductionTotal,BigDecimal cashTotal,BigDecimal deductionTotalUser |
|
406 |
,String refundItemId,CommonService commonService){ |
a1c527
|
407 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
408 |
Map<String,Object> values = new HashMap<>(); |
ae6ff7
|
409 |
|
510678
|
410 |
//更新退款子单的信息,更新现金和划扣金额保存 |
2a45d4
|
411 |
values.put("deductionTotal",deductionTotal); |
1869f3
|
412 |
values.put("deductionTotalUser",deductionTotalUser==null?BigDecimal.ZERO:deductionTotalUser); |
2a45d4
|
413 |
values.put("cashTotal",cashTotal); |
C |
414 |
values.put("id",refundItemId); |
1869f3
|
415 |
sqlSentence.sqlUpdate("deductionTotal = #{m.deductionTotal},deductionTotalUser = #{m.deductionTotalUser},cashTotal = #{m.cashTotal} WHERE id = #{m.id}",values); |
C |
416 |
if(commonService.updateWhere(RefundRecordItemMapper.class,sqlSentence) != 1){ |
|
417 |
throw new TipsException("更新退款子项信息失败!"); |
|
418 |
} |
|
419 |
} |
|
420 |
|
|
421 |
/**处理二级子退款方式数据 |
|
422 |
* @param deductionTotalUser 用户项目被扣减的划扣金额 |
|
423 |
* @param refundRecord 退款记录总表 |
|
424 |
* @param refundRecordItemSource 退款记录子表 |
|
425 |
* @param refundCarryVo 总携带参数结构 |
|
426 |
* @param commonService 映射 |
|
427 |
* @return 总携带参数结构 |
|
428 |
*/ |
|
429 |
public static RefundCarryVo refundRecordMotnedItemTwoHandle(BigDecimal deductionTotalUser,RefundRecord refundRecord,RefundRecordItemSource refundRecordItemSource |
|
430 |
,RefundCarryVo refundCarryVo,CommonService commonService){ |
|
431 |
|
|
432 |
//装载支付方式退款信息 |
|
433 |
refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
|
434 |
//没有退款方式,跳过当前处理 |
|
435 |
if(refundCarryVo.getRefundRecordMethodList().size() == 0){ |
|
436 |
return refundCarryVo; |
|
437 |
} |
|
438 |
|
|
439 |
SqlSentence sqlSentence = new SqlSentence(); |
|
440 |
Map<String,Object> values = new HashMap<>(); |
|
441 |
|
|
442 |
//支付方式占比 |
|
443 |
BigDecimal payMothedPercentage; |
|
444 |
//计算退款方式的占比 |
|
445 |
if(refundRecord.getRefundTotal().compareTo(BigDecimal.ZERO) > 0){ |
|
446 |
payMothedPercentage = refundRecordItemSource.getRefundMoney().divide(refundRecord.getRefundTotal(),15,RoundingMode.HALF_UP); |
|
447 |
}else{ |
|
448 |
payMothedPercentage = BigDecimal.ZERO; |
|
449 |
} |
|
450 |
|
|
451 |
//处理退款方式 |
|
452 |
refundCarryVo = insertRefundItemMothed(refundRecordItemSource.getId(),refundRecordItemSource.getRefundMoney(),payMothedPercentage,OrderSourceConstans.TYPE_RETAIL |
|
453 |
,refundRecordItemSource.getOrderItemSonId(),refundCarryVo,refundRecord,commonService); |
|
454 |
|
|
455 |
values.put("deductionTotal",refundCarryVo.getDeductionTotal()); |
|
456 |
values.put("deductionTotalUser",deductionTotalUser==null?BigDecimal.ZERO:deductionTotalUser); |
|
457 |
values.put("cashTotal",refundCarryVo.getCashTotal()); |
|
458 |
values.put("id",refundRecordItemSource.getId()); |
|
459 |
sqlSentence.sqlUpdate("deductionTotal = #{m.deductionTotal},deductionTotalUser = #{m.deductionTotalUser},cashTotal = #{m.cashTotal} WHERE id = #{m.id}",values); |
|
460 |
if(commonService.updateWhere(RefundRecordItemSourceMapper.class,sqlSentence) != 1){ |
|
461 |
throw new TipsException("更新退款子项信息失败[94]!"); |
|
462 |
} |
|
463 |
|
|
464 |
return refundCarryVo; |
|
465 |
} |
|
466 |
|
|
467 |
/**退款子单退款方式处理保存 |
|
468 |
* @param refundItemId 退款子单标识 |
|
469 |
* @param refundItemTotal 退款子单实际需要退款总金额 |
|
470 |
* @param payMothedPercentage 支付方式占比 |
|
471 |
* @param orderItemType 订单子单级别 |
|
472 |
* @param orderItemId 订单子单标识 |
|
473 |
* @param refundCarryVo 总结构对象 |
|
474 |
* @param refundRecord 退款总记录 |
|
475 |
* @param commonService 映射 |
|
476 |
* @return 总结构对象 |
|
477 |
*/ |
|
478 |
public static RefundCarryVo insertRefundItemMothed(String refundItemId,BigDecimal refundItemTotal,BigDecimal payMothedPercentage,String orderItemType |
|
479 |
,String orderItemId,RefundCarryVo refundCarryVo,RefundRecord refundRecord,CommonService commonService){ |
|
480 |
|
|
481 |
//总退款方式金额数据 |
|
482 |
List<RefundRecordMethod> refundRecordMethodList = refundCarryVo.getRefundRecordMethodList(); |
|
483 |
//进行升序排序,避免后面不够分配 |
|
484 |
refundRecordMethodList = refundRecordMethodList.stream().sorted(Comparator.comparing(RefundRecordMethod::getpTotal)).collect(Collectors.toList()); |
|
485 |
|
510678
|
486 |
//获取子单的支付方式记录,计算可退款金额 |
1869f3
|
487 |
List<ConsumePayItem> consumePayItemList; |
C |
488 |
if(OrderSourceConstans.TYPE_PROJECT.equals(orderItemType)){ |
510678
|
489 |
//一级订单 |
1869f3
|
490 |
consumePayItemList = getOrderItemOneConsumePay(orderItemId,commonService); |
C |
491 |
}else{ |
510678
|
492 |
//二级订单 |
1869f3
|
493 |
consumePayItemList = getOrderItemTwoConsumePay(orderItemId,commonService); |
C |
494 |
} |
|
495 |
|
510678
|
496 |
////存储支付方式编号的可退款金额,根据支付编号求和,后面的业务判断会用到,key值:支付编号,value:可退金额 |
1869f3
|
497 |
Map<String,BigDecimal> noMap = new HashMap<>(); |
C |
498 |
BigDecimal surplusTotal; |
510678
|
499 |
////存储支付方式编号的支付方式记录,根据支付编号整合,后面的业务会用到,key值:支付编号,value:支付记录集合 |
1869f3
|
500 |
Map<String,List<ConsumePayItem>> noPayItemMap = new HashMap<>(); |
C |
501 |
List<ConsumePayItem> noPayItemList; |
|
502 |
|
|
503 |
////////填充支付方式记录的退款金额,计算剩余可退金额,支付方式记录的退款金额需要去查询计算获取 |
510678
|
504 |
//获取订单子单已经退款的退款方式金额,根据支付方式记录的标识求和返回 |
1869f3
|
505 |
List<RefundRecordConsumePay> refundRecordConsumePayList = getRefundRecordConsumePay(orderItemId,null,false,true,commonService); |
C |
506 |
//转化成map,可以根据支付方式记录的标识直接获取到数据 |
ae6ff7
|
507 |
Map<String, RefundRecordConsumePay> refundRecordConsumePayMap = refundRecordConsumePayList.stream().collect( |
C |
508 |
Collectors.toMap(RefundRecordConsumePay::getConsumePayId,(a) -> a)); |
|
509 |
RefundRecordConsumePay refundRecordConsumePay; |
|
510 |
for(ConsumePayItem consumePayItem:consumePayItemList){ |
|
511 |
refundRecordConsumePay = refundRecordConsumePayMap.get(consumePayItem.getConsumePayId()); |
|
512 |
if(refundRecordConsumePay != null){ |
|
513 |
//已退款金额 |
|
514 |
consumePayItem.setRefundTotal(refundRecordConsumePay.getRefundTotal()); |
|
515 |
//可退款金额 |
|
516 |
consumePayItem.setpTotal(consumePayItem.getpTotal().subtract(refundRecordConsumePay.getRefundTotal()).setScale(2,RoundingMode.HALF_UP)); |
|
517 |
} |
1869f3
|
518 |
//计算每个支付编码可退款金额 |
C |
519 |
surplusTotal = noMap.computeIfAbsent(consumePayItem.getNumberNo(),k->BigDecimal.ZERO); |
|
520 |
surplusTotal = surplusTotal.add(consumePayItem.getpTotal()).setScale(2,RoundingMode.HALF_UP); |
|
521 |
noMap.put(consumePayItem.getNumberNo(),surplusTotal); |
ae6ff7
|
522 |
|
1869f3
|
523 |
//支付编码集合整合 |
C |
524 |
noPayItemList = noPayItemMap.computeIfAbsent(consumePayItem.getNumberNo(),k->new ArrayList<>()); |
|
525 |
noPayItemList.add(consumePayItem); |
|
526 |
} |
ae6ff7
|
527 |
|
1869f3
|
528 |
List<RefundRecordConsumePay> refundConsumePayList = new ArrayList<>(); |
C |
529 |
|
|
530 |
////引用对象 |
ae6ff7
|
531 |
RefundRecordItemMethod refundRecordItemMethod; |
1869f3
|
532 |
RefundRecordMethod refundRecordMethod; |
C |
533 |
//需要退的退款编号金额 |
|
534 |
BigDecimal mothedTotal; |
|
535 |
//支付编号分配的退款金额 |
|
536 |
BigDecimal mothedCutTotal; |
|
537 |
//分配的划扣金额总和 |
|
538 |
BigDecimal deductionTotal = BigDecimal.ZERO; |
|
539 |
//分配的现金金额总和 |
|
540 |
BigDecimal cashTotal = BigDecimal.ZERO; |
ae6ff7
|
541 |
|
1869f3
|
542 |
////退款方式金额分配 |
C |
543 |
for(int i = 0;i <refundRecordMethodList.size();i++){ |
|
544 |
refundRecordMethod = refundRecordMethodList.get(i); |
|
545 |
|
|
546 |
////子项退款方式填充 |
|
547 |
refundRecordItemMethod = new RefundRecordItemMethod(); |
|
548 |
refundRecordItemMethod.setNumberNo(refundRecordMethod.getNumberNo()); |
|
549 |
refundRecordItemMethod.setName(refundRecordMethod.getName()); |
|
550 |
//支付方式 |
|
551 |
refundRecordItemMethod.setPaymentMethodId(refundRecordMethod.getPaymentMethodId()); |
|
552 |
refundRecordItemMethod.setIsMoneyPay(refundRecordMethod.getIsMoneyPay()); |
|
553 |
refundRecordItemMethod.setIsExecute(refundRecordMethod.getIsExecute()); |
|
554 |
refundRecordItemMethod.setIsPay(refundRecordMethod.getIsPay()); |
|
555 |
//退款方式 |
|
556 |
refundRecordItemMethod.setRefundNumberNo(refundRecordMethod.getRefundNumberNo()); |
|
557 |
refundRecordItemMethod.setRefundName(refundRecordMethod.getRefundName()); |
|
558 |
refundRecordItemMethod.setRefundMethodId(refundRecordMethod.getRefundMethodId()); |
|
559 |
|
|
560 |
//计算退款方式的金额 |
|
561 |
if(i == refundRecordMethodList.size()-1){ |
|
562 |
////最后一个 |
|
563 |
refundRecordItemMethod.setActualTotal(refundItemTotal); |
|
564 |
}else { |
|
565 |
////不是最后一个 |
|
566 |
refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); |
ae6ff7
|
567 |
} |
1869f3
|
568 |
//判断与剩余的未分配退款方式金额 |
C |
569 |
if (refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getpTotal()) > 0){ |
|
570 |
refundRecordItemMethod.setActualTotal(refundRecordMethod.getpTotal()); |
|
571 |
} |
|
572 |
//判断与剩下的未分配金额校验 |
|
573 |
if(refundRecordItemMethod.getActualTotal().compareTo(refundItemTotal) > 0){ |
|
574 |
refundRecordItemMethod.setActualTotal(refundItemTotal); |
|
575 |
} |
|
576 |
//可支付方式可退款金额 |
|
577 |
surplusTotal = noMap.computeIfAbsent(refundRecordItemMethod.getNumberNo(),k-> BigDecimal.ZERO); |
|
578 |
if(refundRecordItemMethod.getActualTotal().compareTo(surplusTotal) > 0){ |
|
579 |
refundRecordItemMethod.setActualTotal(surplusTotal); |
|
580 |
} |
ae6ff7
|
581 |
|
2a45d4
|
582 |
refundRecordItemMethod.setRealRefundTotal(refundRecordItemMethod.getActualTotal()); |
1869f3
|
583 |
refundRecordItemMethod.setCommonType(orderItemType); |
C |
584 |
refundRecordItemMethod.setCommonId(orderItemId); |
|
585 |
refundRecordItemMethod.setOrderId(refundRecordMethod.getOrderId()); |
|
586 |
refundRecordItemMethod.setRefundRecordItemId(refundItemId); |
|
587 |
refundRecordItemMethod.setRefundRecordId(refundRecord.getId()); |
|
588 |
commonService.insert(RefundRecordItemMethodMapper.class,refundRecordItemMethod); |
ae6ff7
|
589 |
|
1869f3
|
590 |
//减去已经分配的退款方式金额 |
C |
591 |
refundRecordMethod.setpTotal(refundRecordMethod.getpTotal().subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP)); |
|
592 |
//减去已经分配的退款金额 |
|
593 |
refundItemTotal = refundItemTotal.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); |
|
594 |
//减去已经分配的可退款金额 |
|
595 |
surplusTotal = surplusTotal.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); |
|
596 |
noMap.put(refundRecordItemMethod.getNumberNo(),surplusTotal); |
ae6ff7
|
597 |
|
1869f3
|
598 |
///////生成关联支付方式记录和退款方式关联 |
510678
|
599 |
//根据支付编号获取支付方式记录 |
1869f3
|
600 |
noPayItemList = noPayItemMap.computeIfAbsent(refundRecordItemMethod.getNumberNo(),k->new ArrayList<>()); |
510678
|
601 |
//进行升序排序,避免后面不够分配 |
C |
602 |
noPayItemList = noPayItemList.stream().sorted(Comparator.comparing(ConsumePayItem::getpTotal)).collect(Collectors.toList()); |
ae6ff7
|
603 |
mothedTotal = refundRecordItemMethod.getActualTotal(); |
1869f3
|
604 |
for(ConsumePayItem consumePayItem:noPayItemList){ |
ae6ff7
|
605 |
if(consumePayItem.getpTotal().compareTo(BigDecimal.ZERO) < 1){ |
C |
606 |
continue; |
|
607 |
} |
|
608 |
//计算扣减金额 |
|
609 |
if(consumePayItem.getpTotal().compareTo(mothedTotal) > 0){ |
|
610 |
mothedCutTotal = mothedTotal; |
|
611 |
}else{ |
|
612 |
mothedCutTotal = consumePayItem.getpTotal(); |
|
613 |
} |
|
614 |
|
|
615 |
//划扣金额 |
|
616 |
if(consumePayItem.getIsMoneyPay().equals(ConsumePayItem.YES)){ |
2a45d4
|
617 |
cashTotal = cashTotal.add(mothedCutTotal).setScale(2,RoundingMode.HALF_UP); |
ae6ff7
|
618 |
} |
1869f3
|
619 |
//现金金额 |
ae6ff7
|
620 |
if(consumePayItem.getIsExecute().equals(ConsumePayItem.YES)){ |
2a45d4
|
621 |
deductionTotal = deductionTotal.add(mothedCutTotal).setScale(2,RoundingMode.HALF_UP); |
ae6ff7
|
622 |
} |
C |
623 |
|
|
624 |
//生成关联记录 |
|
625 |
refundRecordConsumePay = insertRefundRecordConsumePay(mothedCutTotal,refundRecordItemMethod.getCommonType(),refundRecordItemMethod.getCommonId(),refundRecord.getOrderId(),consumePayItem.getNumberNo() |
2a45d4
|
626 |
,consumePayItem.getName(),consumePayItem.getIsMoneyPay(),consumePayItem.getIsExecute(),consumePayItem.getConsumePayId(),refundRecordItemMethod.getId(),refundItemId,refundRecord.getId(),commonService); |
1869f3
|
627 |
refundConsumePayList.add(refundRecordConsumePay); |
ae6ff7
|
628 |
|
1869f3
|
629 |
//支付方式记录减掉已经分配退款方式金额 |
C |
630 |
consumePayItem.setpTotal(consumePayItem.getpTotal().subtract(mothedCutTotal).setScale(2,RoundingMode.HALF_UP)); |
|
631 |
//减掉已经分配退款方式金额 |
ae6ff7
|
632 |
mothedTotal = mothedTotal.subtract(mothedCutTotal).setScale(2, RoundingMode.HALF_UP); |
1869f3
|
633 |
//分配完成,跳出循环 |
ae6ff7
|
634 |
if(mothedTotal.compareTo(BigDecimal.ZERO) < 1){ |
C |
635 |
//跳出循环 |
|
636 |
break; |
|
637 |
} |
|
638 |
} |
|
639 |
} |
1869f3
|
640 |
//判断是否已经分配完 |
C |
641 |
if(refundItemTotal.compareTo(BigDecimal.ZERO) > 0){ |
|
642 |
throw new TipsException("分配退款金额错误["+orderItemType+"]"); |
ae6ff7
|
643 |
} |
1869f3
|
644 |
|
C |
645 |
refundCarryVo.setDeductionTotal(deductionTotal); |
|
646 |
refundCarryVo.setCashTotal(cashTotal); |
|
647 |
refundCarryVo.setRefundConsumePayList(refundConsumePayList); |
|
648 |
|
|
649 |
return refundCarryVo; |
ae6ff7
|
650 |
} |
C |
651 |
|
|
652 |
|
|
653 |
/** |
|
654 |
* 退款-处理优惠券 |
|
655 |
* @param refundRecord 退款总数据 |
|
656 |
* @param commonService 映射 |
|
657 |
*/ |
|
658 |
public static void handCoupon(RefundRecord refundRecord,CommonService commonService) { |
|
659 |
SqlSentence sqlSentence = new SqlSentence(); |
|
660 |
Map<String, Object> map = new HashMap<>(); |
|
661 |
|
|
662 |
//回去回退优惠券 |
|
663 |
map.put("refundRecordId",refundRecord.getId()); |
a1c527
|
664 |
sqlSentence.sqlSentence("select * from refund_record_coupon where refundRecordId=#{m.refundRecordId} and isDel=0 ",map); |
ae6ff7
|
665 |
List<RefundRecordCoupon> refundRecordCouponList=commonService.selectList(RefundRecordCouponMapper.class,sqlSentence); |
C |
666 |
|
|
667 |
//退款成功 |
a1c527
|
668 |
CouponOrderDiscountLog couponOrderDiscountLog; |
ae6ff7
|
669 |
for (RefundRecordCoupon refundRecordCoupon : refundRecordCouponList) { |
a1c527
|
670 |
|
C |
671 |
couponOrderDiscountLog=commonService.selectOneByKey(CouponOrderDiscountLogMapper.class,refundRecordCoupon.getCouponOrderId()); |
|
672 |
if(couponOrderDiscountLog==null){ |
|
673 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单优惠卷标识不正确"); |
|
674 |
} |
ae6ff7
|
675 |
|
C |
676 |
//变更订单优惠券记录状态 |
|
677 |
map.clear(); |
|
678 |
map.put("status", BaseEntity.YES); |
a1c527
|
679 |
map.put("id", couponOrderDiscountLog.getId()); |
e9e32c
|
680 |
sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id}",map); |
ae6ff7
|
681 |
if(commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence) != 1){ |
C |
682 |
throw new TipsException("优惠券回退失败!"); |
|
683 |
} |
|
684 |
|
|
685 |
//领建优惠券跳过回退 |
|
686 |
if(HIS_COUPON_CODE.equals(couponOrderDiscountLog.getCouponNumberId())){ |
|
687 |
continue; |
|
688 |
} |
|
689 |
|
|
690 |
//优惠券状态变化 |
|
691 |
map.put("isUse", BaseEntity.NO); |
|
692 |
map.put("useTime", null); |
|
693 |
map.put("useType", CouponNumber.USE_TYPE_UNKNOW); |
|
694 |
map.put("id", couponOrderDiscountLog.getCouponNumberId()); |
e9e32c
|
695 |
sqlSentence.sqlSentence(" isUse=#{m.isUse},useTime=#{m.useTime},useType=#{m.useType},isUse=#{m.isUse} WHERE id = #{m.id} ",map); |
ae6ff7
|
696 |
if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 1){ |
C |
697 |
throw new TipsException("优惠券回退失败[67]!"); |
|
698 |
} |
|
699 |
} |
|
700 |
} |
|
701 |
|
|
702 |
/** |
|
703 |
* 退款-处理活动规则增值金和积分 |
|
704 |
*/ |
|
705 |
private static void handActivityRule(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, |
|
706 |
Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, OrderInfo orderInfo) { |
|
707 |
if(orderInfo!=null && StringUtils.noNull(orderInfo.getActivityId())){ |
|
708 |
ActivityRule activityRule=commonService.selectOneByKeyBlob(ActivityRuleMapper.class,orderInfo.getActivityId()); |
|
709 |
if(activityRule!=null){ |
|
710 |
map.put("activityRuleId",activityRule.getId()); |
|
711 |
map.put("type", ActivityAction.TYPE_INTEGRAL); |
|
712 |
map.put("type1",ActivityAction.TYPE_VALUEADDEDFUND); |
|
713 |
map.put("type2",ActivityAction.TYPE_COUPON); |
e9e32c
|
714 |
sqlSentence.sqlSentence("select * from activity_action where activityRuleId=#{m.activityRuleId} and (type=#{m.type} or type=#{m.type1} or type=#{m.type2}) and isDel=0",map); |
ae6ff7
|
715 |
List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence); |
C |
716 |
if(activityActions!=null && activityActions.size()>0){ |
|
717 |
for (ActivityAction activityAction : activityActions) { |
|
718 |
if(ActivityAction.TYPE_INTEGRAL.equals(activityAction.getType())){ |
|
719 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
720 |
if(new BigDecimal(activityAction.getWorth()).negate().compareTo(BigDecimal.ZERO)!=0){ |
|
721 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"退款扣减活动规则赠送积分",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
722 |
} |
|
723 |
}else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(activityAction.getType())){ |
|
724 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
725 |
if(new BigDecimal(activityAction.getWorth()).negate().compareTo(BigDecimal.ZERO)!=0){ |
|
726 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"退款扣减活动规则赠送增值金",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
727 |
} |
|
728 |
}else if(ActivityAction.TYPE_COUPON.equals(activityAction.getType())){ |
|
729 |
map.put("oldValidState",BaseEntity.YES); |
|
730 |
map.put("newValidState",BaseEntity.NO); |
|
731 |
map.put("couponId",activityAction.getCrmCouponId()); |
|
732 |
map.put("commonId",ordersTotal.getId()); |
e9e32c
|
733 |
sqlSentence.sqlSentence(" validState=#{m.newValidState} where couponId=#{m.couponId} and commonId=#{m.commonId} and validState=#{m.oldValidState} ",map); |
ae6ff7
|
734 |
commonService.updateWhere(CouponNumberMapper.class,sqlSentence); |
C |
735 |
} |
|
736 |
} |
|
737 |
} |
|
738 |
} |
|
739 |
} |
|
740 |
|
|
741 |
} |
a1c527
|
742 |
|
C |
743 |
/**退款-处理普通订单信息(比如:项目、促销、卡项) |
|
744 |
* @param refundCarryVo 全局携带参数结构 |
|
745 |
* @param operationId 操作人标识 |
|
746 |
* @param refundRecord 退款总标识 |
|
747 |
* @param ordersTotal 订单 |
|
748 |
* @param commonService 映射 |
|
749 |
* @return 全局携带参数结构 |
ae6ff7
|
750 |
*/ |
a1c527
|
751 |
public static RefundCarryVo numberOfRefunds(RefundCarryVo refundCarryVo,String operationId, RefundRecord refundRecord,OrdersTotal ordersTotal,CommonService commonService) { |
ae6ff7
|
752 |
|
C |
753 |
SqlSentence sqlSentence = new SqlSentence(); |
|
754 |
Map<String, Object> map = new HashMap<>(); |
|
755 |
|
|
756 |
//获取退款子单 |
|
757 |
map.put("refundRecordId",refundRecord.getId()); |
a1c527
|
758 |
sqlSentence.sqlSentence("SELECT * FROM refund_record_item WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",map); |
ae6ff7
|
759 |
List<RefundRecordItem> refundRecordItems =commonService.selectList(RefundRecordItemMapper.class,sqlSentence); |
a1c527
|
760 |
if(refundRecordItems == null || refundRecordItems.size() == 0){ |
ae6ff7
|
761 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到退款子订单信息"); |
C |
762 |
} |
|
763 |
|
1869f3
|
764 |
//根据支付记录总表的标识来整合已退的金额,key值:支付记录总表标识,value:金额数据 |
C |
765 |
Map<String,RefundRecordConsumePay> refundRecordConsumePayMap = new HashMap<>(); |
|
766 |
RefundRecordConsumePay refundRecordConsumePay; |
ae6ff7
|
767 |
|
C |
768 |
for (RefundRecordItem refundRecordItem: refundRecordItems) { |
1869f3
|
769 |
//初始化总结构携带参数 |
C |
770 |
refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
|
771 |
refundCarryVo.setDeductionTotal(BigDecimal.ZERO); |
|
772 |
refundCarryVo.setCashTotal(BigDecimal.ZERO); |
2a45d4
|
773 |
refundCarryVo.setDeductionTotalUser(BigDecimal.ZERO); |
510678
|
774 |
//商品类型判断 |
ae6ff7
|
775 |
switch (refundRecordItem.getType()){ |
C |
776 |
case OrderItemConstants.TYPE_RETAIL: |
1869f3
|
777 |
refundCarryVo = handRefundRerail(refundRecord,refundRecordItem,refundCarryVo,commonService); |
ae6ff7
|
778 |
break; |
C |
779 |
case OrderItemConstants.TYPE_DRUG: |
1869f3
|
780 |
refundCarryVo = handRefundRerail(refundRecord,refundRecordItem,refundCarryVo,commonService); |
ae6ff7
|
781 |
break; |
C |
782 |
case OrderItemConstants.TYPE_PROJECT: |
1869f3
|
783 |
refundCarryVo = handRefundNoExecution(refundRecord,refundRecordItem,refundCarryVo,commonService); |
ae6ff7
|
784 |
break; |
C |
785 |
case OrderItemConstants.TYPE_PROMOTION: |
1869f3
|
786 |
refundCarryVo = handRefundPromotion(operationId, refundRecord, ordersTotal,refundRecordItem,refundCarryVo,commonService); |
ae6ff7
|
787 |
break; |
C |
788 |
case OrderItemConstants.TYPE_CARD: |
1869f3
|
789 |
refundCarryVo = handRefundCard(refundRecord,refundRecordItem,refundCarryVo,commonService); |
ae6ff7
|
790 |
break; |
C |
791 |
case OrderItemConstants.CARD_BAG: |
1869f3
|
792 |
refundCarryVo = handRefundPromotion(operationId, refundRecord, ordersTotal,refundRecordItem,refundCarryVo,commonService); |
ae6ff7
|
793 |
break; |
C |
794 |
default:break; |
|
795 |
} |
1869f3
|
796 |
|
C |
797 |
//遍历叠加支付方式记录的退款金额 |
|
798 |
for(RefundRecordConsumePay re:refundCarryVo.getRefundConsumePayList()){ |
2a45d4
|
799 |
refundRecordConsumePay = refundRecordConsumePayMap.computeIfAbsent(re.getConsumePayId(),k->new RefundRecordConsumePay(BigDecimal.ZERO,re.getNumberNo(),re.getName(),re.getIsMoneyPay(),re.getIsExecute(),re.getConsumePayId())); |
1869f3
|
800 |
refundRecordConsumePay.setRefundTotal(refundRecordConsumePay.getRefundTotal().add(re.getRefundTotal())); |
C |
801 |
} |
ae6ff7
|
802 |
} |
1869f3
|
803 |
|
C |
804 |
//转载返回支付方式记录的退款金额 |
|
805 |
List<RefundRecordConsumePay> refundRecordConsumePayList = new ArrayList<>(); |
|
806 |
for (Map.Entry<String, RefundRecordConsumePay> entry : refundRecordConsumePayMap.entrySet()) { |
|
807 |
refundRecordConsumePayList.add(entry.getValue()); |
a1c527
|
808 |
} |
C |
809 |
|
|
810 |
//校验金额是不是已经分配完 |
|
811 |
for(RefundRecordMethod refundRecordMethod:refundCarryVo.getRefundRecordMethodList()){ |
|
812 |
if(refundRecordMethod.getpTotal().compareTo(BigDecimal.ZERO) > 0){ |
|
813 |
throw new TipsException("退款金额分配错误!"); |
|
814 |
} |
1869f3
|
815 |
} |
C |
816 |
|
|
817 |
refundCarryVo.setRefundConsumePayList(refundRecordConsumePayList); |
|
818 |
return refundCarryVo; |
ae6ff7
|
819 |
} |
C |
820 |
|
|
821 |
/** |
|
822 |
* 退款一级是商品 |
|
823 |
* @param refundRecord 退款总信息 |
|
824 |
* @param refundRecordItem 退款子单 |
|
825 |
* @param commonService 映射 |
|
826 |
*/ |
1869f3
|
827 |
private static RefundCarryVo handRefundRerail(RefundRecord refundRecord, RefundRecordItem refundRecordItem |
C |
828 |
, RefundCarryVo refundCarryVo, CommonService commonService) { |
ae6ff7
|
829 |
|
C |
830 |
//判断操作完了去修改子订单状态 |
|
831 |
OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
|
832 |
if (orderItem==null){ |
|
833 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息"); |
|
834 |
} |
|
835 |
//剩余可退款数量 |
|
836 |
Integer surplusNum = orderItem.getBuyNum()-orderItem.getHasReNum(); |
|
837 |
if(refundRecordItem.getRefundNum() > surplusNum){ |
|
838 |
throw new TipsException("退款数量不能大于可退款数量!"); |
|
839 |
} |
|
840 |
|
|
841 |
//变更退款子项信息 |
a1c527
|
842 |
int refundStatus; |
ae6ff7
|
843 |
if (surplusNum.equals(refundRecordItem.getRefundNum())){ |
1869f3
|
844 |
refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; |
ae6ff7
|
845 |
}else{ |
1869f3
|
846 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
ae6ff7
|
847 |
} |
C |
848 |
|
1869f3
|
849 |
//更新子订单信息 |
C |
850 |
updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); |
|
851 |
|
ae6ff7
|
852 |
//退款方式处理 |
1869f3
|
853 |
return refundRecordMotnedItemHandle(null,refundRecord,refundRecordItem,refundCarryVo,commonService); |
ae6ff7
|
854 |
} |
C |
855 |
|
|
856 |
/** |
|
857 |
* 退款-处理未执行划扣 项目类型 |
a1c527
|
858 |
* @param refundRecord 退款总记录 |
C |
859 |
* @param refundRecordItem 退款一级子记录 |
ae6ff7
|
860 |
*/ |
1869f3
|
861 |
private static RefundCarryVo handRefundNoExecution(RefundRecord refundRecord, RefundRecordItem refundRecordItem |
C |
862 |
,RefundCarryVo refundCarryVo,CommonService commonService) { |
ae6ff7
|
863 |
|
C |
864 |
//找到子单 |
|
865 |
OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
|
866 |
if (orderItem==null){ |
|
867 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息"); |
|
868 |
} |
a1c527
|
869 |
|
C |
870 |
SqlSentence sqlSentence = new SqlSentence(); |
|
871 |
Map<String, Object> map = new HashMap<>(); |
|
872 |
|
ae6ff7
|
873 |
//找到用户项目 |
C |
874 |
map.put("commonId",refundRecordItem.getOrderItemId()); |
|
875 |
sqlSentence.sqlSentence("select * from user_project_item where isDel = 0 and commonId = #{m.commonId} and isTransfer = 0",map); |
|
876 |
UserProjectItem userProjectItem =commonService.selectOne(UserProjectItemMapper.class,sqlSentence); |
|
877 |
if (userProjectItem == null) { |
|
878 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到用户子项项目信息"); |
|
879 |
} |
|
880 |
|
|
881 |
if(userProjectItem.getNotUsedNum() < refundRecordItem.getRefundNum()){ |
|
882 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于可退次数!"); |
|
883 |
} |
|
884 |
|
|
885 |
//用户项目操作 |
1869f3
|
886 |
UserProjectDeductionVo userProjectDeductionVo = UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_DEDUCTION,null |
ae6ff7
|
887 |
,refundRecordItem.getId(),refundRecordItem.getRefundNum(),refundRecord.getOperatorAppId(),refundRecord.getOperatorAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getRemarks()+"|用户备注:"+refundRecord.getRefundReason(),commonService); |
2a45d4
|
888 |
|
C |
889 |
refundCarryVo.setDeductionTotalUser(userProjectDeductionVo.getDeductionTotal()); |
ae6ff7
|
890 |
|
C |
891 |
//计算子单是否还有剩余的可扣疗程数 |
|
892 |
int surplusNum = orderItem.getUsedTotal()-orderItem.getHasReNum(); |
|
893 |
if(refundRecordItem.getRefundNum() > surplusNum){ |
|
894 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于子单可退次数[54]!"); |
|
895 |
} |
|
896 |
|
a1c527
|
897 |
int refundStatus; |
ae6ff7
|
898 |
if(refundRecordItem.getRefundNum() == surplusNum){ |
C |
899 |
refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; |
|
900 |
}else{ |
|
901 |
refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
|
902 |
} |
|
903 |
|
1869f3
|
904 |
//更新子订单信息 |
C |
905 |
updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); |
ae6ff7
|
906 |
|
C |
907 |
//退款方式处理 |
1869f3
|
908 |
return refundRecordMotnedItemHandle(userProjectDeductionVo.getDeductionTotal(),refundRecord,refundRecordItem,refundCarryVo,commonService); |
ae6ff7
|
909 |
} |
C |
910 |
|
a1c527
|
911 |
/**退款-处理卡项 |
C |
912 |
* @param refundRecord 退款总记录 |
|
913 |
* @param refundRecordItem 退款一级记录 |
|
914 |
* @param refundCarryVo 全局携带参数结构 |
|
915 |
* @param commonService 映射 |
|
916 |
* @return 全局携带参数结构 |
ae6ff7
|
917 |
*/ |
1869f3
|
918 |
public static RefundCarryVo handRefundCard(RefundRecord refundRecord, RefundRecordItem refundRecordItem,RefundCarryVo refundCarryVo,CommonService commonService) { |
ae6ff7
|
919 |
|
C |
920 |
//判断操作完了去修改子订单状态 |
|
921 |
OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
|
922 |
if (orderItem==null){ |
1869f3
|
923 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息"); |
ae6ff7
|
924 |
} |
C |
925 |
Integer surplusNum = orderItem.getBuyNum() - orderItem.getHasReNum(); |
|
926 |
if(refundRecordItem.getRefundNum() > surplusNum){ |
|
927 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款作废卡包提示:没有找到对应的卡包可退[020]"); |
|
928 |
} |
|
929 |
|
|
930 |
//找到可退款卡包 |
|
931 |
List<UserCard> userCardList = PartialRefundUtil.getRefundCard(orderItem.getId(),commonService); |
|
932 |
if(refundRecordItem.getRefundNum() > userCardList.size()){ |
|
933 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款作废卡包提示:没有找到对应的卡包可退[021]"); |
|
934 |
} |
|
935 |
|
a1c527
|
936 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
937 |
Map<String, Object> map = new HashMap<>(); |
|
938 |
|
1869f3
|
939 |
//变更卡项状态 |
ae6ff7
|
940 |
UserCard userCard; |
1869f3
|
941 |
RefundRecordCard refundRecordCard; |
ae6ff7
|
942 |
for (int i = 0; i < refundRecordItem.getRefundNum(); i++) { |
C |
943 |
userCard= userCardList.get(i); |
|
944 |
map.put("id",userCard.getId()); |
|
945 |
map.put("effectiveStatus", UserProjectConstants.EFF_STATUS_CANCEL); |
2e8393
|
946 |
map.put("oldEffectiveStatus", UserProjectConstants.EFF_STATUS_YES); |
C |
947 |
sqlSentence.sqlSentence(" effectiveStatus=#{m.effectiveStatus} WHERE id = #{m.id} AND effectiveStatus = #{m.oldEffectiveStatus}",map); |
|
948 |
if(commonService.updateWhere(UserCardMapper.class,sqlSentence) != 1){ |
|
949 |
throw new TipsException("用户卡包状态已发生变化,请重试!"); |
|
950 |
} |
1869f3
|
951 |
|
C |
952 |
//生成退款关联 |
|
953 |
refundRecordCard = new RefundRecordCard(); |
|
954 |
refundRecordCard.setUserCardId(userCard.getId()); |
|
955 |
refundRecordCard.setRefundRecordId(refundRecord.getId()); |
|
956 |
refundRecordCard.setRefundRecordItemId(refundRecordItem.getId()); |
a1c527
|
957 |
commonService.insert(RefundRecordCardMapper.class,refundRecordCard); |
ae6ff7
|
958 |
} |
C |
959 |
|
a1c527
|
960 |
int refundStatus; |
ae6ff7
|
961 |
if (surplusNum.equals(refundRecordItem.getRefundNum())){ |
1869f3
|
962 |
refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; |
ae6ff7
|
963 |
}else { |
1869f3
|
964 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
C |
965 |
|
ae6ff7
|
966 |
} |
1869f3
|
967 |
//更新子订单信息 |
C |
968 |
updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); |
ae6ff7
|
969 |
|
C |
970 |
//退款方式处理 |
1869f3
|
971 |
refundCarryVo = refundRecordMotnedItemHandle(null,refundRecord,refundRecordItem,refundCarryVo,commonService); |
C |
972 |
return refundCarryVo; |
ae6ff7
|
973 |
} |
C |
974 |
|
a1c527
|
975 |
/**退款-处理卡包 |
ae6ff7
|
976 |
*/ |
1869f3
|
977 |
public static void handCardBag(String operationId,RefundRecord refundRecord, OrdersTotal ordersTotal |
C |
978 |
,RefundRecordItem refundRecordItem,RefundCarryVo refundCarryVo,CommonService commonService) { |
ae6ff7
|
979 |
|
a1c527
|
980 |
//查看订单信息 |
C |
981 |
OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
|
982 |
if(orderItem == null ){ |
|
983 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息!"); |
|
984 |
} |
|
985 |
|
ae6ff7
|
986 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
987 |
Map<String, Object> map = new HashMap<>(); |
|
988 |
|
|
989 |
map.put("refundRecordItemId",refundRecordItem.getId()); |
a1c527
|
990 |
sqlSentence.sqlSentence("select * from refund_record_item_source where refundRecordItemId =#{m.refundRecordItemId}",map); |
ae6ff7
|
991 |
List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence); |
C |
992 |
if(sons.size() == 0 ){ |
|
993 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息[015]!"); |
|
994 |
} |
|
995 |
|
|
996 |
for (RefundRecordItemSource son : sons) { |
1869f3
|
997 |
refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
C |
998 |
refundCarryVo.setDeductionTotal(BigDecimal.ZERO); |
|
999 |
refundCarryVo.setCashTotal(BigDecimal.ZERO); |
ae6ff7
|
1000 |
switch (GroupTypeEnum.getCode(son.getType())){ |
C |
1001 |
case PROJECT: |
1869f3
|
1002 |
//handRefundNoSonExecution(refundRecord,son,refundCarryVo,commonService); |
ae6ff7
|
1003 |
break; |
C |
1004 |
case RETAIL: |
1869f3
|
1005 |
//handRefundSonRerail(refundRecord,son,refundCarryVo,commonService ); |
C |
1006 |
//deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem); |
ae6ff7
|
1007 |
break; |
C |
1008 |
case INCREMENT: |
|
1009 |
//增值金 |
|
1010 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
1011 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
1012 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送增值金扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
1013 |
} |
|
1014 |
break; |
|
1015 |
case STORED: |
|
1016 |
//储值金额 |
|
1017 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
1018 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
1019 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送储值金额扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
|
1020 |
} |
|
1021 |
break; |
|
1022 |
case INTEGRAL: |
|
1023 |
//积分 |
|
1024 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
1025 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
1026 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送积分扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
1027 |
} |
|
1028 |
break; |
|
1029 |
} |
|
1030 |
} |
|
1031 |
|
|
1032 |
//更改二级子订单退款状态 |
|
1033 |
map.put("orderItemId",orderItem.getId()); |
|
1034 |
sqlSentence.setSqlSentence("select * from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0"); |
|
1035 |
List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); |
|
1036 |
|
a1c527
|
1037 |
List<Integer> collect = orderItemSonList.stream().map(OrderItemSon::getRefundStatus).collect(Collectors.toList()); |
ae6ff7
|
1038 |
if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){ |
C |
1039 |
orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); |
|
1040 |
orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
|
1041 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
|
1042 |
orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); |
|
1043 |
orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
|
1044 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ |
|
1045 |
orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
|
1046 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
|
1047 |
orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH); |
|
1048 |
orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
|
1049 |
orderItem.setHasReNum(orderItem.getBuyNum()); |
|
1050 |
}else { |
|
1051 |
orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
|
1052 |
} |
|
1053 |
|
|
1054 |
commonService.updateAll(OrderItemMapper.class,orderItem); |
|
1055 |
} |
|
1056 |
|
a1c527
|
1057 |
/**退款需要删除用户卡包使用记录 |
C |
1058 |
* @param cardItemInfoId 卡包的卡项子项 |
|
1059 |
* @param sourceId 卡包使用记录来源标识 |
e9e32c
|
1060 |
* @param orderId 卡包使用记录来源总表标识 |
a1c527
|
1061 |
* @param refundNum 退款数量 |
C |
1062 |
* @param commonService 映射 |
ae6ff7
|
1063 |
*/ |
e9e32c
|
1064 |
public static void deleteUserCardUsed(String cardItemInfoId,String sourceId,String orderId,Integer refundNum |
a1c527
|
1065 |
,CommonService commonService){ |
1869f3
|
1066 |
|
a1c527
|
1067 |
//查出用户,commonId:卡项的组合项标识 |
C |
1068 |
CardItemInfo cardItemInfo=commonService.selectOneByKey(CardItemInfoMapper.class,cardItemInfoId); |
|
1069 |
if(cardItemInfo ==null){ |
|
1070 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包的组合项"); |
|
1071 |
} |
|
1072 |
|
|
1073 |
//获取权益类型 |
|
1074 |
CardEquity cardEquity = commonService.selectOneByKey(CardEquityMapper.class,cardItemInfo.getCardEquityId()); |
|
1075 |
if(cardEquity == null){ |
|
1076 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包的组合项权益类型"); |
e9e32c
|
1077 |
} |
C |
1078 |
|
|
1079 |
SqlSentence sqlSentence = new SqlSentence(); |
|
1080 |
Map<String,Object> map = new HashMap<>(); |
|
1081 |
|
|
1082 |
//获取使用记录 |
|
1083 |
map.put("cardItemInfoId",cardItemInfoId); |
|
1084 |
map.put("sourceId",sourceId); |
|
1085 |
sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 0" + |
|
1086 |
" AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId = #{m.sourceId}",map); |
|
1087 |
List<UserCardUsed> userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); |
|
1088 |
|
|
1089 |
//因为之前的使用记录有些没有关联到订单,所以找不到 |
|
1090 |
if(userCardUsedList == null || userCardUsedList.size() == 0){ |
|
1091 |
map.clear(); |
|
1092 |
map.put("cardItemInfoId",cardItemInfoId); |
|
1093 |
sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 0" + |
|
1094 |
" AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId IS NULL",map); |
|
1095 |
userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); |
a1c527
|
1096 |
} |
C |
1097 |
|
|
1098 |
//计算退回的卡次 |
|
1099 |
int returnNum; |
|
1100 |
//因为有些是算次数抵扣的,所以要算 |
|
1101 |
if(CardEquity.EQUITY_TYPE_TIME_CARD.equals(cardEquity.getEquityType())){ |
|
1102 |
//次卡:总次数=开单的总次数*每次划扣的次数 |
510678
|
1103 |
returnNum= refundNum * cardItemInfo.getEveryDrawNum(); |
a1c527
|
1104 |
}else if(CardEquity.EQUITY_TYPE_N_M.equals(cardEquity.getEquityType())){ |
C |
1105 |
returnNum = refundNum; |
|
1106 |
}else{ |
|
1107 |
returnNum = refundNum; |
|
1108 |
} |
|
1109 |
|
|
1110 |
if(returnNum > userCardUsedList.size()){ |
1869f3
|
1111 |
throw new TipsException("卡包可退数量错误!"); |
C |
1112 |
} |
|
1113 |
|
e9e32c
|
1114 |
//已经操作数量 |
1869f3
|
1115 |
int opNum = 0; |
e9e32c
|
1116 |
StringBuilder sql; |
1869f3
|
1117 |
for(UserCardUsed userCardUsed:userCardUsedList){ |
e9e32c
|
1118 |
sql = new StringBuilder(); |
C |
1119 |
sql.append("isDel = 1"); |
|
1120 |
map.clear(); |
1869f3
|
1121 |
map.put("id",userCardUsed.getId()); |
e9e32c
|
1122 |
if(StringUtils.isEmpty(userCardUsed.getOrderId())){ |
C |
1123 |
sql.append(",orderId = #{m.orderId}"); |
|
1124 |
map.put("orderId",orderId); |
|
1125 |
} |
|
1126 |
if(StringUtils.isEmpty(userCardUsed.getSourceId())){ |
|
1127 |
sql.append(",sourceId = #{m.sourceId}"); |
|
1128 |
map.put("sourceId",sourceId); |
|
1129 |
} |
|
1130 |
sql.append(" WHERE id = #{m.id} AND isDel = 0"); |
|
1131 |
sqlSentence.sqlUpdate(sql.toString(),map); |
1869f3
|
1132 |
opNum = opNum+commonService.updateWhere(UserCardUsedMapper.class,sqlSentence); |
C |
1133 |
} |
a1c527
|
1134 |
if(opNum != returnNum){ |
C |
1135 |
throw new TipsException("卡包回退数量错误!"); |
1869f3
|
1136 |
} |
C |
1137 |
|
ae6ff7
|
1138 |
} |
1869f3
|
1139 |
|
a1c527
|
1140 |
/**退款-处理促销 |
C |
1141 |
* @param operationId 操作人标识 |
|
1142 |
* @param refundRecord 退款总记录 |
|
1143 |
* @param ordersTotal 订单 |
|
1144 |
* @param refundRecordItem 退款一级记录 |
|
1145 |
* @param refundCarryVo 全局携带参数结构 |
|
1146 |
* @param commonService 映射 |
|
1147 |
* @return 全局携带参数结构 |
ae6ff7
|
1148 |
*/ |
1869f3
|
1149 |
private static RefundCarryVo handRefundPromotion(String operationId, RefundRecord refundRecord, OrdersTotal ordersTotal |
C |
1150 |
, RefundRecordItem refundRecordItem,RefundCarryVo refundCarryVo,CommonService commonService) { |
ae6ff7
|
1151 |
|
C |
1152 |
//查看订单信息 |
1869f3
|
1153 |
OrderItem orderItem = commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
ae6ff7
|
1154 |
if(orderItem == null ){ |
C |
1155 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息[84]!"); |
|
1156 |
} |
|
1157 |
|
a1c527
|
1158 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
1159 |
Map<String, Object> map = new HashMap<>(); |
|
1160 |
|
ae6ff7
|
1161 |
//获取退款二级单 |
C |
1162 |
map.put("refundRecordItemId",refundRecordItem.getId()); |
a1c527
|
1163 |
sqlSentence.sqlSentence("select * from refund_record_item_source where isDel = 0 AND refundRecordItemId = #{m.refundRecordItemId}",map); |
ae6ff7
|
1164 |
List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence); |
C |
1165 |
|
1869f3
|
1166 |
//根据支付记录总表的标识来整合已退的金额,key值:支付记录总表标识,value:金额数据 |
C |
1167 |
Map<String,RefundRecordConsumePay> refundRecordConsumePayMap = new HashMap<>(); |
|
1168 |
RefundRecordConsumePay refundRecordConsumePay; |
|
1169 |
//计算本次退款方式的划扣金额 |
|
1170 |
BigDecimal deductionTotal = BigDecimal.ZERO; |
|
1171 |
//计算本次退款方式的现金金额 |
|
1172 |
BigDecimal cashTotal = BigDecimal.ZERO; |
2a45d4
|
1173 |
//分配的用户项目划扣金额 |
C |
1174 |
BigDecimal deductionTotalUser = BigDecimal.ZERO; |
1869f3
|
1175 |
|
C |
1176 |
for (RefundRecordItemSource son : sons) { |
|
1177 |
//初始化总结构携带参数 |
|
1178 |
refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
|
1179 |
refundCarryVo.setDeductionTotal(BigDecimal.ZERO); |
|
1180 |
refundCarryVo.setCashTotal(BigDecimal.ZERO); |
2a45d4
|
1181 |
refundCarryVo.setDeductionTotalUser(BigDecimal.ZERO); |
1869f3
|
1182 |
switch (GroupTypeEnum.getCode(son.getType())){ |
C |
1183 |
case PROJECT: |
|
1184 |
refundCarryVo = handRefundNoSonExecution(refundRecord,refundRecordItem,son,refundCarryVo,commonService); |
|
1185 |
break; |
|
1186 |
case RETAIL: |
a1c527
|
1187 |
refundCarryVo = handRefundSonRerail(refundRecord,refundRecordItem,son,refundCarryVo,commonService); |
1869f3
|
1188 |
break; |
C |
1189 |
case INCREMENT: |
|
1190 |
//增值金 |
|
1191 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
1192 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
1193 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送增值金扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
1194 |
} |
|
1195 |
break; |
|
1196 |
case STORED: |
|
1197 |
//储值金额 |
|
1198 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
1199 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
1200 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送储值金额扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
|
1201 |
} |
|
1202 |
break; |
|
1203 |
case INTEGRAL: |
|
1204 |
//积分 |
|
1205 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
1206 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
1207 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送积分扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
1208 |
} |
|
1209 |
break; |
|
1210 |
} |
|
1211 |
deductionTotal = deductionTotal.add(refundCarryVo.getDeductionTotal()); |
|
1212 |
cashTotal = cashTotal.add(refundCarryVo.getCashTotal()); |
2a45d4
|
1213 |
deductionTotalUser = deductionTotalUser.add(refundCarryVo.getDeductionTotalUser()); |
1869f3
|
1214 |
//遍历叠加支付方式记录的退款金额 |
C |
1215 |
for(RefundRecordConsumePay re:refundCarryVo.getRefundConsumePayList()){ |
2a45d4
|
1216 |
refundRecordConsumePay = refundRecordConsumePayMap.computeIfAbsent(re.getConsumePayId(),k->new RefundRecordConsumePay(BigDecimal.ZERO,re.getNumberNo(),re.getName(),re.getIsMoneyPay(),re.getIsExecute(),re.getConsumePayId())); |
1869f3
|
1217 |
refundRecordConsumePay.setRefundTotal(refundRecordConsumePay.getRefundTotal().add(re.getRefundTotal())); |
ae6ff7
|
1218 |
} |
C |
1219 |
} |
|
1220 |
|
1869f3
|
1221 |
//转载返回支付方式记录的退款金额 |
C |
1222 |
List<RefundRecordConsumePay> refundRecordConsumePayList = new ArrayList<>(); |
|
1223 |
for (Map.Entry<String, RefundRecordConsumePay> entry : refundRecordConsumePayMap.entrySet()) { |
|
1224 |
refundRecordConsumePayList.add(entry.getValue()); |
|
1225 |
} |
|
1226 |
refundCarryVo.setCashTotal(cashTotal); |
|
1227 |
refundCarryVo.setDeductionTotal(deductionTotal); |
2a45d4
|
1228 |
refundCarryVo.setDeductionTotalUser(deductionTotalUser); |
1869f3
|
1229 |
refundCarryVo.setRefundConsumePayList(refundRecordConsumePayList); |
2a45d4
|
1230 |
|
C |
1231 |
//更新退款子单 |
|
1232 |
updateRefundItem(refundCarryVo.getDeductionTotal(),refundCarryVo.getCashTotal(),refundCarryVo.getDeductionTotalUser() |
|
1233 |
,refundRecordItem.getId(),commonService); |
ae6ff7
|
1234 |
|
1869f3
|
1235 |
//获取其子项 |
ae6ff7
|
1236 |
map.put("orderItemId",orderItem.getId()); |
e9e32c
|
1237 |
sqlSentence.sqlSentence("select refundStatus from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0",map); |
ae6ff7
|
1238 |
List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); |
a1c527
|
1239 |
int refundStatus; |
1869f3
|
1240 |
Integer refundNum = 0; |
a1c527
|
1241 |
List<Integer> collect = orderItemSonList.stream().map(OrderItemSon::getRefundStatus).collect(Collectors.toList()); |
1869f3
|
1242 |
|
ae6ff7
|
1243 |
if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){ |
1869f3
|
1244 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
ae6ff7
|
1245 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ |
1869f3
|
1246 |
if(collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
C |
1247 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
|
1248 |
}else{ |
|
1249 |
refundStatus = OrderTotalConstants.STATUS_REFUND_NONE; |
|
1250 |
} |
ae6ff7
|
1251 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
1869f3
|
1252 |
refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; |
C |
1253 |
refundNum = orderItem.getBuyNum(); |
ae6ff7
|
1254 |
}else { |
1869f3
|
1255 |
refundStatus = OrderTotalConstants.STATUS_REFUND_NONE; |
ae6ff7
|
1256 |
} |
C |
1257 |
|
1869f3
|
1258 |
//更新子订单信息 |
C |
1259 |
updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundNum,commonService); |
|
1260 |
|
|
1261 |
return refundCarryVo; |
ae6ff7
|
1262 |
} |
C |
1263 |
|
1869f3
|
1264 |
/**退款-处理二级子订单未执行划扣 项目类型 |
a1c527
|
1265 |
* @param refundRecord 退款总记录 |
C |
1266 |
* @param refundRecordItem 退款一级子单 |
|
1267 |
* @param refundRecordItemSource 退款二级子单 |
|
1268 |
* @param refundCarryVo 全局携带参数接口 |
|
1269 |
* @param commonService 映射 |
ae6ff7
|
1270 |
*/ |
1869f3
|
1271 |
private static RefundCarryVo handRefundNoSonExecution(RefundRecord refundRecord,RefundRecordItem refundRecordItem, RefundRecordItemSource refundRecordItemSource |
C |
1272 |
,RefundCarryVo refundCarryVo,CommonService commonService) { |
ae6ff7
|
1273 |
|
C |
1274 |
//判断操作完了去修改子订单状态 |
510678
|
1275 |
OrderItemSon orderItemSon = commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId()); |
ae6ff7
|
1276 |
if (orderItemSon==null){ |
510678
|
1277 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到二级子订单信息[02]"); |
ae6ff7
|
1278 |
} |
C |
1279 |
|
|
1280 |
UserProjectItem userProjectItem = getUserProject(orderItemSon.getId(),commonService); |
|
1281 |
if(userProjectItem == null){ |
510678
|
1282 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"用户项目获取失败[06]!"); |
ae6ff7
|
1283 |
} |
C |
1284 |
if(userProjectItem.getNotUsedNum()<refundRecordItemSource.getRefundNum()){ |
|
1285 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于可退次数[83]!"); |
|
1286 |
} |
|
1287 |
|
|
1288 |
//计算子单是否还有剩余的可扣疗程数 |
|
1289 |
int surplusNum = orderItemSon.getUsedTotal() - orderItemSon.getHasReNum(); |
|
1290 |
if(refundRecordItemSource.getRefundNum() > surplusNum){ |
510678
|
1291 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于可退次数[56]!"); |
ae6ff7
|
1292 |
} |
C |
1293 |
|
1869f3
|
1294 |
//处理用户项目,减去用户项目数量 |
C |
1295 |
UserProjectDeductionVo userProjectDeductionVo= UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_DEDUCTION,null |
ae6ff7
|
1296 |
,refundRecordItemSource.getId(),refundRecordItemSource.getRefundNum(),refundRecord.getOperatorAppId(),refundRecord.getOperatorAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getRemarks()+"|用户备注:"+refundRecord.getRefundReason(),commonService); |
2a45d4
|
1297 |
|
C |
1298 |
refundCarryVo.setDeductionTotalUser(userProjectDeductionVo.getDeductionTotal()); |
ae6ff7
|
1299 |
|
a1c527
|
1300 |
int refundStatus; |
ae6ff7
|
1301 |
if(surplusNum == refundRecordItemSource.getRefundNum()){ |
C |
1302 |
refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; |
|
1303 |
}else{ |
|
1304 |
refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
|
1305 |
} |
|
1306 |
|
1869f3
|
1307 |
//更新子单信息 |
C |
1308 |
updateOrderItemTwo(orderItemSon,refundStatus,refundRecordItemSource.getRefundMoney(),refundRecordItemSource.getRefundNum(),commonService); |
|
1309 |
|
|
1310 |
//处理退款支付方式 |
|
1311 |
refundCarryVo = refundRecordMotnedItemTwoHandle(userProjectDeductionVo.getDeductionTotal(),refundRecord,refundRecordItemSource,refundCarryVo,commonService); |
|
1312 |
|
|
1313 |
if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ |
|
1314 |
//是卡包的,刪除卡包使用 |
e9e32c
|
1315 |
deleteUserCardUsed(orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService); |
ae6ff7
|
1316 |
} |
C |
1317 |
|
1869f3
|
1318 |
return refundCarryVo; |
ae6ff7
|
1319 |
} |
1869f3
|
1320 |
|
C |
1321 |
/**退款二级是商品 |
a1c527
|
1322 |
* @param refundRecord 退款总记录 |
C |
1323 |
* @param refundRecordItem 退款一级子单 |
|
1324 |
* @param refundRecordItemSource 退款二级子单 |
|
1325 |
* @param refundCarryVo 全局携带参数结构 |
|
1326 |
* @param commonService 映射 |
|
1327 |
* @return 全局携带参数结构 |
ae6ff7
|
1328 |
*/ |
a1c527
|
1329 |
private static RefundCarryVo handRefundSonRerail(RefundRecord refundRecord,RefundRecordItem refundRecordItem, RefundRecordItemSource refundRecordItemSource |
1869f3
|
1330 |
,RefundCarryVo refundCarryVo,CommonService commonService) { |
ae6ff7
|
1331 |
|
C |
1332 |
//判断操作完了去修改子订单状态 |
1869f3
|
1333 |
OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId()); |
C |
1334 |
if (orderItemSon==null){ |
ae6ff7
|
1335 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息"); |
C |
1336 |
} |
|
1337 |
|
1869f3
|
1338 |
//计算子单是否还有剩余的可扣疗程数 |
C |
1339 |
int surplusNum = orderItemSon.getBuyNum() - orderItemSon.getHasReNum(); |
|
1340 |
if(refundRecordItemSource.getRefundNum() > surplusNum){ |
|
1341 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于可退次数[84]!"); |
ae6ff7
|
1342 |
} |
C |
1343 |
|
a1c527
|
1344 |
int refundStatus; |
1869f3
|
1345 |
if(surplusNum == refundRecordItemSource.getRefundNum()){ |
C |
1346 |
refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; |
|
1347 |
}else{ |
|
1348 |
refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
|
1349 |
} |
|
1350 |
|
|
1351 |
updateOrderItemTwo(orderItemSon,refundStatus,refundRecordItemSource.getRefundMoney(),refundRecordItemSource.getRefundNum(),commonService); |
|
1352 |
|
|
1353 |
//处理退款支付方式 |
|
1354 |
refundCarryVo = refundRecordMotnedItemTwoHandle(null,refundRecord,refundRecordItemSource,refundCarryVo,commonService); |
a1c527
|
1355 |
|
C |
1356 |
if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ |
|
1357 |
//是卡包的,刪除卡包使用 |
e9e32c
|
1358 |
deleteUserCardUsed(orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService); |
a1c527
|
1359 |
} |
1869f3
|
1360 |
|
C |
1361 |
return refundCarryVo; |
|
1362 |
} |
|
1363 |
|
|
1364 |
/**更新订单一级子单的信息 |
|
1365 |
* @param orderItem 订单子单 |
|
1366 |
* @param refundStatus 退款状态 |
|
1367 |
* @param refundTotal 退款金额 |
|
1368 |
* @param refundNum 退款数量 |
|
1369 |
* @param commonService 映射 |
|
1370 |
*/ |
|
1371 |
public static void updateOrderItemOne(OrderItem orderItem,Integer refundStatus,BigDecimal refundTotal,Integer refundNum |
|
1372 |
,CommonService commonService){ |
|
1373 |
SqlSentence sqlSentence = new SqlSentence(); |
|
1374 |
Map<String,Object> values = new HashMap<>(); |
|
1375 |
|
510678
|
1376 |
values.put("id", orderItem.getId()); |
1869f3
|
1377 |
values.put("refundStatus", refundStatus); |
C |
1378 |
values.put("refundTotal",refundTotal); |
|
1379 |
values.put("refundNum",refundNum); |
|
1380 |
values.put("oldHasReNum",orderItem.getHasReNum()); |
|
1381 |
sqlSentence.sqlUpdate(" refundStatus=#{m.refundStatus},reTotal=reTotal+#{m.refundTotal},hasReNum=hasReNum+#{m.refundNum}" + |
510678
|
1382 |
" WHERE isDel = 0 AND id = #{m.id} AND hasReNum = #{m.oldHasReNum}",values); |
1869f3
|
1383 |
if(commonService.updateWhere(OrderItemMapper.class,sqlSentence) != 1){ |
C |
1384 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"当前订单信息已发生变化,请重试[012]!"); |
|
1385 |
} |
|
1386 |
} |
|
1387 |
|
|
1388 |
/**更新订单二级子单的信息 |
|
1389 |
* @param orderItemSon 订单子单 |
|
1390 |
* @param refundStatus 退款状态 |
|
1391 |
* @param refundTotal 退款金额 |
|
1392 |
* @param refundNum 退款数量 |
|
1393 |
* @param commonService 映射 |
|
1394 |
*/ |
|
1395 |
public static void updateOrderItemTwo(OrderItemSon orderItemSon,Integer refundStatus,BigDecimal refundTotal,Integer refundNum |
|
1396 |
,CommonService commonService){ |
|
1397 |
SqlSentence sqlSentence = new SqlSentence(); |
|
1398 |
Map<String,Object> values = new HashMap<>(); |
|
1399 |
|
|
1400 |
values.put("id", orderItemSon.getId()); |
|
1401 |
values.put("refundStatus", refundStatus); |
|
1402 |
values.put("refundTotal",refundTotal); |
|
1403 |
values.put("refundNum",refundNum); |
|
1404 |
values.put("oldHasReNum",orderItemSon.getHasReNum()); |
510678
|
1405 |
sqlSentence.sqlUpdate(" refundStatus = #{m.refundStatus},reTotal=reTotal+#{m.refundTotal},hasReNum=hasReNum+#{m.refundNum}" + |
1869f3
|
1406 |
" where isDel=0 AND id = #{m.id} AND hasReNum = #{m.oldHasReNum}",values); |
C |
1407 |
if(commonService.updateWhere(OrderItemSonMapper.class,sqlSentence) != 1){ |
|
1408 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"当前订单信息已发生变化,请重试[012]!"); |
|
1409 |
} |
|
1410 |
} |
|
1411 |
|
a1c527
|
1412 |
/**获取订单一级子单的支付方式记录 |
C |
1413 |
* @param orderItemId 订单一级子单标识 |
|
1414 |
* @param commonService 映射 |
|
1415 |
* @return 订单一级子单的支付方式记录 |
1869f3
|
1416 |
*/ |
C |
1417 |
public static List<ConsumePayItem> getOrderItemOneConsumePay(String orderItemId,CommonService commonService){ |
|
1418 |
|
|
1419 |
SqlSentence sqlSentence = new SqlSentence(); |
|
1420 |
Map<String,Object> values = new HashMap<>(); |
|
1421 |
|
|
1422 |
//获取子单的支付方式,一级子单支付记录,计算可退款金额 |
|
1423 |
values.put("typeId",orderItemId); |
|
1424 |
sqlSentence.sqlSentence("SELECT * FROM consume_pay_item WHERE isDel = 0 AND typeId = #{m.typeId}",values); |
2a45d4
|
1425 |
return commonService.selectList(ConsumePayItemMapper.class,sqlSentence); |
1869f3
|
1426 |
} |
C |
1427 |
|
a1c527
|
1428 |
/**获取订单二级子单的支付方式记录 |
C |
1429 |
* @param orderItemId 订单一级子单标识 |
|
1430 |
* @param commonService 映射 |
|
1431 |
* @return 订单二级子单的支付方式记录 |
1869f3
|
1432 |
*/ |
C |
1433 |
public static List<ConsumePayItem> getOrderItemTwoConsumePay(String orderItemId,CommonService commonService){ |
|
1434 |
|
|
1435 |
SqlSentence sqlSentence = new SqlSentence(); |
|
1436 |
Map<String,Object> values = new HashMap<>(); |
|
1437 |
|
|
1438 |
//获取子单的支付方式,一级子单支付记录,计算可退款金额 |
|
1439 |
values.put("typeId",orderItemId); |
|
1440 |
sqlSentence.sqlSentence("SELECT * FROM consume_pay_item_son WHERE isDel = 0 AND typeId = #{m.typeId}",values); |
2a45d4
|
1441 |
List<ConsumePayItemSon> consumePayItemSonList = commonService.selectList(ConsumePayItemSonMapper.class,sqlSentence); |
C |
1442 |
List<ConsumePayItem> consumePayItemList = new ArrayList<>(); |
|
1443 |
ConsumePayItem consumePayItem; |
|
1444 |
for(ConsumePayItemSon consumePayItemSon:consumePayItemSonList){ |
|
1445 |
consumePayItem = new ConsumePayItem(); |
|
1446 |
BeanUtils.copyProperties(consumePayItemSon,consumePayItem); |
|
1447 |
consumePayItemList.add(consumePayItem); |
|
1448 |
} |
|
1449 |
return consumePayItemList; |
ae6ff7
|
1450 |
} |
C |
1451 |
|
|
1452 |
/**获取已退款方式金额,根据支付方式编号求和返回 |
|
1453 |
* 注意:groupByONumberNo和groupByConsumePayId不能同时使用 |
2a45d4
|
1454 |
* @param itemId 订单子单标识 |
ae6ff7
|
1455 |
* @param refundRecordItemId 退款子单标识 |
C |
1456 |
* @param groupByONumberNo 根据支付方式编号求和 |
|
1457 |
* @param groupByConsumePayId 根据支付方式记录标识求和 |
|
1458 |
* @param commonService 映射 |
|
1459 |
* @return 返回已退款方式金额集合 |
|
1460 |
*/ |
|
1461 |
public static List<RefundRecordConsumePay> getRefundRecordConsumePay(String itemId,String refundRecordItemId,boolean groupByONumberNo |
|
1462 |
,boolean groupByConsumePayId,CommonService commonService){ |
|
1463 |
SqlSentence sqlSentence = new SqlSentence(); |
|
1464 |
Map<String,Object> values = new HashMap<>(); |
|
1465 |
StringBuilder sql = new StringBuilder(); |
|
1466 |
|
|
1467 |
sql.append("SELECT"); |
|
1468 |
if(groupByONumberNo){ |
2a45d4
|
1469 |
sql.append(" a.numberNo,"); |
ae6ff7
|
1470 |
} |
C |
1471 |
if(groupByConsumePayId){ |
2a45d4
|
1472 |
sql.append(" a.consumePayId,"); |
ae6ff7
|
1473 |
} |
2a45d4
|
1474 |
sql.append("SUM(a.refundTotal) AS refundTotal FROM refund_record_consume_pay a"); |
C |
1475 |
sql.append(" JOIN refund_record rr ON rr.id = a.refundRecordId AND rr.isDel = 0 AND rr.refundStatus = #{m.refundStatus}"); |
ae6ff7
|
1476 |
sql.append(" WHERE a.isDel = 0"); |
C |
1477 |
if(StringUtils.noNull(itemId)){ |
|
1478 |
sql.append(" AND a.commonId = #{m.commonId}"); |
|
1479 |
} |
|
1480 |
if(StringUtils.noNull(refundRecordItemId)){ |
|
1481 |
sql.append(" AND a.refundRecordItemId = #{m.refundRecordItemId}"); |
|
1482 |
} |
|
1483 |
if(groupByONumberNo){ |
|
1484 |
sql.append(" GROUP BY a.numberNo"); |
|
1485 |
} |
|
1486 |
if(groupByConsumePayId){ |
|
1487 |
sql.append(" GROUP BY a.consumePayId"); |
|
1488 |
} |
|
1489 |
//获取已退款的支付方式 |
|
1490 |
values.put("commonId",itemId); |
2a45d4
|
1491 |
values.put("refundStatus", RefundStatus.STATUS_SUCC_REFUND); |
ae6ff7
|
1492 |
sqlSentence.sqlSentence(sql.toString(),values); |
C |
1493 |
return commonService.selectList(RefundRecordConsumePayMapper.class,sqlSentence); |
|
1494 |
} |
|
1495 |
|
|
1496 |
/**保存退款方式和支付方式关联 |
|
1497 |
* @param refundTotal 退款金额 |
|
1498 |
* @param commonType 子单级别,可空 |
|
1499 |
* @param commonId 子单标识,可空 |
|
1500 |
* @param orderId 总单标识 |
|
1501 |
* @param numberNo 支付方式编号 |
|
1502 |
* @param name 支付方式名称 |
|
1503 |
* @param consumePayId 支付方式记录标识 |
|
1504 |
* @param refundMethodId 退款方式标识 |
|
1505 |
* @param refundRecordItemId 退款子记录标识,可空 |
|
1506 |
* @param refundRecordId 退款总记录标识 |
|
1507 |
* @param commonService 映射 |
|
1508 |
* @return 返回关联记录 |
|
1509 |
*/ |
|
1510 |
public static RefundRecordConsumePay insertRefundRecordConsumePay(BigDecimal refundTotal, String commonType, String commonId, String orderId |
2a45d4
|
1511 |
, String numberNo,String name,Integer isMoneyPay,Integer isExecute, String consumePayId, String refundMethodId,String refundRecordItemId,String refundRecordId,CommonService commonService){ |
ae6ff7
|
1512 |
//生成关联记录 |
C |
1513 |
RefundRecordConsumePay refundRecordConsumePay = new RefundRecordConsumePay(); |
|
1514 |
refundRecordConsumePay.setRefundTotal(refundTotal); |
|
1515 |
refundRecordConsumePay.setCommonType(commonType); |
|
1516 |
refundRecordConsumePay.setCommonId(commonId); |
|
1517 |
refundRecordConsumePay.setOrderId(orderId); |
|
1518 |
refundRecordConsumePay.setName(name); |
|
1519 |
refundRecordConsumePay.setNumberNo(numberNo); |
2a45d4
|
1520 |
refundRecordConsumePay.setIsMoneyPay(isMoneyPay); |
C |
1521 |
refundRecordConsumePay.setIsExecute(isExecute); |
ae6ff7
|
1522 |
refundRecordConsumePay.setConsumePayId(consumePayId); |
C |
1523 |
refundRecordConsumePay.setRefundMethodId(refundMethodId); |
|
1524 |
refundRecordConsumePay.setRefundRecordItemId(refundRecordItemId); |
|
1525 |
refundRecordConsumePay.setRefundRecordId(refundRecordId); |
|
1526 |
commonService.insert(RefundRecordConsumePayMapper.class,refundRecordConsumePay); |
|
1527 |
return refundRecordConsumePay; |
|
1528 |
} |
|
1529 |
|
|
1530 |
/**获取可退款的用户卡项 |
|
1531 |
* @param sourceId 订单子单标识 |
|
1532 |
* @return 可退款的用户卡项 |
|
1533 |
*/ |
|
1534 |
public static List<UserCard> getRefundCard(String sourceId,CommonService commonService){ |
|
1535 |
SqlSentence sqlSentence = new SqlSentence(); |
|
1536 |
Map<String,Object> sqlMap = new HashMap<>(); |
|
1537 |
//获取用户卡项 |
|
1538 |
sqlMap.put("sourceId",sourceId); |
|
1539 |
sqlMap.put("status",UserCard.TYPE_NO_USED); |
|
1540 |
sqlMap.put("effectiveStatus",UserProjectConstants.EFF_STATUS_YES); |
|
1541 |
sqlSentence.sqlSentence("SELECT * FROM user_card WHERE isDel = 0 AND sourceId = #{m.sourceId} AND status = #{m.status}" + |
|
1542 |
" AND effectiveStatus = #{m.effectiveStatus} AND turnAddId IS NULL",sqlMap); |
|
1543 |
return commonService.selectList(UserCardMapper.class,sqlSentence); |
|
1544 |
|
|
1545 |
} |
|
1546 |
|
|
1547 |
/**获取用户项目*/ |
|
1548 |
public static UserProjectItem getUserProject(String commonId,CommonService commonService){ |
|
1549 |
SqlSentence sqlSentence = new SqlSentence(); |
|
1550 |
Map<String, Object> map = new HashMap<>(); |
|
1551 |
|
|
1552 |
map.put("commonId",commonId); |
|
1553 |
sqlSentence.sqlSentence("select * from user_project_item where isDel=0 and commonId=#{m.commonId} and isTransfer = 0",map); |
a1c527
|
1554 |
return commonService.selectOne(UserProjectItemMapper.class,sqlSentence); |
ae6ff7
|
1555 |
} |
C |
1556 |
|
|
1557 |
} |