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