zhouxiang
2023-02-23 bec88badaeb0341a1d5429b31357eb37c0b16fb0
提交 | 用户 | age
3764dc 1 package com.hx.phip.util.api;
Z 2
31b1dc 3 import com.alibaba.fastjson.JSON;
3764dc 4 import com.hx.common.service.CommonService;
Z 5 import com.hx.mybatisTool.SqlSentence;
6 import com.hx.phiappt.common.*;
ae1cd0 7 import com.hx.phiappt.constants.enums.GroupTypeEnum;
3764dc 8 import com.hx.phiappt.constants.tool.RefundToolUtil;
Z 9 import com.hx.phiappt.constants.tool.SqlSplicingTool;
10 import com.hx.phiappt.model.BaseEntity;
11 import com.hx.phiappt.model.UserMoney;
c9e2be 12 import com.hx.phiappt.model.activity.ActivityAction;
Z 13 import com.hx.phiappt.model.activity.ActivityRule;
575cd4 14 import com.hx.phiappt.model.consume.ConsumePay;
36bc5e 15 import com.hx.phiappt.model.coupon.CouponNumber;
Z 16 import com.hx.phiappt.model.coupon.CouponOrderDiscountLog;
c9e2be 17 import com.hx.phiappt.model.order.*;
36bc5e 18 import com.hx.phiappt.model.refund.*;
f3a0dd 19 import com.hx.phiappt.model.user.UserCard;
89750d 20 import com.hx.phiappt.model.user.UserCardUsed;
3764dc 21 import com.hx.phiappt.model.user.UserProject;
Z 22 import com.hx.phiappt.model.user.UserProjectItem;
23 import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
24 import com.hx.phip.config.CustomParameter;
25 import com.hx.phip.dao.mapper.*;
f3a0dd 26 import com.hx.util.StringUtils;
3764dc 27 import com.platform.exception.PlatTipsException;
Z 28 import com.platform.resultTool.PlatformCode;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import java.math.BigDecimal;
eb3765 33 import java.util.*;
f3a0dd 34 import java.util.stream.Collectors;
3764dc 35
Z 36 /**
37  * @Author
38  */
39 public class PartialRefundUtil {
40     private static final Logger logger = LoggerFactory.getLogger(PartialRefundUtil.class);
41     /**
eda2c5 42      * 退款总流程工具
3764dc 43      * @param commonService
Z 44      * @param operationId
45      * @param operationNme
46      * @param refundId
47      * @param
48      * @param appIdCode
49      */
909b33 50     public static OrdersTotal refundProcess(CommonService commonService, String operationId, String operationNme, String refundId, CustomParameter customParameter, String appIdCode) {
3764dc 51         SqlSentence sqlSentence = new SqlSentence();
Z 52         Map<String,Object> map=new HashMap<>();
53         sqlSentence.setM(map);
54         //退款成功
31b1dc 55         map.put("refundStatus", RefundStatus.STATUS_APPLY_REFUND);
3764dc 56         map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND);
Z 57         map.put("refundId", refundId);
31b1dc 58         sqlSentence.setSqlSentence("select * from refund_record where isDel=0 and refundStatus=#{m.refundStatus} and id=#{m.refundId}");
3764dc 59         RefundRecord refundRecord =commonService.selectOne(RefundRecordMapper.class,sqlSentence);
Z 60         if(refundRecord ==null){
61             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到该退款信息!");
62         }
63         StringBuffer stringBuffer = new StringBuffer();
8785de 64         stringBuffer.append("select name,actualTotal,refundRecordId,refundNumberNo as numberNo,id,consumePayId from refund_record_method WHERE refundRecordId  in (");
3764dc 65         SqlSplicingTool.selectIn(stringBuffer, Arrays.asList((String) map.get("refundId")));
Z 66         sqlSentence.setSqlSentence(stringBuffer.toString());
67         List<Map<String, Object>> refundMethodList = commonService.selectListMap(RefundRecordMethodMapper.class,sqlSentence);
68         if(refundMethodList==null && refundMethodList.size()==0){
69             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"没有找到该退款订单对应的支付方式");
70         }
71         //查看订单信息
72         OrdersTotal ordersTotal=commonService.selectOneByKeyBlob(OrdersTotalMapper.class,refundRecord.getOrderId());
73         if(ordersTotal==null ){
74             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到订单信息!");
75         }
c9e2be 76         //查看订单其他信息
Z 77         map.put("orderId", ordersTotal.getId());
78         sqlSentence.setSqlSentence("select * from orders_info where isDel=0 and orderId=#{m.orderId}");
79         OrderInfo orderInfo=commonService.selectOne(OrderInfoMapper.class,sqlSentence);
3764dc 80
Z 81         //查询用户是否有账户信息,退款需要处理资金
82         map.put("userId",refundRecord.getUserId());
83         sqlSentence.setSqlSentence("select * from user_money WHERE  userId=#{m.userId} and isDel=0");
84         UserMoney userMoney=commonService.selectOne(UserMoneyMapper.class,sqlSentence);
85         if(userMoney==null){
86             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到该用户的资金信息");
87         }
36bc5e 88         //处理优惠券
Z 89         handCoupon(commonService, sqlSentence, map, refundRecord,ordersTotal);
3764dc 90
Z 91         if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){
92             //充值订单需要把充值的储值金 拿回来   因为储值金需要开单来处理,所以不需要增加日志
b18c61 93             //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 94             if(ordersTotal.getTotal().compareTo(BigDecimal.ZERO)!=0){
95                 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);
96                 OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, "储值金客户退回金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND);
97                 commonService.insert(OrderLogMapper.class,orderLog);
98                 //活动规则退款处理
99                 handActivityRule(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,orderInfo);
100             }
101
3764dc 102         }else if(OrderTotalConstants.TYPE_CARD_BAG.equals(ordersTotal.getType())){
Z 103             //卡包处理
733330 104             numberOfRefunds(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,customParameter);
3764dc 105         } else {
Z 106             //普通订单处理
107             if(refundRecord.getRefundType() ==0){
108                 numberOfRefunds(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,customParameter);
109             }
110         }
111
112
113
114         //增加增值金
115         boolean cashStatus=false;//判断是否有现金或者其他现金支付
575cd4 116         ConsumePay consumePay;
3764dc 117         for(Map<String,Object> methodMap:refundMethodList){
Z 118             BigDecimal actualTotal=(BigDecimal) methodMap.get("actualTotal");
119             String name=(String) methodMap.get("name");
b9b969 120             String id=(String) methodMap.get("id");
575cd4 121             String consumePayId=(String) methodMap.get("consumePayId");
3764dc 122             if(PayMethodTypeConstants.PAY_STORED.equals(methodMap.get("numberNo"))){
279fe1 123
277835 124                 //储值金额 
b18c61 125                 //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 126                 if(actualTotal.compareTo(BigDecimal.ZERO)!=0){
127                     UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式储值金额退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),actualTotal, UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
128                     OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, name+"退款金额:"+actualTotal, 0, OrderLogConstants.LOG_TYPE_REFUND);
129                     commonService.insert(OrderLogMapper.class,orderLog);
130                 }
3764dc 131             }else if(PayMethodTypeConstants.PAY_ADD_FUND.equals(methodMap.get("numberNo"))){
Z 132                 //增值金
b18c61 133                 //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 134                 if(actualTotal.compareTo(BigDecimal.ZERO)!=0){
135                     UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式增值金退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),actualTotal, UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
136                     OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name,0, OrderLogConstants.LOG_TYPE_REFUND);
137                     commonService.insert(OrderLogMapper.class,orderLog);
138                 }
3764dc 139             }else if(PayMethodTypeConstants.PAY_INTEGRAL.equals(methodMap.get("numberNo"))){
Z 140                 //积分
b18c61 141                 //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 142                 if(actualTotal.compareTo(BigDecimal.ZERO)!=0){
143                     UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式积分退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),actualTotal, UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
144                     OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name+"退款金额:"+actualTotal,0, OrderLogConstants.LOG_TYPE_REFUND);
145                     commonService.insert(OrderLogMapper.class,orderLog);
146                 }
3764dc 147             }else {
Z 148                 cashStatus=true;
149                 //现金支付
74aebf 150                 if(actualTotal.compareTo(BigDecimal.ZERO)<1){
Z 151                     continue;
152                 }
3764dc 153                 OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name+"退款金额:"+actualTotal,0, OrderLogConstants.LOG_TYPE_REFUND);
da4ad2 154                 orderLog.setOrderId(ordersTotal.getId());
3764dc 155                 commonService.insert(OrderLogMapper.class,orderLog);
Z 156
157                 //现金支付需要创建创建退款单进行退款
158                 RefundNote refundNote=new RefundNote(actualTotal, (String) methodMap.get("numberNo"),name,ordersTotal.getId(),refundRecord.getUserId());
277835 159                 refundNote.setRefundRecordId(refundRecord.getId());
3764dc 160                 commonService.insert(RefundNoteMapper.class,refundNote);
Z 161             }
b9b969 162             //修改实际退款金额
254bde 163             sqlSentence.setSqlSentence(" realRefundTotal=#{m.realRefundTotal} where   id=#{m.refundMethodId}");
d4d93e 164             map.put("realRefundTotal",actualTotal);
b9b969 165             map.put("refundMethodId",id);
Z 166             commonService.updateWhere(RefundRecordMethodMapper.class,sqlSentence);
575cd4 167
Z 168             //修改支付方式已退款金额
169             consumePay=commonService.selectOneByKey(ConsumePayMapper.class,consumePayId);
170             consumePay.setRefundTotal(consumePay.getRefundTotal().add(actualTotal));
171             commonService.updateAll(ConsumePayMapper.class,consumePay);
172
3764dc 173         }
Z 174
175         //退款总订单
176         map.put("refundStatus", RefundStatus.STATUS_SUCC_REFUND);
177         map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND);
eb3765 178         map.put("editTime", new Date());
3764dc 179         map.put("refundId", refundId);
Z 180         map.put("isDel", BaseEntity.NO);
eb3765 181         sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus},editTime=#{m.editTime} where id=#{m.refundId} and isDel=#{m.isDel} and refundStatus=#{m.oldRefundStatus}");
3764dc 182         commonService.updateWhere(RefundRecordMapper.class,sqlSentence);
Z 183
e5067d 184         //更改总订单退款状态
Z 185         map.put("orderId",ordersTotal.getId());
186         sqlSentence.setSqlSentence("select * from order_item WHERE  orderId=#{m.orderId} and isDel=0");
187         List<OrderItem> orderItemList=commonService.selectList(OrderItemMapper.class,sqlSentence);
3764dc 188
f3a0dd 189         List<Integer> collect = orderItemList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList());
Z 190         if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){
191             ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
192             ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
193         }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){
194             ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
195             ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
196         }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){
197             ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE);
198         }else {
20e683 199             ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH);
fd0dd6 200             ordersTotal.setStatus(OrderTotalConstants.STATUS_CANCEL);
f3a0dd 201             ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
e5067d 202         }
0a9391 203         ordersTotal.setIsSyncOrder(BaseEntity.NO);
eb3765 204         ordersTotal.setEditTime(new Date());
909b33 205         commonService.updateAll(OrdersTotalMapper.class,ordersTotal);
Z 206         return ordersTotal;
3764dc 207     }
36bc5e 208     /**
Z 209      * 退款-处理优惠券
210      * @param commonService
211      * @param sqlSentence
212      * @param map
213      * @param refundRecord
214      */
215     public static void handCoupon(CommonService commonService,  SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord,OrdersTotal ordersTotal) {
216         map.put("refundRecordId",refundRecord.getId());
217         sqlSentence.setSqlSentence("select * from refund_record_coupon where  refundRecordId=#{m.refundRecordId} and isDel=0 ");
218         List<RefundRecordCoupon> refundRecordCouponList=commonService.selectList(RefundRecordCouponMapper.class,sqlSentence);
219         //退款成功
90917f 220         map.put("status", BaseEntity.YES);
36bc5e 221         CouponOrderDiscountLog couponOrderDiscountLog=null;
Z 222         for (RefundRecordCoupon refundRecordCoupon : refundRecordCouponList) {
90917f 223             sqlSentence.setSqlSentence("  status=#{m.status} WHERE id = #{m.id}  ");
3fabd5 224             map.put("id", refundRecordCoupon.getCouponOrderId());
6e4c52 225             couponOrderDiscountLog=commonService.selectOneByKey(CouponOrderDiscountLogMapper.class,refundRecordCoupon.getCouponOrderId());
36bc5e 226             if(couponOrderDiscountLog==null){
Z 227                 throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单优惠卷id不正确");
228             }
6e4c52 229             commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence);
36bc5e 230
e4ba4e 231             if("his_coupon_code".equals(couponOrderDiscountLog.getCouponNumberId())){
Z 232                 continue;
233             }
36bc5e 234             map.put("isUse", BaseEntity.NO);
Z 235             map.put("useTime", null);
236             map.put("useType", CouponNumber.USE_TYPE_UNKNOW);
237             map.put("id", couponOrderDiscountLog.getCouponNumberId());
238             sqlSentence.setSqlSentence("  isUse=#{m.isUse},useTime=#{m.useTime},useType=#{m.useType},isUse=#{m.isUse} WHERE id = #{m.id}  ");
239             commonService.updateWhere(CouponNumberMapper.class,sqlSentence);
240         }
241
242
243     }
3764dc 244
c9e2be 245     /**
Z 246      * 退款-处理活动规则增值金和积分
247      * @param commonService
248      * @param operationId
249      * @param operationNme
250      * @param sqlSentence
251      * @param map
252      * @param refundRecord
253      * @param ordersTotal
254      */
255     private static void handActivityRule(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence,
256                                          Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, OrderInfo orderInfo) {
257         if(orderInfo!=null && StringUtils.noNull(orderInfo.getActivityId())){
258             ActivityRule activityRule=commonService.selectOneByKeyBlob(ActivityRuleMapper.class,orderInfo.getActivityId());
259             if(activityRule!=null){
260                 map.put("activityRuleId",activityRule.getId());
261                 map.put("type", ActivityAction.TYPE_INTEGRAL);
262                 map.put("type1",ActivityAction.TYPE_VALUEADDEDFUND);
cd08a4 263                 map.put("type2",ActivityAction.TYPE_COUPON);
5d4388 264                 sqlSentence.setSqlSentence("select * from activity_action where activityRuleId=#{m.activityRuleId} and (type=#{m.type} or type=#{m.type1} or type=#{m.type2}) and isDel=0");
c9e2be 265                 List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence);
Z 266                 if(activityActions!=null && activityActions.size()>0){
267                     for (ActivityAction activityAction : activityActions) {
268                         if(ActivityAction.TYPE_INTEGRAL.equals(activityAction.getType())){
b18c61 269                             //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 270                             if(new BigDecimal(activityAction.getWorth()).negate().compareTo(BigDecimal.ZERO)!=0){
271                                 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);
272                             }
c9e2be 273                         }else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(activityAction.getType())){
b18c61 274                             //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 275                             if(new BigDecimal(activityAction.getWorth()).negate().compareTo(BigDecimal.ZERO)!=0){
276                                 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);
277                             }
cd08a4 278                         }else if(ActivityAction.TYPE_COUPON.equals(activityAction.getType())){
Z 279                             map.put("oldValidState",BaseEntity.YES);
280                             map.put("newValidState",BaseEntity.NO);
281                             map.put("couponId",activityAction.getCrmCouponId());
282                             map.put("commonId",ordersTotal.getId());
283                             sqlSentence.setSqlSentence(" validState=#{m.newValidState} where couponId=#{m.couponId} and commonId=#{m.commonId} and validState=#{m.oldValidState} ");
284                             commonService.updateWhere(CouponNumberMapper.class,sqlSentence);
c9e2be 285                         }
Z 286                     }
287                 }
288             }
289         }
3764dc 290
c9e2be 291     }
3764dc 292     /**
Z 293      * 退款-处理普通订单信息(比如:项目、促销、卡项)
294      * @param commonService
295      * @param operationId               操作人标识
296      * @param operationNme              操作人名称
297      * @param sqlSentence
298      * @param map
299      * @param refundRecord
300      */
301     public static void numberOfRefunds(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence,
302                                        Map<String, Object> map, RefundRecord refundRecord,OrdersTotal ordersTotal,CustomParameter customParameter) {
303         map.put("refundId",map.get("refundId"));
304         sqlSentence.setSqlSentence("select * from refund_record_item where isDel=0 and refundRecordId=#{m.refundId}");
305         List<RefundRecordItem> refundRecordItems =commonService.selectList(RefundRecordItemMapper.class,sqlSentence);
306         if(refundRecordItems==null && refundRecordItems.size()==0){
307             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到退款子订单信息");
308         }
309         for (RefundRecordItem v: refundRecordItems) {
310             switch (v.getType()){
733330 311                 case OrderItemConstants.TYPE_RETAIL:
Z 312                     handRefundRerail(commonService, sqlSentence, map, refundRecord, v);
313                     break;
55dbe8 314                 case OrderItemConstants.TYPE_DRUG:
Z 315                     handRefundRerail(commonService, sqlSentence, map, refundRecord, v);
316                     break;
3764dc 317                 case OrderItemConstants.TYPE_PROJECT:
Z 318                     handRefundNoExecution(commonService, operationId, operationNme, sqlSentence, map, refundRecord, v);
319                     break;
320                 case OrderItemConstants.TYPE_PROMOTION:
ae1cd0 321                     handRefundPromotion(commonService, operationId, operationNme, sqlSentence, map, refundRecord, ordersTotal, v);
3764dc 322                     break;
Z 323                 case OrderItemConstants.TYPE_CARD:
f3a0dd 324                     handRefundCard(commonService, operationId, sqlSentence, map, refundRecord, ordersTotal, v);
3764dc 325                     break;
Z 326                 case OrderItemConstants.CARD_BAG:
733330 327                     handCardBag(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,v,customParameter);
3764dc 328                     break;
Z 329                 default:break;
330             }
331         }
332     }
333
733330 334     /**
Z 335      * 退款一级是商品
336      * @param commonService
337      * @param sqlSentence
338      * @param map
339      * @param refundRecord
340      * @param v
341      */
342     private static void handRefundRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItem v) {
343
344         //判断操作完了去修改子订单状态
345         OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
346         if (orderItem==null){
347             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息");
348         }
78cf78 349         map.put("isDel", BaseEntity.NO);
733330 350         map.put("orderItemId", v.getOrderItemId());
Z 351         map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
352         Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum();
353         map.put("hasReNum",hasReNum);
354         if (hasReNum==orderItem.getBuyNum()){
355             map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH);
356         }else {
357             map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART);
358         }
359
360         sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
361         commonService.updateWhere(OrderItemMapper.class,sqlSentence);
362     }
3764dc 363     /**
ae1cd0 364      * 退款-处理未执行划扣   项目类型
3764dc 365      * @param commonService
Z 366      * @param operationId               操作人
367      * @param operationNme              操作人名称
368      * @param sqlSentence
369      * @param map
370      * @param refundRecord
371      * @param v
372      */
373     private static void handRefundNoExecution(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItem v) {
374         sqlSentence.setSqlSentence("select * from user_project_item where isDel=0 and commonId='"+v.getOrderItemId()+"' and shopId='"+refundRecord.getRefundShopId()+"' " +
375                 " and userId ='"+refundRecord.getUserId()+"'");
376         UserProjectItem userProjectItem =commonService.selectOne(UserProjectItemMapper.class,sqlSentence);
377         if (userProjectItem == null) {
378             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到用户子项项目信息");
379         }
21e712 380         Integer usedNum=userProjectItem.getNotUsedNum()-v.getRefundNum();
e5067d 381         Integer cancelNum=userProjectItem.getCancelNum()+v.getRefundNum();
Z 382
21e712 383         map.put("usedNum", usedNum);
04bdfc 384         map.put("isDel", BaseEntity.NO);
e5067d 385         map.put("cancelNum", cancelNum);
3764dc 386         map.put("userProjectItemId", userProjectItem.getId());
04bdfc 387         sqlSentence.setSqlSentence(" cancelNum=#{m.cancelNum},notUsedNum=#{m.usedNum} where isDel=#{m.isDel} AND id=#{m.userProjectItemId} AND notUsedNum > 0 ");
3764dc 388         commonService.updateWhere(UserProjectItemMapper.class,sqlSentence);
Z 389
390         UserProject userProject=commonService.selectOneByKey(UserProjectMapper.class,userProjectItem.getUserProjectId());
391         userProject.setNotUsedNum(userProject.getNotUsedNum()-v.getRefundNum());
392         commonService.updateAll(UserProjectMapper.class,userProject);
e5067d 393         //判断操作完了去修改子订单状态
Z 394         OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
395         if (orderItem==null){
396             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息");
397         }
398
399         Integer refundStatus=OrderTotalConstants.STATUS_REFUND_NONE;
400         if(usedNum==0){
401             //已经没有可以执行数量
402             refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH;
403         }else {
404             refundStatus=OrderTotalConstants.STATUS_REFUND_PART;
405         }
406         map.put("orderItemId", v.getOrderItemId());
407         map.put("refundStatus", refundStatus);
408         map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
409         map.put("hasReNum",cancelNum/(orderItem.getUsedTotal()/orderItem.getBuyNum()));
410
411         sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
412         commonService.updateWhere(OrderItemMapper.class,sqlSentence);
3764dc 413     }
ae1cd0 414     /**
f3a0dd 415      * 退款-处理卡项
Z 416      * @param commonService
417      * @param operationId
418      * @param sqlSentence
419      * @param map
420      * @param refundRecord
421      * @param ordersTotal
422      * @param v
423      */
424     public static void handRefundCard(CommonService commonService, String operationId, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem v) {
425
426         //判断操作完了去修改子订单状态
427         OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
428         if (orderItem==null){
429             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息");
430         }
431         //作废卡包
31b1dc 432
8785de 433         map.put("hisOrderId",ordersTotal.getHisOrderId());
Z 434         map.put("orderId",ordersTotal.getId());
435         map.put("effectiveStatus",UserProjectConstants.EFF_STATUS_YES);
436         map.put("status",UserCard.TYPE_NO_USED);
437         map.put("isDel",BaseEntity.NO);
44dc13 438         sqlSentence.setSqlSentence("select id from user_card where (hisOrderId =#{m.hisOrderId} OR orderId =#{m.orderId})  AND effectiveStatus=#{m.effectiveStatus} AND status=#{m.status} AND doneeUserId IS NULL AND isDel=#{m.isDel}  ");
8785de 439         List<UserCard> userCards = commonService.selectList(UserCardMapper.class, sqlSentence);
Z 440         if(userCards==null || userCards.size()==0){
44dc13 441             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款作废卡包提示:没有找到对应的卡包可退:"+ordersTotal.getId());
8785de 442         }else {
Z 443             UserCard userCard=null;
444             for (int i = 0; i < v.getRefundNum(); i++) {
445                 userCard=userCards.get(i);
446                 map.put("id",userCard.getId());
447                 map.put("effectiveStatus", UserProjectConstants.EFF_STATUS_CANCEL);
448                 sqlSentence.setSqlSentence(" effectiveStatus=#{m.effectiveStatus} where id=#{m.id} ");
449                 commonService.updateWhere(UserCardMapper.class,sqlSentence);
f3a0dd 450             }
8785de 451         }
31b1dc 452
f3a0dd 453         //更改订单子订单状态
Z 454         map.put("orderItemId", v.getOrderItemId());
455         map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
456         Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum();
457         map.put("hasReNum",hasReNum);
458         if (hasReNum==orderItem.getBuyNum()){
459             map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH);
460         }else {
461             map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART);
462         }
463
464
465         sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
466         commonService.updateWhere(OrderItemMapper.class,sqlSentence);
467     }
733330 468
Z 469     /**
470      * 退款-处理卡包
471      * @param commonService
472      * @param operationId
473      * @param operationNme
474      * @param sqlSentence
475      * @param map
476      * @param refundRecord
477      * @param ordersTotal
478      * @param v
479      */
480     public static void handCardBag(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map,
481                                    RefundRecord refundRecord, OrdersTotal ordersTotal,RefundRecordItem v,CustomParameter customParameter) {
482         //查看订单信息
483         OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
484         if(orderItem==null ){
485             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息!");
486         }
487         map.put("refundRecordItemId",v.getId());
488         sqlSentence.setSqlSentence("select * from refund_record_item_source where refundRecordItemId =#{m.refundRecordItemId}");
489         List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence);
490         if( sons!=null && sons.size()>0 ){
491             for (RefundRecordItemSource son : sons) {
492                 switch (GroupTypeEnum.getCode(son.getType())){
493                     case PROJECT:
494                         handRefundNoSonExecution(commonService, sqlSentence, map, refundRecord, son);
682ce5 495                         deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem);
733330 496                         break;
Z 497                     case RETAIL:
498                         handRefundSonRerail(commonService, sqlSentence, map, refundRecord, son);
682ce5 499                         deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem);
733330 500                         break;
Z 501                     case INCREMENT:
502                         //增值金
b18c61 503                         //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 504                         if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
505                             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);
506                         }
733330 507                         break;
Z 508                     case STORED:
509                         //储值金额
b18c61 510                         //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 511                         if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
512                             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);
513                         }
733330 514                         break;
Z 515                     case INTEGRAL:
516                         //积分
b18c61 517                         //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 518                         if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
519                             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);
520                         }
733330 521                         break;
Z 522                 }
523             }
524         }
78cf78 525         //更改二级子订单退款状态
Z 526
527         map.put("orderItemId",orderItem.getId());
528         sqlSentence.setSqlSentence("select * from order_item_source WHERE  orderItemId=#{m.orderItemId} and isDel=0");
529         List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence);
530
531         List<Integer> collect = orderItemSonList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList());
532         if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){
533             orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
534             orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
535         }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){
536             orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
537             orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
538         }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){
539             orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE);
540         }else {
541             orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH);
542             orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
543             orderItem.setHasReNum(orderItem.getBuyNum());
544         }
545
546         commonService.updateAll(OrderItemMapper.class,orderItem);
733330 547     }
89750d 548
Z 549     /**
550      * 退款需要删除用户卡包使用记录
551      * @param sqlSentence
552      * @param map
553      * @param ordersTotal
554      * @param commonService
555      * @param son
556      */
682ce5 557     public static void deleteUserCardUsed(SqlSentence sqlSentence, Map<String, Object> map,OrdersTotal ordersTotal,CommonService commonService,RefundRecordItemSource son,OrderItem orderItem){
89750d 558
Z 559
560         OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,son.getOrderItemSonId());
561         Integer hasReNum=orderItemSon.getHasReNum();
562
563         map.put("isDel",BaseEntity.NO);
564         map.put("orderId",ordersTotal.getId());
565         map.put("commonId",orderItemSon.getGoodsId());
218258 566         sqlSentence.setSqlSentence(" SELECT * FROM user_card_used WHERE orderId = #{m.orderId} and commonId=#{m.commonId} ORDER BY isDel,createTime  ");
89750d 567         List<UserCardUsed> userCardUsedList=commonService.selectList(UserCardUsedMapper.class,sqlSentence);
Z 568
0eb5bc 569         if(userCardUsedList==null || userCardUsedList.size()==0){
Z 570             //因为可能领建的老订单所以伪造的操作记录是没数据的
682ce5 571             map.put("userCardId",orderItem.getCommonId());
Z 572             sqlSentence.setSqlSentence(" SELECT * FROM user_card_used WHERE commonId=#{m.commonId} and userCardId=#{m.userCardId} ORDER BY isDel,createTime  ");
0eb5bc 573             userCardUsedList=commonService.selectList(UserCardUsedMapper.class,sqlSentence);
Z 574         }
575
89750d 576         UserCardUsed userCardUsed;
Z 577         for (int i = 0; i < hasReNum; i++) {
578             userCardUsed=userCardUsedList.get(i);
579             userCardUsed.setIsDel(BaseEntity.YES);
580             commonService.updateAll(UserCardUsedMapper.class,userCardUsed);
581         }
582     }
f3a0dd 583     /**
ae1cd0 584      * 退款-处理促销
Z 585      * @param commonService
586      * @param operationId
587      * @param operationNme
588      * @param sqlSentence
589      * @param map
590      * @param refundRecord
591      * @param ordersTotal
592      * @param v
593      */
594     private static void handRefundPromotion(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem v) {
822da4 595         //查看订单信息
Z 596         OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
597         if(orderItem==null ){
598             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息!");
599         }
600
b099fc 601         map.put("refundRecordItemId",v.getId());
Z 602         sqlSentence.setSqlSentence("select * from refund_record_item_source where refundRecordItemId =#{m.refundRecordItemId}");
603         List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence);
ae1cd0 604         if( sons!=null && sons.size()>0 ){
b099fc 605             for (RefundRecordItemSource son : sons) {
ae1cd0 606                 switch (GroupTypeEnum.getCode(son.getType())){
Z 607                     case PROJECT:
608                         v.setOrderItemId(son.getId());
b099fc 609                         v.setRefundNum(son.getRefundNum());
Z 610                         handRefundNoSonExecution(commonService, sqlSentence, map, refundRecord, son);
733330 611                         break;
Z 612                     case RETAIL:
613                         v.setOrderItemId(son.getId());
614                         v.setRefundNum(son.getRefundNum());
615                         handRefundSonRerail(commonService, sqlSentence, map, refundRecord, son);
ae1cd0 616                         break;
Z 617                     case INCREMENT:
618                         //增值金
b18c61 619                         //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 620                         if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
621                             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);
622                         }
ae1cd0 623                         break;
Z 624                     case STORED:
625                         //储值金额
b18c61 626                         //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 627                         if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
628                             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);
629                         }
ae1cd0 630                         break;
Z 631                     case INTEGRAL:
632                         //积分
b18c61 633                         //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
Z 634                         if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
635                             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);
636                         }
ae1cd0 637                         break;
Z 638                 }
639             }
640         }
822da4 641
Z 642         //更改二级子订单退款状态
643
f3a0dd 644         map.put("orderItemId",orderItem.getId());
822da4 645         sqlSentence.setSqlSentence("select * from order_item_source WHERE  orderItemId=#{m.orderItemId} and isDel=0");
Z 646         List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence);
f3a0dd 647
Z 648         List<Integer> collect = orderItemSonList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList());
649         if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){
650             orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
651             orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
652         }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){
653             orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
654             orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
655         }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){
656             orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE);
657         }else {
da4ad2 658             orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH);
f3a0dd 659             orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
Z 660             orderItem.setHasReNum(orderItem.getBuyNum());
822da4 661         }
f3a0dd 662
822da4 663         commonService.updateAll(OrderItemMapper.class,orderItem);
ae1cd0 664     }
b099fc 665     /**
Z 666      * 退款-处理二级子订单未执行划扣   项目类型
667      * @param commonService
668      * @param sqlSentence
669      * @param map
670      * @param refundRecord
671      * @param v
672      */
673     private static void handRefundNoSonExecution(CommonService commonService, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) {
674         sqlSentence.setSqlSentence("select * from user_project_item where isDel=0 and commonId='"+v.getOrderItemSonId()+"' and shopId='"+refundRecord.getRefundShopId()+"' " +
675                 " and userId ='"+refundRecord.getUserId()+"'");
676         UserProjectItem userProjectItem =commonService.selectOne(UserProjectItemMapper.class,sqlSentence);
677         if (userProjectItem == null) {
678             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到用户子项项目信息");
679         }
680         Integer usedNum=userProjectItem.getNotUsedNum()-v.getRefundNum();
681         Integer cancelNum=userProjectItem.getCancelNum()+v.getRefundNum();
682
683         map.put("usedNum", usedNum);
684         map.put("isDel", BaseEntity.NO);
685         map.put("cancelNum", cancelNum);
686         map.put("userProjectItemId", userProjectItem.getId());
687         sqlSentence.setSqlSentence(" cancelNum=#{m.cancelNum},notUsedNum=#{m.usedNum} where isDel=#{m.isDel} AND id=#{m.userProjectItemId} AND notUsedNum > 0 ");
688         commonService.updateWhere(UserProjectItemMapper.class,sqlSentence);
689
690         UserProject userProject=commonService.selectOneByKey(UserProjectMapper.class,userProjectItem.getUserProjectId());
691         userProject.setNotUsedNum(userProject.getNotUsedNum()-v.getRefundNum());
692         commonService.updateAll(UserProjectMapper.class,userProject);
693         //判断操作完了去修改子订单状态
822da4 694         OrderItemSon orderItem=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId());
b099fc 695         if (orderItem==null){
822da4 696             logger.info("二级子订单id:{}",v.getOrderItemSonId());
b099fc 697             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息");
Z 698         }
f3a0dd 699         Integer refundStatus=OrderTotalConstants.STATUS_REFUND_NONE;
Z 700         if(usedNum==0){
701             //已经没有可以执行数量
702             refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH;
703         }else {
704             refundStatus=OrderTotalConstants.STATUS_REFUND_PART;
705         }
b099fc 706         map.put("orderItemId", v.getOrderItemSonId());
822da4 707         map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
b099fc 708         map.put("hasReNum",cancelNum/(orderItem.getUsedTotal()/orderItem.getBuyNum()));
f3a0dd 709         map.put("refundStatus", refundStatus);
Z 710         sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
822da4 711         commonService.updateWhere(OrderItemSonMapper.class,sqlSentence);
b099fc 712     }
733330 713     /**
Z 714      * 退款二级是商品
715      * @param commonService
716      * @param sqlSentence
717      * @param map
718      * @param refundRecord
719      * @param v
720      */
721     private static void handRefundSonRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) {
722
723         //判断操作完了去修改子订单状态
724         OrderItemSon orderItem=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId());
725         if (orderItem==null){
726             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息");
727         }
728
729         map.put("orderItemId", v.getOrderItemSonId());
730         map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
731         Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum();
732         map.put("hasReNum",hasReNum);
0d63af 733         map.put("isDel",BaseEntity.NO);
733330 734         if (hasReNum==orderItem.getBuyNum()){
Z 735             map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH);
736         }else {
737             map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART);
738         }
739
740         sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
741         commonService.updateWhere(OrderItemSonMapper.class,sqlSentence);
742     }
3764dc 743 }