From 1869f358a6aaccf4e4f76df73f10ef5e1e5d8313 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期五, 31 三月 2023 19:26:59 +0800 Subject: [PATCH] 退款重构 --- phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java | 166 ------- phi_platform_common/src/main/java/com/hx/phip/tool/order/PaymentCountTool.java | 37 + phi_platform_user/src/main/java/com/hx/phip/util/api/PartialRefundUtil.java | 938 ++++++++++++++++++++++++++-------------------- phi_platform_common/src/main/java/com/hx/phip/vo/order/refund/RefundCarryVo.java | 27 + 4 files changed, 599 insertions(+), 569 deletions(-) diff --git a/phi_platform_common/src/main/java/com/hx/phip/tool/order/PaymentCountTool.java b/phi_platform_common/src/main/java/com/hx/phip/tool/order/PaymentCountTool.java index 7aec44f..fa95631 100644 --- a/phi_platform_common/src/main/java/com/hx/phip/tool/order/PaymentCountTool.java +++ b/phi_platform_common/src/main/java/com/hx/phip/tool/order/PaymentCountTool.java @@ -26,17 +26,18 @@ * @param realRefundTotal 宸查��鎬婚噾棰� * @param sum 璐拱鎬绘暟閲� * @param surplusNum 鍓╀綑鏁伴噺 - * @param refunNum 璁$畻鏁伴噺 + * @param refundTotal 璁$畻鎬婚噾棰濓紝绌哄�艰嚜鍔ㄨ绠� + * @param refundNum 璁$畻鏁伴噺 * @param payMethodVoList 鏀粯鏂瑰紡锛屾煡璇onsumePay瀛愮被 * @return 鍙傛暟缁撴瀯 */ public static DistributionRedundVo countMakeWay(String itemId, BigDecimal total, BigDecimal realRefundTotal, Integer sum, Integer surplusNum - , Integer refunNum, List<PayMethodVo> payMethodVoList, CommonService commonService){ + , BigDecimal refundTotal,Integer refundNum, List<PayMethodVo> payMethodVoList, CommonService commonService){ if(surplusNum == null){ throw new TipsException("鍙��娆炬暟閲忎笉鑳戒负绌猴紒"); } - if(refunNum == null){ + if(refundNum == null){ throw new TipsException("閫�娆炬暟閲忎笉鑳戒负绌猴紒"); } @@ -44,21 +45,23 @@ DistributionRedundVo distributionRedundVo = new DistributionRedundVo(); //閫�娆炬暟閲忓崰鎬绘暟鍗犳瘮璁$畻 - BigDecimal scale = BigDecimal.valueOf(refunNum).divide(BigDecimal.valueOf(sum),15, RoundingMode.HALF_UP); + BigDecimal scale = BigDecimal.valueOf(refundNum).divide(BigDecimal.valueOf(sum),15, RoundingMode.HALF_UP); //鍓╀綑鍙��娆鹃噾棰� BigDecimal surplusTotal = total.subtract(realRefundTotal).setScale(2,RoundingMode.HALF_UP); //绠楀嚭鏈瑕侀��娆鹃噾棰� - BigDecimal refundTotal; - if(surplusNum.equals(refunNum)) { - //鏈�鍚庨��娆炬暟閲� - refundTotal = surplusTotal; - }else{ - //涓嶆槸鏈�鍚庨��娆炬暟閲忥紝鏍规嵁閫�娆炬暟閲忓崰姣旀潵绠楅��娆鹃噾棰� - refundTotal = total.multiply(scale).setScale(2,RoundingMode.HALF_UP); - if(refundTotal.compareTo(surplusTotal) > 0){ + if(refundTotal == null){ + if(surplusNum.equals(refundNum)) { + //鏈�鍚庨��娆炬暟閲� refundTotal = surplusTotal; + }else{ + //涓嶆槸鏈�鍚庨��娆炬暟閲忥紝鏍规嵁閫�娆炬暟閲忓崰姣旀潵绠楅��娆鹃噾棰� + refundTotal = total.multiply(scale).setScale(2,RoundingMode.HALF_UP); + if(refundTotal.compareTo(surplusTotal) > 0){ + refundTotal = surplusTotal; + } } } + //杞浇鍒嗛厤濂界殑鏀粯鏂瑰紡鍜岄噾棰� @@ -96,7 +99,7 @@ distributionPay.setIsMoneyPay(payMethodVo.getIsMoneyPay()); distributionPay.setIsExecute(payMethodVo.getIsExecute()); - if(surplusNum.equals(refunNum)){ + if(surplusNum.equals(refundNum)){ ////鏄��娆炬渶鍚庣殑鏁伴噺 distributionPay.setRefundTotal(payMethodVo.getSurplusTotal()); }else{ @@ -109,10 +112,10 @@ //濡傛灉绗笁浣嶅皬鏁版湁浣欐暟锛岄偅涔堝氨杩�1鍒嗛挶 distributionPay.setRefundTotal(payMethodVo.getPayTotal().multiply(scale).setScale(2,RoundingMode.UP)); } - //鍒ゆ柇涓庡墿浣欓噾棰濆姣� - if(distributionPay.getRefundTotal().compareTo(payMethodVo.getSurplusTotal()) > 0){ - distributionPay.setRefundTotal(payMethodVo.getSurplusTotal()); - } + } + //鍒ゆ柇涓庡墿浣欓噾棰濆姣� + if(distributionPay.getRefundTotal().compareTo(payMethodVo.getSurplusTotal()) > 0){ + distributionPay.setRefundTotal(payMethodVo.getSurplusTotal()); } if(distributionPay.getRefundTotal().compareTo(refundTotal) > 0){ distributionPay.setRefundTotal(refundTotal); diff --git a/phi_platform_common/src/main/java/com/hx/phip/vo/order/refund/RefundCarryVo.java b/phi_platform_common/src/main/java/com/hx/phip/vo/order/refund/RefundCarryVo.java new file mode 100644 index 0000000..9e97322 --- /dev/null +++ b/phi_platform_common/src/main/java/com/hx/phip/vo/order/refund/RefundCarryVo.java @@ -0,0 +1,27 @@ +package com.hx.phip.vo.order.refund; + +import com.hx.phiappt.model.refund.RefundRecordConsumePay; +import com.hx.phiappt.model.refund.RefundRecordMethod; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author CJH + */ +@Data +public class RefundCarryVo { + + /**閫�娆剧殑閫�娆炬柟寮忛噾棰�-璇ュ弬鏁颁竴寮�濮嬪氨鎼哄甫*/ + private List<RefundRecordMethod> refundRecordMethodList; + + //***************鍐呴儴鎼哄甫浣滅敤鍙傛暟锛屾敞鎰忎娇鐢�******************** + /**鍒嗛厤鐨勯��娆炬柟寮忎笌鏀粯璁板綍鐨勫叧鑱旀暟鎹�*/ + private List<RefundRecordConsumePay> refundConsumePayList; + /**鍒嗛厤鐨勫垝鎵i噾棰濇�诲拰*/ + private BigDecimal deductionTotal; + /**鍒嗛厤鐨勭幇閲戦噾棰濇�诲拰*/ + private BigDecimal cashTotal; + +} diff --git a/phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java b/phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java index 43b9cff..07dd0cf 100644 --- a/phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java +++ b/phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java @@ -28,7 +28,7 @@ import com.hx.phip.service.refund.RefundRecordMethodService; import com.hx.phip.service.refund.RefundRecordService; import com.hx.phip.tool.CreateNo; -import com.hx.phip.tool.order.PartialRefundUtil; +import com.hx.phip.util.api.PartialRefundUtil; import com.hx.phip.tool.order.PaymentCountTool; import com.hx.phip.util.api.*; import com.hx.phip.vo.order.payment.PayMethodVo; @@ -554,7 +554,8 @@ //璁$畻閫�娆炬柟寮忛噾棰� DistributionRedundVo distributionRedundVo = PaymentCountTool.countMakeWay(orderItem.getId(),orderItem.getActualTotal(),refundRecordItem==null?BigDecimal.ZERO:refundRecordItem.getOccupyRefundTotal() - ,buyNum,surplusNum,orderItemRefundDto.getRefundNum(),payMethodVoList,commonService); + ,buyNum,surplusNum,null,orderItemRefundDto.getRefundNum(),payMethodVoList,commonService); + distributionRedundVo.setGoodsType(orderItem.getType()); distributionRedundVo.setGoodsName(orderItem.getGoodsName()); @@ -624,7 +625,7 @@ RefundRecordItemSource refundRecordItemSource = commonService.selectOne(RefundRecordItemSourceMapper.class,sqlSentence); //璁$畻閫�娆炬柟寮忛噾棰� DistributionRedundVo distributionRedundVo = PaymentCountTool.countMakeWay(orderItemSon.getId(),orderItemSon.getActualTotal(),refundRecordItemSource==null?BigDecimal.ZERO:refundRecordItemSource.getOccupyRefundTotal() - ,buyNum,surplusNum,orderItemSourceRefundDto.getRefundNum(),payMethodVoList,commonService); + ,buyNum,surplusNum,null,orderItemSourceRefundDto.getRefundNum(),payMethodVoList,commonService); distributionRedundVo.setGoodsType(orderItemSon.getType()); distributionRedundVo.setGoodsName(orderItemSon.getGoodsName()); return distributionRedundVo; @@ -1190,11 +1191,6 @@ */ public void insertRefundRecordItem(OrderRefundDto orderRefundDto,StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord,List<RefundRecordMethod> refundRecordMethodList){ - SqlSentence sqlSentence = new SqlSentence(); - Map<String,Object> map=new HashMap<>(); - - sqlSentence.sqlSentence(" select * from user_project_item where commonId=#{m.commonId} and isDel=0 AND isTransfer = 0 ",map); - map.put("userId", ordersTotal.getUserId()); orderNodeBuilder.append("-璁板綍閫�娆捐鎯�"); //璁$畻閲戦鍗犳瘮锛屽鎴烽�夋嫨閫�娆炬�婚噾棰濆拰鍙��鎬婚噾棰濆崰姣� @@ -1208,9 +1204,6 @@ //鎬婚��娆鹃噾棰濓紝鐢ㄤ簬鍚庨潰璁$畻鍒嗘憡閲戦 BigDecimal refundTotal = refundRecord.getRefundTotal(); - //瑁呰浇鍙傛暟 - List<RefundRecordItemMethod> refundRecordItemMethodList; - //鍚庨潰璁捐鍒嗛厤閲戦闂锛岃杩涜鍗囧簭鎺掑簭锛岄伩鍏嶅埌鏈�鍚庝笉澶� List<OrderItemRefundDto> refundList = orderRefundDto.getRefundList(); refundList = refundList.stream().sorted(Comparator.comparing(OrderItemRefundDto::getApproveRefundTotal)).collect(Collectors.toList()); @@ -1218,14 +1211,9 @@ /////寮曠敤鍙傛暟 RefundRecordItem refundRecordItem; OrderItemRefundDto orderItemRefundDto; - RefundRecordItemMethod refundRecordItemMethod; - RefundRecordMethod refundRecordMethod; OrderItem orderItem; - //鏀粯鏂瑰紡鍗犳瘮 - BigDecimal payMothedPercentage; for(int i = 0;i < refundList.size();i++){ orderItemRefundDto = refundList.get(i); - refundRecordItemMethodList = new ArrayList<>(); orderItem = orderItemMapper.selectOneByKey(orderItemRefundDto.getOrderItemId()); if(orderItem == null){ @@ -1270,84 +1258,18 @@ //璁$畻鍓╀綑瑕佸垎閰嶇殑閫�娆炬�婚噾棰� refundTotal = refundTotal.subtract(refundRecordItem.getRefundMoney()).setScale(2,RoundingMode.HALF_UP); - /* //璁$畻閫�娆炬柟寮忕殑鍗犳瘮 - if(orderRefundDto.getRefundTotal().compareTo(BigDecimal.ZERO) > 0){ - payMothedPercentage = refundRecordItem.getRefundMoney().divide(orderRefundDto.getRefundTotal(),15,RoundingMode.HALF_UP); - }else{ - payMothedPercentage = BigDecimal.ZERO; - } - ////閫�娆炬柟寮忛噾棰濆垎閰� - if(refundRecordMethodList != null && refundRecordMethodList.size() > 0){ - //杩涜鍗囧簭鎺掑簭锛岄伩鍏嶅悗闈笉澶熷垎閰� - refundRecordMethodList = refundRecordMethodList.stream().sorted(Comparator.comparing(RefundRecordMethod::getpTotal)).collect(Collectors.toList()); - - //瀛愬崟閫�娆炬柟寮� - BigDecimal refundTotalItem = refundRecordItem.getRefundMoney(); - - for(int j = 0;j <refundRecordMethodList.size();j++){ - refundRecordMethod = refundRecordMethodList.get(j); - - ////瀛愰」閫�娆炬柟寮忓~鍏� - 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(j == refundRecordMethodList.size()-1){ - ////鏈�鍚庝竴涓� - refundRecordItemMethod.setActualTotal(refundTotalItem); - }else { - ////涓嶆槸鏈�鍚庝竴涓� - refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); - } - if(refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getActualTotal()) > 0){ - refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal()); - } - if(refundRecordItemMethod.getActualTotal().compareTo(refundTotalItem) > 0){ - refundRecordItemMethod.setActualTotal(refundTotalItem); - } - //鍒ゆ柇涓庡墿浣欑殑鏈垎閰嶉��娆炬柟寮忛噾棰� - if (refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getpTotal()) > 0){ - refundRecordItemMethod.setActualTotal(refundRecordMethod.getpTotal()); - } - refundRecordItemMethod.setCommonType(OrderSourceConstans.TYPE_PROJECT); - refundRecordItemMethod.setCommonId(refundRecordItem.getOrderItemId()); - refundRecordItemMethod.setOrderId(refundRecordMethod.getOrderId()); - refundRecordItemMethod.setRefundRecordItemId(refundRecordItem.getId()); - refundRecordItemMethod.setRefundRecordId(refundRecord.getId()); - refundRecordItemMethodMapper.insert(refundRecordItemMethod); - //杞浇鍒嗛厤濂界殑 - refundRecordItemMethodList.add(refundRecordItemMethod); - - //鍑忓幓宸茬粡鍒嗛厤鐨勯��娆炬柟寮忛噾棰� - refundRecordMethod.setpTotal(refundRecordMethod.getpTotal().subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP)); - //璁$畻瀛愰」鍓╀綑鍙垎閰嶉噾棰� - refundTotalItem = refundTotalItem.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); - } - if(refundTotalItem.compareTo(BigDecimal.ZERO) > 0){ - throw new TipsException("鍒嗛厤閫�娆鹃噾棰濋敊璇痆77]"); - } - }*/ //瀛愬崟瀛愰」澶勭悊 - insertRefundRecordItemTwo(refundRecordItem,refundRecord,orderItemRefundDto.getOrderItemSourceRefundDtos(),refundRecordItemMethodList); + insertRefundRecordItemTwo(refundRecordItem,refundRecord,orderItemRefundDto.getOrderItemSourceRefundDtos()); } - //澶勭悊姣忎釜椤圭洰姣忎釜鏀粯鏂瑰紡鐨勫垎鎽婇噾棰� - //handleRefundRecordItemMethod(refundRecord, refundRecordItems); + if(refundTotal.compareTo(BigDecimal.ZERO) > 0){ + throw new TipsException("閫�娆鹃噾棰濆垎閰嶉敊璇痆01]锛�"); + } + } /**浜岀骇瀛愬崟澶勭悊*/ - public void insertRefundRecordItemTwo(RefundRecordItem recordItem,RefundRecord refundRecord,List<OrderItemSourceRefundDto> orderItemSourceRefundDtos - ,List<RefundRecordItemMethod> refundRecordItemMethodList){ + public void insertRefundRecordItemTwo(RefundRecordItem recordItem,RefundRecord refundRecord,List<OrderItemSourceRefundDto> orderItemSourceRefundDtos){ if(orderItemSourceRefundDtos == null || orderItemSourceRefundDtos.size() == 0){ return; } @@ -1369,10 +1291,7 @@ OrderItemSon orderItemSon; OrderItemSourceRefundDto orderItemSourceRefundDto; RefundRecordItemSource refundRecordItemSource; - RefundRecordItemMethod refundRecordItemMethod; - RefundRecordItemMethod refundRecordItemSonMethod; - //鏀粯鏂瑰紡鍗犳瘮 - BigDecimal payMothedPercentage; + for(int i = 0;i<orderItemSourceRefundDtos.size();i++){ orderItemSourceRefundDto = orderItemSourceRefundDtos.get(i); @@ -1418,67 +1337,10 @@ //鍑忓幓宸茬粡鍒嗛厤閫�娆鹃噾棰� refundTotal = refundTotal.subtract(refundRecordItemSource.getRefundMoney()).setScale(2,RoundingMode.HALF_UP); - /*//璁$畻鏀粯鏂瑰紡閲戦姣斾緥 - if(recordItem.getRefundMoney().compareTo(BigDecimal.ZERO) > 0){ - payMothedPercentage = orderItemSourceRefundDto.getRefundMoney().divide(recordItem.getRefundMoney(),15,RoundingMode.HALF_UP); - }else{ - payMothedPercentage = BigDecimal.ZERO; - } - //////閲戦鍒嗛厤 - //閫�娆炬柟寮忛噾棰濆垎閰� - if(refundRecordItemMethodList != null && refundRecordItemMethodList.size() > 0){ - //杩涜鍗囧簭鎺掑簭锛岄伩鍏嶅悗闈笉澶� - refundRecordItemMethodList = refundRecordItemMethodList.stream().sorted(Comparator.comparing(RefundRecordItemMethod::getpTotal)).collect(Collectors.toList()); + } - BigDecimal refundTotalItem = refundRecordItemSource.getRefundMoney(); - for(int j = 0;j <refundRecordItemMethodList.size();j++){ - refundRecordItemMethod = refundRecordItemMethodList.get(j); - - ////瀛愰」閫�娆炬柟寮忓~鍏� - refundRecordItemSonMethod = new RefundRecordItemMethod(); - refundRecordItemSonMethod.setNumberNo(refundRecordItemMethod.getNumberNo()); - refundRecordItemSonMethod.setName(refundRecordItemMethod.getName()); - //鏀粯鏂瑰紡 - refundRecordItemSonMethod.setPaymentMethodId(refundRecordItemMethod.getPaymentMethodId()); - refundRecordItemSonMethod.setIsMoneyPay(refundRecordItemMethod.getIsMoneyPay()); - refundRecordItemSonMethod.setIsExecute(refundRecordItemMethod.getIsExecute()); - refundRecordItemSonMethod.setIsPay(refundRecordItemMethod.getIsPay()); - //閫�娆炬柟寮� - refundRecordItemSonMethod.setRefundNumberNo(refundRecordItemMethod.getRefundNumberNo()); - refundRecordItemSonMethod.setRefundName(refundRecordItemMethod.getRefundName()); - refundRecordItemSonMethod.setRefundMethodId(refundRecordItemMethod.getRefundMethodId()); - - //閫�娆鹃噾棰� - if(j == refundRecordItemMethodList.size()-1){ - ////鏈�鍚庝竴涓� - refundRecordItemSonMethod.setActualTotal(refundTotalItem); - }else { - ////涓嶆槸鏈�鍚庝竴涓� - refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); - } - if(refundRecordItemSonMethod.getActualTotal().compareTo(refundRecordItemMethod.getActualTotal()) > 0){ - refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getActualTotal()); - } - if(refundRecordItemSonMethod.getActualTotal().compareTo(refundTotalItem) > 0){ - refundRecordItemSonMethod.setActualTotal(refundTotalItem); - } - if(refundRecordItemSonMethod.getActualTotal().compareTo(refundRecordItemMethod.getpTotal()) > 0){ - refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getpTotal()); - } - - refundRecordItemSonMethod.setCommonType(OrderSourceConstans.TYPE_RETAIL); - refundRecordItemSonMethod.setCommonId(refundRecordItemSource.getOrderItemSonId()); - refundRecordItemSonMethod.setOrderId(refundRecordItemMethod.getOrderId()); - refundRecordItemSonMethod.setRefundRecordItemId(refundRecordItemSource.getId()); - refundRecordItemSonMethod.setRefundRecordId(refundRecord.getId()); - refundRecordItemMethodMapper.insert(refundRecordItemSonMethod); - - //鍑忓幓宸茬粡鍒嗛厤鐨勯��娆鹃噾棰� - refundTotalItem = refundTotalItem.subtract(refundRecordItemSonMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); - //鍑忓幓宸茬粡鍒嗛厤鐨勯��娆炬柟寮忛噾棰� - refundRecordItemMethod.setpTotal(refundRecordItemMethod.getpTotal().subtract(refundRecordItemSonMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP)); - } - }*/ + if(refundTotal.compareTo(BigDecimal.ZERO) > 0){ + throw new TipsException("閫�娆鹃噾棰濆垎閰嶉敊璇痆02]锛�"); } } diff --git a/phi_platform_common/src/main/java/com/hx/phip/tool/order/PartialRefundUtil.java b/phi_platform_user/src/main/java/com/hx/phip/util/api/PartialRefundUtil.java similarity index 60% rename from phi_platform_common/src/main/java/com/hx/phip/tool/order/PartialRefundUtil.java rename to phi_platform_user/src/main/java/com/hx/phip/util/api/PartialRefundUtil.java index 0f5bea3..c4a2791 100644 --- a/phi_platform_common/src/main/java/com/hx/phip/tool/order/PartialRefundUtil.java +++ b/phi_platform_user/src/main/java/com/hx/phip/util/api/PartialRefundUtil.java @@ -1,4 +1,4 @@ -package com.hx.phip.tool.order; +package com.hx.phip.util.api; import com.hx.common.service.CommonService; import com.hx.exception.TipsException; @@ -12,7 +12,6 @@ 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.consume.ConsumePayItemSon; import com.hx.phiappt.model.coupon.CouponNumber; import com.hx.phiappt.model.coupon.CouponOrderDiscountLog; import com.hx.phiappt.model.order.*; @@ -24,7 +23,8 @@ 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.payment.PayMethodVo; +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; @@ -83,6 +83,15 @@ if(userMoney==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(refundRecord,commonService); @@ -251,39 +260,140 @@ } } - /**澶勭悊涓�绾у瓙閫�娆炬柟寮忔暟鎹�*/ - public static List<RefundRecordConsumePay> refundRecordMotnedItemHandle(RefundRecord refundRecord,RefundRecordItem refundRecordItem - ,List<RefundRecordMethod> refundRecordMethodList,CommonService commonService){ + /**澶勭悊涓�绾у瓙閫�娆炬柟寮忔暟鎹� + * @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<>(); - //鑾峰彇閫�娆炬柟寮忎俊鎭� - values.put("refundRecordItemId",refundRecordItem.getId()); - sqlSentence.sqlSentence("SELECT * FROM refund_record_item_method WHERE isDel = 0 AND refundRecordItemId = #{m.refundRecordItemId}",values); - List<RefundRecordItemMethod> refundRecordItemMethodList = commonService.selectList(RefundRecordItemMethodMapper.class,sqlSentence); - - //瑁呰浇鏀粯鏂瑰紡閫�娆句俊鎭� - List<RefundRecordConsumePay> refundConsumePayList = new ArrayList<>(); - - //娌℃湁閫�娆炬柟寮忥紝璺宠繃褰撳墠澶勭悊 - if(refundRecordItemMethodList.size() == 0){ - return refundConsumePayList; + //鏀粯鏂瑰紡鍗犳瘮 + BigDecimal payMothedPercentage; + //璁$畻閫�娆炬柟寮忕殑鍗犳瘮 + if(refundRecord.getRefundTotal().compareTo(BigDecimal.ZERO) > 0){ + payMothedPercentage = refundRecordItem.getRefundMoney().divide(refundRecord.getRefundTotal(),15,RoundingMode.HALF_UP); + }else{ + payMothedPercentage = BigDecimal.ZERO; } - //鑾峰彇瀛愬崟鐨勬敮浠樻柟寮忥紝涓�绾у瓙鍗曟敮浠樿褰� - values.clear(); - values.put("typeId",refundRecordItem.getOrderItemId()); - sqlSentence.sqlSentence("SELECT * FROM consume_pay_item WHERE isDel = 0 AND typeId = #{m.typeId}",values); - List<ConsumePayItem> consumePayItemList = commonService.selectList(ConsumePayMapper.class,sqlSentence); + //澶勭悊閫�娆炬柟寮� + refundCarryVo = insertRefundItemMothed(refundRecordItem.getId(),refundRecordItem.getRefundMoney(),payMothedPercentage,OrderSourceConstans.TYPE_PROJECT + ,refundRecordItem.getOrderItemId(),refundCarryVo,refundRecord,commonService); + //鏇存柊鐜伴噾鍜屽垝鎵i噾棰濅繚瀛� + 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鍊硷細鏀粯缂栧彿锛寁alue锛氬彲閫�閲戦 + Map<String,BigDecimal> noMap = new HashMap<>(); + BigDecimal surplusTotal; + ////瀛樺偍鏀粯鏂瑰紡缂栧彿鐨勬敮浠樻柟寮忚褰曪紝鏍规嵁鏀粯缂栧彿鏁村悎锛屽悗闈㈢殑鍒ゆ柇浼氱敤鍒帮紝key鍊硷細鏀粯缂栧彿锛寁alue锛氭敮浠樿褰曢泦鍚� + Map<String,List<ConsumePayItem>> noPayItemMap = new HashMap<>(); + List<ConsumePayItem> noPayItemList; + + ////////濉厖鏀粯鏂瑰紡璁板綍鐨勯��娆鹃噾棰濓紝璁$畻鍓╀綑鍙��閲戦锛屾敮浠樻柟寮忚褰曠殑閫�娆鹃噾棰濋渶瑕佸幓鏌ヨ璁$畻鑾峰彇 //鑾峰彇宸茬粡閫�娆剧殑閫�娆炬柟寮忛噾棰濓紝鏍规嵁鏀粯鏂瑰紡璁板綍鐨勬爣璇嗘眰鍜岃繑鍥� - List<RefundRecordConsumePay> refundRecordConsumePayList = getRefundRecordConsumePay(refundRecordItem.getOrderItemId(),null,false,true,commonService); - //杞寲鎴恗ap + List<RefundRecordConsumePay> refundRecordConsumePayList = getRefundRecordConsumePay(orderItemId,null,false,true,commonService); + //杞寲鎴恗ap锛屽彲浠ユ牴鎹敮浠樻柟寮忚褰曠殑鏍囪瘑鐩存帴鑾峰彇鍒版暟鎹� 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){ @@ -292,97 +402,93 @@ //鍙��娆鹃噾棰� 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); + } //杩涜鍗囧簭鎺掑簭锛岄伩鍏嶅悗闈笉澶熷垎閰� - refundRecordMethodList = refundRecordMethodList.stream().sorted(Comparator.comparing(RefundRecordMethod::getpTotal)).collect(Collectors.toList()); + 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); + } - //閫�娆剧殑鍒掓墸閲戦 - BigDecimal deductionTotal = BigDecimal.ZERO; - //閫�娆剧殑鐜伴噾閲戦 - BigDecimal cashTotal = BigDecimal.ZERO; - //閫�娆炬柟寮忔�婚噾棰� - BigDecimal mothedTotal; - //鏀粯鏂瑰紡鎵e噺閲戦 - BigDecimal mothedCutTotal; - ///////寮曠敤瀵硅薄 + List<RefundRecordConsumePay> refundConsumePayList = new ArrayList<>(); + + ////寮曠敤瀵硅薄 RefundRecordItemMethod refundRecordItemMethod; - //鏀粯鏂瑰紡鍗犳瘮 - BigDecimal payMothedPercentage; + RefundRecordMethod refundRecordMethod; + //闇�瑕侀��鐨勯��娆剧紪鍙烽噾棰� + BigDecimal mothedTotal; + //鏀粯缂栧彿鍒嗛厤鐨勯��娆鹃噾棰� + BigDecimal mothedCutTotal; + //鍒嗛厤鐨勫垝鎵i噾棰濇�诲拰 + BigDecimal deductionTotal = BigDecimal.ZERO; + //鍒嗛厤鐨勭幇閲戦噾棰濇�诲拰 + BigDecimal cashTotal = BigDecimal.ZERO; - for(RefundRecordMethod refundRecordMethod:refundRecordMethodList){ - //璁$畻閫�娆炬柟寮忕殑鍗犳瘮 - if(refundRecord.getRefundTotal().compareTo(BigDecimal.ZERO) > 0){ - payMothedPercentage = refundRecordItem.getRefundMoney().divide(refundRecord.getRefundTotal(),15,RoundingMode.HALF_UP); - }else{ - payMothedPercentage = 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); + } - //瀛愬崟閫�娆炬柟寮� - BigDecimal refundTotalItem = refundRecordItem.getRefundMoney(); + refundRecordItemMethod.setCommonType(orderItemType); + refundRecordItemMethod.setCommonId(orderItemId); + refundRecordItemMethod.setOrderId(refundRecordMethod.getOrderId()); + refundRecordItemMethod.setRefundRecordItemId(refundItemId); + refundRecordItemMethod.setRefundRecordId(refundRecord.getId()); + commonService.insert(RefundRecordItemMethodMapper.class,refundRecordItemMethod); - for(int j = 0;j <refundRecordMethodList.size();j++){ - refundRecordMethod = refundRecordMethodList.get(j); + //鍑忓幓宸茬粡鍒嗛厤鐨勯��娆炬柟寮忛噾棰� + 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); - ////瀛愰」閫�娆炬柟寮忓~鍏� - 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(j == refundRecordMethodList.size()-1){ - ////鏈�鍚庝竴涓� - refundRecordItemMethod.setActualTotal(refundTotalItem); - }else { - ////涓嶆槸鏈�鍚庝竴涓� - refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); - } - if(refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getActualTotal()) > 0){ - refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal()); - } - if(refundRecordItemMethod.getActualTotal().compareTo(refundTotalItem) > 0){ - refundRecordItemMethod.setActualTotal(refundTotalItem); - } - //鍒ゆ柇涓庡墿浣欑殑鏈垎閰嶉��娆炬柟寮忛噾棰� - if (refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getpTotal()) > 0){ - refundRecordItemMethod.setActualTotal(refundRecordMethod.getpTotal()); - } - refundRecordItemMethod.setCommonType(OrderSourceConstans.TYPE_PROJECT); - refundRecordItemMethod.setCommonId(refundRecordItem.getOrderItemId()); - refundRecordItemMethod.setOrderId(refundRecordMethod.getOrderId()); - refundRecordItemMethod.setRefundRecordItemId(refundRecordItem.getId()); - refundRecordItemMethod.setRefundRecordId(refundRecord.getId()); - commonService.insert(RefundRecordItemMethodMapper.class,refundRecordItemMethod); - //杞浇鍒嗛厤濂界殑 - refundRecordItemMethodList.add(refundRecordItemMethod); - - //鍑忓幓宸茬粡鍒嗛厤鐨勯��娆炬柟寮忛噾棰� - refundRecordMethod.setpTotal(refundRecordMethod.getpTotal().subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP)); - //璁$畻瀛愰」鍓╀綑鍙垎閰嶉噾棰� - refundTotalItem = refundTotalItem.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); - } - if(refundTotalItem.compareTo(BigDecimal.ZERO) > 0){ - throw new TipsException("鍒嗛厤閫�娆鹃噾棰濋敊璇痆77]"); - } - - } - - //澧炲姞澧炲�奸噾 - for(RefundRecordItemMethod refundRecordItemMethod:refundRecordItemMethodList){ - //褰撳墠閫�娆炬柟寮忕殑閫�娆鹃噾棰� + ///////鐢熸垚鍏宠仈鏀粯鏂瑰紡璁板綍鍜岄��娆炬柟寮忓叧鑱� + noPayItemList = noPayItemMap.computeIfAbsent(refundRecordItemMethod.getNumberNo(),k->new ArrayList<>()); mothedTotal = refundRecordItemMethod.getActualTotal(); - - for(ConsumePayItem consumePayItem:consumePayItemList){ + for(ConsumePayItem consumePayItem:noPayItemList){ if(consumePayItem.getpTotal().compareTo(BigDecimal.ZERO) < 1){ continue; } @@ -393,147 +499,41 @@ mothedCutTotal = consumePayItem.getpTotal(); } - //鏇存柊鏀粯璁板綍淇℃伅 - values.clear(); - values.put("refundTotal",mothedCutTotal); - values.put("id",consumePayItem.getId()); - sqlSentence.sqlUpdate("refundTotal = refundTotal + #{m.refundTotal} WHERE id = #{m.id} AND actualTotal >= refundTotal + #{m.refundTotal}",values); - if(commonService.updateWhere(ConsumePayItemMapper.class,sqlSentence) != 1){ - throw new TipsException("閫�娆鹃噾棰濋敊璇痆424]锛�"); - } - //鍒掓墸閲戦 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.getId(),refundRecordItemMethod.getId(),refundRecordItem.getId(),refundRecord.getId(),commonService); - refundRecordConsumePayList.add(refundRecordConsumePay); + ,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(mothedTotal.compareTo(BigDecimal.ZERO) > 0){ - throw new TipsException("閫�娆鹃噾棰濋敊璇痆543]锛�"); - } - - //鏇存柊鐜伴噾鍜屽垝鎵i噾棰濅繚瀛� - values.put("deductionTotal",deductionTotal); - values.put("cashTotal",cashTotal); - values.put("id",refundRecordItem.getId()); - sqlSentence.sqlUpdate("deductionTotal = #{m.deductionTotal},cashTotal = #{m.cashTotal} WHERE id = #{m.id}",values); - if(commonService.updateWhere(RefundRecordItemMapper.class,sqlSentence) != 1){ - throw new TipsException("鏇存柊閫�娆惧瓙椤逛俊鎭け璐ワ紒"); - } } - return refundRecordConsumePayList; - } - - /**澶勭悊浜岀骇瀛愰��娆炬柟寮忔暟鎹�*/ - public static void refundRecordMotnedItemTwoHandle(RefundRecord refundRecord,RefundRecordItemSource refundRecordItemSource,CommonService commonService){ - - SqlSentence sqlSentence = new SqlSentence(); - Map<String,Object> values = new HashMap<>(); - - //鑾峰彇閫�娆炬柟寮� - values.put("refundRecordItemId",refundRecordItemSource.getId()); - sqlSentence.sqlSentence("SELECT * FROM refund_record_item_method WHERE isDel = 0 AND refundRecordItemId = #{m.refundRecordItemId}",values); - List<RefundRecordItemMethod> refundRecordItemMethodList = commonService.selectList(RefundRecordItemMethodMapper.class,sqlSentence); - - //閫�娆炬柟寮忔�婚噾棰� - BigDecimal mothedTotal; - //鏀粯鏂瑰紡鎵e噺閲戦 - BigDecimal mothedCutTotal; - //寮曠敤瀵硅薄 - RefundRecordConsumePay refundRecordConsumePay; - List<ConsumePayItemSon> consumePayItemSonList; - - BigDecimal deductionTotal = BigDecimal.ZERO; - BigDecimal cashTotal = BigDecimal.ZERO; - - //澧炲姞澧炲�奸噾 - for(RefundRecordItemMethod refundRecordItemMethod:refundRecordItemMethodList){ - mothedTotal = refundRecordItemMethod.getActualTotal(); - - //淇敼瀹為檯閫�娆鹃噾棰� - values.put("realRefundTotal",refundRecordItemMethod.getActualTotal()); - values.put("id",refundRecordItemMethod.getId()); - sqlSentence.sqlUpdate(" realRefundTotal=#{m.realRefundTotal} where id = #{m.id}",values); - if(commonService.updateWhere(RefundRecordItemMethodMapper.class,sqlSentence) != 1){ - throw new TipsException("鏇存柊閫�娆句俊鎭敊璇痆001]"); - } - - //鑾峰彇鏀粯鏂瑰紡 - values.put("orderId",refundRecord.getOrderId()); - values.put("numberNo",refundRecordItemMethod.getNumberNo()); - values.put("typeId",refundRecordItemMethod.getCommonId()); - //涓�绾у瓙鍗曟敮浠樿褰� - sqlSentence.sqlSentence("SELECT *,ROUND(actualTotal-refundTotal,2) AS pTotal FROM consume_pay_item_son WHERE isDel = 0 AND orderId = #{m.orderId} AND numberNo = #{m.numberNo} AND typeId = #{m.typeId} ORDER BY pTotal ASC",values); - consumePayItemSonList = commonService.selectList(ConsumePayMapper.class,sqlSentence); - for(ConsumePayItemSon consumePayItemSon:consumePayItemSonList){ - if(consumePayItemSon.getpTotal().compareTo(BigDecimal.ZERO) < 1){ - continue; - } - //璁$畻鎵e噺閲戦 - if(consumePayItemSon.getpTotal().compareTo(mothedTotal) > 0){ - mothedCutTotal = mothedTotal; - }else{ - mothedCutTotal = consumePayItemSon.getpTotal(); - } - - //鏇存柊鏀粯璁板綍淇℃伅 - values.clear(); - values.put("refundTotal",mothedCutTotal); - values.put("id",consumePayItemSon.getId()); - sqlSentence.sqlUpdate("refundTotal = refundTotal + #{m.refundTotal} WHERE id = #{m.id} AND actualTotal >= refundTotal + #{m.refundTotal}",values); - if(commonService.updateWhere(ConsumePayItemSonMapper.class,sqlSentence) != 1){ - throw new TipsException("閫�娆鹃噾棰濋敊璇痆426]锛�"); - } - - //鍒掓墸閲戦 - if(consumePayItemSon.getIsMoneyPay().equals(ConsumePayItem.YES)){ - deductionTotal = deductionTotal.add(mothedCutTotal).setScale(2,RoundingMode.HALF_UP); - - } - if(consumePayItemSon.getIsExecute().equals(ConsumePayItem.YES)){ - cashTotal = cashTotal.add(mothedCutTotal).setScale(2,RoundingMode.HALF_UP); - } - - //鐢熸垚鍏宠仈璁板綍 - insertRefundRecordConsumePay(mothedCutTotal,refundRecordItemMethod.getCommonType(),refundRecordItemMethod.getCommonId(),refundRecord.getOrderId(),consumePayItemSon.getNumberNo() - ,consumePayItemSon.getName(),consumePayItemSon.getId(),refundRecordItemMethod.getId(),refundRecordItemSource.getId(),refundRecord.getId(),commonService); - - //璁$畻涓哄垎閰嶉噾棰� - mothedTotal = mothedTotal.subtract(mothedCutTotal).setScale(2, RoundingMode.HALF_UP); - if(mothedTotal.compareTo(BigDecimal.ZERO) < 1){ - //璺冲嚭寰幆 - break; - } - } - - values.put("deductionTotal",deductionTotal); - values.put("cashTotal",cashTotal); - values.put("id",refundRecordItemSource.getId()); - sqlSentence.sqlUpdate("deductionTotal = #{m.deductionTotal},cashTotal = #{m.cashTotal} WHERE id = #{m.id}",values); - if(commonService.updateWhere(RefundRecordItemSourceMapper.class,sqlSentence) != 1){ - throw new TipsException("鏇存柊閫�娆惧瓙椤逛俊鎭け璐ワ紒"); - } - if(mothedTotal.compareTo(BigDecimal.ZERO) > 0){ - throw new TipsException("閫�娆鹃噾棰濋敊璇痆427]锛�"); - } + //鍒ゆ柇鏄惁宸茬粡鍒嗛厤瀹� + if(refundItemTotal.compareTo(BigDecimal.ZERO) > 0){ + throw new TipsException("鍒嗛厤閫�娆鹃噾棰濋敊璇痆"+orderItemType+"]"); } + + refundCarryVo.setDeductionTotal(deductionTotal); + refundCarryVo.setCashTotal(cashTotal); + refundCarryVo.setRefundConsumePayList(refundConsumePayList); + + return refundCarryVo; } @@ -635,15 +635,10 @@ * @param refundRecord * @param commonService */ - public static void numberOfRefunds(String operationId, String operationNme, RefundRecord refundRecord,OrdersTotal ordersTotal,CustomParameter customParameter,CommonService commonService) { + 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.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); //鑾峰彇閫�娆惧瓙鍗� map.clear(); @@ -654,31 +649,54 @@ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒伴��娆惧瓙璁㈠崟淇℃伅"); } - List<RefundRecordConsumePay> refundRecordConsumePayList; + //鏍规嵁鏀粯璁板綍鎬昏〃鐨勬爣璇嗘潵鏁村悎宸查��鐨勯噾棰濓紝key鍊硷細鏀粯璁板綍鎬昏〃鏍囪瘑锛寁alue:閲戦鏁版嵁 + 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(refundRecord,refundRecordItem,commonService); + refundCarryVo = handRefundRerail(refundRecord,refundRecordItem,refundCarryVo,commonService); break; case OrderItemConstants.TYPE_DRUG: - handRefundRerail(refundRecord,refundRecordItem,commonService); + refundCarryVo = handRefundRerail(refundRecord,refundRecordItem,refundCarryVo,commonService); break; case OrderItemConstants.TYPE_PROJECT: - handRefundNoExecution(commonService, operationId, operationNme, 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; } /** @@ -687,8 +705,8 @@ * @param refundRecordItem 閫�娆惧瓙鍗� * @param commonService 鏄犲皠 */ - private static List<RefundRecordConsumePay> handRefundRerail(RefundRecord refundRecord, RefundRecordItem refundRecordItem - ,List<RefundRecordMethod> refundRecordMethodList,CommonService commonService) { + private static RefundCarryVo handRefundRerail(RefundRecord refundRecord, RefundRecordItem refundRecordItem + , RefundCarryVo refundCarryVo, CommonService commonService) { //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); @@ -700,28 +718,20 @@ if(refundRecordItem.getRefundNum() > surplusNum){ throw new TipsException("閫�娆炬暟閲忎笉鑳藉ぇ浜庡彲閫�娆炬暟閲�!"); } - SqlSentence sqlSentence = new SqlSentence(); - Map<String, Object> map = new HashMap<>(); //鍙樻洿閫�娆惧瓙椤逛俊鎭� + Integer refundStatus; if (surplusNum.equals(refundRecordItem.getRefundNum())){ - map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH); + refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; }else{ - map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART); - } - map.put("isDel", BaseEntity.NO); - map.put("orderItemId", refundRecordItem.getOrderItemId()); - map.put("refundTotal",refundRecordItem.getRefundMoney()); - map.put("refundNum",refundRecordItem.getRefundNum()); - map.put("oldHasReNum",orderItem.getHasReNum()); - sqlSentence.setSqlSentence(" refundStatus = #{m.refundStatus}, reTotal = reTotal+#{m.refundTotal}, hasReNum=hasReNum+#{m.refundNum}" + - " WHERE isDel = #{m.isDel} AND id = #{m.orderItemId} AND hasReNum = #{m.oldHasReNum} "); - if(commonService.updateWhere(OrderItemMapper.class,sqlSentence) != 1){ - throw new TipsException("閫�娆惧け璐ワ紝璁㈠崟宸插彂鐢熷彉鍖栵紝璇烽噸璇�!"); + refundStatus = OrderTotalConstants.STATUS_REFUND_PART; } + //鏇存柊瀛愯鍗曚俊鎭� + updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); + //閫�娆炬柟寮忓鐞� - return refundRecordMotnedItemHandle(refundRecord,refundRecordItem,refundRecordMethodList,commonService); + return refundRecordMotnedItemHandle(null,refundRecord,refundRecordItem,refundCarryVo,commonService); } /** @@ -729,7 +739,8 @@ * @param refundRecord * @param refundRecordItem */ - private static void handRefundNoExecution(RefundRecord refundRecord, RefundRecordItem refundRecordItem,CommonService commonService) { + private static RefundCarryVo handRefundNoExecution(RefundRecord refundRecord, RefundRecordItem refundRecordItem + ,RefundCarryVo refundCarryVo,CommonService commonService) { SqlSentence sqlSentence = new SqlSentence(); Map<String, Object> map = new HashMap<>(); @@ -752,7 +763,7 @@ } //鐢ㄦ埛椤圭洰鎿嶄綔 - UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_DEDUCTION,null + 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); //璁$畻瀛愬崟鏄惁杩樻湁鍓╀綑鐨勫彲鎵g枟绋嬫暟 @@ -768,30 +779,20 @@ refundStatus=OrderTotalConstants.STATUS_REFUND_PART; } - map.clear(); - map.put("orderItemId", orderItem.getId()); - map.put("refundStatus", refundStatus); - map.put("refundTotal",refundRecordItem.getRefundMoney()); - map.put("refundNum",refundRecordItem.getRefundNum()); - map.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}",map); - if(commonService.updateWhere(OrderItemMapper.class,sqlSentence) != 1){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"褰撳墠璁㈠崟淇℃伅宸插彂鐢熷彉鍖栵紝璇烽噸璇昜012]锛�"); - } + //鏇存柊瀛愯鍗曚俊鎭� + updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); //閫�娆炬柟寮忓鐞� - refundRecordMotnedItemHandle(refundRecord,refundRecordItem,commonService); + return refundRecordMotnedItemHandle(userProjectDeductionVo.getDeductionTotal(),refundRecord,refundRecordItem,refundCarryVo,commonService); } /** * 閫�娆�-澶勭悊鍗¢」 * @param commonService * @param refundRecord - * @param ordersTotal * @param refundRecordItem */ - public static void handRefundCard(RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem refundRecordItem,CommonService commonService) { + public static RefundCarryVo handRefundCard(RefundRecord refundRecord, RefundRecordItem refundRecordItem,RefundCarryVo refundCarryVo,CommonService commonService) { SqlSentence sqlSentence = new SqlSentence(); Map<String, Object> map = new HashMap<>(); @@ -799,7 +800,7 @@ //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� 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){ @@ -812,33 +813,38 @@ 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} "); + 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())){ - map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH); + refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; }else { - map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART); + refundStatus = OrderTotalConstants.STATUS_REFUND_PART; + } - //鏇存敼璁㈠崟瀛愯鍗曠姸鎬� - map.put("orderItemId", refundRecordItem.getOrderItemId()); - map.put("refundTotal",refundRecordItem.getRefundMoney()); - map.put("refundNum",refundRecordItem.getRefundNum()); - map.put("oldHasReNum",refundRecordItem.getRefundNum()); - sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=reTotal+#{m.refundTotal}, hasReNum=hasReNum+#{m.refundNum}" + - " where isDel=#{m.isDel} AND id=#{m.orderItemId} AND hasReNum = #{m.oldHasReNum}"); - if(commonService.updateWhere(OrderItemMapper.class,sqlSentence) != 1){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"褰撳墠璁㈠崟淇℃伅宸插彂鐢熷彉鍖栵紝璇烽噸璇昜012]锛�"); - } + //鏇存柊瀛愯鍗曚俊鎭� + updateOrderItemOne(orderItem,refundStatus,refundRecordItem.getRefundMoney(),refundRecordItem.getRefundNum(),commonService); //閫�娆炬柟寮忓鐞� - refundRecordMotnedItemHandle(refundRecord,refundRecordItem,commonService); + refundCarryVo = refundRecordMotnedItemHandle(null,refundRecord,refundRecordItem,refundCarryVo,commonService); + return refundCarryVo; } /** @@ -849,8 +855,8 @@ * @param ordersTotal * @param refundRecordItem */ - public static void handCardBag(String operationId,RefundRecord refundRecord - , OrdersTotal ordersTotal,RefundRecordItem refundRecordItem,CommonService commonService) { + 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<>(); @@ -868,14 +874,16 @@ } for (RefundRecordItemSource son : sons) { + refundCarryVo.setRefundConsumePayList(new ArrayList<>()); + refundCarryVo.setDeductionTotal(BigDecimal.ZERO); + refundCarryVo.setCashTotal(BigDecimal.ZERO); switch (GroupTypeEnum.getCode(son.getType())){ case PROJECT: - handRefundNoSonExecution(commonService, sqlSentence, map, refundRecord, son); - deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem); + //handRefundNoSonExecution(refundRecord,son,refundCarryVo,commonService); break; case RETAIL: - handRefundSonRerail(commonService, sqlSentence, map, refundRecord, son); - deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem); + //handRefundSonRerail(refundRecord,son,refundCarryVo,commonService ); + //deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem); break; case INCREMENT: //澧炲�奸噾 @@ -931,31 +939,49 @@ * 閫�娆鹃渶瑕佸垹闄ょ敤鎴峰崱鍖呬娇鐢ㄨ褰� * @param commonService */ - public static void deleteUserCardUsed(String userCardId,CommonService commonService){ + public static void deleteUserCardUsed(String cardItemInfoId,String sourceId,Integer hasReNum,CommonService commonService){ SqlSentence sqlSentence = new SqlSentence(); - Map<String, Object> map = new HashMap<>(); + Map<String,Object> map = new HashMap<>(); - map.put("isDel",UserCardUsed.YES); - map.put("userCardId",userCardId); - sqlSentence.sqlUpdate("isDel = #{m.isDel} WHERE userCardId = #{m.userCardId}",map); - commonService.updateWhere(UserCardUsedMapper.class,sqlSentence); + //鑾峰彇浣跨敤璁板綍 + 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); + + if(hasReNum > userCardUsedList.size()){ + throw new TipsException("鍗″寘鍙��鏁伴噺閿欒锛�"); + } + + 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 refundRecord * @param ordersTotal - * @param v + * @param refundRecordItem */ - private static void handRefundPromotion(String operationId, RefundRecord refundRecord, OrdersTotal ordersTotal - , RefundRecordItem refundRecordItem,CommonService commonService) { + 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,refundRecordItem.getOrderItemId()); + OrderItem orderItem = commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); if(orderItem == null ){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏈壘鍒板瓙璁㈠崟淇℃伅[84]!"); } @@ -965,82 +991,107 @@ 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: - //澧炲�奸噾 - //鍒ゆ柇閲戦涓嶇瓑浜�0锛屾墠鎵ц鎿嶄綔锛屼笉鐒舵搷浣滀綑棰濈殑鏃跺�欎細鐖嗘搷浣滄暟閲忔垨閲戦涓嶈兘涓�0 - if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ - UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"瀹℃牳閫氳繃閫�娆�:淇冮攢璧犻�佸鍊奸噾鎵e噺",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: - //鍌ㄥ�奸噾棰� - //鍒ゆ柇閲戦涓嶇瓑浜�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: - //绉垎 - //鍒ゆ柇閲戦涓嶇瓑浜�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; - } + //鏍规嵁鏀粯璁板綍鎬昏〃鐨勬爣璇嗘潵鏁村悎宸查��鐨勯噾棰濓紝key鍊硷細鏀粯璁板綍鎬昏〃鏍囪瘑锛寁alue:閲戦鏁版嵁 + 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(),"瀹℃牳閫氳繃閫�娆�:淇冮攢璧犻�佸鍊奸噾鎵e噺",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: + //鍌ㄥ�奸噾棰� + //鍒ゆ柇閲戦涓嶇瓑浜�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: + //绉垎 + //鍒ゆ柇閲戦涓嶇瓑浜�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; + } + 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)){ - 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_FINSH; + refundNum = orderItem.getBuyNum(); }else { - orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); + 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(RefundRecord refundRecord, RefundRecordItemSource refundRecordItemSource,CommonService commonService) { - - SqlSentence sqlSentence = new SqlSentence(); - Map<String,Object> map = new HashMap<>(); + private static RefundCarryVo handRefundNoSonExecution(RefundRecord refundRecord,RefundRecordItem refundRecordItem, RefundRecordItemSource refundRecordItemSource + ,RefundCarryVo refundCarryVo,CommonService commonService) { //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId()); @@ -1062,11 +1113,9 @@ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆炬鏁板ぇ浜庡彲閫�娆℃暟[84]锛�"); } - //澶勭悊鐢ㄦ埛椤圭洰 - //鐢ㄦ埛椤圭洰鎿嶄綔 - UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_DEDUCTION,null + //澶勭悊鐢ㄦ埛椤圭洰锛屽噺鍘荤敤鎴烽」鐩暟閲� + 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()){ @@ -1075,50 +1124,139 @@ refundStatus=OrderTotalConstants.STATUS_REFUND_PART; } - map.clear(); - map.put("id",refundRecordItemSource.getOrderItemSonId()); - map.put("refundTotal",refundRecordItemSource.getRefundMoney()); - map.put("refundNum",refundRecordItemSource.getRefundNum()); - map.put("oldHasReNum",orderItemSon.getHasReNum()); - map.put("refundStatus", refundStatus); - sqlSentence.sqlUpdate(" refundStatus=#{m.refundStatus}, reTotal=reTotal+#{m.refundTotal}, hasReNum=hasReNum+#{m.refundNum}" + - " where isDel=0 AND id=#{m.id} AND hasReNum = #{m.oldHasReNum}",map); - if(commonService.updateWhere(OrderItemSonMapper.class,sqlSentence) != 1){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"褰撳墠璁㈠崟淇℃伅宸插彂鐢熷彉鍖栵紝璇烽噸璇昜013]锛�"); + //鏇存柊瀛愬崟淇℃伅 + 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); } - //鍒櫎鍗″寘浣跨敤 - deleteUserCardUsed(orderItemSon.get,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); + //璁$畻瀛愬崟鏄惁杩樻湁鍓╀綑鐨勫彲鎵g枟绋嬫暟 + 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); } /**鑾峰彇宸查��娆炬柟寮忛噾棰濓紝鏍规嵁鏀粯鏂瑰紡缂栧彿姹傚拰杩斿洖 -- Gitblit v1.8.0