| | |
| | | package com.hx.phip.util.api; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.hx.common.service.CommonService; |
| | | import com.hx.exception.TipsException; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import com.hx.phiappt.common.*; |
| | | import com.hx.phiappt.constants.enums.GroupTypeEnum; |
| | | import com.hx.phiappt.constants.tool.RefundToolUtil; |
| | | import com.hx.phiappt.constants.tool.SqlSplicingTool; |
| | | import com.hx.phiappt.model.BaseEntity; |
| | | import com.hx.phiappt.model.UserMoney; |
| | | import com.hx.phiappt.model.activity.ActivityAction; |
| | | import com.hx.phiappt.model.activity.ActivityRule; |
| | | import com.hx.phiappt.model.consume.ConsumePay; |
| | | import com.hx.phiappt.model.consume.ConsumePayItem; |
| | | import com.hx.phiappt.model.coupon.CouponNumber; |
| | | import com.hx.phiappt.model.coupon.CouponOrderDiscountLog; |
| | | import com.hx.phiappt.model.order.*; |
| | | import com.hx.phiappt.model.refund.*; |
| | | import com.hx.phiappt.model.user.UserCard; |
| | | import com.hx.phiappt.model.user.UserCardUsed; |
| | | import com.hx.phiappt.model.user.UserProject; |
| | | import com.hx.phiappt.model.user.UserProjectItem; |
| | | import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed; |
| | | import com.hx.phip.config.CustomParameter; |
| | | import com.hx.phip.dao.mapper.*; |
| | | import com.hx.phip.tool.user.UserProjectTool; |
| | | import com.hx.phip.vo.order.refund.RefundCarryVo; |
| | | import com.hx.phip.vo.user.UserProjectDeductionVo; |
| | | import com.hx.util.StringUtils; |
| | | import com.platform.exception.PlatTipsException; |
| | | import com.platform.resultTool.PlatformCode; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | * @Author |
| | | */ |
| | | public class PartialRefundUtil { |
| | | private static final Logger logger = LoggerFactory.getLogger(PartialRefundUtil.class); |
| | | |
| | | /**领建优惠券标识*/ |
| | | public static final String HIS_COUPON_CODE = "his_coupon_code"; |
| | | |
| | | /** |
| | | * 退款总流程工具 |
| | | * @param commonService |
| | | * @param operationId |
| | | * @param operationNme |
| | | * @param refundId |
| | | * @param |
| | | * @param appIdCode |
| | | */ |
| | | public static OrdersTotal refundProcess(CommonService commonService, String operationId, String operationNme, String refundId, CustomParameter customParameter, String appIdCode) { |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> map=new HashMap<>(); |
| | | sqlSentence.setM(map); |
| | | //退款成功 |
| | | map.put("refundStatus", RefundStatus.STATUS_APPLY_REFUND); |
| | | map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND); |
| | | map.put("refundId", refundId); |
| | | sqlSentence.setSqlSentence("select * from refund_record where isDel=0 and refundStatus=#{m.refundStatus} and id=#{m.refundId}"); |
| | | RefundRecord refundRecord =commonService.selectOne(RefundRecordMapper.class,sqlSentence); |
| | | public static OrdersTotal refundProcess(CommonService commonService, String operationId, String operationNme, String refundId, CustomParameter customParameter) { |
| | | |
| | | RefundRecord refundRecord = commonService.selectOneByKeyBlob(RefundRecordMapper.class,refundId); |
| | | if(refundRecord ==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到该退款信息!"); |
| | | } |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | stringBuffer.append("select name,actualTotal,refundRecordId,refundNumberNo as numberNo,id,consumePayId from refund_record_method WHERE refundRecordId in ("); |
| | | SqlSplicingTool.selectIn(stringBuffer, Arrays.asList((String) map.get("refundId"))); |
| | | sqlSentence.setSqlSentence(stringBuffer.toString()); |
| | | List<Map<String, Object>> refundMethodList = commonService.selectListMap(RefundRecordMethodMapper.class,sqlSentence); |
| | | if(refundMethodList==null && refundMethodList.size()==0){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"没有找到该退款订单对应的支付方式"); |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | |
| | | //退款总订单状态变更 |
| | | values.clear(); |
| | | values.put("refundStatus", RefundStatus.STATUS_SUCC_REFUND); |
| | | values.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND); |
| | | values.put("isDel", BaseEntity.NO); |
| | | values.put("id",refundRecord.getId()); |
| | | sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus} WHERE id = #{m.refundId} AND isDel=#{m.isDel} AND refundStatus = #{m.oldRefundStatus}"); |
| | | if(commonService.updateWhere(RefundRecordMapper.class,sqlSentence) != 1){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作失败,退款单状态已改变!"); |
| | | } |
| | | //查看订单信息 |
| | | OrdersTotal ordersTotal=commonService.selectOneByKeyBlob(OrdersTotalMapper.class,refundRecord.getOrderId()); |
| | | if(ordersTotal==null ){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到订单信息!"); |
| | | |
| | | //回去订单信息 |
| | | OrdersTotal ordersTotal = commonService.selectOneByKeyBlob(OrdersTotalMapper.class,refundRecord.getOrderId()); |
| | | if(ordersTotal == null ){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到订单信息!"); |
| | | } |
| | | //查看订单其他信息 |
| | | map.put("orderId", ordersTotal.getId()); |
| | | sqlSentence.setSqlSentence("select * from orders_info where isDel=0 and orderId=#{m.orderId}"); |
| | | OrderInfo orderInfo=commonService.selectOne(OrderInfoMapper.class,sqlSentence); |
| | | |
| | | //查询用户是否有账户信息,退款需要处理资金 |
| | | map.put("userId",refundRecord.getUserId()); |
| | | sqlSentence.setSqlSentence("select * from user_money WHERE userId=#{m.userId} and isDel=0"); |
| | | values.put("userId",refundRecord.getUserId()); |
| | | sqlSentence.setSqlSentence("SELECT * FROM user_money WHERE userId=#{m.userId} AND isDel=0"); |
| | | UserMoney userMoney=commonService.selectOne(UserMoneyMapper.class,sqlSentence); |
| | | if(userMoney==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到该用户的资金信息"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该用户的资金信息"); |
| | | } |
| | | |
| | | //获取总退款方式 |
| | | values.put("refundRecordId",refundRecord.getId()); |
| | | sqlSentence.sqlSentence("SELECT * FROM refund_record_method WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",values); |
| | | List<RefundRecordMethod> refundRecordMethodList = commonService.selectList(RefundRecordMethodMapper.class,sqlSentence); |
| | | |
| | | //全程使用携带参数对象 |
| | | RefundCarryVo refundCarryVo = new RefundCarryVo(); |
| | | refundCarryVo.setRefundRecordMethodList(refundRecordMethodList); |
| | | |
| | | //处理优惠券 |
| | | handCoupon(commonService, sqlSentence, map, refundRecord,ordersTotal); |
| | | handCoupon(refundRecord,commonService); |
| | | //处理总退款方式数据 |
| | | refundRecordMotnedHandle(operationId,operationNme,refundRecord,ordersTotal,commonService); |
| | | //子单退款项处理 |
| | | numberOfRefunds(operationId, operationNme, refundRecord,ordersTotal,customParameter,commonService); |
| | | |
| | | if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){ |
| | | //充值订单需要把充值的储值金 拿回来 因为储值金需要开单来处理,所以不需要增加日志 |
| | | 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); |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, "储值金客户退回金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | //活动规则退款处理 |
| | | handActivityRule(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,orderInfo); |
| | | }else if(OrderTotalConstants.TYPE_CARD_BAG.equals(ordersTotal.getType())){ |
| | | //卡包处理 |
| | | numberOfRefunds(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,customParameter); |
| | | } else { |
| | | //普通订单处理 |
| | | if(refundRecord.getRefundType() ==0){ |
| | | numberOfRefunds(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,customParameter); |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(ordersTotal.getActualTotal().compareTo(BigDecimal.ZERO)!=0){ |
| | | //交给审批前操作 |
| | | /* 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); |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, "储值金客户退回金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | commonService.insert(OrderLogMapper.class,orderLog);*/ |
| | | //活动规则退款处理 |
| | | // handActivityRule(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,orderInfo); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //增加增值金 |
| | | boolean cashStatus=false;//判断是否有现金或者其他现金支付 |
| | | ConsumePay consumePay; |
| | | for(Map<String,Object> methodMap:refundMethodList){ |
| | | BigDecimal actualTotal=(BigDecimal) methodMap.get("actualTotal"); |
| | | String name=(String) methodMap.get("name"); |
| | | String id=(String) methodMap.get("id"); |
| | | String consumePayId=(String) methodMap.get("consumePayId"); |
| | | if(PayMethodTypeConstants.PAY_STORED.equals(methodMap.get("numberNo"))){ |
| | | |
| | | //储值金额 |
| | | UserMoneyUtil.setNewUserMoneyUnclaimed(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); |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, name+"退款金额:"+actualTotal, 0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | }else if(PayMethodTypeConstants.PAY_ADD_FUND.equals(methodMap.get("numberNo"))){ |
| | | //增值金 |
| | | UserMoneyUtil.setNewUserMoneyUnclaimed(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); |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name,0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | }else if(PayMethodTypeConstants.PAY_INTEGRAL.equals(methodMap.get("numberNo"))){ |
| | | //积分 |
| | | UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式积分退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),actualTotal, UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name+"退款金额:"+actualTotal,0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | }else { |
| | | cashStatus=true; |
| | | //现金支付 |
| | | if(actualTotal.compareTo(BigDecimal.ZERO)<1){ |
| | | continue; |
| | | } |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name+"退款金额:"+actualTotal,0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | orderLog.setOrderId(ordersTotal.getId()); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | |
| | | //现金支付需要创建创建退款单进行退款 |
| | | RefundNote refundNote=new RefundNote(actualTotal, (String) methodMap.get("numberNo"),name,ordersTotal.getId(),refundRecord.getUserId()); |
| | | refundNote.setRefundRecordId(refundRecord.getId()); |
| | | commonService.insert(RefundNoteMapper.class,refundNote); |
| | | } |
| | | //修改实际退款金额 |
| | | sqlSentence.setSqlSentence(" realRefundTotal=#{m.realRefundTotal} where id=#{m.refundMethodId}"); |
| | | map.put("realRefundTotal",actualTotal); |
| | | map.put("refundMethodId",id); |
| | | commonService.updateWhere(RefundRecordMethodMapper.class,sqlSentence); |
| | | |
| | | //修改支付方式已退款金额 |
| | | consumePay=commonService.selectOneByKey(ConsumePayMapper.class,consumePayId); |
| | | consumePay.setRefundTotal(consumePay.getRefundTotal().add(actualTotal)); |
| | | commonService.updateAll(ConsumePayMapper.class,consumePay); |
| | | |
| | | } |
| | | |
| | | //退款总订单 |
| | | map.put("refundStatus", RefundStatus.STATUS_SUCC_REFUND); |
| | | map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND); |
| | | map.put("editTime", new Date()); |
| | | map.put("refundId", refundId); |
| | | map.put("isDel", BaseEntity.NO); |
| | | sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus},editTime=#{m.editTime} where id=#{m.refundId} and isDel=#{m.isDel} and refundStatus=#{m.oldRefundStatus}"); |
| | | commonService.updateWhere(RefundRecordMapper.class,sqlSentence); |
| | | |
| | | //更改总订单退款状态 |
| | | map.put("orderId",ordersTotal.getId()); |
| | | values.clear(); |
| | | values.put("orderId",ordersTotal.getId()); |
| | | sqlSentence.setSqlSentence("select * from order_item WHERE orderId=#{m.orderId} and isDel=0"); |
| | | List<OrderItem> orderItemList=commonService.selectList(OrderItemMapper.class,sqlSentence); |
| | | |
| | |
| | | ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ |
| | | ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
| | | }else { |
| | | }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
| | | ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH); |
| | | ordersTotal.setStatus(OrderTotalConstants.STATUS_CANCEL); |
| | | ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | }else { |
| | | if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){ |
| | | if(ordersTotal.getActualTotal().compareTo(refundRecord.getRefundTotal()) <= 0){ |
| | | ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH); |
| | | }else{ |
| | | ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); |
| | | } |
| | | }else{ |
| | | ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
| | | } |
| | | } |
| | | ordersTotal.setIsSyncOrder(BaseEntity.NO); |
| | | ordersTotal.setEditTime(new Date()); |
| | | commonService.updateAll(OrdersTotalMapper.class,ordersTotal); |
| | | return ordersTotal; |
| | | } |
| | | |
| | | /**处理总退款方式数据*/ |
| | | public static void refundRecordMotnedHandle(String operationId,String operationNme,RefundRecord refundRecord,OrdersTotal ordersTotal,CommonService commonService){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | |
| | | //获取总退款方式 |
| | | map.put("refundRecordId",refundRecord.getId()); |
| | | sqlSentence.sqlSentence("SELECT * FROM refund_record_method WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",map); |
| | | List<RefundRecordMethod> refundRecordMethodList = commonService.selectList(RefundRecordMethodMapper.class,sqlSentence); |
| | | |
| | | |
| | | //退款方式总金额 |
| | | BigDecimal mothedTotal; |
| | | //支付方式扣减金额 |
| | | BigDecimal mothedCutTotal; |
| | | |
| | | //引用对象 |
| | | List<ConsumePay> consumePayList; |
| | | for(RefundRecordMethod refundRecordMethod:refundRecordMethodList){ |
| | | mothedTotal = refundRecordMethod.getActualTotal(); |
| | | if(PayMethodTypeConstants.PAY_STORED.equals(refundRecordMethod.getRefundNumberNo())){ |
| | | //储值金额 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)>0){ |
| | | UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式储值金额退回",operationId,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundRecord.getId(),refundRecordMethod.getActualTotal(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, refundRecordMethod.getName()+"退款金额:"+refundRecordMethod.getActualTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | } |
| | | }else if(PayMethodTypeConstants.PAY_ADD_FUND.equals(refundRecordMethod.getRefundNumberNo())){ |
| | | //增值金 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)!=0){ |
| | | UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式增值金退回",operationId,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundRecord.getId(),refundRecordMethod.getActualTotal(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,refundRecordMethod.getName(),0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | } |
| | | }else if(PayMethodTypeConstants.PAY_INTEGRAL.equals(refundRecordMethod.getRefundNumberNo())){ |
| | | //积分 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)!=0){ |
| | | UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式积分退回",operationId,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundRecord.getId(),refundRecordMethod.getActualTotal(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,refundRecordMethod.getName()+"退款金额:"+refundRecordMethod.getActualTotal(),0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | } |
| | | }else { |
| | | //现金支付 |
| | | if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)<1){ |
| | | continue; |
| | | } |
| | | OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,refundRecordMethod.getName()+"退款金额:"+refundRecordMethod.getActualTotal(),0, OrderLogConstants.LOG_TYPE_REFUND); |
| | | orderLog.setOrderId(ordersTotal.getId()); |
| | | commonService.insert(OrderLogMapper.class,orderLog); |
| | | |
| | | //现金支付需要创建创建退款单进行退款 |
| | | RefundNote refundNote = new RefundNote(refundRecordMethod.getActualTotal(), refundRecordMethod.getNumberNo(),refundRecordMethod.getName(),ordersTotal.getId(),refundRecord.getUserId()); |
| | | refundNote.setRefundRecordId(refundRecord.getId()); |
| | | commonService.insert(RefundNoteMapper.class,refundNote); |
| | | } |
| | | //修改实际退款金额 |
| | | map.put("realRefundTotal",refundRecordMethod.getActualTotal()); |
| | | map.put("id",refundRecordMethod.getId()); |
| | | sqlSentence.sqlUpdate(" realRefundTotal=realRefundTotal + #{m.realRefundTotal} where id = #{m.id}",map); |
| | | if(commonService.updateWhere(RefundRecordMethodMapper.class,sqlSentence) != 1){ |
| | | throw new TipsException("更新退款方式信息错误[001]"); |
| | | } |
| | | |
| | | //获取支付方式 |
| | | map.put("orderId",refundRecord.getOrderId()); |
| | | map.put("numberNo",refundRecordMethod.getNumberNo()); |
| | | sqlSentence.sqlSentence("SELECT *,ROUND(actualTotal-refundTotal,2) AS pTotal FROM consume_pay WHERE isDel = 0 AND orderId = #{m.orderId} AND numberNo = #{m.numberNo} ORDER BY pTotal ASC",map); |
| | | consumePayList = commonService.selectList(ConsumePayMapper.class,sqlSentence); |
| | | for(ConsumePay consumePay:consumePayList){ |
| | | if(consumePay.getpTotal().compareTo(BigDecimal.ZERO) < 1){ |
| | | continue; |
| | | } |
| | | //计算扣减金额 |
| | | if(consumePay.getpTotal().compareTo(mothedTotal) > 0){ |
| | | mothedCutTotal = mothedTotal; |
| | | }else{ |
| | | mothedCutTotal = consumePay.getpTotal(); |
| | | } |
| | | |
| | | //更新支付记录退款信息 |
| | | map.clear(); |
| | | map.put("refundTotal",mothedCutTotal); |
| | | map.put("id",consumePay.getId()); |
| | | sqlSentence.sqlUpdate("refundTotal = refundTotal + #{m.refundTotal} WHERE id = #{m.id} AND actualTotal >= refundTotal + #{m.refundTotal}",map); |
| | | if(commonService.updateWhere(ConsumePayMapper.class,sqlSentence) != 1){ |
| | | throw new TipsException("退款金额错误!"); |
| | | } |
| | | |
| | | //生成关联记录 |
| | | insertRefundRecordConsumePay(mothedCutTotal,null,null,refundRecord.getOrderId(),consumePay.getNumberNo() |
| | | ,consumePay.getName(),consumePay.getId(),refundRecord.getId(),refundRecordMethod.getId(),commonService); |
| | | |
| | | //计算未分配金额 |
| | | mothedTotal = mothedTotal.subtract(mothedCutTotal).setScale(2, RoundingMode.HALF_UP); |
| | | //已经分配完成,跳出循环 |
| | | if(mothedTotal.compareTo(BigDecimal.ZERO) < 1){ |
| | | //跳出循环 |
| | | break; |
| | | } |
| | | } |
| | | //判断退款金额是否已经全部分配 |
| | | if(mothedTotal.compareTo(BigDecimal.ZERO) > 0){ |
| | | throw new TipsException("退款金额错误[426]!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /**处理一级子退款方式数据 |
| | | * @param deductionTotalUser 用户项目被扣减的划扣金额,可空 |
| | | * @param refundRecord 退款记录总表 |
| | | * @param refundRecordItem 退款记录子表 |
| | | * @param refundCarryVo 总携带参数结构 |
| | | * @param commonService 映射 |
| | | * @return 总携带参数结构 |
| | | */ |
| | | public static RefundCarryVo refundRecordMotnedItemHandle(BigDecimal deductionTotalUser,RefundRecord refundRecord,RefundRecordItem refundRecordItem |
| | | ,RefundCarryVo refundCarryVo,CommonService commonService){ |
| | | |
| | | //装载支付方式退款信息 |
| | | refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
| | | //没有退款方式,跳过当前处理 |
| | | if(refundCarryVo.getRefundRecordMethodList().size() == 0){ |
| | | return refundCarryVo; |
| | | } |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | |
| | | //支付方式占比 |
| | | BigDecimal payMothedPercentage; |
| | | //计算退款方式的占比 |
| | | if(refundRecord.getRefundTotal().compareTo(BigDecimal.ZERO) > 0){ |
| | | payMothedPercentage = refundRecordItem.getRefundMoney().divide(refundRecord.getRefundTotal(),15,RoundingMode.HALF_UP); |
| | | }else{ |
| | | payMothedPercentage = BigDecimal.ZERO; |
| | | } |
| | | |
| | | //处理退款方式 |
| | | refundCarryVo = insertRefundItemMothed(refundRecordItem.getId(),refundRecordItem.getRefundMoney(),payMothedPercentage,OrderSourceConstans.TYPE_PROJECT |
| | | ,refundRecordItem.getOrderItemId(),refundCarryVo,refundRecord,commonService); |
| | | |
| | | //更新现金和划扣金额保存 |
| | | values.put("deductionTotal",refundCarryVo.getDeductionTotal()); |
| | | values.put("deductionTotalUser",deductionTotalUser==null?BigDecimal.ZERO:deductionTotalUser); |
| | | values.put("cashTotal",refundCarryVo.getCashTotal()); |
| | | values.put("id",refundRecordItem.getId()); |
| | | sqlSentence.sqlUpdate("deductionTotal = #{m.deductionTotal},deductionTotalUser = #{m.deductionTotalUser},cashTotal = #{m.cashTotal} WHERE id = #{m.id}",values); |
| | | if(commonService.updateWhere(RefundRecordItemMapper.class,sqlSentence) != 1){ |
| | | throw new TipsException("更新退款子项信息失败!"); |
| | | } |
| | | |
| | | return refundCarryVo; |
| | | } |
| | | |
| | | /**处理二级子退款方式数据 |
| | | * @param deductionTotalUser 用户项目被扣减的划扣金额 |
| | | * @param refundRecord 退款记录总表 |
| | | * @param refundRecordItemSource 退款记录子表 |
| | | * @param refundCarryVo 总携带参数结构 |
| | | * @param commonService 映射 |
| | | * @return 总携带参数结构 |
| | | */ |
| | | public static RefundCarryVo refundRecordMotnedItemTwoHandle(BigDecimal deductionTotalUser,RefundRecord refundRecord,RefundRecordItemSource refundRecordItemSource |
| | | ,RefundCarryVo refundCarryVo,CommonService commonService){ |
| | | |
| | | //装载支付方式退款信息 |
| | | refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
| | | //没有退款方式,跳过当前处理 |
| | | if(refundCarryVo.getRefundRecordMethodList().size() == 0){ |
| | | return refundCarryVo; |
| | | } |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | |
| | | //支付方式占比 |
| | | BigDecimal payMothedPercentage; |
| | | //计算退款方式的占比 |
| | | if(refundRecord.getRefundTotal().compareTo(BigDecimal.ZERO) > 0){ |
| | | payMothedPercentage = refundRecordItemSource.getRefundMoney().divide(refundRecord.getRefundTotal(),15,RoundingMode.HALF_UP); |
| | | }else{ |
| | | payMothedPercentage = BigDecimal.ZERO; |
| | | } |
| | | |
| | | //处理退款方式 |
| | | refundCarryVo = insertRefundItemMothed(refundRecordItemSource.getId(),refundRecordItemSource.getRefundMoney(),payMothedPercentage,OrderSourceConstans.TYPE_RETAIL |
| | | ,refundRecordItemSource.getOrderItemSonId(),refundCarryVo,refundRecord,commonService); |
| | | |
| | | values.put("deductionTotal",refundCarryVo.getDeductionTotal()); |
| | | values.put("deductionTotalUser",deductionTotalUser==null?BigDecimal.ZERO:deductionTotalUser); |
| | | values.put("cashTotal",refundCarryVo.getCashTotal()); |
| | | values.put("id",refundRecordItemSource.getId()); |
| | | sqlSentence.sqlUpdate("deductionTotal = #{m.deductionTotal},deductionTotalUser = #{m.deductionTotalUser},cashTotal = #{m.cashTotal} WHERE id = #{m.id}",values); |
| | | if(commonService.updateWhere(RefundRecordItemSourceMapper.class,sqlSentence) != 1){ |
| | | throw new TipsException("更新退款子项信息失败[94]!"); |
| | | } |
| | | |
| | | return refundCarryVo; |
| | | } |
| | | |
| | | /**退款子单退款方式处理保存 |
| | | * @param refundItemId 退款子单标识 |
| | | * @param refundItemTotal 退款子单实际需要退款总金额 |
| | | * @param payMothedPercentage 支付方式占比 |
| | | * @param orderItemType 订单子单级别 |
| | | * @param orderItemId 订单子单标识 |
| | | * @param refundCarryVo 总结构对象 |
| | | * @param refundRecord 退款总记录 |
| | | * @param commonService 映射 |
| | | * @return 总结构对象 |
| | | */ |
| | | public static RefundCarryVo insertRefundItemMothed(String refundItemId,BigDecimal refundItemTotal,BigDecimal payMothedPercentage,String orderItemType |
| | | ,String orderItemId,RefundCarryVo refundCarryVo,RefundRecord refundRecord,CommonService commonService){ |
| | | |
| | | //总退款方式金额数据 |
| | | List<RefundRecordMethod> refundRecordMethodList = refundCarryVo.getRefundRecordMethodList(); |
| | | //进行升序排序,避免后面不够分配 |
| | | refundRecordMethodList = refundRecordMethodList.stream().sorted(Comparator.comparing(RefundRecordMethod::getpTotal)).collect(Collectors.toList()); |
| | | |
| | | //获取子单的支付方式,子单支付记录,计算可退款金额 |
| | | List<ConsumePayItem> consumePayItemList; |
| | | if(OrderSourceConstans.TYPE_PROJECT.equals(orderItemType)){ |
| | | consumePayItemList = getOrderItemOneConsumePay(orderItemId,commonService); |
| | | }else{ |
| | | consumePayItemList = getOrderItemTwoConsumePay(orderItemId,commonService); |
| | | } |
| | | |
| | | ////存储支付方式编号的可退款金额,根据支付编号求和,后面的判断会用到,key值:支付编号,value:可退金额 |
| | | Map<String,BigDecimal> noMap = new HashMap<>(); |
| | | BigDecimal surplusTotal; |
| | | ////存储支付方式编号的支付方式记录,根据支付编号整合,后面的判断会用到,key值:支付编号,value:支付记录集合 |
| | | Map<String,List<ConsumePayItem>> noPayItemMap = new HashMap<>(); |
| | | List<ConsumePayItem> noPayItemList; |
| | | |
| | | ////////填充支付方式记录的退款金额,计算剩余可退金额,支付方式记录的退款金额需要去查询计算获取 |
| | | //获取已经退款的退款方式金额,根据支付方式记录的标识求和返回 |
| | | List<RefundRecordConsumePay> refundRecordConsumePayList = getRefundRecordConsumePay(orderItemId,null,false,true,commonService); |
| | | //转化成map,可以根据支付方式记录的标识直接获取到数据 |
| | | Map<String, RefundRecordConsumePay> refundRecordConsumePayMap = refundRecordConsumePayList.stream().collect( |
| | | Collectors.toMap(RefundRecordConsumePay::getConsumePayId,(a) -> a)); |
| | | RefundRecordConsumePay refundRecordConsumePay; |
| | | for(ConsumePayItem consumePayItem:consumePayItemList){ |
| | | refundRecordConsumePay = refundRecordConsumePayMap.get(consumePayItem.getConsumePayId()); |
| | | if(refundRecordConsumePay != null){ |
| | | //已退款金额 |
| | | consumePayItem.setRefundTotal(refundRecordConsumePay.getRefundTotal()); |
| | | //可退款金额 |
| | | consumePayItem.setpTotal(consumePayItem.getpTotal().subtract(refundRecordConsumePay.getRefundTotal()).setScale(2,RoundingMode.HALF_UP)); |
| | | } |
| | | //计算每个支付编码可退款金额 |
| | | surplusTotal = noMap.computeIfAbsent(consumePayItem.getNumberNo(),k->BigDecimal.ZERO); |
| | | surplusTotal = surplusTotal.add(consumePayItem.getpTotal()).setScale(2,RoundingMode.HALF_UP); |
| | | noMap.put(consumePayItem.getNumberNo(),surplusTotal); |
| | | |
| | | } |
| | | //进行升序排序,避免后面不够分配 |
| | | consumePayItemList = consumePayItemList.stream().sorted(Comparator.comparing(ConsumePayItem::getpTotal)).collect(Collectors.toList()); |
| | | for(ConsumePayItem consumePayItem:consumePayItemList){ |
| | | //支付编码集合整合 |
| | | noPayItemList = noPayItemMap.computeIfAbsent(consumePayItem.getNumberNo(),k->new ArrayList<>()); |
| | | noPayItemList.add(consumePayItem); |
| | | } |
| | | |
| | | List<RefundRecordConsumePay> refundConsumePayList = new ArrayList<>(); |
| | | |
| | | ////引用对象 |
| | | RefundRecordItemMethod refundRecordItemMethod; |
| | | RefundRecordMethod refundRecordMethod; |
| | | //需要退的退款编号金额 |
| | | BigDecimal mothedTotal; |
| | | //支付编号分配的退款金额 |
| | | BigDecimal mothedCutTotal; |
| | | //分配的划扣金额总和 |
| | | BigDecimal deductionTotal = BigDecimal.ZERO; |
| | | //分配的现金金额总和 |
| | | BigDecimal cashTotal = BigDecimal.ZERO; |
| | | |
| | | ////退款方式金额分配 |
| | | for(int i = 0;i <refundRecordMethodList.size();i++){ |
| | | refundRecordMethod = refundRecordMethodList.get(i); |
| | | |
| | | ////子项退款方式填充 |
| | | refundRecordItemMethod = new RefundRecordItemMethod(); |
| | | refundRecordItemMethod.setNumberNo(refundRecordMethod.getNumberNo()); |
| | | refundRecordItemMethod.setName(refundRecordMethod.getName()); |
| | | //支付方式 |
| | | refundRecordItemMethod.setPaymentMethodId(refundRecordMethod.getPaymentMethodId()); |
| | | refundRecordItemMethod.setIsMoneyPay(refundRecordMethod.getIsMoneyPay()); |
| | | refundRecordItemMethod.setIsExecute(refundRecordMethod.getIsExecute()); |
| | | refundRecordItemMethod.setIsPay(refundRecordMethod.getIsPay()); |
| | | //退款方式 |
| | | refundRecordItemMethod.setRefundNumberNo(refundRecordMethod.getRefundNumberNo()); |
| | | refundRecordItemMethod.setRefundName(refundRecordMethod.getRefundName()); |
| | | refundRecordItemMethod.setRefundMethodId(refundRecordMethod.getRefundMethodId()); |
| | | |
| | | //计算退款方式的金额 |
| | | if(i == refundRecordMethodList.size()-1){ |
| | | ////最后一个 |
| | | refundRecordItemMethod.setActualTotal(refundItemTotal); |
| | | }else { |
| | | ////不是最后一个 |
| | | refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); |
| | | } |
| | | //判断与剩余的未分配退款方式金额 |
| | | if (refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getpTotal()) > 0){ |
| | | refundRecordItemMethod.setActualTotal(refundRecordMethod.getpTotal()); |
| | | } |
| | | //判断与剩下的未分配金额校验 |
| | | if(refundRecordItemMethod.getActualTotal().compareTo(refundItemTotal) > 0){ |
| | | refundRecordItemMethod.setActualTotal(refundItemTotal); |
| | | } |
| | | //可支付方式可退款金额 |
| | | surplusTotal = noMap.computeIfAbsent(refundRecordItemMethod.getNumberNo(),k-> BigDecimal.ZERO); |
| | | if(refundRecordItemMethod.getActualTotal().compareTo(surplusTotal) > 0){ |
| | | refundRecordItemMethod.setActualTotal(surplusTotal); |
| | | } |
| | | |
| | | refundRecordItemMethod.setCommonType(orderItemType); |
| | | refundRecordItemMethod.setCommonId(orderItemId); |
| | | refundRecordItemMethod.setOrderId(refundRecordMethod.getOrderId()); |
| | | refundRecordItemMethod.setRefundRecordItemId(refundItemId); |
| | | refundRecordItemMethod.setRefundRecordId(refundRecord.getId()); |
| | | commonService.insert(RefundRecordItemMethodMapper.class,refundRecordItemMethod); |
| | | |
| | | //减去已经分配的退款方式金额 |
| | | refundRecordMethod.setpTotal(refundRecordMethod.getpTotal().subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP)); |
| | | //减去已经分配的退款金额 |
| | | refundItemTotal = refundItemTotal.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); |
| | | //减去已经分配的可退款金额 |
| | | surplusTotal = surplusTotal.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); |
| | | noMap.put(refundRecordItemMethod.getNumberNo(),surplusTotal); |
| | | |
| | | ///////生成关联支付方式记录和退款方式关联 |
| | | noPayItemList = noPayItemMap.computeIfAbsent(refundRecordItemMethod.getNumberNo(),k->new ArrayList<>()); |
| | | mothedTotal = refundRecordItemMethod.getActualTotal(); |
| | | for(ConsumePayItem consumePayItem:noPayItemList){ |
| | | if(consumePayItem.getpTotal().compareTo(BigDecimal.ZERO) < 1){ |
| | | continue; |
| | | } |
| | | //计算扣减金额 |
| | | if(consumePayItem.getpTotal().compareTo(mothedTotal) > 0){ |
| | | mothedCutTotal = mothedTotal; |
| | | }else{ |
| | | mothedCutTotal = consumePayItem.getpTotal(); |
| | | } |
| | | |
| | | //划扣金额 |
| | | if(consumePayItem.getIsMoneyPay().equals(ConsumePayItem.YES)){ |
| | | deductionTotal = deductionTotal.add(mothedCutTotal).setScale(2,RoundingMode.HALF_UP); |
| | | } |
| | | //现金金额 |
| | | if(consumePayItem.getIsExecute().equals(ConsumePayItem.YES)){ |
| | | cashTotal = cashTotal.add(mothedCutTotal).setScale(2,RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | //生成关联记录 |
| | | refundRecordConsumePay = insertRefundRecordConsumePay(mothedCutTotal,refundRecordItemMethod.getCommonType(),refundRecordItemMethod.getCommonId(),refundRecord.getOrderId(),consumePayItem.getNumberNo() |
| | | ,consumePayItem.getName(),consumePayItem.getConsumePayId(),refundRecordItemMethod.getId(),refundItemId,refundRecord.getId(),commonService); |
| | | refundConsumePayList.add(refundRecordConsumePay); |
| | | |
| | | //支付方式记录减掉已经分配退款方式金额 |
| | | consumePayItem.setpTotal(consumePayItem.getpTotal().subtract(mothedCutTotal).setScale(2,RoundingMode.HALF_UP)); |
| | | //减掉已经分配退款方式金额 |
| | | mothedTotal = mothedTotal.subtract(mothedCutTotal).setScale(2, RoundingMode.HALF_UP); |
| | | //分配完成,跳出循环 |
| | | if(mothedTotal.compareTo(BigDecimal.ZERO) < 1){ |
| | | //跳出循环 |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | //判断是否已经分配完 |
| | | if(refundItemTotal.compareTo(BigDecimal.ZERO) > 0){ |
| | | throw new TipsException("分配退款金额错误["+orderItemType+"]"); |
| | | } |
| | | |
| | | refundCarryVo.setDeductionTotal(deductionTotal); |
| | | refundCarryVo.setCashTotal(cashTotal); |
| | | refundCarryVo.setRefundConsumePayList(refundConsumePayList); |
| | | |
| | | return refundCarryVo; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 退款-处理优惠券 |
| | | * @param commonService |
| | | * @param sqlSentence |
| | | * @param map |
| | | * @param refundRecord |
| | | * @param refundRecord 退款总数据 |
| | | * @param commonService 映射 |
| | | */ |
| | | public static void handCoupon(CommonService commonService, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord,OrdersTotal ordersTotal) { |
| | | public static void handCoupon(RefundRecord refundRecord,CommonService commonService) { |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | |
| | | //回去回退优惠券 |
| | | map.put("refundRecordId",refundRecord.getId()); |
| | | sqlSentence.setSqlSentence("select * from refund_record_coupon where refundRecordId=#{m.refundRecordId} and isDel=0 "); |
| | | sqlSentence.setSqlSentence("select * from refund_record_coupon where refundRecordId=#{m.refundRecordId} and isDel=0 "); |
| | | List<RefundRecordCoupon> refundRecordCouponList=commonService.selectList(RefundRecordCouponMapper.class,sqlSentence); |
| | | |
| | | //退款成功 |
| | | map.put("isDel", BaseEntity.YES); |
| | | CouponOrderDiscountLog couponOrderDiscountLog=null; |
| | | for (RefundRecordCoupon refundRecordCoupon : refundRecordCouponList) { |
| | | sqlSentence.setSqlSentence(" isDel=#{m.isDel} WHERE id = #{m.id} "); |
| | | map.put("id", refundRecordCoupon.getCouponOrderId()); |
| | | couponOrderDiscountLog=commonService.selectOneByKey(CouponOrderDiscountLogMapper.class,refundRecordCoupon.getCouponOrderId()); |
| | | if(couponOrderDiscountLog==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单优惠卷id不正确"); |
| | | } |
| | | commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence); |
| | | |
| | | //变更订单优惠券记录状态 |
| | | map.clear(); |
| | | map.put("status", BaseEntity.YES); |
| | | map.put("id", refundRecordCoupon.getCouponOrderId()); |
| | | sqlSentence.setSqlSentence("status=#{m.status} WHERE id = #{m.id} "); |
| | | if(commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence) != 1){ |
| | | throw new TipsException("优惠券回退失败!"); |
| | | } |
| | | |
| | | //领建优惠券跳过回退 |
| | | if(HIS_COUPON_CODE.equals(couponOrderDiscountLog.getCouponNumberId())){ |
| | | continue; |
| | | } |
| | | |
| | | //优惠券状态变化 |
| | | map.put("isUse", BaseEntity.NO); |
| | | map.put("useTime", null); |
| | | map.put("useType", CouponNumber.USE_TYPE_UNKNOW); |
| | | map.put("id", couponOrderDiscountLog.getCouponNumberId()); |
| | | sqlSentence.setSqlSentence(" isUse=#{m.isUse},useTime=#{m.useTime},useType=#{m.useType},isUse=#{m.isUse} WHERE id = #{m.id} "); |
| | | commonService.updateWhere(CouponNumberMapper.class,sqlSentence); |
| | | if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 1){ |
| | | throw new TipsException("优惠券回退失败[67]!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | if(activityActions!=null && activityActions.size()>0){ |
| | | for (ActivityAction activityAction : activityActions) { |
| | | if(ActivityAction.TYPE_INTEGRAL.equals(activityAction.getType())){ |
| | | 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); |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(new BigDecimal(activityAction.getWorth()).negate().compareTo(BigDecimal.ZERO)!=0){ |
| | | 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); |
| | | } |
| | | }else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(activityAction.getType())){ |
| | | 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); |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(new BigDecimal(activityAction.getWorth()).negate().compareTo(BigDecimal.ZERO)!=0){ |
| | | 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); |
| | | } |
| | | }else if(ActivityAction.TYPE_COUPON.equals(activityAction.getType())){ |
| | | map.put("oldValidState",BaseEntity.YES); |
| | | map.put("newValidState",BaseEntity.NO); |
| | |
| | | } |
| | | /** |
| | | * 退款-处理普通订单信息(比如:项目、促销、卡项) |
| | | * @param commonService |
| | | * @param operationId 操作人标识 |
| | | * @param operationNme 操作人名称 |
| | | * @param sqlSentence |
| | | * @param map |
| | | * @param operationId 操作人标识 |
| | | * @param operationNme 操作人名 |
| | | * @param refundRecord |
| | | * @param commonService |
| | | */ |
| | | public static void numberOfRefunds(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, |
| | | Map<String, Object> map, RefundRecord refundRecord,OrdersTotal ordersTotal,CustomParameter customParameter) { |
| | | map.put("refundId",map.get("refundId")); |
| | | sqlSentence.setSqlSentence("select * from refund_record_item where isDel=0 and refundRecordId=#{m.refundId}"); |
| | | public static RefundCarryVo numberOfRefunds(RefundCarryVo refundCarryVo,String operationId, String operationNme, RefundRecord refundRecord,OrdersTotal ordersTotal,CustomParameter customParameter,CommonService commonService) { |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | |
| | | //获取退款子单 |
| | | map.clear(); |
| | | map.put("refundRecordId",refundRecord.getId()); |
| | | sqlSentence.setSqlSentence("SELECT * FROM refund_record_item WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}"); |
| | | List<RefundRecordItem> refundRecordItems =commonService.selectList(RefundRecordItemMapper.class,sqlSentence); |
| | | if(refundRecordItems==null && refundRecordItems.size()==0){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到退款子订单信息"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到退款子订单信息"); |
| | | } |
| | | for (RefundRecordItem v: refundRecordItems) { |
| | | switch (v.getType()){ |
| | | |
| | | //根据支付记录总表的标识来整合已退的金额,key值:支付记录总表标识,value:金额数据 |
| | | Map<String,RefundRecordConsumePay> refundRecordConsumePayMap = new HashMap<>(); |
| | | RefundRecordConsumePay refundRecordConsumePay; |
| | | |
| | | for (RefundRecordItem refundRecordItem: refundRecordItems) { |
| | | //初始化总结构携带参数 |
| | | refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
| | | refundCarryVo.setDeductionTotal(BigDecimal.ZERO); |
| | | refundCarryVo.setCashTotal(BigDecimal.ZERO); |
| | | |
| | | switch (refundRecordItem.getType()){ |
| | | case OrderItemConstants.TYPE_RETAIL: |
| | | handRefundRerail(commonService, sqlSentence, map, refundRecord, v); |
| | | refundCarryVo = handRefundRerail(refundRecord,refundRecordItem,refundCarryVo,commonService); |
| | | break; |
| | | case OrderItemConstants.TYPE_DRUG: |
| | | handRefundRerail(commonService, sqlSentence, map, refundRecord, v); |
| | | refundCarryVo = handRefundRerail(refundRecord,refundRecordItem,refundCarryVo,commonService); |
| | | break; |
| | | case OrderItemConstants.TYPE_PROJECT: |
| | | handRefundNoExecution(commonService, operationId, operationNme, sqlSentence, map, refundRecord, v); |
| | | refundCarryVo = handRefundNoExecution(refundRecord,refundRecordItem,refundCarryVo,commonService); |
| | | break; |
| | | case OrderItemConstants.TYPE_PROMOTION: |
| | | handRefundPromotion(commonService, operationId, operationNme, sqlSentence, map, refundRecord, ordersTotal, v); |
| | | refundCarryVo = handRefundPromotion(operationId, refundRecord, ordersTotal,refundRecordItem,refundCarryVo,commonService); |
| | | break; |
| | | case OrderItemConstants.TYPE_CARD: |
| | | handRefundCard(commonService, operationId, sqlSentence, map, refundRecord, ordersTotal, v); |
| | | refundCarryVo = handRefundCard(refundRecord,refundRecordItem,refundCarryVo,commonService); |
| | | break; |
| | | case OrderItemConstants.CARD_BAG: |
| | | handCardBag(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,v,customParameter); |
| | | refundCarryVo = handRefundPromotion(operationId, refundRecord, ordersTotal,refundRecordItem,refundCarryVo,commonService); |
| | | //refundCarryVo = handCardBag(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,refundRecordItem,customParameter); |
| | | break; |
| | | default:break; |
| | | } |
| | | |
| | | //遍历叠加支付方式记录的退款金额 |
| | | for(RefundRecordConsumePay re:refundCarryVo.getRefundConsumePayList()){ |
| | | refundRecordConsumePay = refundRecordConsumePayMap.computeIfAbsent(re.getConsumePayId(),k->new RefundRecordConsumePay(BigDecimal.ZERO,re.getNumberNo(),re.getConsumePayId())); |
| | | refundRecordConsumePay.setRefundTotal(refundRecordConsumePay.getRefundTotal().add(re.getRefundTotal())); |
| | | } |
| | | } |
| | | |
| | | //转载返回支付方式记录的退款金额 |
| | | List<RefundRecordConsumePay> refundRecordConsumePayList = new ArrayList<>(); |
| | | for (Map.Entry<String, RefundRecordConsumePay> entry : refundRecordConsumePayMap.entrySet()) { |
| | | refundRecordConsumePayList.add(entry.getValue()); |
| | | } |
| | | |
| | | refundCarryVo.setRefundConsumePayList(refundRecordConsumePayList); |
| | | return refundCarryVo; |
| | | } |
| | | |
| | | /** |
| | | * 退款一级是商品 |
| | | * @param commonService |
| | | * @param sqlSentence |
| | | * @param map |
| | | * @param refundRecord |
| | | * @param v |
| | | * @param refundRecord 退款总信息 |
| | | * @param refundRecordItem 退款子单 |
| | | * @param commonService 映射 |
| | | */ |
| | | private static void handRefundRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItem v) { |
| | | private static RefundCarryVo handRefundRerail(RefundRecord refundRecord, RefundRecordItem refundRecordItem |
| | | , RefundCarryVo refundCarryVo, CommonService commonService) { |
| | | |
| | | //判断操作完了去修改子订单状态 |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
| | | if (orderItem==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息"); |
| | | } |
| | | map.put("isDel", BaseEntity.NO); |
| | | map.put("orderItemId", v.getOrderItemId()); |
| | | map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney())); |
| | | Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum(); |
| | | map.put("hasReNum",hasReNum); |
| | | if (hasReNum==orderItem.getBuyNum()){ |
| | | map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH); |
| | | }else { |
| | | map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART); |
| | | //剩余可退款数量 |
| | | Integer surplusNum = orderItem.getBuyNum()-orderItem.getHasReNum(); |
| | | if(refundRecordItem.getRefundNum() > surplusNum){ |
| | | throw new TipsException("退款数量不能大于可退款数量!"); |
| | | } |
| | | |
| | | sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} "); |
| | | commonService.updateWhere(OrderItemMapper.class,sqlSentence); |
| | | //变更退款子项信息 |
| | | Integer refundStatus; |
| | | if (surplusNum.equals(refundRecordItem.getRefundNum())){ |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; |
| | | }else{ |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
| | | } |
| | | |
| | | //更新子订单信息 |
| | | updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); |
| | | |
| | | //退款方式处理 |
| | | return refundRecordMotnedItemHandle(null,refundRecord,refundRecordItem,refundCarryVo,commonService); |
| | | } |
| | | |
| | | /** |
| | | * 退款-处理未执行划扣 项目类型 |
| | | * @param commonService |
| | | * @param operationId 操作人 |
| | | * @param operationNme 操作人名称 |
| | | * @param sqlSentence |
| | | * @param map |
| | | * @param refundRecord |
| | | * @param v |
| | | * @param refundRecordItem |
| | | */ |
| | | private static void handRefundNoExecution(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItem v) { |
| | | sqlSentence.setSqlSentence("select * from user_project_item where isDel=0 and commonId='"+v.getOrderItemId()+"' and shopId='"+refundRecord.getRefundShopId()+"' " + |
| | | " and userId ='"+refundRecord.getUserId()+"'"); |
| | | private static RefundCarryVo handRefundNoExecution(RefundRecord refundRecord, RefundRecordItem refundRecordItem |
| | | ,RefundCarryVo refundCarryVo,CommonService commonService) { |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | |
| | | //找到子单 |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
| | | if (orderItem==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息"); |
| | | } |
| | | //找到用户项目 |
| | | map.clear(); |
| | | map.put("commonId",refundRecordItem.getOrderItemId()); |
| | | sqlSentence.sqlSentence("select * from user_project_item where isDel = 0 and commonId = #{m.commonId} and isTransfer = 0",map); |
| | | UserProjectItem userProjectItem =commonService.selectOne(UserProjectItemMapper.class,sqlSentence); |
| | | if (userProjectItem == null) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到用户子项项目信息"); |
| | | } |
| | | Integer usedNum=userProjectItem.getNotUsedNum()-v.getRefundNum(); |
| | | Integer cancelNum=userProjectItem.getCancelNum()+v.getRefundNum(); |
| | | |
| | | map.put("usedNum", usedNum); |
| | | map.put("isDel", BaseEntity.NO); |
| | | map.put("cancelNum", cancelNum); |
| | | map.put("userProjectItemId", userProjectItem.getId()); |
| | | sqlSentence.setSqlSentence(" cancelNum=#{m.cancelNum},notUsedNum=#{m.usedNum} where isDel=#{m.isDel} AND id=#{m.userProjectItemId} AND notUsedNum > 0 "); |
| | | commonService.updateWhere(UserProjectItemMapper.class,sqlSentence); |
| | | |
| | | UserProject userProject=commonService.selectOneByKey(UserProjectMapper.class,userProjectItem.getUserProjectId()); |
| | | userProject.setNotUsedNum(userProject.getNotUsedNum()-v.getRefundNum()); |
| | | commonService.updateAll(UserProjectMapper.class,userProject); |
| | | //判断操作完了去修改子订单状态 |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); |
| | | if (orderItem==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到用户子项项目信息"); |
| | | } |
| | | |
| | | Integer refundStatus=OrderTotalConstants.STATUS_REFUND_NONE; |
| | | if(usedNum==0){ |
| | | //已经没有可以执行数量 |
| | | if(userProjectItem.getNotUsedNum() < refundRecordItem.getRefundNum()){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于可退次数!"); |
| | | } |
| | | |
| | | //用户项目操作 |
| | | UserProjectDeductionVo userProjectDeductionVo = UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_DEDUCTION,null |
| | | ,refundRecordItem.getId(),refundRecordItem.getRefundNum(),refundRecord.getOperatorAppId(),refundRecord.getOperatorAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getRemarks()+"|用户备注:"+refundRecord.getRefundReason(),commonService); |
| | | |
| | | //计算子单是否还有剩余的可扣疗程数 |
| | | int surplusNum = orderItem.getUsedTotal()-orderItem.getHasReNum(); |
| | | if(refundRecordItem.getRefundNum() > surplusNum){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于子单可退次数[54]!"); |
| | | } |
| | | |
| | | Integer refundStatus; |
| | | if(refundRecordItem.getRefundNum() == surplusNum){ |
| | | refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; |
| | | }else { |
| | | }else{ |
| | | refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
| | | } |
| | | map.put("orderItemId", v.getOrderItemId()); |
| | | map.put("refundStatus", refundStatus); |
| | | map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney())); |
| | | map.put("hasReNum",cancelNum/(orderItem.getUsedTotal()/orderItem.getBuyNum())); |
| | | |
| | | sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} "); |
| | | commonService.updateWhere(OrderItemMapper.class,sqlSentence); |
| | | //更新子订单信息 |
| | | updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); |
| | | |
| | | //退款方式处理 |
| | | return refundRecordMotnedItemHandle(userProjectDeductionVo.getDeductionTotal(),refundRecord,refundRecordItem,refundCarryVo,commonService); |
| | | } |
| | | |
| | | /** |
| | | * 退款-处理卡项 |
| | | * @param commonService |
| | | * @param operationId |
| | | * @param sqlSentence |
| | | * @param map |
| | | * @param refundRecord |
| | | * @param ordersTotal |
| | | * @param v |
| | | * @param refundRecordItem |
| | | */ |
| | | public static void handRefundCard(CommonService commonService, String operationId, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem v) { |
| | | public static RefundCarryVo handRefundCard(RefundRecord refundRecord, RefundRecordItem refundRecordItem,RefundCarryVo refundCarryVo,CommonService commonService) { |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | |
| | | //判断操作完了去修改子订单状态 |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
| | | if (orderItem==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息"); |
| | | } |
| | | //作废卡包 |
| | | Integer surplusNum = orderItem.getBuyNum() - orderItem.getHasReNum(); |
| | | if(refundRecordItem.getRefundNum() > surplusNum){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款作废卡包提示:没有找到对应的卡包可退[020]"); |
| | | } |
| | | |
| | | map.put("hisOrderId",ordersTotal.getHisOrderId()); |
| | | map.put("orderId",ordersTotal.getId()); |
| | | map.put("effectiveStatus",UserProjectConstants.EFF_STATUS_YES); |
| | | map.put("status",UserCard.TYPE_NO_USED); |
| | | map.put("isDel",BaseEntity.NO); |
| | | sqlSentence.setSqlSentence("select id from user_card where (hisOrderId =#{m.hisOrderId} OR orderId =#{m.orderId}) AND effectiveStatus=#{m.effectiveStatus} AND status=#{m.status} AND isDel=#{m.isDel} "); |
| | | List<UserCard> userCards = commonService.selectList(UserCardMapper.class, sqlSentence); |
| | | if(userCards==null || userCards.size()==0){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款作废卡包提示:根据领建标识查询订单没有找到卡包信息,无法作废,领建订单标识:"+ordersTotal.getHisOrderId()); |
| | | //找到可退款卡包 |
| | | List<UserCard> userCardList = PartialRefundUtil.getRefundCard(orderItem.getId(),commonService); |
| | | if(refundRecordItem.getRefundNum() > userCardList.size()){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款作废卡包提示:没有找到对应的卡包可退[021]"); |
| | | } |
| | | |
| | | //变更卡项状态 |
| | | UserCard userCard; |
| | | RefundRecordCard refundRecordCard; |
| | | for (int i = 0; i < refundRecordItem.getRefundNum(); i++) { |
| | | userCard= userCardList.get(i); |
| | | map.put("id",userCard.getId()); |
| | | map.put("effectiveStatus", UserProjectConstants.EFF_STATUS_CANCEL); |
| | | sqlSentence.setSqlSentence(" effectiveStatus=#{m.effectiveStatus} where id = #{m.id} "); |
| | | commonService.updateWhere(UserCardMapper.class,sqlSentence); |
| | | |
| | | //生成退款关联 |
| | | refundRecordCard = new RefundRecordCard(); |
| | | refundRecordCard.setUserCardId(userCard.getId()); |
| | | refundRecordCard.setRefundRecordId(refundRecord.getId()); |
| | | refundRecordCard.setRefundRecordItemId(refundRecordItem.getId()); |
| | | |
| | | 退款卡包关联保存 |
| | | } |
| | | |
| | | Integer refundStatus; |
| | | if (surplusNum.equals(refundRecordItem.getRefundNum())){ |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; |
| | | }else { |
| | | UserCard userCard=null; |
| | | for (int i = 0; i < v.getRefundNum(); i++) { |
| | | userCard=userCards.get(i); |
| | | map.put("id",userCard.getId()); |
| | | map.put("effectiveStatus", UserProjectConstants.EFF_STATUS_CANCEL); |
| | | sqlSentence.setSqlSentence(" effectiveStatus=#{m.effectiveStatus} where id=#{m.id} "); |
| | | commonService.updateWhere(UserCardMapper.class,sqlSentence); |
| | | } |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
| | | |
| | | } |
| | | //更新子订单信息 |
| | | updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); |
| | | |
| | | //更改订单子订单状态 |
| | | map.put("orderItemId", v.getOrderItemId()); |
| | | map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney())); |
| | | Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum(); |
| | | map.put("hasReNum",hasReNum); |
| | | if (hasReNum==orderItem.getBuyNum()){ |
| | | map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH); |
| | | }else { |
| | | map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART); |
| | | } |
| | | |
| | | |
| | | sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} "); |
| | | commonService.updateWhere(OrderItemMapper.class,sqlSentence); |
| | | //退款方式处理 |
| | | refundCarryVo = refundRecordMotnedItemHandle(null,refundRecord,refundRecordItem,refundCarryVo,commonService); |
| | | return refundCarryVo; |
| | | } |
| | | |
| | | /** |
| | | * 退款-处理卡包 |
| | | * @param commonService |
| | | * @param operationId |
| | | * @param operationNme |
| | | * @param sqlSentence |
| | | * @param map |
| | | * @param refundRecord |
| | | * @param ordersTotal |
| | | * @param v |
| | | * @param refundRecordItem |
| | | */ |
| | | public static void handCardBag(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, |
| | | RefundRecord refundRecord, OrdersTotal ordersTotal,RefundRecordItem v,CustomParameter customParameter) { |
| | | public static void handCardBag(String operationId,RefundRecord refundRecord, OrdersTotal ordersTotal |
| | | ,RefundRecordItem refundRecordItem,RefundCarryVo refundCarryVo,CommonService commonService) { |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | |
| | | //查看订单信息 |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
| | | if(orderItem==null ){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息!"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息!"); |
| | | } |
| | | map.put("refundRecordItemId",v.getId()); |
| | | map.put("refundRecordItemId",refundRecordItem.getId()); |
| | | sqlSentence.setSqlSentence("select * from refund_record_item_source where refundRecordItemId =#{m.refundRecordItemId}"); |
| | | List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence); |
| | | if( sons!=null && sons.size()>0 ){ |
| | | for (RefundRecordItemSource son : sons) { |
| | | switch (GroupTypeEnum.getCode(son.getType())){ |
| | | case PROJECT: |
| | | handRefundNoSonExecution(commonService, sqlSentence, map, refundRecord, son); |
| | | deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem); |
| | | break; |
| | | case RETAIL: |
| | | handRefundSonRerail(commonService, sqlSentence, map, refundRecord, son); |
| | | deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem); |
| | | break; |
| | | case INCREMENT: |
| | | //增值金 |
| | | if(sons.size() == 0 ){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息[015]!"); |
| | | } |
| | | |
| | | for (RefundRecordItemSource son : sons) { |
| | | refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
| | | refundCarryVo.setDeductionTotal(BigDecimal.ZERO); |
| | | refundCarryVo.setCashTotal(BigDecimal.ZERO); |
| | | switch (GroupTypeEnum.getCode(son.getType())){ |
| | | case PROJECT: |
| | | //handRefundNoSonExecution(refundRecord,son,refundCarryVo,commonService); |
| | | break; |
| | | case RETAIL: |
| | | //handRefundSonRerail(refundRecord,son,refundCarryVo,commonService ); |
| | | //deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem); |
| | | break; |
| | | case INCREMENT: |
| | | //增值金 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
| | | 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); |
| | | break; |
| | | case STORED: |
| | | //储值金额 |
| | | } |
| | | break; |
| | | case STORED: |
| | | //储值金额 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
| | | 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); |
| | | break; |
| | | case INTEGRAL: |
| | | //积分 |
| | | } |
| | | break; |
| | | case INTEGRAL: |
| | | //积分 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
| | | 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); |
| | | break; |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //更改二级子订单退款状态 |
| | | |
| | | map.put("orderItemId",orderItem.getId()); |
| | |
| | | orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ |
| | | orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
| | | }else { |
| | | }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
| | | orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH); |
| | | orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | orderItem.setHasReNum(orderItem.getBuyNum()); |
| | | }else { |
| | | orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
| | | } |
| | | |
| | | commonService.updateAll(OrderItemMapper.class,orderItem); |
| | |
| | | |
| | | /** |
| | | * 退款需要删除用户卡包使用记录 |
| | | * @param sqlSentence |
| | | * @param map |
| | | * @param ordersTotal |
| | | * @param commonService |
| | | * @param son |
| | | */ |
| | | public static void deleteUserCardUsed(SqlSentence sqlSentence, Map<String, Object> map,OrdersTotal ordersTotal,CommonService commonService,RefundRecordItemSource son,OrderItem orderItem){ |
| | | public static void deleteUserCardUsed(String cardItemInfoId,String sourceId,Integer hasReNum,CommonService commonService){ |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | |
| | | OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,son.getOrderItemSonId()); |
| | | Integer hasReNum=orderItemSon.getHasReNum(); |
| | | //获取使用记录 |
| | | map.put("cardItemInfoId",cardItemInfoId); |
| | | map.put("sourceId",sourceId); |
| | | sqlSentence.setSqlSentence(" SELECT * FROM user_card_used WHERE isDel = 0" + |
| | | " AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId = #{m.sourceId}"); |
| | | List<UserCardUsed> userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); |
| | | |
| | | map.put("isDel",BaseEntity.NO); |
| | | map.put("orderId",ordersTotal.getId()); |
| | | map.put("commonId",orderItemSon.getGoodsId()); |
| | | sqlSentence.setSqlSentence(" SELECT * FROM user_card_used WHERE orderId = #{m.orderId} and commonId=#{m.commonId} ORDER BY isDel,createTime "); |
| | | List<UserCardUsed> userCardUsedList=commonService.selectList(UserCardUsedMapper.class,sqlSentence); |
| | | |
| | | if(userCardUsedList==null || userCardUsedList.size()==0){ |
| | | //因为可能领建的老订单所以伪造的操作记录是没数据的 |
| | | map.put("userCardId",orderItem.getCommonId()); |
| | | sqlSentence.setSqlSentence(" SELECT * FROM user_card_used WHERE commonId=#{m.commonId} and userCardId=#{m.userCardId} ORDER BY isDel,createTime "); |
| | | userCardUsedList=commonService.selectList(UserCardUsedMapper.class,sqlSentence); |
| | | if(hasReNum > userCardUsedList.size()){ |
| | | throw new TipsException("卡包可退数量错误!"); |
| | | } |
| | | |
| | | UserCardUsed userCardUsed; |
| | | for (int i = 0; i < hasReNum; i++) { |
| | | userCardUsed=userCardUsedList.get(i); |
| | | userCardUsed.setIsDel(BaseEntity.YES); |
| | | commonService.updateAll(UserCardUsedMapper.class,userCardUsed); |
| | | int opNum = 0; |
| | | sqlSentence.sqlUpdate("isDel = 1 WHERE id = #{m.id} AND isDel = 0",map); |
| | | for(UserCardUsed userCardUsed:userCardUsedList){ |
| | | map.put("id",userCardUsed.getId()); |
| | | opNum = opNum+commonService.updateWhere(UserCardUsedMapper.class,sqlSentence); |
| | | } |
| | | if(opNum != hasReNum){ |
| | | throw new TipsException("卡包回退错误!"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 退款-处理促销 |
| | | * @param commonService |
| | | * @param operationId |
| | | * @param operationNme |
| | | * @param sqlSentence |
| | | * @param map |
| | | * @param refundRecord |
| | | * @param ordersTotal |
| | | * @param v |
| | | * @param refundRecordItem |
| | | */ |
| | | private static void handRefundPromotion(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem v) { |
| | | private static RefundCarryVo handRefundPromotion(String operationId, RefundRecord refundRecord, OrdersTotal ordersTotal |
| | | , RefundRecordItem refundRecordItem,RefundCarryVo refundCarryVo,CommonService commonService) { |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | |
| | | //查看订单信息 |
| | | OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); |
| | | if(orderItem==null ){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息!"); |
| | | OrderItem orderItem = commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
| | | if(orderItem == null ){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息[84]!"); |
| | | } |
| | | |
| | | map.put("refundRecordItemId",v.getId()); |
| | | sqlSentence.setSqlSentence("select * from refund_record_item_source where refundRecordItemId =#{m.refundRecordItemId}"); |
| | | //获取退款二级单 |
| | | map.put("refundRecordItemId",refundRecordItem.getId()); |
| | | sqlSentence.setSqlSentence("select * from refund_record_item_source where isDel = 0 AND refundRecordItemId = #{m.refundRecordItemId}"); |
| | | List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence); |
| | | if( sons!=null && sons.size()>0 ){ |
| | | for (RefundRecordItemSource son : sons) { |
| | | switch (GroupTypeEnum.getCode(son.getType())){ |
| | | case PROJECT: |
| | | v.setOrderItemId(son.getId()); |
| | | v.setRefundNum(son.getRefundNum()); |
| | | handRefundNoSonExecution(commonService, sqlSentence, map, refundRecord, son); |
| | | break; |
| | | case RETAIL: |
| | | v.setOrderItemId(son.getId()); |
| | | v.setRefundNum(son.getRefundNum()); |
| | | handRefundSonRerail(commonService, sqlSentence, map, refundRecord, son); |
| | | break; |
| | | case INCREMENT: |
| | | //增值金 |
| | | |
| | | //根据支付记录总表的标识来整合已退的金额,key值:支付记录总表标识,value:金额数据 |
| | | Map<String,RefundRecordConsumePay> refundRecordConsumePayMap = new HashMap<>(); |
| | | RefundRecordConsumePay refundRecordConsumePay; |
| | | //计算本次退款方式的划扣金额 |
| | | BigDecimal deductionTotal = BigDecimal.ZERO; |
| | | //计算本次退款方式的现金金额 |
| | | BigDecimal cashTotal = BigDecimal.ZERO; |
| | | |
| | | for (RefundRecordItemSource son : sons) { |
| | | //初始化总结构携带参数 |
| | | refundCarryVo.setRefundConsumePayList(new ArrayList<>()); |
| | | refundCarryVo.setDeductionTotal(BigDecimal.ZERO); |
| | | refundCarryVo.setCashTotal(BigDecimal.ZERO); |
| | | switch (GroupTypeEnum.getCode(son.getType())){ |
| | | case PROJECT: |
| | | refundCarryVo = handRefundNoSonExecution(refundRecord,refundRecordItem,son,refundCarryVo,commonService); |
| | | break; |
| | | case RETAIL: |
| | | refundCarryVo = handRefundSonRerail(refundRecord,son,refundCarryVo,commonService); |
| | | if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ |
| | | //是卡包的,刪除卡包使用 |
| | | deleteUserCardUsed(orderItem.getUserCardId(),commonService); |
| | | } |
| | | break; |
| | | case INCREMENT: |
| | | //增值金 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
| | | 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); |
| | | break; |
| | | case STORED: |
| | | //储值金额 |
| | | } |
| | | break; |
| | | case STORED: |
| | | //储值金额 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
| | | 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); |
| | | break; |
| | | case INTEGRAL: |
| | | //积分 |
| | | } |
| | | break; |
| | | case INTEGRAL: |
| | | //积分 |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
| | | 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); |
| | | break; |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | deductionTotal = deductionTotal.add(refundCarryVo.getDeductionTotal()); |
| | | cashTotal = cashTotal.add(refundCarryVo.getCashTotal()); |
| | | //遍历叠加支付方式记录的退款金额 |
| | | for(RefundRecordConsumePay re:refundCarryVo.getRefundConsumePayList()){ |
| | | refundRecordConsumePay = refundRecordConsumePayMap.computeIfAbsent(re.getConsumePayId(),k->new RefundRecordConsumePay(BigDecimal.ZERO,re.getNumberNo(),re.getConsumePayId())); |
| | | refundRecordConsumePay.setRefundTotal(refundRecordConsumePay.getRefundTotal().add(re.getRefundTotal())); |
| | | } |
| | | } |
| | | |
| | | //更改二级子订单退款状态 |
| | | //转载返回支付方式记录的退款金额 |
| | | List<RefundRecordConsumePay> refundRecordConsumePayList = new ArrayList<>(); |
| | | for (Map.Entry<String, RefundRecordConsumePay> entry : refundRecordConsumePayMap.entrySet()) { |
| | | refundRecordConsumePayList.add(entry.getValue()); |
| | | } |
| | | refundCarryVo.setCashTotal(cashTotal); |
| | | refundCarryVo.setDeductionTotal(deductionTotal); |
| | | refundCarryVo.setRefundConsumePayList(refundRecordConsumePayList); |
| | | |
| | | //获取其子项 |
| | | map.put("orderItemId",orderItem.getId()); |
| | | sqlSentence.setSqlSentence("select * from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0"); |
| | | sqlSentence.setSqlSentence("select refundStatus from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0"); |
| | | List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); |
| | | |
| | | Integer refundStatus; |
| | | Integer refundNum = 0; |
| | | List<Integer> collect = orderItemSonList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList()); |
| | | |
| | | if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){ |
| | | orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); |
| | | orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
| | | orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); |
| | | orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
| | | }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ |
| | | orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); |
| | | if(collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
| | | }else{ |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_NONE; |
| | | } |
| | | }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; |
| | | refundNum = orderItem.getBuyNum(); |
| | | }else { |
| | | orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH); |
| | | orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | orderItem.setHasReNum(orderItem.getBuyNum()); |
| | | refundStatus = OrderTotalConstants.STATUS_REFUND_NONE; |
| | | } |
| | | |
| | | commonService.updateAll(OrderItemMapper.class,orderItem); |
| | | //更新子订单信息 |
| | | updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundNum,commonService); |
| | | |
| | | return refundCarryVo; |
| | | } |
| | | /** |
| | | * 退款-处理二级子订单未执行划扣 项目类型 |
| | | * @param commonService |
| | | * @param sqlSentence |
| | | * @param map |
| | | |
| | | /**退款-处理二级子订单未执行划扣 项目类型 |
| | | * @param refundRecord |
| | | * @param v |
| | | * @param refundRecordItemSource |
| | | * @param refundCarryVo |
| | | * @param commonService |
| | | */ |
| | | private static void handRefundNoSonExecution(CommonService commonService, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) { |
| | | sqlSentence.setSqlSentence("select * from user_project_item where isDel=0 and commonId='"+v.getOrderItemSonId()+"' and shopId='"+refundRecord.getRefundShopId()+"' " + |
| | | " and userId ='"+refundRecord.getUserId()+"'"); |
| | | UserProjectItem userProjectItem =commonService.selectOne(UserProjectItemMapper.class,sqlSentence); |
| | | if (userProjectItem == null) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到用户子项项目信息"); |
| | | } |
| | | Integer usedNum=userProjectItem.getNotUsedNum()-v.getRefundNum(); |
| | | Integer cancelNum=userProjectItem.getCancelNum()+v.getRefundNum(); |
| | | private static RefundCarryVo handRefundNoSonExecution(RefundRecord refundRecord,RefundRecordItem refundRecordItem, RefundRecordItemSource refundRecordItemSource |
| | | ,RefundCarryVo refundCarryVo,CommonService commonService) { |
| | | |
| | | map.put("usedNum", usedNum); |
| | | map.put("isDel", BaseEntity.NO); |
| | | map.put("cancelNum", cancelNum); |
| | | map.put("userProjectItemId", userProjectItem.getId()); |
| | | sqlSentence.setSqlSentence(" cancelNum=#{m.cancelNum},notUsedNum=#{m.usedNum} where isDel=#{m.isDel} AND id=#{m.userProjectItemId} AND notUsedNum > 0 "); |
| | | commonService.updateWhere(UserProjectItemMapper.class,sqlSentence); |
| | | |
| | | UserProject userProject=commonService.selectOneByKey(UserProjectMapper.class,userProjectItem.getUserProjectId()); |
| | | userProject.setNotUsedNum(userProject.getNotUsedNum()-v.getRefundNum()); |
| | | commonService.updateAll(UserProjectMapper.class,userProject); |
| | | //判断操作完了去修改子订单状态 |
| | | OrderItemSon orderItem=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId()); |
| | | if (orderItem==null){ |
| | | logger.info("二级子订单id:{}",v.getOrderItemSonId()); |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息"); |
| | | OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId()); |
| | | if (orderItemSon==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到二级子订单信息"); |
| | | } |
| | | Integer refundStatus=OrderTotalConstants.STATUS_REFUND_NONE; |
| | | if(usedNum==0){ |
| | | //已经没有可以执行数量 |
| | | |
| | | UserProjectItem userProjectItem = getUserProject(orderItemSon.getId(),commonService); |
| | | if(userProjectItem == null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"用户项目获取失败!"); |
| | | } |
| | | if(userProjectItem.getNotUsedNum()<refundRecordItemSource.getRefundNum()){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于可退次数[83]!"); |
| | | } |
| | | |
| | | //计算子单是否还有剩余的可扣疗程数 |
| | | int surplusNum = orderItemSon.getUsedTotal() - orderItemSon.getHasReNum(); |
| | | if(refundRecordItemSource.getRefundNum() > surplusNum){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于可退次数[84]!"); |
| | | } |
| | | |
| | | //处理用户项目,减去用户项目数量 |
| | | UserProjectDeductionVo userProjectDeductionVo= UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_DEDUCTION,null |
| | | ,refundRecordItemSource.getId(),refundRecordItemSource.getRefundNum(),refundRecord.getOperatorAppId(),refundRecord.getOperatorAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getRemarks()+"|用户备注:"+refundRecord.getRefundReason(),commonService); |
| | | |
| | | Integer refundStatus; |
| | | if(surplusNum == refundRecordItemSource.getRefundNum()){ |
| | | refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; |
| | | }else { |
| | | }else{ |
| | | refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
| | | } |
| | | map.put("orderItemId", v.getOrderItemSonId()); |
| | | map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney())); |
| | | map.put("hasReNum",cancelNum/(orderItem.getUsedTotal()/orderItem.getBuyNum())); |
| | | map.put("refundStatus", refundStatus); |
| | | sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} "); |
| | | commonService.updateWhere(OrderItemSonMapper.class,sqlSentence); |
| | | |
| | | //更新子单信息 |
| | | updateOrderItemTwo(orderItemSon,refundStatus,refundRecordItemSource.getRefundMoney(),refundRecordItemSource.getRefundNum(),commonService); |
| | | |
| | | //处理退款支付方式 |
| | | refundCarryVo = refundRecordMotnedItemTwoHandle(userProjectDeductionVo.getDeductionTotal(),refundRecord,refundRecordItemSource,refundCarryVo,commonService); |
| | | |
| | | if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ |
| | | //是卡包的,刪除卡包使用 |
| | | deleteUserCardUsed(orderItemSon.getCardItemInfoId(),orderItemSon.getId(),refundRecordItemSource.getRefundNum(),commonService); |
| | | } |
| | | |
| | | return refundCarryVo; |
| | | } |
| | | /** |
| | | * 退款二级是商品 |
| | | * @param commonService |
| | | * @param sqlSentence |
| | | * @param map |
| | | |
| | | /**退款二级是商品 |
| | | * @param refundRecord |
| | | * @param v |
| | | * @param refundRecordItemSource |
| | | * @param refundCarryVo |
| | | * @param commonService |
| | | * @return |
| | | */ |
| | | private static void handRefundSonRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) { |
| | | private static RefundCarryVo handRefundSonRerail(RefundRecord refundRecord, RefundRecordItemSource refundRecordItemSource |
| | | ,RefundCarryVo refundCarryVo,CommonService commonService) { |
| | | |
| | | //判断操作完了去修改子订单状态 |
| | | OrderItemSon orderItem=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId()); |
| | | if (orderItem==null){ |
| | | OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId()); |
| | | if (orderItemSon==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息"); |
| | | } |
| | | |
| | | map.put("orderItemId", v.getOrderItemSonId()); |
| | | map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney())); |
| | | Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum(); |
| | | map.put("hasReNum",hasReNum); |
| | | map.put("isDel",BaseEntity.NO); |
| | | if (hasReNum==orderItem.getBuyNum()){ |
| | | map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH); |
| | | }else { |
| | | map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART); |
| | | //计算子单是否还有剩余的可扣疗程数 |
| | | int surplusNum = orderItemSon.getBuyNum() - orderItemSon.getHasReNum(); |
| | | if(refundRecordItemSource.getRefundNum() > surplusNum){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于可退次数[84]!"); |
| | | } |
| | | |
| | | sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} "); |
| | | commonService.updateWhere(OrderItemSonMapper.class,sqlSentence); |
| | | Integer refundStatus; |
| | | if(surplusNum == refundRecordItemSource.getRefundNum()){ |
| | | refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; |
| | | }else{ |
| | | refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
| | | } |
| | | |
| | | updateOrderItemTwo(orderItemSon,refundStatus,refundRecordItemSource.getRefundMoney(),refundRecordItemSource.getRefundNum(),commonService); |
| | | |
| | | //处理退款支付方式 |
| | | refundCarryVo = refundRecordMotnedItemTwoHandle(null,refundRecord,refundRecordItemSource,refundCarryVo,commonService); |
| | | |
| | | return refundCarryVo; |
| | | } |
| | | |
| | | /**更新订单一级子单的信息 |
| | | * @param orderItem 订单子单 |
| | | * @param refundStatus 退款状态 |
| | | * @param refundTotal 退款金额 |
| | | * @param refundNum 退款数量 |
| | | * @param commonService 映射 |
| | | */ |
| | | public static void updateOrderItemOne(OrderItem orderItem,Integer refundStatus,BigDecimal refundTotal,Integer refundNum |
| | | ,CommonService commonService){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | |
| | | values.put("orderItemId", orderItem.getId()); |
| | | values.put("refundStatus", refundStatus); |
| | | values.put("refundTotal",refundTotal); |
| | | values.put("refundNum",refundNum); |
| | | values.put("oldHasReNum",orderItem.getHasReNum()); |
| | | sqlSentence.sqlUpdate(" refundStatus=#{m.refundStatus},reTotal=reTotal+#{m.refundTotal},hasReNum=hasReNum+#{m.refundNum}" + |
| | | " where isDel=0 AND id=#{m.orderItemId} AND hasReNum = #{m.oldHasReNum}",values); |
| | | if(commonService.updateWhere(OrderItemMapper.class,sqlSentence) != 1){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"当前订单信息已发生变化,请重试[012]!"); |
| | | } |
| | | } |
| | | |
| | | /**更新订单二级子单的信息 |
| | | * @param orderItemSon 订单子单 |
| | | * @param refundStatus 退款状态 |
| | | * @param refundTotal 退款金额 |
| | | * @param refundNum 退款数量 |
| | | * @param commonService 映射 |
| | | */ |
| | | public static void updateOrderItemTwo(OrderItemSon orderItemSon,Integer refundStatus,BigDecimal refundTotal,Integer refundNum |
| | | ,CommonService commonService){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | |
| | | values.put("id", orderItemSon.getId()); |
| | | values.put("refundStatus", refundStatus); |
| | | values.put("refundTotal",refundTotal); |
| | | values.put("refundNum",refundNum); |
| | | values.put("oldHasReNum",orderItemSon.getHasReNum()); |
| | | sqlSentence.sqlUpdate(" refundStatus=#{m.refundStatus},reTotal=reTotal+#{m.refundTotal},hasReNum=hasReNum+#{m.refundNum}" + |
| | | " where isDel=0 AND id = #{m.id} AND hasReNum = #{m.oldHasReNum}",values); |
| | | if(commonService.updateWhere(OrderItemSonMapper.class,sqlSentence) != 1){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"当前订单信息已发生变化,请重试[012]!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取订单一级子单的支付方式记录 |
| | | * @param orderItemId |
| | | * @param commonService |
| | | * @return |
| | | */ |
| | | public static List<ConsumePayItem> getOrderItemOneConsumePay(String orderItemId,CommonService commonService){ |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | |
| | | //获取子单的支付方式,一级子单支付记录,计算可退款金额 |
| | | values.clear(); |
| | | values.put("typeId",orderItemId); |
| | | sqlSentence.sqlSentence("SELECT * FROM consume_pay_item WHERE isDel = 0 AND typeId = #{m.typeId}",values); |
| | | return commonService.selectList(ConsumePayMapper.class,sqlSentence); |
| | | } |
| | | |
| | | /** |
| | | * 获取订单二级级子单的支付方式记录 |
| | | * @param orderItemId |
| | | * @param commonService |
| | | * @return |
| | | */ |
| | | public static List<ConsumePayItem> getOrderItemTwoConsumePay(String orderItemId,CommonService commonService){ |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | |
| | | //获取子单的支付方式,一级子单支付记录,计算可退款金额 |
| | | values.clear(); |
| | | values.put("typeId",orderItemId); |
| | | sqlSentence.sqlSentence("SELECT * FROM consume_pay_item_son WHERE isDel = 0 AND typeId = #{m.typeId}",values); |
| | | return commonService.selectList(ConsumePayMapper.class,sqlSentence); |
| | | } |
| | | |
| | | /**获取已退款方式金额,根据支付方式编号求和返回 |
| | | * 注意:groupByONumberNo和groupByConsumePayId不能同时使用 |
| | | * @param itemId 子单标识 |
| | | * @param refundRecordItemId 退款子单标识 |
| | | * @param groupByONumberNo 根据支付方式编号求和 |
| | | * @param groupByConsumePayId 根据支付方式记录标识求和 |
| | | * @param commonService 映射 |
| | | * @return 返回已退款方式金额集合 |
| | | */ |
| | | public static List<RefundRecordConsumePay> getRefundRecordConsumePay(String itemId,String refundRecordItemId,boolean groupByONumberNo |
| | | ,boolean groupByConsumePayId,CommonService commonService){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | StringBuilder sql = new StringBuilder(); |
| | | |
| | | sql.append("SELECT"); |
| | | if(groupByONumberNo){ |
| | | sql.append(" numberNo,"); |
| | | } |
| | | if(groupByConsumePayId){ |
| | | sql.append(" consumePayId,"); |
| | | } |
| | | sql.append("SUM(refundTotal) AS refundTotal FROM refund_record_consume_pay a"); |
| | | sql.append(" JOIN refund_record rr ON rr.isDel = 0 AND rr.status = #{status}"); |
| | | sql.append(" WHERE a.isDel = 0"); |
| | | if(StringUtils.noNull(itemId)){ |
| | | sql.append(" AND a.commonId = #{m.commonId}"); |
| | | } |
| | | if(StringUtils.noNull(refundRecordItemId)){ |
| | | sql.append(" AND a.refundRecordItemId = #{m.refundRecordItemId}"); |
| | | } |
| | | if(groupByONumberNo){ |
| | | sql.append(" GROUP BY a.numberNo"); |
| | | } |
| | | if(groupByConsumePayId){ |
| | | sql.append(" GROUP BY a.consumePayId"); |
| | | } |
| | | //获取已退款的支付方式 |
| | | values.put("commonId",itemId); |
| | | values.put("status", RefundStatus.STATUS_SUCC_REFUND); |
| | | sqlSentence.sqlSentence(sql.toString(),values); |
| | | return commonService.selectList(RefundRecordConsumePayMapper.class,sqlSentence); |
| | | } |
| | | |
| | | /**保存退款方式和支付方式关联 |
| | | * @param refundTotal 退款金额 |
| | | * @param commonType 子单级别,可空 |
| | | * @param commonId 子单标识,可空 |
| | | * @param orderId 总单标识 |
| | | * @param numberNo 支付方式编号 |
| | | * @param name 支付方式名称 |
| | | * @param consumePayId 支付方式记录标识 |
| | | * @param refundMethodId 退款方式标识 |
| | | * @param refundRecordItemId 退款子记录标识,可空 |
| | | * @param refundRecordId 退款总记录标识 |
| | | * @param commonService 映射 |
| | | * @return 返回关联记录 |
| | | */ |
| | | public static RefundRecordConsumePay insertRefundRecordConsumePay(BigDecimal refundTotal, String commonType, String commonId, String orderId |
| | | , String numberNo,String name, String consumePayId, String refundMethodId,String refundRecordItemId,String refundRecordId,CommonService commonService){ |
| | | //生成关联记录 |
| | | RefundRecordConsumePay refundRecordConsumePay = new RefundRecordConsumePay(); |
| | | refundRecordConsumePay.setRefundTotal(refundTotal); |
| | | refundRecordConsumePay.setCommonType(commonType); |
| | | refundRecordConsumePay.setCommonId(commonId); |
| | | refundRecordConsumePay.setOrderId(orderId); |
| | | refundRecordConsumePay.setName(name); |
| | | refundRecordConsumePay.setNumberNo(numberNo); |
| | | refundRecordConsumePay.setConsumePayId(consumePayId); |
| | | refundRecordConsumePay.setRefundMethodId(refundMethodId); |
| | | refundRecordConsumePay.setRefundRecordItemId(refundRecordItemId); |
| | | refundRecordConsumePay.setRefundRecordId(refundRecordId); |
| | | commonService.insert(RefundRecordConsumePayMapper.class,refundRecordConsumePay); |
| | | return refundRecordConsumePay; |
| | | } |
| | | |
| | | /**获取可退款的用户卡项 |
| | | * @param sourceId 订单子单标识 |
| | | * @return 可退款的用户卡项 |
| | | */ |
| | | public static List<UserCard> getRefundCard(String sourceId,CommonService commonService){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> sqlMap = new HashMap<>(); |
| | | //获取用户卡项 |
| | | sqlMap.put("sourceId",sourceId); |
| | | sqlMap.put("status",UserCard.TYPE_NO_USED); |
| | | sqlMap.put("effectiveStatus",UserProjectConstants.EFF_STATUS_YES); |
| | | sqlSentence.sqlSentence("SELECT * FROM user_card WHERE isDel = 0 AND sourceId = #{m.sourceId} AND status = #{m.status}" + |
| | | " AND effectiveStatus = #{m.effectiveStatus} AND turnAddId IS NULL",sqlMap); |
| | | return commonService.selectList(UserCardMapper.class,sqlSentence); |
| | | |
| | | } |
| | | |
| | | /**获取用户项目*/ |
| | | public static UserProjectItem getUserProject(String commonId,CommonService commonService){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | |
| | | map.clear(); |
| | | map.put("commonId",commonId); |
| | | sqlSentence.sqlSentence("select * from user_project_item where isDel=0 and commonId=#{m.commonId} and isTransfer = 0",map); |
| | | UserProjectItem userProjectItem =commonService.selectOne(UserProjectItemMapper.class,sqlSentence); |
| | | return userProjectItem; |
| | | } |
| | | |
| | | } |