chenjiahe
2024-03-01 f87850bb6c6109a3bda06ab474575631407bbf09
提交 | 用户 | age
fd7281 1 package com.hx.phip.tool.refund;
C 2
160c33 3 import com.alibaba.fastjson.JSON;
fd7281 4 import com.hx.common.service.CommonService;
160c33 5 import com.hx.exception.TipsException;
528195 6 import com.hx.mybatisTool.SqlSentence;
160c33 7 import com.hx.phiappt.common.*;
C 8 import com.hx.phiappt.constants.enums.GroupTypeEnum;
9 import com.hx.phiappt.constants.tool.RefundToolUtil;
fd7281 10 import com.hx.phiappt.model.BaseEntity;
C 11 import com.hx.phiappt.model.activity.ActivityAction;
12 import com.hx.phiappt.model.activity.ActivityRule;
160c33 13 import com.hx.phiappt.model.cardItem.CardEquity;
C 14 import com.hx.phiappt.model.cardItem.CardItemInfo;
15 import com.hx.phiappt.model.coupon.CouponNumber;
16 import com.hx.phiappt.model.coupon.CouponOrderDiscountLog;
17 import com.hx.phiappt.model.order.*;
18 import com.hx.phiappt.model.refund.*;
19 import com.hx.phiappt.model.user.UserCard;
20 import com.hx.phiappt.model.user.UserCardUsed;
21 import com.hx.phiappt.model.user.UserProjectItem;
fd7281 22 import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
528195 23 import com.hx.phip.dao.mapper.*;
160c33 24 import com.hx.phip.service.order.impl.OrderRefundServiceImpl;
cfedbf 25 import com.hx.phip.tool.order.OrderTool;
4ebb90 26 import com.hx.phip.tool.user.UserCardTool;
160c33 27 import com.hx.phip.tool.user.UserProjectTool;
fd7281 28 import com.hx.phip.util.api.UserMoneyUtil;
e490fa 29 import com.hx.phip.vo.order.refund.RefundCarryVo;
4ebb90 30 import com.hx.phip.vo.user.UserCardItemInfoVo;
fd7281 31 import com.hx.util.StringUtils;
C 32 import com.platform.exception.PlatTipsException;
33 import com.platform.resultTool.PlatformCode;
160c33 34 import org.slf4j.Logger;
C 35 import org.slf4j.LoggerFactory;
fd7281 36
C 37 import java.math.BigDecimal;
528195 38 import java.util.HashMap;
fd7281 39 import java.util.List;
528195 40 import java.util.Map;
160c33 41 import java.util.stream.Collectors;
fd7281 42
C 43 /**
44  * 订单退款单作废工具
160c33 45  * @author CJH
fd7281 46  */
C 47 public class OrderRefundCancelTool {
48
160c33 49     /**log4j日志*/
C 50     private static final Logger logger = LoggerFactory.getLogger(OrderRefundServiceImpl.class.getName());
51
4ebb90 52     /**操作类型-0退款执行*/
C 53     public static final int OPT_TYPE_EXECUTE = 0;
54     /**操作类型—1作废退款*/
55     public static final int OPT_TYPE_CANCEL = 1;
56
245f89 57     public static final String REFUND_REMARK = "订单退款";
C 58
160c33 59
C 60     /**处理总退款方式数据*/
b3fdea 61     public static List<RefundRecordMethod> refundRecordMotnedHandle(RefundRecord refundRecord,OrdersTotal ordersTotal,StringBuilder orderNodeBuilder,CommonService commonService){
160c33 62         SqlSentence sqlSentence = new SqlSentence();
C 63         Map<String,Object> values = new HashMap<>();
64
65         //获取总退款方式
66         values.put("refundRecordId",refundRecord.getId());
67         sqlSentence.sqlSentence("SELECT * FROM refund_record_method WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",values);
68         List<RefundRecordMethod> refundRecordMethodList = commonService.selectList(RefundRecordMethodMapper.class,sqlSentence);
a9c1ab 69         //退款的支付方式记录数据,总的
160c33 70         values.clear();
C 71         values.put("refundRecordId",refundRecord.getId());
a9c1ab 72         sqlSentence.sqlSentence("SELECT * FROM refund_record_consume_pay WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId} AND refundRecordItemId IS NULL",values);
160c33 73         List<RefundRecordConsumePay> refundConsumePayList = commonService.selectList(RefundRecordConsumePayMapper.class,sqlSentence);
C 74
75         for(RefundRecordConsumePay refundRecordConsumePay:refundConsumePayList){
76             //更新支付记录退款信息
77             values.clear();
78             values.put("refundTotal",refundRecordConsumePay.getRefundTotal().negate());
79             values.put("id",refundRecordConsumePay.getConsumePayId());
4ebb90 80             sqlSentence.sqlUpdate("refundTotal = refundTotal + #{m.refundTotal} WHERE id = #{m.id} AND refundTotal + #{m.refundTotal} >= 0",values);
160c33 81             if(commonService.updateWhere(ConsumePayMapper.class,sqlSentence) != 1){
C 82                 throw new TipsException("退款金额错误[33]!");
83             }
84
85             //更新支付记录退款信息
86             values.clear();
87             values.put("status",RefundRecordConsumePay.NO);
88             values.put("statusOld",RefundRecordConsumePay.YES);
89             values.put("id",refundRecordConsumePay.getId());
01fbcb 90             sqlSentence.sqlUpdate("status = #{m.status} WHERE id = #{m.id} AND status = #{m.statusOld}",values);
160c33 91             if(commonService.updateWhere(RefundRecordConsumePayMapper.class,sqlSentence) != 1){
C 92                 throw new TipsException("退款金额记录状态错误!");
93             }
94
95         }
96
b3fdea 97         //处理扣减账号资金
160c33 98         for(RefundRecordMethod refundRecordMethod:refundRecordMethodList){
C 99             if(PayMethodTypeConstants.PAY_STORED.equals(refundRecordMethod.getRefundNumberNo())){
100                 //储值金额 
101                 //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
102                 if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)>0){
103                     UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getInvalidRemarks(),"作废退款:支付方式储值金额扣减",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),refundRecordMethod.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
104                     OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, refundRecord.getInvalidId(), refundRecord.getInvalidName(), refundRecordMethod.getName()+"作废退款金额:"+refundRecordMethod.getRealRefundTotal(), 1, OrderLogConstants.LOG_TYPE_REFUND_UNDO);
105                     commonService.insert(OrderLogMapper.class,orderLog);
b3fdea 106                     if(orderNodeBuilder != null){
C 107                         orderNodeBuilder.append("-[作废退款]扣减退款金额(储值金):").append(refundRecordMethod.getRealRefundTotal());
108                     }
160c33 109                 }
C 110             }else if(PayMethodTypeConstants.PAY_ADD_FUND.equals(refundRecordMethod.getRefundNumberNo())){
111                 //增值金
112                 //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
113                 if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)!=0){
114                     UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"作废退款:支付方式增值金退回",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),refundRecordMethod.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
115                     OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,refundRecord.getInvalidId(),refundRecord.getInvalidName(),refundRecordMethod.getName(),1, OrderLogConstants.LOG_TYPE_REFUND_UNDO);
116                     commonService.insert(OrderLogMapper.class,orderLog);
b3fdea 117                     if(orderNodeBuilder != null){
C 118                         orderNodeBuilder.append("-[作废退款]扣减退款金额(增值金):").append(refundRecordMethod.getRealRefundTotal());
119                     }
160c33 120                 }
C 121             }else if(PayMethodTypeConstants.PAY_INTEGRAL.equals(refundRecordMethod.getRefundNumberNo())){
122                 //积分
123                 //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
124                 if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)!=0){
125                     UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"作废退款:支付方式积分退回",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),refundRecordMethod.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
126                     OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,refundRecord.getInvalidId(),refundRecord.getInvalidName(),refundRecordMethod.getName()+"作废退款金额:"+refundRecordMethod.getRealRefundTotal(),1, OrderLogConstants.LOG_TYPE_REFUND_UNDO);
127                     commonService.insert(OrderLogMapper.class,orderLog);
b3fdea 128                     if(orderNodeBuilder != null){
C 129                         orderNodeBuilder.append("-[作废退款]扣减退款金额(积分):").append(refundRecordMethod.getRealRefundTotal());
130                     }
160c33 131                 }
C 132             }else {
133                 //现金支付
134                 if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)<1){
135                     continue;
136                 }
137                 OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,refundRecord.getInvalidId(),refundRecord.getInvalidName(),refundRecordMethod.getName()+"作废退款金额:"+refundRecordMethod.getRealRefundTotal(),1, OrderLogConstants.LOG_TYPE_REFUND_UNDO);
138                 orderLog.setOrderId(ordersTotal.getId());
139                 commonService.insert(OrderLogMapper.class,orderLog);
140             }
141         }
b3fdea 142         return refundRecordMethodList;
160c33 143     }
C 144
145     /**充值单特需处理
146      * @param ordersTotal 订单
147      * @param refundRecord 退款单
148      * @param optType 操作类型:0退款执行,1作废退款
f5e288 149      * @param optName 操作名称,如:申请退款、作废退款、审核拒绝
160c33 150      * @param commonService 映射
C 151      */
b3fdea 152     public static void rechargeHandle(OrdersTotal ordersTotal, RefundRecord refundRecord,int optType,String optName,StringBuilder orderNodeBuilder, CommonService commonService){
755975 153
fd7281 154         if(!OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){
C 155             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作失败,不是充值单!");
156         }
157         if(ordersTotal.getTotal().compareTo(BigDecimal.ZERO) < 1){
158             return;
159         }
4ebb90 160         OrderLog orderLog;
C 161         if(optType == OPT_TYPE_EXECUTE){
160c33 162             //充值金额扣减
bfdc6b 163             UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),REFUND_REMARK+"["+ordersTotal.getOrderNo()+"]","退款单:"+refundRecord.getCode()+";"+optName+",扣减充值资金:"+ordersTotal.getTotal(),refundRecord.getOperatorId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),ordersTotal.getTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
f5e288 164             orderLog = RefundToolUtil.setOrderLog(refundRecord, refundRecord.getOperatorId(), refundRecord.getOperatorName(), "充值单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND);
b3fdea 165
4ebb90 166         }else if(optType == OPT_TYPE_CANCEL){
160c33 167             //充值金额回退
245f89 168             UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),REFUND_REMARK+"["+ordersTotal.getOrderNo()+"]","退款单:"+refundRecord.getCode()+";"+optName+",退回充值资金:"+ordersTotal.getTotal(),refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),ordersTotal.getTotal(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_REFUND_CANCEL,commonService,UserMoneyUnclaimed.NO);
f5e288 169             orderLog = RefundToolUtil.setOrderLog(refundRecord, refundRecord.getOperatorId(), refundRecord.getOperatorName(), "充值单:"+ordersTotal.getOrderNo()+";"+optName+",退回预扣除金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND);
160c33 170         }else{
C 171             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[1]["+optType+"]!");
b3fdea 172         }
C 173         if(orderNodeBuilder !=null){
174             orderNodeBuilder.append("-[").append(optName).append("]充值单充值金操作(储值金):").append(ordersTotal.getTotal());
160c33 175         }
4ebb90 176         orderLog.setOrderId(ordersTotal.getId());
C 177         commonService.insert(OrderLogMapper.class,orderLog);
fd7281 178     }
C 179
160c33 180     /**活动规则处理
C 181      * @param ordersTotal 订单
182      * @param refundRecord 退款单
183      * @param optType 操作类型:0退款执行,1作废退款
f5e288 184      * @param optName 操作名称,如:申请退款、作废退款、审核拒绝
160c33 185      * @param commonService 映射
C 186      */
b3fdea 187     public static void activityRuleHandle(OrdersTotal ordersTotal, RefundRecord refundRecord,int optType,String optName,StringBuilder orderNodeBuilder,CommonService commonService){
fd7281 188
528195 189         //先获取活动规则
C 190         SqlSentence sqlSentence = new SqlSentence();
191         Map<String,Object> values = new HashMap<>();
192
193         values.put("orderId",ordersTotal.getId());
194         sqlSentence.sqlSentence("SELECT * FROM orders_activity_info WHERE isDel = 0 AND orderId = #{m.orderId}",values);
195         List<OrdersActivityInfo> ordersActivityInfoList = commonService.selectList(OrdersActivityInfoMapper.class,sqlSentence);
196         if(ordersActivityInfoList.size() > 0){
160c33 197             //订单活动信息处理
b3fdea 198             activityRulePollingHandle2(ordersActivityInfoList,optType,optName,ordersTotal,refundRecord,orderNodeBuilder,commonService);
528195 199         }else{
160c33 200             //没有订单活动信息处理,就获取保存在订单里面的活动标识
C 201             values.clear();
202             values.put("orderId",ordersTotal.getId());
528195 203             sqlSentence.sqlSentence("SELECT * FROM orders_info WHERE isDel = 0 AND orderId = #{m.orderId}",values);
C 204             OrderInfo orderInfo = commonService.selectOne(OrderInfoMapper.class,sqlSentence);
160c33 205             if(orderInfo!=null && StringUtils.noNull(orderInfo.getActivityId())){
b3fdea 206                 activityRulePollingHandle1(orderInfo.getActivityId(),optType,optName,ordersTotal,refundRecord,orderNodeBuilder,commonService);
160c33 207             }
C 208         }
209     }
528195 210
160c33 211     /**处理活动标识保存在订单里面的
C 212      * @param activityId 活动标识
213      * @param optType 操作类型:0退款执行,1退款作废
f5e288 214      * @param optName 操作名称,如:申请退款、作废退款、审核拒绝
160c33 215      * @param ordersTotal 订单
C 216      * @param refundRecord 退款单
217      * @param commonService 映射
218      */
b3fdea 219     public static void activityRulePollingHandle1(String activityId,int optType,String optName,OrdersTotal ordersTotal,RefundRecord refundRecord
C 220             ,StringBuilder orderNodeBuilder,CommonService commonService){
160c33 221         SqlSentence sqlSentence = new SqlSentence();
C 222         Map<String,Object> values = new HashMap<>();
223
224         //查找活动规则,没有找到就跳出循环
225         ActivityRule activityRule = commonService.selectOneByKeyBlob(ActivityRuleMapper.class,activityId);
226         if(activityRule == null){
227             return;
528195 228         }
C 229
160c33 230         values.put("activityRuleId",activityRule.getId());
C 231         values.put("type", ActivityAction.TYPE_INTEGRAL);
232         values.put("type1",ActivityAction.TYPE_VALUEADDEDFUND);
233         values.put("type2",ActivityAction.TYPE_COUPON);
234         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",values);
235         List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence);
236         if(activityActions!=null && activityActions.size()>0){
237             for (ActivityAction activityAction : activityActions) {
238                 if(ActivityAction.TYPE_INTEGRAL.equals(activityAction.getType())){
239                     //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
240                     if(new BigDecimal(activityAction.getWorth()).compareTo(BigDecimal.ZERO) == 0){
241                         continue;
242                     }
4ebb90 243                     if(optType == OPT_TYPE_EXECUTE){
f5e288 244                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除活动规则赠送储值金金额:"+activityAction.getWorth(),refundRecord.getOperatorId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
4ebb90 245                     }else if(optType == OPT_TYPE_CANCEL){
bfdc6b 246                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",返还赠送储值金预扣除金额:"+activityAction.getWorth(),refundRecord.getInvalidId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_REFUND_CANCEL,commonService,UserMoneyUnclaimed.YES);
160c33 247                     }else{
C 248                         throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[2]["+optType+"]!");
249                     }
b3fdea 250                     if(orderNodeBuilder !=null){
C 251                         orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(积分):").append(activityAction.getWorth());
252                     }
160c33 253                 }else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(activityAction.getType())){
C 254                     //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
755975 255                     if(new BigDecimal(activityAction.getWorth()).compareTo(BigDecimal.ZERO) == 0 ){
160c33 256                         continue;
C 257                     }
4ebb90 258                     if(optType == OPT_TYPE_EXECUTE){
f5e288 259                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除活动规则赠送增值金金额:"+activityAction.getWorth(),refundRecord.getOperatorId(),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);
4ebb90 260                     }else if(optType == OPT_TYPE_CANCEL){
bfdc6b 261                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",返还赠送增值金预扣除金额:"+activityAction.getWorth(),refundRecord.getInvalidId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_REFUND_CANCEL,commonService,UserMoneyUnclaimed.YES);
160c33 262                     }else{
C 263                         throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[3]["+optType+"]!");
264                     }
b3fdea 265                     if(orderNodeBuilder !=null){
C 266                         orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(增值金):").append(activityAction.getWorth());
267                     }
160c33 268                 }else if(ActivityAction.TYPE_COUPON.equals(activityAction.getType())){
4ebb90 269                     values.put("oldValidState",optType==OPT_TYPE_EXECUTE? BaseEntity.YES:BaseEntity.NO);
C 270                     values.put("newValidState",optType==OPT_TYPE_EXECUTE?BaseEntity.NO:BaseEntity.YES);
160c33 271                     values.put("couponId",activityAction.getCrmCouponId());
C 272                     values.put("commonId",ordersTotal.getId());
273                     sqlSentence.sqlSentence(" validState=#{m.newValidState} where couponId=#{m.couponId} and commonId=#{m.commonId} and validState=#{m.oldValidState} ",values);
b3fdea 274                     if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 0){
C 275                         if(orderNodeBuilder !=null){
276                             orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(优惠券):").append(activityAction.getWorthName());
277                         }
278                     }
160c33 279                 }
C 280             }
281         }
282     }
fd7281 283
160c33 284     /**处理活动保存在订单活动信息里面的
C 285      * @param ordersActivityInfoList 订单活动数据
286      * @param optType 操作类型:0退款退回,1作废退款
f5e288 287      * @param optName 操作名称,如:申请退款、作废退款、审核拒绝
160c33 288      * @param ordersTotal 订单
C 289      * @param refundRecord 退款单
290      * @param commonService 映射
291      */
f5e288 292     public static void activityRulePollingHandle2(List<OrdersActivityInfo> ordersActivityInfoList,int optType,String optName,OrdersTotal ordersTotal
b3fdea 293             ,RefundRecord refundRecord,StringBuilder orderNodeBuilder,CommonService commonService){
160c33 294         if(ordersActivityInfoList == null || ordersActivityInfoList.size()==0){
C 295             return;
296         }
297         SqlSentence sqlSentence = new SqlSentence();
298         Map<String,Object> values = new HashMap<>();
299
b3fdea 300         //是否变更订单活动状态
C 301         boolean changeStatus;
160c33 302         //获取订单活动条目
C 303         List<OrdersActivityInfoItem> ordersActivityInfoItemList;
304         for(OrdersActivityInfo ordersActivityInfo:ordersActivityInfoList){
305             values.clear();
306             values.put("activityInfoId",ordersActivityInfo.getId());
307             values.put("performStatus",OrdersActivityInfoItem.STATUS_PERFORM_SEND_OUT);
4ebb90 308             values.put("handleStatus",optType==OPT_TYPE_EXECUTE?OrdersActivityInfoItem.HANDLE_STATUS_SUCCESS:OrdersActivityInfoItem.HANDLE_STATUS_CANCEL);
160c33 309             sqlSentence.sqlSentence("SELECT * FROM orders_activity_info_item WHERE isDel = 0 AND activityInfoId = #{m.activityInfoId} AND performStatus = #{m.performStatus} AND handleStatus = #{m.handleStatus}",values);
C 310             ordersActivityInfoItemList = commonService.selectList(OrdersActivityInfoItemMapper.class,sqlSentence);
311             for(OrdersActivityInfoItem ordersActivityInfoItem:ordersActivityInfoItemList){
b3fdea 312                 changeStatus = false;
160c33 313                 if(ActivityAction.TYPE_INTEGRAL.equals(ordersActivityInfoItem.getType())){
C 314                     //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
315                     if(new BigDecimal(ordersActivityInfoItem.getWorth()).compareTo(BigDecimal.ZERO) == 0){
316                         continue;
317                     }
4ebb90 318                     if(optType == OPT_TYPE_EXECUTE){
f5e288 319                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除活动规则赠送储值金金额:"+ordersActivityInfoItem.getWorth(),refundRecord.getOperatorId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(ordersActivityInfoItem.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
4ebb90 320                     }else if(optType == OPT_TYPE_CANCEL){
f5e288 321                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",返还赠送储值金预扣除金额:"+ordersActivityInfoItem.getWorth(),refundRecord.getInvalidId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(ordersActivityInfoItem.getWorth()), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
160c33 322                     }else{
C 323                         throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[2]["+optType+"]!");
324                     }
b3fdea 325                     if(orderNodeBuilder !=null){
C 326                         orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(积分):").append(ordersActivityInfoItem.getWorth());
327                     }
328                     changeStatus = true;
160c33 329                 }else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(ordersActivityInfoItem.getType())){
C 330                     //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
755975 331                     if(new BigDecimal(ordersActivityInfoItem.getWorth()).compareTo(BigDecimal.ZERO) == 0 ){
160c33 332                         continue;
C 333                     }
4ebb90 334                     if(optType == OPT_TYPE_EXECUTE){
f5e288 335                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除活动规则赠送增值金金额:"+ordersActivityInfoItem.getWorth(),refundRecord.getOperatorId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(ordersActivityInfoItem.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
4ebb90 336                     }else if(optType == OPT_TYPE_CANCEL){
f5e288 337                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",返还赠送增值金预扣除金额:"+ordersActivityInfoItem.getWorth(),refundRecord.getInvalidId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(ordersActivityInfoItem.getWorth()), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
160c33 338                     }else{
C 339                         throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[3]["+optType+"]!");
340                     }
b3fdea 341                     if(orderNodeBuilder !=null){
C 342                         orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(增值金):").append(ordersActivityInfoItem.getWorth());
343                     }
344                     changeStatus = true;
160c33 345                 }else if(ActivityAction.TYPE_COUPON.equals(ordersActivityInfoItem.getType())){
4ebb90 346                     values.clear();
C 347                     values.put("oldValidState",optType==OPT_TYPE_EXECUTE? BaseEntity.YES:BaseEntity.NO);
348                     values.put("newValidState",optType==OPT_TYPE_EXECUTE?BaseEntity.NO:BaseEntity.YES);
160c33 349                     values.put("id",ordersActivityInfoItem.getCouponNumberId());
4ebb90 350                     sqlSentence.sqlSentence(" validState=#{m.newValidState} where id=#{m.id} AND validState = #{m.oldValidState} ",values);
160c33 351                     //优惠券不判断回退
b3fdea 352                     if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 0){
C 353                         if(orderNodeBuilder !=null){
354                             orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(优惠券):").append(ordersActivityInfoItem.getWorthName());
355                         }
356                         changeStatus = true;
357                     }
160c33 358                 }
b3fdea 359                 if(changeStatus){
C 360                     //更新订单活动信息状态
361                     values.clear();
362                     values.put("handleStatus",optType==OPT_TYPE_EXECUTE?OrdersActivityInfoItem.HANDLE_STATUS_CANCEL:OrdersActivityInfoItem.HANDLE_STATUS_SUCCESS);
363                     values.put("handleStatusOld",optType==OPT_TYPE_EXECUTE?OrdersActivityInfoItem.HANDLE_STATUS_SUCCESS:OrdersActivityInfoItem.HANDLE_STATUS_CANCEL);
364                     values.put("performStatusOld",OrdersActivityInfoItem.STATUS_PERFORM_SEND_OUT);
365                     values.put("id",ordersActivityInfoItem.getId());
366                     sqlSentence.sqlSentence("handleStatus = #{m.handleStatus} WHERE id = #{m.id} AND handleStatus = #{m.handleStatusOld} AND performStatus = #{m.performStatusOld}",values);
367                     if(commonService.updateWhere(OrdersActivityInfoItemMapper.class,sqlSentence) != 1){
368                         throw new PlatTipsException(PlatformCode.ERROR_TIPS,"活动条目状态变化错误:");
369                     }
160c33 370                 }
C 371             }
372         }
373     }
374
375     /**
376      * 退款作废-处理优惠券
377      * @param ordersTotal 订单
378      * @param refundRecord 退款总数据
379      * @param commonService 映射
380      */
b3fdea 381     public static void handCoupon(OrdersTotal ordersTotal,RefundRecord refundRecord,StringBuilder orderNodeBuilder,CommonService commonService) {
160c33 382
C 383         //回退的优惠券变成使用状态
384         //如果该优惠券在别的订单使用了,那么就不再理会
385
386         SqlSentence sqlSentence = new SqlSentence();
387         Map<String, Object> values = new HashMap<>();
388
389         values.put("refundRecordId",refundRecord.getId());
4ebb90 390         sqlSentence.sqlSentence("select * from refund_record_coupon where refundRecordId = #{m.refundRecordId} and isDel=0 ",values);
160c33 391         List<RefundRecordCoupon> refundRecordCouponList=commonService.selectList(RefundRecordCouponMapper.class,sqlSentence);
C 392
393         CouponOrderDiscountLog couponOrderDiscountLog;
394         for (RefundRecordCoupon refundRecordCoupon : refundRecordCouponList) {
395
396             couponOrderDiscountLog=commonService.selectOneByKey(CouponOrderDiscountLogMapper.class,refundRecordCoupon.getCouponOrderId());
397             if(couponOrderDiscountLog==null){
398                 throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单优惠卷标识不正确");
399             }
400
401             //领建优惠券跳过回退
402             if(PartialRefundUtil.HIS_COUPON_CODE.equals(couponOrderDiscountLog.getCouponNumberId())){
403                 //变更订单优惠券记录状态
404                 values.clear();
405                 values.put("status", BaseEntity.NO);
406                 values.put("oldStatus", BaseEntity.YES);
407                 values.put("id", couponOrderDiscountLog.getId());
408                 sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values);
409                 if(commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence) != 1){
410                     throw new TipsException("优惠券回退失败!");
411                 }
412             }else{
413                 //优惠券状态变化
414                 values.clear();
415                 values.put("isUse", BaseEntity.YES);
416                 values.put("isUseOld", BaseEntity.NO);
417                 values.put("useTime", couponOrderDiscountLog.getCreateTime());
418                 values.put("useType", CouponNumber.USE_TYPE_USER);
419                 values.put("id", couponOrderDiscountLog.getCouponNumberId());
420                 sqlSentence.sqlSentence("  isUse=#{m.isUse},useTime=#{m.useTime},useType=#{m.useType},isUse=#{m.isUse} WHERE id = #{m.id} AND isUse = #{m.isUseOld}",values);
b3fdea 421                 if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 0){
C 422                     if(orderNodeBuilder != null){
423                         orderNodeBuilder.append("-[作废退款]使用优惠券处理:"+couponOrderDiscountLog.getTitle());
424                     }
160c33 425                     //变更订单优惠券记录状态
C 426                     values.clear();
427                     values.put("status", BaseEntity.NO);
428                     values.put("oldStatus", BaseEntity.YES);
429                     values.put("id", couponOrderDiscountLog.getId());
430                     sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values);
431                     if(commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence) != 1) {
432                         throw new TipsException("优惠券回退失败!");
fd7281 433                     }
C 434                 }
435             }
436         }
437     }
438
cfedbf 439     /**作废退款-爆款活动赠送处理*/
C 440     public static void burstActivityHandle(StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord,CommonService commonService){
441         //不是爆款活动
442         if(ordersTotal.getActivityPageType() != OrderTotalConstants.ACTIVITY_TYPE_BURST){
443             return;
444         }
445
446         //查找是否处理了赠送的增值金
447         SqlSentence sqlSentence = new SqlSentence();
448         Map<String,Object> values = new HashMap<>();
f87850 449         values.put("isDel",RefundUserAssets.DEL_BURST);
cfedbf 450         values.put("orderId",refundRecord.getOrderId());
C 451         sqlSentence.sqlSentence("SELECT * FROM refund_user_assets rua WHERE rua.isDel = #{m.isDel} AND rua.status = 1 AND rua.amountStatus IN(1,3) AND rua.orderId = #{m.orderId}",values);
452         List<RefundUserAssets> refundUserAssetsList = commonService.selectList(RefundUserAssetsMapper.class,sqlSentence);
453         if(refundUserAssetsList.size() == 0){
f87850 454             //---无操作记录
C 455             //获取有效的,如果有,那么就不做处理
456             UserMoneyUnclaimed userMoneyUnclaimed = OrderTool.getActivityGiveByOrder(ordersTotal,BaseEntity.YES,commonService);
457             if(userMoneyUnclaimed != null){
458                 return;
459             }
460             //获取无效的,如果有,那么就要处理规则,没有就跳过
461             userMoneyUnclaimed = OrderTool.getActivityGiveByOrder(ordersTotal,BaseEntity.NO,commonService);
462             if(userMoneyUnclaimed == null){
463                 return;
464             }
465             Integer opType = BaseEntity.YES;
466             if(userMoneyUnclaimed.getStatus() == UserMoneyUnclaimed.STATUS_SUCCEED){
467                 opType = BaseEntity.NO;
468             }
469             //增值金到账处理
470             userMoneyUnclaimed = UserMoneyUtil.setUserMoneyHandle(userMoneyUnclaimed.getUserId(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,userMoneyUnclaimed.getOpNumber(),opType, OperationReasonConstants.OP_REASON_INVITE_ORDER,userMoneyUnclaimed.getOriginSubject(),userMoneyUnclaimed.getRemarks(),userMoneyUnclaimed.getOperatorId()
471                     ,ordersTotal.getId(),ordersTotal.getActivityPageCode(),userMoneyUnclaimed.getMoneyRuleId(),commonService);
472         }else{
473             //有操作记录
474             for(RefundUserAssets refundUserAssets:refundUserAssetsList){
475                 //判断是否已经存在了别的赠送记录
476                 if(OrderTool.getActivityGive(refundUserAssets.getUserId(),ordersTotal.getActivityPageCode(),BaseEntity.YES,commonService).size() == 0){
477                     //是否有扣减用户资产
478                     if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NORMAL){
479                         orderNodeBuilder.append(",活动赠送增加成功");
480                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundUserAssets.getUserId(),refundRecord.getRemarks(),"退款作废:活动赠送资金回退作废",refundUserAssets.getOperatorId()
481                                 ,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundUserAssets.getId(),refundUserAssets.getAmount().negate(),refundUserAssets.getAmountType()
482                                 ,OperationReasonConstants.OP_REASON_BRING_NEW_USER_GIFT_RETRU_CANCEL,commonService,UserMoneyUnclaimed.YES);
483                     }else if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NOT_RECEIVE){
484                         //用户未领取记录,还原
485                         orderNodeBuilder.append(",活动赠送用户未领取,作废的领取记录还原");
486                         values.clear();
487                         values.put("id",refundUserAssets.getUserMoneyUnclaimedId());
488                         values.put("status",UserMoneyUnclaimed.STATUS_WAI);
489                         sqlSentence.sqlUpdate("isDel = 0,isValid = 1 WHERE id = #{m.id} AND isDel = 1 AND isValid = 0 AND status = #{m.status}",values);
490                         if(commonService.updateWhere(UserMoneyUnclaimedMapper.class,sqlSentence) != 1){
491                             throw new TipsException("活动赠送资产记录状态已变化[作废]!");
492                         }
cfedbf 493                     }
C 494                 }
495
f87850 496                 //记录作废
C 497                 values.clear();
498                 values.put("id",refundUserAssets.getId());
499                 values.put("status",RefundUserAssets.STATUS_CANCEL);
500                 values.put("oldStatus",RefundUserAssets.STATUS_NORMAL);
501                 sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values);
502                 if(commonService.updateWhere(RefundUserAssetsMapper.class,sqlSentence) != 1){
503                     throw new TipsException("活动赠送资产退款记录状态已变化[作废]!");
504                 }
cfedbf 505             }
C 506         }
507     }
508
160c33 509     /**退款子项处理*/
C 510     public static void refundRecordItemHandle(OrdersTotal ordersTotal,RefundRecord refundRecord,CommonService commonService){
fd7281 511
160c33 512         SqlSentence sqlSentence = new SqlSentence();
C 513         Map<String,Object> values = new HashMap<>();
514
515         //获取退款子单
516         values.put("refundRecordId",refundRecord.getId());
517         sqlSentence.sqlSentence("SELECT * FROM refund_record_item WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",values);
518         List<RefundRecordItem> refundRecordItems =commonService.selectList(RefundRecordItemMapper.class,sqlSentence);
519         if(refundRecordItems == null || refundRecordItems.size() == 0){
520             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到退款子订单信息");
521         }
522
523         for (RefundRecordItem refundRecordItem: refundRecordItems) {
524             //商品类型判断
525             switch (refundRecordItem.getType()){
526                 case OrderItemConstants.TYPE_RETAIL:
755975 527                     //商品/药品
160c33 528                     rerailHandleOne(refundRecordItem,commonService);
C 529                     break;
530                 case OrderItemConstants.TYPE_DRUG:
755975 531                     //处方单药品
160c33 532                     rerailHandleOne(refundRecordItem,commonService);
C 533                     break;
534                 case OrderItemConstants.TYPE_PROJECT:
755975 535                     //项目
160c33 536                     projectHandleOne(refundRecordItem,refundRecord,commonService);
C 537                     break;
538                 case OrderItemConstants.TYPE_PROMOTION:
755975 539                     //促销
160c33 540                     handRefundPromotion( refundRecordItem, refundRecord, commonService);
C 541                     break;
542                 case OrderItemConstants.TYPE_CARD:
755975 543                     //卡项
160c33 544                     cardHandleOne( refundRecord,  refundRecordItem, commonService);
C 545                     break;
546                 case OrderItemConstants.CARD_BAG:
755975 547                     //卡包
160c33 548                     handRefundPromotion( refundRecordItem, refundRecord, commonService);
C 549                     break;
e065e7 550                 default:
C 551                     //其他
552                     rerailHandleOne(refundRecordItem,commonService);
553                     break;
160c33 554             }
C 555         }
556     }
557
558
559     /**一级订单-商品/药品处理*/
560     public static void rerailHandleOne(RefundRecordItem refundRecordItem,CommonService commonService){
561         //判断操作完了去修改子订单状态
562         OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId());
563         if (orderItem==null){
564             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息");
565         }
566
567         //剩余可退款数量
568         if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){
755975 569             throw new TipsException(orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"作废退款数量不能大于已退款数量!");
160c33 570         }
C 571
572         //变更退款子项信息
573         int refundStatus;
574         if (orderItem.getHasReNum().equals(refundRecordItem.getRefundNum())){
575             refundStatus = OrderTotalConstants.STATUS_REFUND_NONE;
576         }else{
577             refundStatus = OrderTotalConstants.STATUS_REFUND_PART;
578         }
e490fa 579         RefundCarryVo refundCarryVo = new RefundCarryVo();
C 580         refundCarryVo.setRefundTotal(refundRecordItem.getRealRefundTotal().negate());
581         refundCarryVo.setIntegralTotal(refundRecordItem.getRealRefundIntegral().negate());
582         refundCarryVo.setDeductionTotal(refundRecordItem.getDeductionTotal().negate());
583         refundCarryVo.setCashTotal(refundRecordItem.getCashTotal().negate());
584         refundCarryVo.setCashPurenessTotal(refundRecordItem.getCashPurenessTotal().negate());
585         refundCarryVo.setRechargeTotal(refundRecordItem.getRechargeTotal().negate());
586         refundCarryVo.setIncrementTotal(refundRecordItem.getIncrementTotal().negate());
160c33 587
C 588         //更新子订单信息
e490fa 589         PartialRefundUtil.updateOrderItemOne(orderItem,refundStatus,refundCarryVo,-refundRecordItem.getRealRefundNum(), commonService);
160c33 590     }
C 591
592     /**一级订单-项目处理*/
593     public static void projectHandleOne(RefundRecordItem refundRecordItem,RefundRecord refundRecord,CommonService commonService){
594         //找到子单
595         OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId());
596         if (orderItem==null){
597             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息");
598         }
755975 599         //计算子单是否还有剩余的可扣疗程数
C 600         if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){
601             throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"退款次数大于可退次数[54]!");
602         }
160c33 603
C 604         //找到用户项目
01fbcb 605         UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(orderItem.getId(),commonService);
160c33 606         if (userProjectItem == null) {
755975 607             throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"未找到用户子项项目信息");
160c33 608         }
C 609         if(userProjectItem.getCancelNum() < refundRecordItem.getRefundNum()){
755975 610             throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"作废退款次数大于用户项目已退次数!");
160c33 611         }
C 612
613         //用户项目操作
755975 614         UserProjectTool.userProjectDeduction(userProjectItem, UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_RETURN,refundRecordItem.getDeductionTotalUser()
C 615                 ,refundRecordItem.getId(),refundRecordItem.getRealRefundNum(),refundRecord.getInvalidAppId(),refundRecord.getInvalidAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getInvalidRemarks(),commonService);
160c33 616
C 617         int refundStatus;
618         if(refundRecordItem.getRefundNum().equals(orderItem.getHasReNum())){
619             refundStatus=OrderTotalConstants.STATUS_REFUND_NONE;
620         }else{
621             refundStatus=OrderTotalConstants.STATUS_REFUND_PART;
622         }
623
e490fa 624         RefundCarryVo refundCarryVo = new RefundCarryVo();
C 625         refundCarryVo.setRefundTotal(refundRecordItem.getRealRefundTotal().negate());
626         refundCarryVo.setIntegralTotal(refundRecordItem.getRealRefundIntegral().negate());
627         refundCarryVo.setDeductionTotal(refundRecordItem.getDeductionTotal().negate());
628         refundCarryVo.setCashTotal(refundRecordItem.getCashTotal().negate());
629         refundCarryVo.setCashPurenessTotal(refundRecordItem.getCashPurenessTotal().negate());
630         refundCarryVo.setRechargeTotal(refundRecordItem.getRechargeTotal().negate());
631         refundCarryVo.setIncrementTotal(refundRecordItem.getIncrementTotal().negate());
632
160c33 633         //更新子订单信息
e490fa 634         PartialRefundUtil.updateOrderItemOne(orderItem,refundStatus,refundCarryVo,-refundRecordItem.getRealRefundNum(),commonService);
160c33 635     }
C 636
637     /**一级子单-处理促销*/
638     private static void handRefundPromotion(RefundRecordItem refundRecordItem, RefundRecord refundRecord, CommonService commonService) {
639
640         //查看订单信息
641         OrderItem orderItem = commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId());
642         if(orderItem == null ){
643             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息[84]!");
644         }
645
646         SqlSentence sqlSentence = new SqlSentence();
647         Map<String, Object> map = new HashMap<>();
648
649         //获取退款二级单
650         map.put("refundRecordItemId",refundRecordItem.getId());
651         sqlSentence.sqlSentence("select * from refund_record_item_source where isDel = 0 AND refundRecordItemId = #{m.refundRecordItemId}",map);
652         List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence);
653
654         for (RefundRecordItemSource son : sons) {
655             switch (GroupTypeEnum.getCode(son.getType())){
656                 case PROJECT:
657                     projectHandleTwo(refundRecord,refundRecordItem, son,orderItem.getUserCardId(),commonService);
658                     break;
659                 case RETAIL:
660                     rerailHandleTwo(refundRecord,refundRecordItem,son,orderItem.getUserCardId(),commonService);
661                     break;
662                 case INCREMENT:
663                     //增值金
664                     //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
665                     if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
666                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"作废退款:促销赠送增值金扣减",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),son.getRealRefundTotal(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
667                     }
668                     break;
669                 case STORED:
670                     //储值金额
671                     //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
672                     if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
673                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"作废退款:促销赠送储值金额扣减",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),son.getRealRefundTotal(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
674                     }
675                     break;
676                 case INTEGRAL:
677                     //积分
678                     //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
679                     if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
680                         UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"作废退款:促销赠送积分扣减",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),son.getRealRefundTotal(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
681                     }
682                     break;
683             }
684
685         }
686
687         //获取其子项
688         map.put("orderItemId",orderItem.getId());
689         sqlSentence.sqlSentence("select refundStatus from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0",map);
690         List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence);
691         int refundStatus;
692         Integer refundNum = 0;
693         List<Integer> collect = orderItemSonList.stream().map(OrderItemSon::getRefundStatus).collect(Collectors.toList());
694
695         if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){
696             refundStatus = OrderTotalConstants.STATUS_REFUND_PART;
697         }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){
698             if(collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){
699                 refundStatus = OrderTotalConstants.STATUS_REFUND_PART;
700             }else{
701                 refundStatus = OrderTotalConstants.STATUS_REFUND_NONE;
702             }
703         }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){
704             refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH;
705             refundNum = orderItem.getBuyNum();
706         }else {
707             refundStatus = OrderTotalConstants.STATUS_REFUND_NONE;
708         }
709
e490fa 710         RefundCarryVo refundCarryVo = new RefundCarryVo();
C 711         refundCarryVo.setRefundTotal(refundRecordItem.getRealRefundTotal().negate());
712         refundCarryVo.setIntegralTotal(refundRecordItem.getRealRefundIntegral().negate());
713         refundCarryVo.setDeductionTotal(refundRecordItem.getDeductionTotal().negate());
714         refundCarryVo.setCashTotal(refundRecordItem.getCashTotal().negate());
715         refundCarryVo.setCashPurenessTotal(refundRecordItem.getCashPurenessTotal().negate());
716         refundCarryVo.setRechargeTotal(refundRecordItem.getRechargeTotal().negate());
717         refundCarryVo.setIncrementTotal(refundRecordItem.getIncrementTotal().negate());
718
160c33 719         //更新子订单信息
e490fa 720         PartialRefundUtil.updateOrderItemOne(orderItem,refundStatus,refundCarryVo,-refundNum,commonService);
160c33 721
C 722     }
723
724     /**二级子订单-项目类型
725      * @param refundRecord 退款总记录
726      * @param refundRecordItem 退款一级子单
727      * @param refundRecordItemSource  退款二级子单
728      * @param userCardId 用户卡包标识
729      * @param commonService 映射
730      */
731     private static void projectHandleTwo(RefundRecord refundRecord,RefundRecordItem refundRecordItem, RefundRecordItemSource refundRecordItemSource
732             ,String userCardId,CommonService commonService) {
733
734         //判断操作完了去修改子订单状态
735         OrderItemSon orderItemSon = commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId());
736         if (orderItemSon==null){
737             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到二级子订单信息[02]");
738         }
755975 739         //计算子单是否还有剩余的可扣疗程数
C 740         if(refundRecordItemSource.getRefundNum() > orderItemSon.getHasReNum()){
741             throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItemSon.getGoodsName()+"["+orderItemSon.getGoodsNo()+"]"+"作废退款次数大于已退次数[56]!");
742         }
160c33 743
C 744         UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(orderItemSon.getId(),commonService);
745         if(userProjectItem == null){
746             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"用户项目获取失败[06]!");
747         }
755975 748         //比较作废退款数量
160c33 749         if(refundRecordItemSource.getRefundNum() > userProjectItem.getCancelNum()){
755975 750             throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItemSon.getGoodsName()+"["+orderItemSon.getGoodsNo()+"]"+"作废退款次数大于用户项目已退次数[56]!");
160c33 751         }
C 752
753         //处理用户项目,减去用户项目数量
755975 754         UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_RETURN,refundRecordItemSource.getDeductionTotalUser()
C 755                 ,refundRecordItemSource.getId(),refundRecordItemSource.getRealRefundNum(),refundRecord.getInvalidAppId(),refundRecord.getInvalidAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getInvalidRemarks(),commonService);
160c33 756
C 757         int refundStatus;
755975 758         if(orderItemSon.getHasReNum().equals(refundRecordItemSource.getRefundNum())){
160c33 759             refundStatus=OrderTotalConstants.STATUS_REFUND_NONE;
C 760         }else{
761             refundStatus=OrderTotalConstants.STATUS_REFUND_PART;
762         }
763
e490fa 764         RefundCarryVo refundCarryVo = new RefundCarryVo();
C 765         refundCarryVo.setRefundTotal(refundRecordItemSource.getRealRefundTotal().negate());
766         refundCarryVo.setIntegralTotal(refundRecordItemSource.getRealRefundIntegral().negate());
767         refundCarryVo.setDeductionTotal(refundRecordItemSource.getDeductionTotal().negate());
768         refundCarryVo.setCashTotal(refundRecordItemSource.getCashTotal().negate());
769         refundCarryVo.setCashPurenessTotal(refundRecordItemSource.getCashPurenessTotal().negate());
770         refundCarryVo.setRechargeTotal(refundRecordItemSource.getRechargeTotal().negate());
771         refundCarryVo.setIncrementTotal(refundRecordItemSource.getIncrementTotal().negate());
772
160c33 773         //更新子单信息
e490fa 774         PartialRefundUtil.updateOrderItemTwo(orderItemSon,refundStatus,refundCarryVo,-refundRecordItemSource.getRealRefundNum(),commonService);
160c33 775
C 776         if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){
755975 777             //是卡包的,找回卡包使用记录
160c33 778             userCardUsedHandle(userCardId,orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService);
C 779         }
780
781     }
782
783     /**二级订单-商品/药品
784      * @param refundRecord 退款总记录
785      * @param refundRecordItem 退款一级子单
786      * @param refundRecordItemSource  退款二级子单
787      * @param commonService 映射
788      * @return 全局携带参数结构
789      */
790     private static void rerailHandleTwo(RefundRecord refundRecord,RefundRecordItem refundRecordItem, RefundRecordItemSource refundRecordItemSource
791             ,String userCardId,CommonService commonService) {
792
793         //判断操作完了去修改子订单状态
794         OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId());
795         if (orderItemSon==null){
796             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息");
797         }
798
799         //计算子单是否还有剩余的可扣疗程数
800         if(refundRecordItemSource.getRefundNum() > orderItemSon.getHasReNum()){
801             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"作废退款次数大于已退次数[84]!");
802         }
803
804         int refundStatus;
805         if(orderItemSon.getHasReNum().equals(refundRecordItemSource.getRefundNum())){
806             refundStatus=OrderTotalConstants.STATUS_REFUND_NONE;
807         }else{
808             refundStatus=OrderTotalConstants.STATUS_REFUND_PART;
809         }
810
e490fa 811         RefundCarryVo refundCarryVo = new RefundCarryVo();
C 812         refundCarryVo.setRefundTotal(refundRecordItemSource.getRealRefundTotal().negate());
813         refundCarryVo.setIntegralTotal(refundRecordItemSource.getRealRefundIntegral().negate());
814         refundCarryVo.setDeductionTotal(refundRecordItemSource.getDeductionTotal().negate());
815         refundCarryVo.setCashTotal(refundRecordItemSource.getCashTotal().negate());
816         refundCarryVo.setCashPurenessTotal(refundRecordItemSource.getCashPurenessTotal().negate());
817         refundCarryVo.setRechargeTotal(refundRecordItemSource.getRechargeTotal().negate());
818         refundCarryVo.setIncrementTotal(refundRecordItemSource.getIncrementTotal().negate());
819
820         PartialRefundUtil.updateOrderItemTwo(orderItemSon,refundStatus,refundCarryVo,-refundRecordItemSource.getRealRefundNum(),commonService);
160c33 821
C 822         if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){
823             //是卡包的,刪除卡包使用
824             userCardUsedHandle(userCardId,orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService);
825         }
826
827     }
828
829     /**卡包使用记录-状态变化
830      * @param userCardId 用户卡包
831      * @param cardItemInfoId 卡包的卡项子项
832      * @param sourceId 卡包使用记录来源标识
833      * @param orderId 卡包使用记录来源总表标识
834      * @param refundNum 退款数量
835      * @param commonService 映射
836      */
837     public static void userCardUsedHandle(String userCardId,String cardItemInfoId,String sourceId,String orderId,Integer refundNum
838             ,CommonService commonService){
839
840         //查出用户,commonId:卡项的组合项标识
755975 841         CardItemInfo cardItemInfo = commonService.selectOneByKey(CardItemInfoMapper.class,cardItemInfoId);
C 842         if(cardItemInfo == null){
160c33 843             logger.error("未找到该卡包的组合项-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum);
C 844             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包的组合项");
845         }
846
4ebb90 847         UserCard userCard = commonService.selectOneByKey(UserCardMapper.class,userCardId);
C 848         if(userCard == null){
849             logger.error("未找到该卡包-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum);
850             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包信息");
851         }
852
160c33 853         //获取权益类型
C 854         CardEquity cardEquity = commonService.selectOneByKey(CardEquityMapper.class,cardItemInfo.getCardEquityId());
855         if(cardEquity == null){
856             logger.error("未找到该卡包的组合项权益类型-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum);
857             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包的组合项权益类型");
858         }
859
860         SqlSentence sqlSentence = new SqlSentence();
861         Map<String,Object> map = new HashMap<>();
862
863         //获取作废使用记录
864         map.put("cardItemInfoId",cardItemInfoId);
865         map.put("sourceId",sourceId);
866         map.put("userCardId",userCardId);
867         sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 1 AND userCardId = #{m.userCardId}" +
868                 " AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId = #{m.sourceId}",map);
869         List<UserCardUsed> userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence);
870
871         //因为之前的使用记录有些没有关联到订单,所以找不到
872         if(userCardUsedList == null || userCardUsedList.size() == 0){
873             map.clear();
874             map.put("cardItemInfoId",cardItemInfoId);
875             map.put("userCardId",userCardId);
876             map.put("orderId",orderId);
877             sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 1 AND userCardId = #{m.userCardId}" +
878                     " AND cardItemInfoId = #{m.cardItemInfoId} AND orderId = #{m.orderId} AND sourceId IS NULL",map);
879             userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence);
880             if(userCardUsedList.size() == 0){
881                 sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 1 AND userCardId = #{m.userCardId}" +
882                         " AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId IS NULL",map);
883                 userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence);
884             }
885         }
886
4ebb90 887         //计算当前数量要扣的卡次
C 888         int returnNum = UserCardTool.countUsedNumber(refundNum,cardItemInfo,cardEquity);
889         //获取可扣卡次
890         UserCardItemInfoVo userCardItemInfoVo = UserCardTool.getSurplusNumber(userCard,cardItemInfo,cardEquity,commonService);
891         if(!userCardItemInfoVo.isNumByNum()){
892             throw new TipsException("作废退款-卡包扣减失败,不符合N选M规则!");
893         }
894         if(returnNum > userCardItemInfoVo.getSurplusNum()){
895             throw new TipsException("作废退款-卡包扣减失败,抵扣次数不足!");
160c33 896         }
C 897
898         if(returnNum > userCardUsedList.size()){
899             logger.error("卡包可退数量错误-卡包作废退款失败,查询语句:{},传入参数:{}",sqlSentence.getSqlSentence(), JSON.toJSONString(sqlSentence.getM()));
900             logger.error("卡包可退数量错误-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{},returnNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum,returnNum);
755975 901             throw new TipsException("卡包作废退款次数量大于可退次数!");
160c33 902         }
C 903
904         //已经操作数量
4ebb90 905         int opNum = returnNum;
160c33 906         StringBuilder sql;
C 907         for(UserCardUsed userCardUsed:userCardUsedList){
908             //判断是否够了,跳出循环
b3fdea 909             if(opNum <= 0){
160c33 910                 break;
C 911             }
4ebb90 912             if(userCardUsed.getCancelNum() <= 0){
C 913                 continue;
914             }
160c33 915             sql = new StringBuilder();
C 916             map.clear();
917             map.put("id",userCardUsed.getId());
4ebb90 918             map.put("cancelNumOld",userCardUsed.getCancelNum());
C 919             if(opNum >= userCardUsed.getCancelNum()){
920                 map.put("isDel",UserCardUsed.NO);
921                 map.put("countNum",userCardUsed.getCancelNum());
922                 opNum = opNum - userCardUsed.getCancelNum();
923             }else{
924                 map.put("isDel",UserCardUsed.YES);
925                 map.put("countNum",opNum);
926                 opNum = 0;
927             }
928             sql.append("isDel = #{m.isDel}");
929             sql.append(",usedNum =  usedNum + #{m.countNum}");
930             sql.append(",cancelNum =  cancelNum - #{m.countNum}");
160c33 931             if(StringUtils.isEmpty(userCardUsed.getOrderId())){
C 932                 sql.append(",orderId = #{m.orderId}");
933                 map.put("orderId",orderId);
934             }
935             if(StringUtils.isEmpty(userCardUsed.getSourceId())){
936                 sql.append(",sourceId = #{m.sourceId}");
937                 map.put("sourceId",sourceId);
938             }
4ebb90 939             sql.append(" WHERE id = #{m.id} AND cancelNum = #{m.cancelNumOld}");
160c33 940             sqlSentence.sqlUpdate(sql.toString(),map);
4ebb90 941             if(commonService.updateWhere(UserCardUsedMapper.class,sqlSentence) != 1){
C 942                 throw new TipsException("卡包使用记录已发生变化,请重试!");
943             }
160c33 944         }
4ebb90 945         if(opNum != 0){
160c33 946             logger.error("卡包回退数量错误-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{},returnNum:{},opNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum,returnNum,opNum);
C 947             throw new TipsException("卡包作废回退数量错误!");
948         }
949
950     }
951
952     /**一级子单-处理卡项
953      * @param refundRecord 退款总记录
954      * @param refundRecordItem 退款一级记录
955      * @param commonService 映射
956      * @return 全局携带参数结构
957      */
958     public static void cardHandleOne(RefundRecord refundRecord, RefundRecordItem refundRecordItem,CommonService commonService) {
959
960         //判断操作完了去修改子订单状态
961         OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId());
962         if (orderItem==null){
963             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息");
964         }
965
966         if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){
967             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"作废退款-卡包提示:作废卡包退款数量大于已退款数量[020]");
968         }
969
970         SqlSentence sqlSentence = new SqlSentence();
971         Map<String,Object> values = new HashMap<>();
972
973
974         //找到已退款卡包
975         values.put("status",RefundRecordCard.YES);
976         values.put("refundRecordItemId",refundRecordItem.getId());
977         sqlSentence.sqlSentence("SELECT * FROM refund_record_card WHERE isDel = 0 AND status = #{m.status} AND refundRecordItemId = #{m.refundRecordItemId}",values);
978         List<RefundRecordCard> refundRecordCardList = commonService.selectList(RefundRecordCardMapper.class,sqlSentence);
979         if(refundRecordItem.getRefundNum() > refundRecordCardList.size()){
980             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"作废退款-卡包提示:作废卡包退款数量大于已退款数量[021]");
981         }
982
983         //变更卡项状态
984         RefundRecordCard refundRecordCard;
985         for (int i = 0; i < refundRecordItem.getRefundNum(); i++) {
986             refundRecordCard= refundRecordCardList.get(i);
987             values.clear();
988             values.put("id",refundRecordCard.getUserCardId());
989             values.put("statusOld", UserCard.TYPE_NO_USED);
990             values.put("effectiveStatus", UserProjectConstants.EFF_STATUS_YES);
991             values.put("oldEffectiveStatus", UserProjectConstants.EFF_STATUS_CANCEL);
992             sqlSentence.sqlSentence(" effectiveStatus=#{m.effectiveStatus} WHERE id = #{m.id} AND effectiveStatus = #{m.oldEffectiveStatus} AND status = #{m.statusOld}",values);
993             if(commonService.updateWhere(UserCardMapper.class,sqlSentence) != 1){
994                 throw new TipsException("用户卡包状态已发生变化,请重试!");
995             }
996
997             values.clear();
998             values.put("id",refundRecordCard.getId());
999             values.put("status",RefundRecordCard.NO);
1000             values.put("statusOld",RefundRecordCard.YES);
1001             sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.statusOld}",values);
1002             if(commonService.updateWhere(RefundRecordCardMapper.class,sqlSentence) != 1){
1003                 throw new TipsException("退款卡包状态已发生变化,请重试!");
1004             }
1005         }
1006
1007         int refundStatus;
ea4351 1008         //根据数量比较
160c33 1009         if (orderItem.getHasReNum().equals(refundRecordItem.getRefundNum())){
C 1010             refundStatus =  OrderTotalConstants.STATUS_REFUND_NONE;
1011         }else {
1012             refundStatus =  OrderTotalConstants.STATUS_REFUND_PART;
1013         }
ea4351 1014         //根据金额比较
C 1015         if(refundStatus == OrderTotalConstants.STATUS_REFUND_NONE){
1016             if(orderItem.getReTotal().compareTo(refundRecordItem.getRealRefundTotal())>0){
1017                 refundStatus =  OrderTotalConstants.STATUS_REFUND_PART;
1018             }
1019         }
1020
3badb7 1021         //查看是否用户卡包退款
C 1022         if(RefundSoruceConstants.TYPE_SOURCE_USER_CARD.equals(refundRecord.getSourceAssistantType())){
1023             CardRefundTool.cardItemCancel(refundRecord,refundRecordItem,commonService);
1024         }
1025
e490fa 1026         RefundCarryVo refundCarryVo = new RefundCarryVo();
C 1027         refundCarryVo.setRefundTotal(refundRecordItem.getRealRefundTotal().negate());
1028         refundCarryVo.setIntegralTotal(refundRecordItem.getRealRefundIntegral().negate());
1029         refundCarryVo.setDeductionTotal(refundRecordItem.getDeductionTotal().negate());
1030         refundCarryVo.setCashTotal(refundRecordItem.getCashTotal().negate());
1031         refundCarryVo.setCashPurenessTotal(refundRecordItem.getCashPurenessTotal().negate());
1032         refundCarryVo.setRechargeTotal(refundRecordItem.getRechargeTotal().negate());
1033         refundCarryVo.setIncrementTotal(refundRecordItem.getIncrementTotal().negate());
1034
160c33 1035         //更新子订单信息
e490fa 1036         PartialRefundUtil.updateOrderItemOne(orderItem,refundStatus,refundCarryVo,-refundRecordItem.getRealRefundNum(),commonService);
160c33 1037     }
fd7281 1038
C 1039 }