From ae6ff75ee416f46ea6f8a90473ea3af9c3a064f0 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期三, 29 三月 2023 19:32:37 +0800 Subject: [PATCH] 退款重构 --- /dev/null | 910 --------------------- phi_platform_user/src/main/java/com/hx/phip/controller/order/OrderRefundController.java | 10 phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java | 302 +++--- phi_platform_common/src/main/java/com/hx/phip/tool/order/PaymentCountTool.java | 40 phi_platform_common/src/main/java/com/hx/phip/vo/order/payment/PayMethodVo.java | 21 phi_platform_common/src/main/resources/mapper/platform/RefundMapper.xml | 20 phi_platform_common/src/main/java/com/hx/phip/config/CustomParameter.java | 0 phi_platform_common/src/main/java/com/hx/phip/tool/order/PartialRefundUtil.java | 1229 ++++++++++++++++++++++++++++ 8 files changed, 1,454 insertions(+), 1,078 deletions(-) diff --git a/phi_platform_user/src/main/java/com/hx/phip/config/CustomParameter.java b/phi_platform_common/src/main/java/com/hx/phip/config/CustomParameter.java similarity index 100% rename from phi_platform_user/src/main/java/com/hx/phip/config/CustomParameter.java rename to phi_platform_common/src/main/java/com/hx/phip/config/CustomParameter.java diff --git a/phi_platform_common/src/main/java/com/hx/phip/tool/order/PartialRefundUtil.java b/phi_platform_common/src/main/java/com/hx/phip/tool/order/PartialRefundUtil.java new file mode 100644 index 0000000..0f5bea3 --- /dev/null +++ b/phi_platform_common/src/main/java/com/hx/phip/tool/order/PartialRefundUtil.java @@ -0,0 +1,1229 @@ +package com.hx.phip.tool.order; + +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.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.consume.ConsumePayItemSon; +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.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.payment.PayMethodVo; +import com.hx.util.StringUtils; +import com.platform.exception.PlatTipsException; +import com.platform.resultTool.PlatformCode; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Author + */ +public class PartialRefundUtil { + + /**棰嗗缓浼樻儬鍒告爣璇�*/ + public static final String HIS_COUPON_CODE = "his_coupon_code"; + + /** + * 閫�娆炬�绘祦绋嬪伐鍏� + * @param commonService + * @param operationId + * @param operationNme + * @param refundId + */ + 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,"鎵句笉鍒拌閫�娆句俊鎭紒"); + } + + 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_TIPS,"鏈壘鍒拌鍗曚俊鎭�!"); + } + + //鏌ヨ鐢ㄦ埛鏄惁鏈夎处鎴蜂俊鎭紝閫�娆鹃渶瑕佸鐞嗚祫閲� + 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_TIPS,"鏈壘鍒拌鐢ㄦ埛鐨勮祫閲戜俊鎭�"); + } + + //澶勭悊浼樻儬鍒� + handCoupon(refundRecord,commonService); + //澶勭悊鎬婚��娆炬柟寮忔暟鎹� + refundRecordMotnedHandle(operationId,operationNme,refundRecord,ordersTotal,commonService); + //瀛愬崟閫�娆鹃」澶勭悊 + numberOfRefunds(operationId, operationNme, refundRecord,ordersTotal,customParameter,commonService); + + if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){ + //鍏呭�艰鍗曢渶瑕佹妸鍏呭�肩殑鍌ㄥ�奸噾 鎷垮洖鏉� 鍥犱负鍌ㄥ�奸噾闇�瑕佸紑鍗曟潵澶勭悊锛屾墍浠ヤ笉闇�瑕佸鍔犳棩蹇� + //鍒ゆ柇閲戦涓嶇瓑浜�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); + } + } + + + //鏇存敼鎬昏鍗曢��娆剧姸鎬� + 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); + + List<Integer> collect = orderItemList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList()); + if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){ + ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); + ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); + }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ + ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); + 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 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; + //鏀粯鏂瑰紡鎵e噺閲戦 + 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; + } + //璁$畻鎵e噺閲戦 + 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]锛�"); + } + } + } + + /**澶勭悊涓�绾у瓙閫�娆炬柟寮忔暟鎹�*/ + public static List<RefundRecordConsumePay> refundRecordMotnedItemHandle(RefundRecord refundRecord,RefundRecordItem refundRecordItem + ,List<RefundRecordMethod> refundRecordMethodList,CommonService commonService){ + + 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; + } + + //鑾峰彇瀛愬崟鐨勬敮浠樻柟寮忥紝涓�绾у瓙鍗曟敮浠樿褰� + 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); + + //鑾峰彇宸茬粡閫�娆剧殑閫�娆炬柟寮忛噾棰濓紝鏍规嵁鏀粯鏂瑰紡璁板綍鐨勬爣璇嗘眰鍜岃繑鍥� + List<RefundRecordConsumePay> refundRecordConsumePayList = getRefundRecordConsumePay(refundRecordItem.getOrderItemId(),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){ + //宸查��娆鹃噾棰� + consumePayItem.setRefundTotal(refundRecordConsumePay.getRefundTotal()); + //鍙��娆鹃噾棰� + consumePayItem.setpTotal(consumePayItem.getpTotal().subtract(refundRecordConsumePay.getRefundTotal()).setScale(2,RoundingMode.HALF_UP)); + } + } + + //杩涜鍗囧簭鎺掑簭锛岄伩鍏嶅悗闈笉澶熷垎閰� + refundRecordMethodList = refundRecordMethodList.stream().sorted(Comparator.comparing(RefundRecordMethod::getpTotal)).collect(Collectors.toList()); + + //閫�娆剧殑鍒掓墸閲戦 + BigDecimal deductionTotal = BigDecimal.ZERO; + //閫�娆剧殑鐜伴噾閲戦 + BigDecimal cashTotal = BigDecimal.ZERO; + //閫�娆炬柟寮忔�婚噾棰� + BigDecimal mothedTotal; + //鏀粯鏂瑰紡鎵e噺閲戦 + BigDecimal mothedCutTotal; + ///////寮曠敤瀵硅薄 + RefundRecordItemMethod refundRecordItemMethod; + //鏀粯鏂瑰紡鍗犳瘮 + BigDecimal payMothedPercentage; + + 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; + } + ////閫�娆炬柟寮忛噾棰濆垎閰� + + //瀛愬崟閫�娆炬柟寮� + 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()); + 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){ + //褰撳墠閫�娆炬柟寮忕殑閫�娆鹃噾棰� + mothedTotal = refundRecordItemMethod.getActualTotal(); + + for(ConsumePayItem consumePayItem:consumePayItemList){ + if(consumePayItem.getpTotal().compareTo(BigDecimal.ZERO) < 1){ + continue; + } + //璁$畻鎵e噺閲戦 + if(consumePayItem.getpTotal().compareTo(mothedTotal) > 0){ + mothedCutTotal = mothedTotal; + }else{ + 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); + + //璁$畻鏈垎閰嶉噾棰� + 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]锛�"); + } + } + } + + + /** + * 閫�娆�-澶勭悊浼樻儬鍒� + * @param refundRecord 閫�娆炬�绘暟鎹� + * @param commonService 鏄犲皠 + */ + 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 "); + List<RefundRecordCoupon> refundRecordCouponList=commonService.selectList(RefundRecordCouponMapper.class,sqlSentence); + + //閫�娆炬垚鍔� + CouponOrderDiscountLog couponOrderDiscountLog=null; + for (RefundRecordCoupon refundRecordCoupon : refundRecordCouponList) { + + //鍙樻洿璁㈠崟浼樻儬鍒歌褰曠姸鎬� + 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} "); + if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 1){ + throw new TipsException("浼樻儬鍒稿洖閫�澶辫触[67]锛�"); + } + } + } + + /** + * 閫�娆�-澶勭悊娲诲姩瑙勫垯澧炲�奸噾鍜岀Н鍒� + * @param commonService + * @param operationId + * @param operationNme + * @param sqlSentence + * @param map + * @param refundRecord + * @param ordersTotal + */ + private static void handActivityRule(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, + Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, OrderInfo orderInfo) { + if(orderInfo!=null && StringUtils.noNull(orderInfo.getActivityId())){ + ActivityRule activityRule=commonService.selectOneByKeyBlob(ActivityRuleMapper.class,orderInfo.getActivityId()); + if(activityRule!=null){ + map.put("activityRuleId",activityRule.getId()); + map.put("type", ActivityAction.TYPE_INTEGRAL); + map.put("type1",ActivityAction.TYPE_VALUEADDEDFUND); + map.put("type2",ActivityAction.TYPE_COUPON); + sqlSentence.setSqlSentence("select * from activity_action where activityRuleId=#{m.activityRuleId} and (type=#{m.type} or type=#{m.type1} or type=#{m.type2}) and isDel=0"); + List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence); + if(activityActions!=null && activityActions.size()>0){ + for (ActivityAction activityAction : activityActions) { + if(ActivityAction.TYPE_INTEGRAL.equals(activityAction.getType())){ + //鍒ゆ柇閲戦涓嶇瓑浜�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())){ + //鍒ゆ柇閲戦涓嶇瓑浜�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); + map.put("couponId",activityAction.getCrmCouponId()); + map.put("commonId",ordersTotal.getId()); + sqlSentence.setSqlSentence(" validState=#{m.newValidState} where couponId=#{m.couponId} and commonId=#{m.commonId} and validState=#{m.oldValidState} "); + commonService.updateWhere(CouponNumberMapper.class,sqlSentence); + } + } + } + } + } + + } + /** + * 閫�娆�-澶勭悊鏅�氳鍗曚俊鎭�(姣斿:椤圭洰銆佷績閿�銆佸崱椤�) + * @param operationId 鎿嶄綔浜烘爣璇� + * @param operationNme 鎿嶄綔浜哄悕 + * @param refundRecord + * @param commonService + */ + public static void numberOfRefunds(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(); + 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_TIPS,"鏈壘鍒伴��娆惧瓙璁㈠崟淇℃伅"); + } + + List<RefundRecordConsumePay> refundRecordConsumePayList; + + for (RefundRecordItem refundRecordItem: refundRecordItems) { + switch (refundRecordItem.getType()){ + case OrderItemConstants.TYPE_RETAIL: + handRefundRerail(refundRecord,refundRecordItem,commonService); + break; + case OrderItemConstants.TYPE_DRUG: + handRefundRerail(refundRecord,refundRecordItem,commonService); + break; + case OrderItemConstants.TYPE_PROJECT: + handRefundNoExecution(commonService, operationId, operationNme, refundRecord,v); + break; + case OrderItemConstants.TYPE_PROMOTION: + handRefundPromotion(commonService, operationId, operationNme, sqlSentence, map, refundRecord, ordersTotal, v); + break; + case OrderItemConstants.TYPE_CARD: + handRefundCard(commonService, operationId, sqlSentence, map, refundRecord, ordersTotal, v); + break; + case OrderItemConstants.CARD_BAG: + handCardBag(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,v,customParameter); + break; + default:break; + } + } + } + + /** + * 閫�娆句竴绾ф槸鍟嗗搧 + * @param refundRecord 閫�娆炬�讳俊鎭� + * @param refundRecordItem 閫�娆惧瓙鍗� + * @param commonService 鏄犲皠 + */ + private static List<RefundRecordConsumePay> handRefundRerail(RefundRecord refundRecord, RefundRecordItem refundRecordItem + ,List<RefundRecordMethod> refundRecordMethodList,CommonService commonService) { + + //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� + OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); + if (orderItem==null){ + throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏈壘鍒板瓙璁㈠崟淇℃伅"); + } + //鍓╀綑鍙��娆炬暟閲� + Integer surplusNum = orderItem.getBuyNum()-orderItem.getHasReNum(); + if(refundRecordItem.getRefundNum() > surplusNum){ + throw new TipsException("閫�娆炬暟閲忎笉鑳藉ぇ浜庡彲閫�娆炬暟閲�!"); + } + SqlSentence sqlSentence = new SqlSentence(); + Map<String, Object> map = new HashMap<>(); + + //鍙樻洿閫�娆惧瓙椤逛俊鎭� + if (surplusNum.equals(refundRecordItem.getRefundNum())){ + map.put("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("閫�娆惧け璐ワ紝璁㈠崟宸插彂鐢熷彉鍖栵紝璇烽噸璇�!"); + } + + //閫�娆炬柟寮忓鐞� + return refundRecordMotnedItemHandle(refundRecord,refundRecordItem,refundRecordMethodList,commonService); + } + + /** + * 閫�娆�-澶勭悊鏈墽琛屽垝鎵� 椤圭洰绫诲瀷 + * @param refundRecord + * @param refundRecordItem + */ + private static void handRefundNoExecution(RefundRecord refundRecord, RefundRecordItem refundRecordItem,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_TIPS,"鏈壘鍒扮敤鎴峰瓙椤归」鐩俊鎭�"); + } + + if(userProjectItem.getNotUsedNum() < refundRecordItem.getRefundNum()){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆炬鏁板ぇ浜庡彲閫�娆℃暟锛�"); + } + + //鐢ㄦ埛椤圭洰鎿嶄綔 + 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枟绋嬫暟 + 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{ + 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]锛�"); + } + + //閫�娆炬柟寮忓鐞� + refundRecordMotnedItemHandle(refundRecord,refundRecordItem,commonService); + } + + /** + * 閫�娆�-澶勭悊鍗¢」 + * @param commonService + * @param refundRecord + * @param ordersTotal + * @param refundRecordItem + */ + public static void handRefundCard(RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem refundRecordItem,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_PARAMETER_NULL,"鏈壘鍒板瓙璁㈠崟淇℃伅"); + } + Integer surplusNum = orderItem.getBuyNum() - orderItem.getHasReNum(); + if(refundRecordItem.getRefundNum() > surplusNum){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆句綔搴熷崱鍖呮彁绀�:娌℃湁鎵惧埌瀵瑰簲鐨勫崱鍖呭彲閫�[020]"); + } + + //鎵惧埌鍙��娆惧崱鍖� + List<UserCard> userCardList = PartialRefundUtil.getRefundCard(orderItem.getId(),commonService); + if(refundRecordItem.getRefundNum() > userCardList.size()){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆句綔搴熷崱鍖呮彁绀�:娌℃湁鎵惧埌瀵瑰簲鐨勫崱鍖呭彲閫�[021]"); + } + + UserCard userCard; + 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); + } + + if (surplusNum.equals(refundRecordItem.getRefundNum())){ + map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH); + }else { + map.put("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]锛�"); + } + + //閫�娆炬柟寮忓鐞� + refundRecordMotnedItemHandle(refundRecord,refundRecordItem,commonService); + } + + /** + * 閫�娆�-澶勭悊鍗″寘 + * @param commonService + * @param operationId + * @param refundRecord + * @param ordersTotal + * @param refundRecordItem + */ + public static void handCardBag(String operationId,RefundRecord refundRecord + , OrdersTotal ordersTotal,RefundRecordItem refundRecordItem,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.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.size() == 0 ){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒板瓙璁㈠崟淇℃伅[015]!"); + } + + 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: + //澧炲�奸噾 + //鍒ゆ柇閲戦涓嶇瓑浜�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; + } + } + + //鏇存敼浜岀骇瀛愯鍗曢��娆剧姸鎬� + + map.put("orderItemId",orderItem.getId()); + sqlSentence.setSqlSentence("select * from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0"); + List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); + + 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)); + }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ + orderItem.setRefundStatus(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()); + }else { + orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); + } + + commonService.updateAll(OrderItemMapper.class,orderItem); + } + + /** + * 閫�娆鹃渶瑕佸垹闄ょ敤鎴峰崱鍖呬娇鐢ㄨ褰� + * @param commonService + */ + public static void deleteUserCardUsed(String userCardId,CommonService commonService){ + + SqlSentence sqlSentence = new SqlSentence(); + 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); + } + /** + * 閫�娆�-澶勭悊淇冮攢 + * @param commonService + * @param operationId + * @param refundRecord + * @param ordersTotal + * @param v + */ + private static void handRefundPromotion(String operationId, RefundRecord refundRecord, OrdersTotal ordersTotal + , RefundRecordItem refundRecordItem,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_PARAMETER_NULL,"鏈壘鍒板瓙璁㈠崟淇℃伅[84]!"); + } + + //鑾峰彇閫�娆句簩绾у崟 + 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: + //澧炲�奸噾 + //鍒ゆ柇閲戦涓嶇瓑浜�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; + } + } + } + + //鏇存敼浜岀骇瀛愯鍗曢��娆剧姸鎬� + + map.put("orderItemId",orderItem.getId()); + sqlSentence.setSqlSentence("select * from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0"); + List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); + + 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)); + }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ + orderItem.setRefundStatus(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()); + }else { + orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); + } + + commonService.updateAll(OrderItemMapper.class,orderItem); + } + + /** + * 閫�娆�-澶勭悊浜岀骇瀛愯鍗曟湭鎵ц鍒掓墸 椤圭洰绫诲瀷 + * @param commonService + * @param sqlSentence + * @param map + * @param refundRecord + * @param v + */ + private static void handRefundNoSonExecution(RefundRecord refundRecord, RefundRecordItemSource refundRecordItemSource,CommonService commonService) { + + SqlSentence sqlSentence = new SqlSentence(); + Map<String,Object> map = new HashMap<>(); + + //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� + OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId()); + if (orderItemSon==null){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒颁簩绾у瓙璁㈠崟淇℃伅"); + } + + 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]锛�"); + } + + //璁$畻瀛愬崟鏄惁杩樻湁鍓╀綑鐨勫彲鎵g枟绋嬫暟 + int surplusNum = orderItemSon.getUsedTotal() - orderItemSon.getHasReNum(); + if(refundRecordItemSource.getRefundNum() > surplusNum){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆炬鏁板ぇ浜庡彲閫�娆℃暟[84]锛�"); + } + + //澶勭悊鐢ㄦ埛椤圭洰 + //鐢ㄦ埛椤圭洰鎿嶄綔 + 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{ + 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]锛�"); + } + + //鍒櫎鍗″寘浣跨敤 + deleteUserCardUsed(orderItemSon.get,commonService); + } + /** + * 閫�娆句簩绾ф槸鍟嗗搧 + * @param commonService + * @param sqlSentence + * @param map + * @param refundRecord + * @param v + */ + private static void handRefundSonRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) { + + //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� + OrderItemSon orderItem=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId()); + if (orderItem==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); + } + + sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} "); + commonService.updateWhere(OrderItemSonMapper.class,sqlSentence); + } + + /**鑾峰彇宸查��娆炬柟寮忛噾棰濓紝鏍规嵁鏀粯鏂瑰紡缂栧彿姹傚拰杩斿洖 + * 娉ㄦ剰锛歡roupByONumberNo鍜実roupByConsumePayId涓嶈兘鍚屾椂浣跨敤 + * @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; + } + +} 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 67721ae..7aec44f 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 @@ -1,6 +1,8 @@ package com.hx.phip.tool.order; +import com.hx.common.service.CommonService; import com.hx.exception.TipsException; +import com.hx.phiappt.model.refund.RefundRecordConsumePay; import com.hx.phip.vo.order.payment.PayMethodVo; import com.hx.phip.vo.order.refund.DistributionRedundMethodVo; import com.hx.phip.vo.order.refund.DistributionRedundVo; @@ -10,6 +12,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /**璁$畻鏀粯鏂瑰紡閲戦 @@ -18,6 +21,7 @@ public class PaymentCountTool { /**璁$畻鏀粯鏂瑰紡鐨勯噾棰� + * @param itemId 瀛愬崟鏂瑰紡 * @param total 鎬婚噾棰� * @param realRefundTotal 宸查��鎬婚噾棰� * @param sum 璐拱鎬绘暟閲� @@ -26,8 +30,8 @@ * @param payMethodVoList 鏀粯鏂瑰紡锛屾煡璇onsumePay瀛愮被 * @return 鍙傛暟缁撴瀯 */ - public static DistributionRedundVo countMakeWay(BigDecimal total,BigDecimal realRefundTotal,Integer sum, Integer surplusNum - , Integer refunNum, List<PayMethodVo> payMethodVoList){ + public static DistributionRedundVo countMakeWay(String itemId, BigDecimal total, BigDecimal realRefundTotal, Integer sum, Integer surplusNum + , Integer refunNum, List<PayMethodVo> payMethodVoList, CommonService commonService){ if(surplusNum == null){ throw new TipsException("鍙��娆炬暟閲忎笉鑳戒负绌猴紒"); @@ -41,26 +45,48 @@ //閫�娆炬暟閲忓崰鎬绘暟鍗犳瘮璁$畻 BigDecimal scale = BigDecimal.valueOf(refunNum).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 = total.subtract(realRefundTotal).setScale(2,RoundingMode.HALF_UP); + refundTotal = surplusTotal; }else{ //涓嶆槸鏈�鍚庨��娆炬暟閲忥紝鏍规嵁閫�娆炬暟閲忓崰姣旀潵绠楅��娆鹃噾棰� refundTotal = total.multiply(scale).setScale(2,RoundingMode.HALF_UP); + if(refundTotal.compareTo(surplusTotal) > 0){ + refundTotal = surplusTotal; + } } + //杞浇鍒嗛厤濂界殑鏀粯鏂瑰紡鍜岄噾棰� List<DistributionRedundMethodVo> distributionPayList = new ArrayList<>(); - if(payMethodVoList != null && payMethodVoList.size() > 0){ + + //鑾峰彇宸查��娆剧殑鏀粯鏂瑰紡閲戦 + List<RefundRecordConsumePay> refundRecordConsumePayList = PartialRefundUtil.getRefundRecordConsumePay(itemId,null,true,false,commonService); + + ///////鎶婂凡閫�娆剧殑閲戦娉ㄥ叆杩涘幓 + //杞寲涓簃ap锛屼笅闈㈡敞鍏ラ��娆鹃噾棰濈敤鍒� + Map<String, PayMethodVo> payMethodVoMap = payMethodVoList.stream().collect(Collectors.toMap(PayMethodVo::getNumberNo,(a) -> a)); + PayMethodVo payMethodVo; + for(RefundRecordConsumePay refundRecordConsumePay:refundRecordConsumePayList){ + payMethodVo = payMethodVoMap.get(refundRecordConsumePay.getNumberNo()); + if(payMethodVo != null){ + //宸查��娆鹃噾棰� + payMethodVo.setRefundTotal(payMethodVo.getRefundTotal().add(refundRecordConsumePay.getRefundTotal()).setScale(2,RoundingMode.HALF_UP)); + //鍓╀綑鏈��娆鹃噾棰� + payMethodVo.setSurplusTotal(payMethodVo.getSurplusTotal().subtract(refundRecordConsumePay.getRefundTotal()).setScale(2,RoundingMode.HALF_UP)); + } + } + //鏀粯鏂瑰紡杩涜鍗囧簭鎺掑簭锛岄伩鍏嶅惊鐜敮浠樻柟寮忕殑鏃跺�欐渶鍚庝竴涓彲鍒嗛厤0鍏冿紝浠庤�屽鑷寸畻瀛愬崟鏈�鍚庝竴涓殑鏃跺�欐病鏈夐挶绠椾簡 payMethodVoList = payMethodVoList.stream().sorted(Comparator.comparing(PayMethodVo::getSurplusTotal)).collect(Collectors.toList()); DistributionRedundMethodVo distributionPay; - PayMethodVo payMethodVo; + for(int i = 0;i<payMethodVoList.size();i++){ payMethodVo = payMethodVoList.get(i); //璧嬪�� diff --git a/phi_platform_common/src/main/java/com/hx/phip/vo/order/payment/PayMethodVo.java b/phi_platform_common/src/main/java/com/hx/phip/vo/order/payment/PayMethodVo.java index ddcd98a..12f891b 100644 --- a/phi_platform_common/src/main/java/com/hx/phip/vo/order/payment/PayMethodVo.java +++ b/phi_platform_common/src/main/java/com/hx/phip/vo/order/payment/PayMethodVo.java @@ -31,4 +31,25 @@ public PayMethodVo() { } + public BigDecimal getRefundTotal() { + if(refundTotal == null){ + refundTotal = BigDecimal.ZERO; + } + return refundTotal; + } + + public void setRefundTotal(BigDecimal refundTotal) { + this.refundTotal = refundTotal; + } + + public BigDecimal getSurplusTotal() { + if(surplusTotal == null){ + surplusTotal = payTotal; + } + return surplusTotal; + } + + public void setSurplusTotal(BigDecimal surplusTotal) { + this.surplusTotal = surplusTotal; + } } diff --git a/phi_platform_common/src/main/resources/mapper/platform/RefundMapper.xml b/phi_platform_common/src/main/resources/mapper/platform/RefundMapper.xml index c80476e..035195d 100644 --- a/phi_platform_common/src/main/resources/mapper/platform/RefundMapper.xml +++ b/phi_platform_common/src/main/resources/mapper/platform/RefundMapper.xml @@ -9,13 +9,11 @@ <select id="selectConsumePayList" resultType="com.hx.phip.vo.order.payment.PayMethodVo"> SELECT ANY_VALUE(name) AS name ,numberNo - ,ROUND(SUM(actualTotal-refundInventedTotal),2) AS surplusTotal + ,ROUND(SUM(actualTotal-refundTotal),2) AS surplusTotal ,ROUND(SUM(actualTotal),2) AS payTotal ,ROUND(SUM(refundTotal),2) AS refundTotal - ,isMoneyPay - ,isExecute FROM consume_pay - WHERE isDel = 0 AND orderId = #{orderId} GROUP BY isMoneyPay,isExecute,numberNo + WHERE isDel = 0 AND orderId = #{orderId} GROUP BY numberNo </select> @@ -23,26 +21,20 @@ <select id="selectConsumePayOneList" resultType="com.hx.phip.vo.order.payment.PayMethodVo"> SELECT ANY_VALUE(name) AS name ,numberNo - ,ROUND(SUM(actualTotal-refundInventedTotal),2) AS surplusTotal + ,ROUND(SUM(actualTotal),2) AS surplusTotal ,ROUND(SUM(actualTotal),2) AS payTotal - ,ROUND(SUM(refundTotal),2) AS refundTotal - ,isMoneyPay - ,isExecute FROM consume_pay_item - WHERE isDel = 0 AND typeId = #{typeId} GROUP BY isMoneyPay,isExecute,numberNo + WHERE isDel = 0 AND typeId = #{typeId} GROUP BY numberNo </select> <!--浜岀骇鏀粯鏂瑰紡璁板綍杩斿洖--> <select id="selectConsumePayTwoList" resultType="com.hx.phip.vo.order.payment.PayMethodVo" > SELECT ANY_VALUE(name) AS name ,numberNo - ,ROUND(SUM(actualTotal-refundInventedTotal),2) AS surplusTotal + ,ROUND(SUM(actualTotal),2) AS surplusTotal ,ROUND(SUM(actualTotal),2) AS payTotal - ,ROUND(SUM(refundTotal),2) AS refundTotal - ,isMoneyPay - ,isExecute FROM consume_pay_item_son - WHERE isDel = 0 AND typeId = #{typeId} GROUP BY isMoneyPay,isExecute,numberNo + WHERE isDel = 0 AND typeId = #{typeId} GROUP BY numberNo </select> diff --git a/phi_platform_user/src/main/java/com/hx/phip/controller/order/OrderRefundController.java b/phi_platform_user/src/main/java/com/hx/phip/controller/order/OrderRefundController.java index 0441861..f95e277 100644 --- a/phi_platform_user/src/main/java/com/hx/phip/controller/order/OrderRefundController.java +++ b/phi_platform_user/src/main/java/com/hx/phip/controller/order/OrderRefundController.java @@ -124,7 +124,7 @@ //杩斿洖闆嗗悎 OrderRefundDto returnMap = orderRefundService.nextStep(ordersTotal,orderRefundDto); - returnMap.setRefundPayMethod(returnMap.getRefundPayMethod()); + returnMap.setRefundPayMethod(returnMap.getPayMethodList()); returnMap.setCouponList(returnMap.getPayCouponList()); return Result.success(returnMap); } @@ -136,6 +136,11 @@ public PlatformResult partRefund(HttpServletRequest request, @RequestBody OrderRefundDto orderRefundDto) { //鎿嶄綔骞冲彴 ThirtApplication thirtApplication = (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY); + //TODO 娴嬭瘯 + thirtApplication = new ThirtApplication(); + thirtApplication.setAppId("54654asdf56sd1e1gv567as1"); + thirtApplication.setName("PHI"); + thirtApplication.setAppIdCode("his"); if(thirtApplication==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"绛惧悕澶辫触,璇锋鏌ョ鍚�!"); } @@ -147,6 +152,9 @@ if(StringUtils.isEmpty(orderRefundDto.getRoleId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鎿嶄綔瑙掕壊鏍囪瘑涓嶈兘涓虹┖"); } + if(StringUtils.isEmpty(orderRefundDto.getOperatorId())){ + throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鎿嶄綔鍛樺伐鏍囪瘑涓嶈兘涓虹┖"); + } if(orderRefundDto.getIsApproval()==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏄惁闇�瑕佸鎵逛笉鑳戒负绌�"); 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 1455686..43b9cff 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 @@ -12,7 +12,6 @@ import com.hx.phiappt.model.*; 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.coupon.CouponOrderDiscountLog; import com.hx.phiappt.model.order.*; import com.hx.phiappt.model.performance.PerformanceInfo; @@ -29,6 +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.tool.order.PaymentCountTool; import com.hx.phip.util.api.*; import com.hx.phip.vo.order.payment.PayMethodVo; @@ -77,10 +77,6 @@ private OrdersTotalMapper ordersTotalMapper; @Resource private OrderItemMapper orderItemMapper; - @Resource - private ConsumePayMapper consumePayMapper; - @Resource - private UserProjectItemMapper userProjectItemMapper; @Resource private OrderItemSonMapper orderItemSonMapper; @@ -134,6 +130,7 @@ */ @Override public List<Map<String, Object>> refundDetails(OrdersTotal ordersTotal) { + SqlSentence sqlSentence = new SqlSentence(); Map<String, Object> sqlMap = new HashMap<>(); sqlSentence.setM(sqlMap); @@ -141,7 +138,7 @@ sqlMap.put("isDel", BaseEntity.NO); sqlMap.put("orderId", ordersTotal.getId()); //涓�绾у瓙璁㈠崟 - sqlSentence.sqlSentence("SELECT * FROM order_item WHERE orderId = #{m.orderId} and isDel = #{m.isDel}",sqlMap); + sqlSentence.sqlSentence("SELECT * FROM order_item WHERE orderId = #{m.orderId} AND isDel = #{m.isDel}",sqlMap); List<OrderItem> orderItemList = orderItemMapper.selectList(sqlSentence); List<Map<String, Object>> orderItems = new ArrayList<>(); @@ -177,14 +174,8 @@ * 澶勭悊涓�绾ф槸椤圭洰鐨� */ public void handleOrderItemIsProject(List<Map<String, Object>> orderItems, OrderItem orderItem) { - - SqlSentence sqlSentence = new SqlSentence(); - Map<String, Object> sqlMap = new HashMap<>(); - //鑾峰彇鐢ㄦ埛椤圭洰 - sqlMap.put("commonId",orderItem.getId()); - sqlSentence.sqlSentence("SELECT * FROM user_project_item upi WHERE upi.isDel = 0 AND upi.commonId = #{m.commonId} AND upi.isTransfer = 0",sqlMap); - UserProjectItem userProjectItem = userProjectItemMapper.selectOne(sqlSentence); + UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(orderItem.getId(),commonService); if(userProjectItem == null){ throw new TipsException("鐢ㄦ埛椤圭洰鑾峰彇澶辫触锛�"); } @@ -241,36 +232,20 @@ Map<String,Object> sqlMap = new HashMap<>(); //鑾峰彇鐢ㄦ埛鍗¢」 - List<UserCard> userCardList = getRefundCard(orderItem.getId()); + List<UserCard> userCardList = PartialRefundUtil.getRefundCard(orderItem.getId(),commonService); //淇℃伅灏佽 Map<String,Object> itemData = itemRefandDataPackage(orderItem,null,null,userCardList); + //鑾峰彇鍗¢」鐨勮缁嗘潯鐩� sqlMap.put("commonId",orderItem.getCommonId()); sqlSentence.sqlSentence(" SELECT groupName,shareMoney FROM card_equity WHERE cardItemId = #{m.commonId} ",sqlMap); List<Map<String, Object>> cardEquitys = cardEquityMapper.selectListMap(sqlSentence); + itemData.put("list", cardEquitys); orderItems.add(itemData); } - - /**鑾峰彇鍙��娆剧殑鐢ㄦ埛鍗¢」 - * @param sourceId 璁㈠崟瀛愬崟鏍囪瘑 - * @return 鍙��娆剧殑鐢ㄦ埛鍗¢」 - */ - public List<UserCard> getRefundCard(String sourceId){ - 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}",sqlMap); - return commonService.selectList(UserCardMapper.class,sqlSentence); - - } - /** * 澶勭悊涓�绾ф槸淇冮攢鐨� @@ -351,15 +326,11 @@ * 澶勭悊浜岀骇鏄」鐩殑 */ public void handleOrderItemSonIsProject(List<Map<String, Object>> promotionList, OrderItemSon orderItemSon) { - SqlSentence sqlSentence = new SqlSentence(); - Map<String,Object> sqlMap = new HashMap<>(); //鑾峰彇鐢ㄦ埛椤圭洰 - sqlMap.put("commonId",orderItemSon.getId()); - sqlSentence.sqlSentence("SELECT * FROM user_project_item upi WHERE upi.isDel = 0 AND upi.commonId = #{m.commonId} AND upi.isTransfer = 0",sqlMap); - UserProjectItem userProjectItem = userProjectItemMapper.selectOne(sqlSentence); + UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(orderItemSon.getId(),commonService); if(userProjectItem == null){ - throw new TipsException("鐢ㄦ埛椤圭洰鑾峰彇澶辫触锛�"); + throw new TipsException("鐢ㄦ埛椤圭洰鑾峰彇澶辫触[24]锛�"); } Map<String,Object> itemData = itemRefandDataPackage(null,orderItemSon,userProjectItem,null); @@ -375,18 +346,13 @@ } /** - * 閫�娆鹃�夋嫨閫�娆炬暟閲忕粍瑁呴噾棰濅俊鎭� + * 閫�娆鹃�夋嫨閫�娆炬暟閲忕粍瑁呴噾棰濅俊鎭紝閫�娆鹃噷闈㈣繖涓潪甯搁噸瑕� * @param orderRefundDto 閫�娆炬暟閲忎俊鎭� * @return 閫�娆鹃噾棰濅俊鎭� */ @Override public OrderRefundDto nextStep(OrdersTotal ordersTotal,OrderRefundDto orderRefundDto) { logger.info("閫�娆鹃�夋嫨閫�娆炬暟閲忕粍瑁呴噾棰濅俊鎭叆鍙傦細{}", JSON.toJSONString(orderRefundDto)); - - //杩斿洖闆嗗悎 - OrderRefundDto returnRefund=new OrderRefundDto(); - - returnRefund.setOrderId(ordersTotal.getId()); //瀛愬崟閫�娆� List<OrderItemRefundDto> refundList = orderRefundDto.getRefundList(); @@ -464,42 +430,29 @@ } //鏀粯鏂瑰紡 - returnRefund.setPayMethodList(refundPayMethods); + orderRefundDto.setPayMethodList(refundPayMethods); //浼樻儬鍗� - List<OrderCouponRefunDto> couponList = nextStepIsCoupon(ordersTotal.getId()); - returnRefund.setPayCouponList(couponList); - - returnRefund.setRefundList(refundList); - returnRefund.setTotalAmount(totalAmount); - - return returnRefund; + orderRefundDto.setTotalAmount(totalAmount); + return orderRefundDto; } /**鑾峰彇鍏呭�煎崟鐨勯��娆炬柟寮忛噾棰�*/ public List<OrderPayMethodDto> rechargeRefundWay(OrdersTotal ordersTotal,BigDecimal totalAmount){ - SqlSentence sqlSentence = new SqlSentence(); - Map<String, Object> sqlMap = new HashMap<>(); - sqlSentence.setM(sqlMap); - sqlMap.put("isDel", BaseEntity.NO); - sqlMap.put("orderId", ordersTotal.getId()); - - //鑾峰彇璁㈠崟鐨勬敮浠樿褰� - sqlSentence.sqlSentence("SELECT numberNo,ANY_VALUE(name) AS name,ROUND(SUM(actualTotal-refundTotal),2) AS pTotal,ROUND(SUM(actualTotal),2),ROUND(SUM(refundTotal),2)" + - " FROM consume_pay WHERE orderId = #{m.orderId} AND isDel = #{m.isDel} GROUP BY numberNo ORDER BY createTime DESC",sqlMap); - List<ConsumePay> consumePayList = consumePayMapper.selectList(sqlSentence); + //鑾峰彇鎬绘敮浠樻柟寮� + List<PayMethodVo> payMethodVoList = refundMapper.selectConsumePayList(ordersTotal.getId()); List<OrderPayMethodDto> consumeList = new ArrayList<>(); OrderPayMethodDto orderPayMethodDto; //鍏呭�艰鍗曞彧鑳藉叏閫� - for (ConsumePay consumePay:consumePayList) { + for (PayMethodVo payMethodVo:payMethodVoList) { //鏀粯鏂瑰紡鍙��閲戦 orderPayMethodDto=new OrderPayMethodDto(); - orderPayMethodDto.setPayMethodNo(consumePay.getNumberNo()); - orderPayMethodDto.setRefundNumberNo(consumePay.getNumberNo()); - orderPayMethodDto.setPayMethodName(consumePay.getName()); - orderPayMethodDto.setRefundNumberName(consumePay.getName()); - orderPayMethodDto.setPayTotal(consumePay.getpTotal()); + orderPayMethodDto.setPayMethodNo(payMethodVo.getNumberNo()); + orderPayMethodDto.setPayMethodName(payMethodVo.getName()); + orderPayMethodDto.setRefundNumberNo(payMethodVo.getNumberNo()); + orderPayMethodDto.setRefundNumberName(payMethodVo.getName()); + orderPayMethodDto.setPayTotal(payMethodVo.getSurplusTotal()); orderPayMethodDto.setMoney(orderPayMethodDto.getPayTotal()); consumeList.add(orderPayMethodDto); @@ -559,9 +512,7 @@ if(OrderItemConstants.TYPE_PROJECT.equals(orderItem.getType())){ //////椤圭洰 - sqlMap.put("commonId",orderItem.getId()); - sqlSentence.sqlSentence("SELECT * FROM user_project_item upi WHERE upi.isDel = 0 AND upi.commonId = #{m.commonId} AND upi.isTransfer = 0",sqlMap); - UserProjectItem userProjectItem = userProjectItemMapper.selectOne(sqlSentence); + UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(orderItem.getId(),commonService); if(userProjectItem == null){ //buyNum = orderItem.getUsedTotal(); //surplusNum = orderItem.getUsedTotal() - orderItem.getHasReNum(); @@ -577,7 +528,7 @@ }else if(OrderItemConstants.TYPE_CARD.equals(orderItem.getType())){ ///////鍗¢」 //鑾峰彇鍙��娆剧殑鍗¢」娆℃暟 - List<UserCard> userCardList = getRefundCard(orderItem.getId()); + List<UserCard> userCardList = PartialRefundUtil.getRefundCard(orderItem.getId(),commonService); buyNum = orderItem.getBuyNum(); surplusNum = userCardList.size(); }else{ @@ -589,7 +540,7 @@ throw new TipsException("閫�娆炬暟閲忎笌鍙��鏁伴噺涓嶇锛�"); } - //鑾峰彇璇ュ瓙鍗曠殑鏀粯鏂瑰紡锛岀浉鍚岀殑鏀粯鏂瑰紡绠楀拰杩斿洖 + //鑾峰彇璇ュ瓙鍗曠殑鏀粯鏂瑰紡锛岀浉鍚岀殑鏀粯鏂瑰紡姹傚拰杩斿洖 List<PayMethodVo> payMethodVoList = refundMapper.selectConsumePayOneList(orderItem.getId()); //鑾峰彇宸查��娆剧殑閲戦 @@ -602,8 +553,8 @@ RefundRecordItem refundRecordItem = commonService.selectOne(RefundRecordItemMapper.class,sqlSentence); //璁$畻閫�娆炬柟寮忛噾棰� - DistributionRedundVo distributionRedundVo = PaymentCountTool.countMakeWay(orderItem.getActualTotal(),refundRecordItem==null?BigDecimal.ZERO:refundRecordItem.getOccupyRefundTotal() - ,buyNum,surplusNum,orderItemRefundDto.getRefundNum(),payMethodVoList); + DistributionRedundVo distributionRedundVo = PaymentCountTool.countMakeWay(orderItem.getId(),orderItem.getActualTotal(),refundRecordItem==null?BigDecimal.ZERO:refundRecordItem.getOccupyRefundTotal() + ,buyNum,surplusNum,orderItemRefundDto.getRefundNum(),payMethodVoList,commonService); distributionRedundVo.setGoodsType(orderItem.getType()); distributionRedundVo.setGoodsName(orderItem.getGoodsName()); @@ -633,9 +584,7 @@ UserProjectItem userProjectItem = null; if(OrderItemConstants.TYPE_PROJECT.equals(goodsType)){ //鑾峰彇鐢ㄦ埛椤圭洰 - sqlMap.put("commonId",orderItemSon.getId()); - sqlSentence.sqlSentence("SELECT * FROM user_project_item upi WHERE upi.isDel = 0 AND upi.commonId = #{m.commonId} AND upi.isTransfer = 0",sqlMap); - userProjectItem = userProjectItemMapper.selectOne(sqlSentence); + userProjectItem = PartialRefundUtil.getUserProject(orderItemSon.getId(),commonService); if(userProjectItem == null){ throw new TipsException("鐢ㄦ埛椤圭洰鑾峰彇澶辫触锛�"); } @@ -674,8 +623,8 @@ " WHERE rris.isDel = 0 AND rris.orderItemSonId = #{m.orderItemSonId}",sqlMap); RefundRecordItemSource refundRecordItemSource = commonService.selectOne(RefundRecordItemSourceMapper.class,sqlSentence); //璁$畻閫�娆炬柟寮忛噾棰� - DistributionRedundVo distributionRedundVo = PaymentCountTool.countMakeWay(orderItemSon.getActualTotal(),refundRecordItemSource==null?BigDecimal.ZERO:refundRecordItemSource.getOccupyRefundTotal() - ,buyNum,surplusNum,orderItemSourceRefundDto.getRefundNum(),payMethodVoList); + DistributionRedundVo distributionRedundVo = PaymentCountTool.countMakeWay(orderItemSon.getId(),orderItemSon.getActualTotal(),refundRecordItemSource==null?BigDecimal.ZERO:refundRecordItemSource.getOccupyRefundTotal() + ,buyNum,surplusNum,orderItemSourceRefundDto.getRefundNum(),payMethodVoList,commonService); distributionRedundVo.setGoodsType(orderItemSon.getType()); distributionRedundVo.setGoodsName(orderItemSon.getGoodsName()); return distributionRedundVo; @@ -804,7 +753,7 @@ throw new TipsException("鎿嶄綔澶辫触锛屽綋鍓嶈鍗曢��娆剧姸鎬佷笉鑳藉啀娆″彂璧烽��娆�!"); } - //鏍¢獙鍙傛暟锛屽拰鑾峰彇绯荤粺鍙傛暟 + //鏍¢獙鍙傛暟鍜岃幏鍙栫郴缁熷弬鏁帮紝闈炲父閲嶈 orderRefundDto = parameterVerification(ordersTotal,orderRefundDto); return handlePartRefund(ordersTotal,orderRefundDto,thirtApplication); @@ -836,6 +785,11 @@ if(payMethodDto == null){ throw new TipsException("鏈壘鍒癧"+orderPayMethodDto.getPayMethodName()+"]鏀粯鏂瑰紡!"); } + //鍒ゆ柇閫�娆炬柟寮� + PaymentMethod refundMethod = paymentMethodService.selectNumberNoUncheckUp(payMethodDto.getRefundNumberNo()); + if(refundMethod==null){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒拌杞崲鏂瑰紡:"+orderPayMethodDto.getRefundNumberName()+"["+orderPayMethodDto.getRefundNumberNo()+"]"); + } if(payMethodDto.getMoney() == null){ throw new TipsException("["+orderPayMethodDto.getPayMethodName()+"]閫�娆鹃噾棰濆繀濉�!"); } @@ -846,7 +800,7 @@ throw new TipsException("褰撳墠閫�娆炬柟寮廩"+orderPayMethodDto.getPayMethodName()+"]閲戦瓒呭嚭鍙��閲戦!"); } payMethodDto.setPayMethodName(orderPayMethodDto.getPayMethodName()); - payMethodDto.setPayMethodNo(orderPayMethodDto.getRefundNumberNo()); + payMethodDto.setPayMethodNo(orderPayMethodDto.getPayMethodNo()); payMethodDto.setPayTotal(orderPayMethodDto.getPayTotal()); refundTotal = refundTotal.add(payMethodDto.getMoney()).setScale(2,RoundingMode.HALF_UP); @@ -944,13 +898,13 @@ //閫�娆炬柟寮忓鐞� List<RefundRecordMethod> refundRecordMethodList = null; - if(orderRefundDto.getRefundPayMethod() !=null && orderRefundDto.getRefundPayMethod().size()>0){ + if(orderRefundDto.getRefundPayMethod() !=null && orderRefundDto.getRefundPayMethod().size() > 0){ refundRecordMethodList = handleRefundPayMethod(orderRefundDto,orderNodeBuilder,ordersTotal,refundRecord); } //閫�娆剧殑瀛愰」澶勭悊 if(orderRefundDto.getRefundList()!=null && orderRefundDto.getRefundList().size()>0){ - handleRefundRecordItem(orderRefundDto,orderNodeBuilder,ordersTotal,refundRecord,refundRecordMethodList); + insertRefundRecordItem(orderRefundDto,orderNodeBuilder,ordersTotal,refundRecord,refundRecordMethodList); } //鍥為��鐨勪紭鎯犲嵎澶勭悊 if(orderRefundDto.getCouponList() != null && orderRefundDto.getCouponList().size()>0){ @@ -1180,7 +1134,7 @@ if (payMethodVo == null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鍙��鏀粯鏂瑰紡鏈壘鍒板搴旂殑鏀粯:"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodNo()+"]"); } - //鍒ゆ柇閫�娆炬柟寮� + //鍒ゆ柇鏀粯鏂瑰紡 PaymentMethod payMethod = paymentMethodService.selectNumberNoUncheckUp(orderPayMethodDto.getPayMethodNo()); if(payMethod == null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒板搴旂殑鏀粯:"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodNo()+"]"); @@ -1188,10 +1142,14 @@ //鍒ゆ柇閫�娆炬柟寮� PaymentMethod refundMethod = paymentMethodService.selectNumberNoUncheckUp(orderPayMethodDto.getRefundNumberNo()); if(refundMethod==null){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒拌杞崲鏂瑰紡:"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodName()+"]"); + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒伴��娆炬柟寮�:"+orderPayMethodDto.getRefundNumberName()+"["+orderPayMethodDto.getRefundNumberNo()+"]"); } if(orderPayMethodDto.getMoney() == null){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"璇峰厛鍐欓��娆炬柟寮廩"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodNo()+"]"+"]閲戦"); + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"璇峰~鍐欓��娆炬柟寮廩"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodNo()+"]"+"]閲戦"); + } + //鍒ゆ柇閲戦 + if(payMethodVo.getSurplusTotal().compareTo(orderPayMethodDto.getMoney()) < 0){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆鹃噾棰濋敊璇�:"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodNo()+"]"); } //鏂板杞崲琛ㄨ褰� @@ -1203,6 +1161,7 @@ //閫�鍥炲鎴风殑鏀粯鏂瑰紡 refundRecordMethod = new RefundRecordMethod(); + refundRecordMethod.setType(refundRecord.getSourceType()); refundRecordMethod.setNumberNo(payMethod.getNumberNo()); refundRecordMethod.setPaymentMethodId(payMethod.getId()); refundRecordMethod.setName(payMethod.getName()); @@ -1217,9 +1176,7 @@ refundRecordMethod.setIsMoneyPayRefund(refundMethod.getIsMoneyPay()); refundRecordMethod.setIsExecuteRefund(refundMethod.getIsExecute()); - //refundRecordMethod.setConsumePayId(consumePay.getId()); refundRecordMethod.setRefundMethodTransId(refundMethodTransformation.getId()); - //refundRecordMethod.setRealRefundTotal(money);//瀹為��娆炬�婚噾棰� 鍚庢湡闇�瑕佷慨鏀� refundRecordMethod.setRemarks(orderPayMethodDto.getRemarks()); refundRecordMethodService.insert(refundRecordMethod); @@ -1231,7 +1188,7 @@ /** * 閫�娆捐褰曞瓙椤� */ - public void handleRefundRecordItem(OrderRefundDto orderRefundDto,StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord,List<RefundRecordMethod> refundRecordMethodList){ + public void insertRefundRecordItem(OrderRefundDto orderRefundDto,StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord,List<RefundRecordMethod> refundRecordMethodList){ SqlSentence sqlSentence = new SqlSentence(); Map<String,Object> map=new HashMap<>(); @@ -1240,7 +1197,7 @@ map.put("userId", ordersTotal.getUserId()); orderNodeBuilder.append("-璁板綍閫�娆捐鎯�"); - //璁$畻閲戦鍗犳瘮 + //璁$畻閲戦鍗犳瘮锛屽鎴烽�夋嫨閫�娆炬�婚噾棰濆拰鍙��鎬婚噾棰濆崰姣� BigDecimal percentage; if(orderRefundDto.getTotalAmount().compareTo(BigDecimal.ZERO) < 1){ percentage = BigDecimal.ZERO; @@ -1248,11 +1205,15 @@ percentage = orderRefundDto.getRefundTotal().divide(orderRefundDto.getTotalAmount(),15,RoundingMode.HALF_UP); } - //閫�娆炬�婚噾棰濓紝鐢ㄤ簬鍚庨潰璁$畻鍒嗘憡閲戦 + //鎬婚��娆鹃噾棰濓紝鐢ㄤ簬鍚庨潰璁$畻鍒嗘憡閲戦 BigDecimal refundTotal = refundRecord.getRefundTotal(); //瑁呰浇鍙傛暟 List<RefundRecordItemMethod> refundRecordItemMethodList; + + //鍚庨潰璁捐鍒嗛厤閲戦闂锛岃杩涜鍗囧簭鎺掑簭锛岄伩鍏嶅埌鏈�鍚庝笉澶� + List<OrderItemRefundDto> refundList = orderRefundDto.getRefundList(); + refundList = refundList.stream().sorted(Comparator.comparing(OrderItemRefundDto::getApproveRefundTotal)).collect(Collectors.toList()); /////寮曠敤鍙傛暟 RefundRecordItem refundRecordItem; @@ -1260,8 +1221,10 @@ RefundRecordItemMethod refundRecordItemMethod; RefundRecordMethod refundRecordMethod; OrderItem orderItem; - for(int i = 0;i<orderRefundDto.getRefundList().size();i++){ - orderItemRefundDto = orderRefundDto.getRefundList().get(i); + //鏀粯鏂瑰紡鍗犳瘮 + BigDecimal payMothedPercentage; + for(int i = 0;i < refundList.size();i++){ + orderItemRefundDto = refundList.get(i); refundRecordItemMethodList = new ArrayList<>(); orderItem = orderItemMapper.selectOneByKey(orderItemRefundDto.getOrderItemId()); @@ -1290,8 +1253,8 @@ refundRecordItem.setRemarks(orderItemRefundDto.getRemarks()); refundRecordItem.setRefundReason(orderItemRefundDto.getRefundReason()); - //璁$畻閫�娆鹃噾棰� - if(i == orderRefundDto.getRefundList().size()-1){ + //////////鍒嗛厤閫�娆鹃噾棰� + if(i == refundList.size()-1){ refundRecordItem.setRefundMoney(refundTotal); }else{ refundRecordItem.setRefundMoney(orderItemRefundDto.getApproveRefundTotal().multiply(percentage).setScale(2,RoundingMode.UP)); @@ -1299,17 +1262,29 @@ if(refundRecordItem.getRefundMoney().compareTo(orderItemRefundDto.getApproveRefundTotal()) > 0){ refundRecordItem.setRefundMoney(orderItemRefundDto.getApproveRefundTotal()); } + //鍒ゆ柇涓庢湭鍒嗛厤鍓╀綑閲戦 if(refundRecordItem.getRefundMoney().compareTo(refundTotal) > 0){ refundRecordItem.setRefundMoney(refundTotal); } - refundTotal = refundTotal.subtract(refundRecordItem.getRefundMoney()).setScale(2,RoundingMode.HALF_UP); refundRecordItemService.insert(refundRecordItem); + //璁$畻鍓╀綑瑕佸垎閰嶇殑閫�娆炬�婚噾棰� + 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();i++){ + + for(int j = 0;j <refundRecordMethodList.size();j++){ refundRecordMethod = refundRecordMethodList.get(j); ////瀛愰」閫�娆炬柟寮忓~鍏� @@ -1332,7 +1307,7 @@ refundRecordItemMethod.setActualTotal(refundTotalItem); }else { ////涓嶆槸鏈�鍚庝竴涓� - refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal().multiply(percentage).setScale(2,RoundingMode.UP)); + refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); } if(refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getActualTotal()) > 0){ refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal()); @@ -1340,21 +1315,30 @@ if(refundRecordItemMethod.getActualTotal().compareTo(refundTotalItem) > 0){ refundRecordItemMethod.setActualTotal(refundTotalItem); } - refundTotalItem = refundTotalItem.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); - + //鍒ゆ柇涓庡墿浣欑殑鏈垎閰嶉��娆炬柟寮忛噾棰� + 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); - } - } - //瀛愬崟瀛愰」澶勭悊 - itemTwoRefundHandle(refundRecordItem,refundRecord,orderItemRefundDto.getOrderItemSourceRefundDtos() - , refundRecordItemMethodList, percentage); + //鍑忓幓宸茬粡鍒嗛厤鐨勯��娆炬柟寮忛噾棰� + 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); } //澶勭悊姣忎釜椤圭洰姣忎釜鏀粯鏂瑰紡鐨勫垎鎽婇噾棰� @@ -1362,11 +1346,22 @@ } /**浜岀骇瀛愬崟澶勭悊*/ - public void itemTwoRefundHandle(RefundRecordItem recordItem,RefundRecord refundRecord,List<OrderItemSourceRefundDto> orderItemSourceRefundDtos - ,List<RefundRecordItemMethod> refundRecordItemMethodList,BigDecimal percentage){ + public void insertRefundRecordItemTwo(RefundRecordItem recordItem,RefundRecord refundRecord,List<OrderItemSourceRefundDto> orderItemSourceRefundDtos + ,List<RefundRecordItemMethod> refundRecordItemMethodList){ if(orderItemSourceRefundDtos == null || orderItemSourceRefundDtos.size() == 0){ return; } + + //璁$畻鍗犳瘮 + BigDecimal percentage; + if(recordItem.getOccupyRefundTotal().compareTo(BigDecimal.ZERO) > 0){ + percentage = recordItem.getRefundMoney().divide(recordItem.getOccupyRefundTotal(),15,RoundingMode.HALF_UP); + }else{ + percentage = BigDecimal.ZERO; + } + + //杩涜鍗囧簭鎺掑簭锛岄伩鍏嶅悗闈笉澶� + orderItemSourceRefundDtos = orderItemSourceRefundDtos.stream().sorted(Comparator.comparing(OrderItemSourceRefundDto::getApproveRefundTotal)).collect(Collectors.toList()); //閫�娆炬�婚噾棰� BigDecimal refundTotal = recordItem.getRefundMoney(); @@ -1375,6 +1370,9 @@ OrderItemSourceRefundDto orderItemSourceRefundDto; RefundRecordItemSource refundRecordItemSource; RefundRecordItemMethod refundRecordItemMethod; + RefundRecordItemMethod refundRecordItemSonMethod; + //鏀粯鏂瑰紡鍗犳瘮 + BigDecimal payMothedPercentage; for(int i = 0;i<orderItemSourceRefundDtos.size();i++){ orderItemSourceRefundDto = orderItemSourceRefundDtos.get(i); @@ -1416,56 +1414,71 @@ if(refundRecordItemSource.getRefundMoney().compareTo(refundTotal) > 0){ refundRecordItemSource.setRefundMoney(refundTotal); } - refundTotal = refundTotal.subtract(refundRecordItemSource.getRefundMoney()).setScale(2,RoundingMode.HALF_UP); refundRecordItemSourceMapper.insert(refundRecordItemSource); + //鍑忓幓宸茬粡鍒嗛厤閫�娆鹃噾棰� + 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();i++){ + for(int j = 0;j <refundRecordItemMethodList.size();j++){ refundRecordItemMethod = refundRecordItemMethodList.get(j); ////瀛愰」閫�娆炬柟寮忓~鍏� - refundRecordItemMethod = new RefundRecordItemMethod(); - refundRecordItemMethod.setNumberNo(refundRecordItemMethod.getNumberNo()); - refundRecordItemMethod.setName(refundRecordItemMethod.getName()); + refundRecordItemSonMethod = new RefundRecordItemMethod(); + refundRecordItemSonMethod.setNumberNo(refundRecordItemMethod.getNumberNo()); + refundRecordItemSonMethod.setName(refundRecordItemMethod.getName()); //鏀粯鏂瑰紡 - refundRecordItemMethod.setPaymentMethodId(refundRecordItemMethod.getPaymentMethodId()); - refundRecordItemMethod.setIsMoneyPay(refundRecordItemMethod.getIsMoneyPay()); - refundRecordItemMethod.setIsExecute(refundRecordItemMethod.getIsExecute()); - refundRecordItemMethod.setIsPay(refundRecordItemMethod.getIsPay()); + refundRecordItemSonMethod.setPaymentMethodId(refundRecordItemMethod.getPaymentMethodId()); + refundRecordItemSonMethod.setIsMoneyPay(refundRecordItemMethod.getIsMoneyPay()); + refundRecordItemSonMethod.setIsExecute(refundRecordItemMethod.getIsExecute()); + refundRecordItemSonMethod.setIsPay(refundRecordItemMethod.getIsPay()); //閫�娆炬柟寮� - refundRecordItemMethod.setRefundNumberNo(refundRecordItemMethod.getRefundNumberNo()); - refundRecordItemMethod.setRefundName(refundRecordItemMethod.getRefundName()); - refundRecordItemMethod.setRefundMethodId(refundRecordItemMethod.getRefundMethodId()); + refundRecordItemSonMethod.setRefundNumberNo(refundRecordItemMethod.getRefundNumberNo()); + refundRecordItemSonMethod.setRefundName(refundRecordItemMethod.getRefundName()); + refundRecordItemSonMethod.setRefundMethodId(refundRecordItemMethod.getRefundMethodId()); //閫�娆鹃噾棰� if(j == refundRecordItemMethodList.size()-1){ ////鏈�鍚庝竴涓� - refundRecordItemMethod.setActualTotal(refundTotalItem); + refundRecordItemSonMethod.setActualTotal(refundTotalItem); }else { ////涓嶆槸鏈�鍚庝竴涓� - refundRecordItemMethod.setActualTotal(refundRecordItemMethod.getActualTotal().multiply(percentage).setScale(2,RoundingMode.UP)); + refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); } - if(refundRecordItemMethod.getActualTotal().compareTo(refundRecordItemMethod.getActualTotal()) > 0){ - refundRecordItemMethod.setActualTotal(refundRecordItemMethod.getActualTotal()); + if(refundRecordItemSonMethod.getActualTotal().compareTo(refundRecordItemMethod.getActualTotal()) > 0){ + refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getActualTotal()); } - if(refundRecordItemMethod.getActualTotal().compareTo(refundTotalItem) > 0){ - refundRecordItemMethod.setActualTotal(refundTotalItem); + if(refundRecordItemSonMethod.getActualTotal().compareTo(refundTotalItem) > 0){ + refundRecordItemSonMethod.setActualTotal(refundTotalItem); } - refundTotalItem = refundTotalItem.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); + if(refundRecordItemSonMethod.getActualTotal().compareTo(refundRecordItemMethod.getpTotal()) > 0){ + refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getpTotal()); + } - refundRecordItemMethod.setCommonType(OrderSourceConstans.TYPE_RETAIL); - refundRecordItemMethod.setCommonId(refundRecordItemSource.getOrderItemSonId()); - refundRecordItemMethod.setOrderId(refundRecordItemMethod.getOrderId()); - refundRecordItemMethod.setRefundRecordItemId(refundRecordItemSource.getId()); - refundRecordItemMethod.setRefundRecordId(refundRecord.getId()); - refundRecordItemMethodMapper.insert(refundRecordItemMethod); - refundRecordItemMethodList.add(refundRecordItemMethod); + 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)); } - } - + }*/ } } @@ -1498,8 +1511,8 @@ String operationId=operator.get("operatorId"); String operatorName=operator.get("operatorName"); - //澶勭悊涓讳笟鍔� orderNodeBuilder.append("-澶勭悊閫�娆炬敮浠樻柟寮忥紝鐢ㄦ埛寰呮墽琛岄」鐩�"); + //澶勭悊涓讳笟鍔� ordersTotal= PartialRefundUtil.refundProcess(commonService, operationId, operatorName, refundRecord.getId(), customParameter); //杩斿洖鏁版嵁 @@ -1509,7 +1522,8 @@ //澶勭悊娆′笟鍔★紝鎶ラ敊涓嶅奖鍝嶄富涓氬姟 - refundRecord=refundRecordService.selectOneByKey(refundRecord.getId()); + refundRecord = refundRecordService.selectOneByKey(refundRecord.getId()); + /** * 鐢ㄦ埛鍗囬檷绾�(璋冪敤鑸埛) 閲戦=鐢ㄦ埛鏀粯鐨勫疄浠樼幇閲戦噾棰�(涓嶅寘鍚偍鍊奸噾) */ @@ -2175,9 +2189,7 @@ if(OrderTotalConstants.STATUS_REFUND_FINSH==orderItemSon.getRefundStatus()){ oldRefundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; - sqlMap.put("commonId", orderItemSon.getId()); - sqlSentence.sqlSentence("SELECT * FROM user_project_item WHERE 銆�commonId = #{m.commonId} AND isTransfer = 0 and isDel = #{m.isDel} LIMIT 1 ",sqlMap); - userProjectItem=userProjectItemMapper.selectOne(sqlSentence); + userProjectItem = PartialRefundUtil.getUserProject(orderItemSon.getId(),commonService); if(userProjectItem.getNotUsedNum()>0){ newRefundStatus=OrderTotalConstants.STATUS_REFUND_PART; @@ -2212,9 +2224,7 @@ for (OrderItem orderItem : orderItemList) { oldRefundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; - sqlMap.put("commonId", orderItem.getId()); - sqlSentence.sqlSentence("SELECT * FROM user_project_item WHERE commonId = #{m.commonId} AND isTransfer = 0 and isDel = #{m.isDel} LIMIT 1 ",sqlMap); - userProjectItem=userProjectItemMapper.selectOne(sqlSentence); + userProjectItem = PartialRefundUtil.getUserProject(orderItem.getId(),commonService); if(userProjectItem.getNotUsedNum()>0){ newRefundStatus=OrderTotalConstants.STATUS_REFUND_PART; diff --git a/phi_platform_user/src/main/java/com/hx/phip/util/api/PartialRefundUtil.java b/phi_platform_user/src/main/java/com/hx/phip/util/api/PartialRefundUtil.java deleted file mode 100644 index 8143de8..0000000 --- a/phi_platform_user/src/main/java/com/hx/phip/util/api/PartialRefundUtil.java +++ /dev/null @@ -1,910 +0,0 @@ -package com.hx.phip.util.api; - -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.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.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.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.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * @Author - */ -public class PartialRefundUtil { - private static final Logger logger = LoggerFactory.getLogger(PartialRefundUtil.class); - /** - * 閫�娆炬�绘祦绋嬪伐鍏� - * @param commonService - * @param operationId - * @param operationNme - * @param refundId - */ - public static OrdersTotal refundProcess(CommonService commonService, String operationId, String operationNme, String refundId, CustomParameter customParameter) { - 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); - if(refundRecord ==null){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鎵句笉鍒拌閫�娆句俊鎭紒"); - } - - //鏌ョ湅璁㈠崟淇℃伅 - OrdersTotal ordersTotal=commonService.selectOneByKeyBlob(OrdersTotalMapper.class,refundRecord.getOrderId()); - if(ordersTotal==null ){ - throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏈壘鍒拌鍗曚俊鎭�!"); - } - //鏌ョ湅璁㈠崟鍏朵粬淇℃伅 - /*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"); - UserMoney userMoney=commonService.selectOne(UserMoneyMapper.class,sqlSentence); - if(userMoney==null){ - throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏈壘鍒拌鐢ㄦ埛鐨勮祫閲戜俊鎭�"); - } - //澶勭悊浼樻儬鍒� - handCoupon(commonService, sqlSentence, map, refundRecord,ordersTotal); - - if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){ - //鍏呭�艰鍗曢渶瑕佹妸鍏呭�肩殑鍌ㄥ�奸噾 鎷垮洖鏉� 鍥犱负鍌ㄥ�奸噾闇�瑕佸紑鍗曟潵澶勭悊锛屾墍浠ヤ笉闇�瑕佸鍔犳棩蹇� - //鍒ゆ柇閲戦涓嶇瓑浜�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); - } - - }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); - } - } - - //澶勭悊鎬婚��娆炬柟寮忔暟鎹� - refundRecordMotnedHandle(operationId,operationNme,ordersTotal,refundRecord,commonService); - - //閫�娆炬�昏鍗� - 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}"); - if(commonService.updateWhere(RefundRecordMapper.class,sqlSentence) != 1){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鎿嶄綔澶辫触锛岄��娆惧崟鐘舵�佸凡鏀瑰彉锛�"); - } - - //鏇存敼鎬昏鍗曢��娆剧姸鎬� - map.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); - - List<Integer> collect = orderItemList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList()); - if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){ - ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); - ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add)); - }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ - ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART); - 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 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,OrdersTotal ordersTotal - ,RefundRecord refundRecord,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; - //鏀粯鏂瑰紡鎵e噺閲戦 - BigDecimal mothedCutTotal; - //寮曠敤瀵硅薄 - RefundRecordConsumePay refundRecordConsumePay; - 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("refundMethodId",refundRecordMethod.getId()); - sqlSentence.sqlUpdate(" realRefundTotal=#{m.realRefundTotal} where id = #{m.refundMethodId}",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; - } - //璁$畻鎵e噺閲戦 - 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("閫�娆鹃噾棰濋敊璇紒"); - } - - //鐢熸垚鍏宠仈璁板綍 - refundRecordConsumePay = new RefundRecordConsumePay(); - refundRecordConsumePay.setRefundMethodId(refundRecordMethod.getId()); - refundRecordConsumePay.setConsumePayId(consumePay.getId()); - refundRecordConsumePay.setRefundTotal(mothedCutTotal); - commonService.insert(RefundRecordConsumePayMapper.class,refundRecordConsumePay); - - //璁$畻涓哄垎閰嶉噾棰� - 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]锛�"); - } - } - - //瀛愰��娆炬柟寮� - refundRecordMotnedItemHandle(refundRecord,commonService); - - } - - /**澶勭悊瀛愰��娆炬柟寮忔暟鎹�*/ - public static void refundRecordMotnedItemHandle(RefundRecord refundRecord,CommonService commonService){ - SqlSentence sqlSentence = new SqlSentence(); - Map<String,Object> values = new HashMap<>(); - - values.put("refundRecordId",refundRecord.getId()); - sqlSentence.sqlSentence("SELECT * FROM refund_record_item_method WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",values); - List<RefundRecordItemMethod> refundRecordItemMethodList = commonService.selectList(RefundRecordItemMethodMapper.class,sqlSentence); - //閫�娆炬柟寮忔�婚噾棰� - BigDecimal mothedTotal; - //鏀粯鏂瑰紡鎵e噺閲戦 - BigDecimal mothedCutTotal; - //寮曠敤瀵硅薄 - RefundRecordConsumePay refundRecordConsumePay; - List<ConsumePayItem> consumePayItemList; - //澧炲姞澧炲�奸噾 - 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()); - if(refundRecordItemMethod.getCommonType().equals(OrderSourceConstans.TYPE_PROJECT)){ - //涓�绾у瓙鍗曟敮浠樿褰� - sqlSentence.sqlSentence("SELECT *,ROUND(actualTotal-refundTotal,2) AS pTotal FROM consume_pay_item WHERE isDel = 0 AND orderId = #{m.orderId} AND numberNo = #{m.numberNo} AND typeId = #{m.typeId} ORDER BY pTotal ASC",values); - }else{ - //浜岀骇瀛愬崟鏀粯璁板綍 - 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); - } - consumePayItemList = commonService.selectList(ConsumePayMapper.class,sqlSentence); - for(ConsumePayItem consumePayItem:consumePayItemList){ - if(consumePayItem.getpTotal().compareTo(BigDecimal.ZERO) < 1){ - continue; - } - //璁$畻鎵e噺閲戦 - if(consumePayItem.getpTotal().compareTo(mothedTotal) > 0){ - mothedCutTotal = mothedTotal; - }else{ - 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(refundRecordItemMethod.getCommonType().equals(OrderSourceConstans.TYPE_PROJECT)){ - //涓�绾у瓙鍗曟敮浠樿褰� - if(commonService.updateWhere(ConsumePayItemMapper.class,sqlSentence) != 1){ - throw new TipsException("閫�娆鹃噾棰濋敊璇痆424]锛�"); - } - }else { - if(commonService.updateWhere(ConsumePayItemSonMapper.class,sqlSentence) != 1){ - throw new TipsException("閫�娆鹃噾棰濋敊璇痆425]锛�"); - } - } - - //鐢熸垚鍏宠仈璁板綍 - refundRecordConsumePay = new RefundRecordConsumePay(); - refundRecordConsumePay.setRefundMethodId(refundRecordItemMethod.getId()); - refundRecordConsumePay.setConsumePayId(consumePayItem.getId()); - refundRecordConsumePay.setRefundTotal(mothedCutTotal); - commonService.insert(RefundRecordConsumePayMapper.class,refundRecordConsumePay); - - //璁$畻涓哄垎閰嶉噾棰� - 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 commonService - * @param sqlSentence - * @param map - * @param refundRecord - */ - public static void handCoupon(CommonService commonService, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord,OrdersTotal ordersTotal) { - map.put("refundRecordId",refundRecord.getId()); - sqlSentence.setSqlSentence("select * from refund_record_coupon where refundRecordId=#{m.refundRecordId} and isDel=0 "); - List<RefundRecordCoupon> refundRecordCouponList=commonService.selectList(RefundRecordCouponMapper.class,sqlSentence); - //閫�娆炬垚鍔� - map.put("status", BaseEntity.YES); - CouponOrderDiscountLog couponOrderDiscountLog=null; - for (RefundRecordCoupon refundRecordCoupon : refundRecordCouponList) { - sqlSentence.setSqlSentence(" status=#{m.status} 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,"璁㈠崟浼樻儬鍗穒d涓嶆纭�"); - } - commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence); - - 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); - } - - - } - - /** - * 閫�娆�-澶勭悊娲诲姩瑙勫垯澧炲�奸噾鍜岀Н鍒� - * @param commonService - * @param operationId - * @param operationNme - * @param sqlSentence - * @param map - * @param refundRecord - * @param ordersTotal - */ - private static void handActivityRule(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, - Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, OrderInfo orderInfo) { - if(orderInfo!=null && StringUtils.noNull(orderInfo.getActivityId())){ - ActivityRule activityRule=commonService.selectOneByKeyBlob(ActivityRuleMapper.class,orderInfo.getActivityId()); - if(activityRule!=null){ - map.put("activityRuleId",activityRule.getId()); - map.put("type", ActivityAction.TYPE_INTEGRAL); - map.put("type1",ActivityAction.TYPE_VALUEADDEDFUND); - map.put("type2",ActivityAction.TYPE_COUPON); - sqlSentence.setSqlSentence("select * from activity_action where activityRuleId=#{m.activityRuleId} and (type=#{m.type} or type=#{m.type1} or type=#{m.type2}) and isDel=0"); - List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence); - if(activityActions!=null && activityActions.size()>0){ - for (ActivityAction activityAction : activityActions) { - if(ActivityAction.TYPE_INTEGRAL.equals(activityAction.getType())){ - //鍒ゆ柇閲戦涓嶇瓑浜�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())){ - //鍒ゆ柇閲戦涓嶇瓑浜�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); - map.put("couponId",activityAction.getCrmCouponId()); - map.put("commonId",ordersTotal.getId()); - sqlSentence.setSqlSentence(" validState=#{m.newValidState} where couponId=#{m.couponId} and commonId=#{m.commonId} and validState=#{m.oldValidState} "); - commonService.updateWhere(CouponNumberMapper.class,sqlSentence); - } - } - } - } - } - - } - /** - * 閫�娆�-澶勭悊鏅�氳鍗曚俊鎭�(姣斿:椤圭洰銆佷績閿�銆佸崱椤�) - * @param commonService - * @param operationId 鎿嶄綔浜烘爣璇� - * @param operationNme 鎿嶄綔浜哄悕绉� - * @param sqlSentence - * @param map - * @param refundRecord - */ - 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}"); - List<RefundRecordItem> refundRecordItems =commonService.selectList(RefundRecordItemMapper.class,sqlSentence); - if(refundRecordItems==null && refundRecordItems.size()==0){ - throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏈壘鍒伴��娆惧瓙璁㈠崟淇℃伅"); - } - for (RefundRecordItem v: refundRecordItems) { - switch (v.getType()){ - case OrderItemConstants.TYPE_RETAIL: - handRefundRerail(commonService, sqlSentence, map, refundRecord, v); - break; - case OrderItemConstants.TYPE_DRUG: - handRefundRerail(commonService, sqlSentence, map, refundRecord, v); - break; - case OrderItemConstants.TYPE_PROJECT: - handRefundNoExecution(commonService, operationId, operationNme, refundRecord,v); - break; - case OrderItemConstants.TYPE_PROMOTION: - handRefundPromotion(commonService, operationId, operationNme, sqlSentence, map, refundRecord, ordersTotal, v); - break; - case OrderItemConstants.TYPE_CARD: - handRefundCard(commonService, operationId, sqlSentence, map, refundRecord, ordersTotal, v); - break; - case OrderItemConstants.CARD_BAG: - handCardBag(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,v,customParameter); - break; - default:break; - } - } - } - - /** - * 閫�娆句竴绾ф槸鍟嗗搧 - * @param commonService - * @param sqlSentence - * @param map - * @param refundRecord - * @param v - */ - private static void handRefundRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItem v) { - - //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� - OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.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); - } - - sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} "); - commonService.updateWhere(OrderItemMapper.class,sqlSentence); - } - /** - * 閫�娆�-澶勭悊鏈墽琛屽垝鎵� 椤圭洰绫诲瀷 - * @param commonService - * @param operationId 鎿嶄綔浜� - * @param operationNme 鎿嶄綔浜哄悕绉� - * @param refundRecord - * @param v - */ - private static void handRefundNoExecution(CommonService commonService, String operationId, String operationNme, RefundRecord refundRecord, RefundRecordItem v) { - SqlSentence sqlSentence = new SqlSentence(); - Map<String, Object> map = new HashMap<>(); - - map.clear(); - map.put("commonId",v.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_TIPS,"鏈壘鍒扮敤鎴峰瓙椤归」鐩俊鎭�"); - } - - if(userProjectItem.getNotUsedNum()<v.getRefundNum()){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆炬鏁板ぇ浜庡彲閫�娆℃暟锛�"); - } - - //鐢ㄦ埛椤圭洰鎿嶄綔 - UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_DEDUCTION,null - ,v.getId(),v.getRefundNum(),refundRecord.getOperatorAppId(),refundRecord.getOperatorAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"鍛樺伐澶囨敞锛�"+refundRecord.getRemarks()+"|鐢ㄦ埛澶囨敞锛�"+refundRecord.getRefundReason(),commonService); - - //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� - OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); - if (orderItem==null){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒板瓙璁㈠崟淇℃伅"); - } - - //璁$畻瀛愬崟鏄惁杩樻湁鍓╀綑鐨勫彲鎵g枟绋嬫暟 - int refundNumTotal = orderItem.getHasReNum()+v.getRefundNum(); - Integer refundStatus; - if(orderItem.getUsedTotal().equals(refundNumTotal)){ - refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; - }else if(orderItem.getUsedTotal()>refundNumTotal){ - refundStatus=OrderTotalConstants.STATUS_REFUND_PART; - }else{ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆炬鏁板ぇ浜庡瓙鍗曞彲閫�娆℃暟锛�"); - } - - map.clear(); - map.put("orderItemId", orderItem.getId()); - map.put("refundStatus", refundStatus); - map.put("refundMoney",v.getRefundMoney()); - map.put("refundNum",v.getRefundNum()); - map.put("oldHasReNum",orderItem.getHasReNum()); - sqlSentence.sqlUpdate(" refundStatus=#{m.refundStatus},reTotal=reTotal+#{m.refundMoney},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]锛�"); - } - } - /** - * 閫�娆�-澶勭悊鍗¢」 - * @param commonService - * @param operationId - * @param sqlSentence - * @param map - * @param refundRecord - * @param ordersTotal - * @param v - */ - public static void handRefundCard(CommonService commonService, String operationId, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem v) { - - //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� - OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); - if (orderItem==null){ - throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏈壘鍒板瓙璁㈠崟淇℃伅"); - } - //浣滃簾鍗″寘 - - 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 doneeUserId IS NULL 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.getId()); - }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); - } - } - - //鏇存敼璁㈠崟瀛愯鍗曠姸鎬� - 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); - } - - /** - * 閫�娆�-澶勭悊鍗″寘 - * @param commonService - * @param operationId - * @param operationNme - * @param sqlSentence - * @param map - * @param refundRecord - * @param ordersTotal - * @param v - */ - public static void handCardBag(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, - RefundRecord refundRecord, OrdersTotal ordersTotal,RefundRecordItem v,CustomParameter customParameter) { - //鏌ョ湅璁㈠崟淇℃伅 - OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); - if(orderItem==null ){ - throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏈壘鍒板瓙璁㈠崟淇℃伅!"); - } - map.put("refundRecordItemId",v.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: - //澧炲�奸噾 - //鍒ゆ柇閲戦涓嶇瓑浜�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; - } - } - } - //鏇存敼浜岀骇瀛愯鍗曢��娆剧姸鎬� - - map.put("orderItemId",orderItem.getId()); - sqlSentence.setSqlSentence("select * from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0"); - List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); - - 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)); - }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ - orderItem.setRefundStatus(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()); - }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){ - - - OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,son.getOrderItemSonId()); - Integer hasReNum=orderItemSon.getHasReNum(); - - 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); - } - - UserCardUsed userCardUsed; - for (int i = 0; i < hasReNum; i++) { - userCardUsed=userCardUsedList.get(i); - userCardUsed.setIsDel(BaseEntity.YES); - commonService.updateAll(UserCardUsedMapper.class,userCardUsed); - } - } - /** - * 閫�娆�-澶勭悊淇冮攢 - * @param commonService - * @param operationId - * @param operationNme - * @param sqlSentence - * @param map - * @param refundRecord - * @param ordersTotal - * @param v - */ - private static void handRefundPromotion(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem v) { - //鏌ョ湅璁㈠崟淇℃伅 - OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId()); - if(orderItem==null ){ - throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"鏈壘鍒板瓙璁㈠崟淇℃伅!"); - } - - map.put("refundRecordItemId",v.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: - 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; - } - } - } - - //鏇存敼浜岀骇瀛愯鍗曢��娆剧姸鎬� - - map.put("orderItemId",orderItem.getId()); - sqlSentence.setSqlSentence("select * from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0"); - List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); - - 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)); - }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ - orderItem.setRefundStatus(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()); - }else { - orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE); - } - - commonService.updateAll(OrderItemMapper.class,orderItem); - } - /** - * 閫�娆�-澶勭悊浜岀骇瀛愯鍗曟湭鎵ц鍒掓墸 椤圭洰绫诲瀷 - * @param commonService - * @param sqlSentence - * @param map - * @param refundRecord - * @param v - */ - private static void handRefundNoSonExecution(CommonService commonService, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) { - map.clear(); - map.put("commonId",v.getOrderItemSonId()); - 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_TIPS,"鏈壘鍒扮敤鎴峰瓙椤归」鐩俊鎭�"); - } - - if(userProjectItem.getNotUsedNum()<v.getRefundNum()){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆炬鏁板ぇ浜庡彲閫�娆℃暟锛�"); - } - - //鐢ㄦ埛椤圭洰鎿嶄綔 - UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_DEDUCTION,null - ,v.getId(),v.getRefundNum(),refundRecord.getOperatorAppId(),refundRecord.getOperatorAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"鍛樺伐澶囨敞锛�"+refundRecord.getRemarks()+"|鐢ㄦ埛澶囨敞锛�"+refundRecord.getRefundReason(),commonService); - - - //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� - OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId()); - if (orderItemSon==null){ - logger.info("浜岀骇瀛愯鍗昳d锛歿}",v.getOrderItemSonId()); - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒颁簩绾у瓙璁㈠崟淇℃伅"); - } - //璁$畻瀛愬崟鏄惁杩樻湁鍓╀綑鐨勫彲鎵g枟绋嬫暟 - int refundNumTotal = orderItemSon.getHasReNum()+v.getRefundNum(); - Integer refundStatus; - if(orderItemSon.getUsedTotal().equals(refundNumTotal)){ - refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH; - }else if(orderItemSon.getUsedTotal()>refundNumTotal){ - refundStatus=OrderTotalConstants.STATUS_REFUND_PART; - }else{ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"閫�娆炬鏁板ぇ浜庡瓙鍗曞彲閫�娆℃暟锛�"); - } - map.clear(); - map.put("orderItemId", v.getOrderItemSonId()); - map.put("refundMoney",v.getRefundMoney()); - map.put("refundNum",v.getRefundNum()); - map.put("oldHasReNum",orderItemSon.getHasReNum()); - map.put("refundStatus", refundStatus); - sqlSentence.sqlUpdate(" refundStatus=#{m.refundStatus}, reTotal=reTotal+#{m.refundMoney}, hasReNum=hasReNum+#{m.refundNum}" + - " where isDel=0 AND id=#{m.orderItemId} AND hasReNum = #{m.oldHasReNum}",map); - if(commonService.updateWhere(OrderItemSonMapper.class,sqlSentence) != 1){ - throw new PlatTipsException(PlatformCode.ERROR_TIPS,"褰撳墠璁㈠崟淇℃伅宸插彂鐢熷彉鍖栵紝璇烽噸璇昜013]锛�"); - } - } - /** - * 閫�娆句簩绾ф槸鍟嗗搧 - * @param commonService - * @param sqlSentence - * @param map - * @param refundRecord - * @param v - */ - private static void handRefundSonRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) { - - //鍒ゆ柇鎿嶄綔瀹屼簡鍘讳慨鏀瑰瓙璁㈠崟鐘舵�� - OrderItemSon orderItem=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId()); - if (orderItem==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); - } - - sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} "); - commonService.updateWhere(OrderItemSonMapper.class,sqlSentence); - } -} -- Gitblit v1.8.0