From e9e32c597f1b95ca18c632cafc551952aa797b81 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期一, 03 四月 2023 10:54:11 +0800 Subject: [PATCH] 退款重构 --- phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java | 68 ++++++++++++++++++++++----------- 1 files changed, 45 insertions(+), 23 deletions(-) diff --git a/phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java b/phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java index 0e8f7fa..949bd3d 100644 --- a/phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java +++ b/phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java @@ -92,7 +92,7 @@ //鏌ヨ鐢ㄦ埛鏄惁鏈夎处鎴蜂俊鎭紝閫�娆鹃渶瑕佸鐞嗚祫閲� values.clear(); values.put("userId",refundRecord.getUserId()); - sqlSentence.setSqlSentence("SELECT * FROM user_money WHERE userId=#{m.userId} AND isDel=0"); + sqlSentence.sqlSentence("SELECT * FROM user_money WHERE userId=#{m.userId} AND isDel=0",values); UserMoney userMoney=commonService.selectOne(UserMoneyMapper.class,sqlSentence); if(userMoney==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒拌鐢ㄦ埛鐨勮祫閲戜俊鎭�"); @@ -132,7 +132,7 @@ //鏇存敼鎬昏鍗曢��娆剧姸鎬� values.clear(); values.put("orderId",ordersTotal.getId()); - sqlSentence.setSqlSentence("select * from order_item WHERE orderId=#{m.orderId} and isDel=0"); + sqlSentence.sqlSentence("select * from order_item WHERE orderId=#{m.orderId} and isDel=0",values); List<OrderItem> orderItemList=commonService.selectList(OrderItemMapper.class,sqlSentence); List<Integer> collect = orderItemList.stream().map(OrderItem::getRefundStatus).collect(Collectors.toList()); @@ -656,7 +656,7 @@ map.clear(); map.put("status", BaseEntity.YES); map.put("id", couponOrderDiscountLog.getId()); - sqlSentence.setSqlSentence("status = #{m.status} WHERE id = #{m.id}"); + sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id}",map); if(commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence) != 1){ throw new TipsException("浼樻儬鍒稿洖閫�澶辫触锛�"); } @@ -671,7 +671,7 @@ 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} "); + sqlSentence.sqlSentence(" isUse=#{m.isUse},useTime=#{m.useTime},useType=#{m.useType},isUse=#{m.isUse} WHERE id = #{m.id} ",map); if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 1){ throw new TipsException("浼樻儬鍒稿洖閫�澶辫触[67]锛�"); } @@ -690,7 +690,7 @@ 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"); + sqlSentence.sqlSentence("select * from activity_action where activityRuleId=#{m.activityRuleId} and (type=#{m.type} or type=#{m.type1} or type=#{m.type2}) and isDel=0",map); List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence); if(activityActions!=null && activityActions.size()>0){ for (ActivityAction activityAction : activityActions) { @@ -709,7 +709,7 @@ 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} "); + sqlSentence.sqlSentence(" validState=#{m.newValidState} where couponId=#{m.couponId} and commonId=#{m.commonId} and validState=#{m.oldValidState} ",map); commonService.updateWhere(CouponNumberMapper.class,sqlSentence); } } @@ -1033,21 +1033,12 @@ /**閫�娆鹃渶瑕佸垹闄ょ敤鎴峰崱鍖呬娇鐢ㄨ褰� * @param cardItemInfoId 鍗″寘鐨勫崱椤瑰瓙椤� * @param sourceId 鍗″寘浣跨敤璁板綍鏉ユ簮鏍囪瘑 + * @param orderId 鍗″寘浣跨敤璁板綍鏉ユ簮鎬昏〃鏍囪瘑 * @param refundNum 閫�娆炬暟閲� * @param commonService 鏄犲皠 */ - public static void deleteUserCardUsed(String cardItemInfoId,String sourceId,Integer refundNum + public static void deleteUserCardUsed(String cardItemInfoId,String sourceId,String orderId,Integer refundNum ,CommonService commonService){ - - SqlSentence sqlSentence = new SqlSentence(); - Map<String,Object> map = new HashMap<>(); - - //鑾峰彇浣跨敤璁板綍 - map.put("cardItemInfoId",cardItemInfoId); - map.put("sourceId",sourceId); - sqlSentence.setSqlSentence(" SELECT * FROM user_card_used WHERE isDel = 0" + - " AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId = #{m.sourceId}"); - List<UserCardUsed> userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); //鏌ュ嚭鐢ㄦ埛,commonId锛氬崱椤圭殑缁勫悎椤规爣璇� CardItemInfo cardItemInfo=commonService.selectOneByKey(CardItemInfoMapper.class,cardItemInfoId); @@ -1055,12 +1046,29 @@ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒拌鍗″寘鐨勭粍鍚堥」"); } - System.out.println("cardItemInfo.getCardEquityId():"+cardItemInfo.getCardEquityId()); - //鑾峰彇鏉冪泭绫诲瀷 CardEquity cardEquity = commonService.selectOneByKey(CardEquityMapper.class,cardItemInfo.getCardEquityId()); if(cardEquity == null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鏈壘鍒拌鍗″寘鐨勭粍鍚堥」鏉冪泭绫诲瀷"); + } + + SqlSentence sqlSentence = new SqlSentence(); + Map<String,Object> map = new HashMap<>(); + + //鑾峰彇浣跨敤璁板綍 + map.put("cardItemInfoId",cardItemInfoId); + map.put("sourceId",sourceId); + sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 0" + + " AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId = #{m.sourceId}",map); + List<UserCardUsed> userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); + + //鍥犱负涔嬪墠鐨勪娇鐢ㄨ褰曟湁浜涙病鏈夊叧鑱斿埌璁㈠崟锛屾墍浠ユ壘涓嶅埌 + if(userCardUsedList == null || userCardUsedList.size() == 0){ + map.clear(); + map.put("cardItemInfoId",cardItemInfoId); + sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 0" + + " AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId IS NULL",map); + userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); } //璁$畻閫�鍥炵殑鍗℃ @@ -1079,10 +1087,24 @@ throw new TipsException("鍗″寘鍙��鏁伴噺閿欒锛�"); } + //宸茬粡鎿嶄綔鏁伴噺 int opNum = 0; - sqlSentence.sqlUpdate("isDel = 1 WHERE id = #{m.id} AND isDel = 0",map); + StringBuilder sql; for(UserCardUsed userCardUsed:userCardUsedList){ + sql = new StringBuilder(); + sql.append("isDel = 1"); + map.clear(); map.put("id",userCardUsed.getId()); + if(StringUtils.isEmpty(userCardUsed.getOrderId())){ + sql.append(",orderId = #{m.orderId}"); + map.put("orderId",orderId); + } + if(StringUtils.isEmpty(userCardUsed.getSourceId())){ + sql.append(",sourceId = #{m.sourceId}"); + map.put("sourceId",sourceId); + } + sql.append(" WHERE id = #{m.id} AND isDel = 0"); + sqlSentence.sqlUpdate(sql.toString(),map); opNum = opNum+commonService.updateWhere(UserCardUsedMapper.class,sqlSentence); } if(opNum != returnNum){ @@ -1188,7 +1210,7 @@ //鑾峰彇鍏跺瓙椤� map.put("orderItemId",orderItem.getId()); - sqlSentence.setSqlSentence("select refundStatus from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0"); + sqlSentence.sqlSentence("select refundStatus from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0",map); List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); int refundStatus; Integer refundNum = 0; @@ -1266,7 +1288,7 @@ if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ //鏄崱鍖呯殑锛屽埅闄ゅ崱鍖呬娇鐢� - deleteUserCardUsed(orderItemSon.getCardItemInfoId(),orderItemSon.getId(),refundRecordItemSource.getRefundNum(),commonService); + deleteUserCardUsed(orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService); } return refundCarryVo; @@ -1309,7 +1331,7 @@ if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ //鏄崱鍖呯殑锛屽埅闄ゅ崱鍖呬娇鐢� - deleteUserCardUsed(orderItemSon.getCardItemInfoId(),orderItemSon.getId(),refundRecordItemSource.getRefundNum(),commonService); + deleteUserCardUsed(orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService); } return refundCarryVo; -- Gitblit v1.8.0