| | |
| | | //查询用户是否有账户信息,退款需要处理资金 |
| | | 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,"未找到该用户的资金信息"); |
| | |
| | | //更改总订单退款状态 |
| | | 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()); |
| | |
| | | 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("优惠券回退失败!"); |
| | | } |
| | |
| | | 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]!"); |
| | | } |
| | |
| | | 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) { |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | /**退款需要删除用户卡包使用记录 |
| | | * @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); |
| | |
| | | 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); |
| | | } |
| | | |
| | | //计算退回的卡次 |
| | |
| | | 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){ |
| | |
| | | |
| | | //获取其子项 |
| | | 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; |
| | |
| | | |
| | | 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; |
| | |
| | | |
| | | 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; |