| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | |
| | | aftersale.setReturnShopSettlement(BigDecimal.ZERO); |
| | | aftersale.setCode(getNextInCode()); |
| | | |
| | | //订单退回返回给经销商的积分 |
| | | if(Objects.nonNull(goodsorder.getDistributionShopId())&&goodsorder.getReturnCustomerIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | Shop shop = shopMapper.selectById(goodsorder.getDistributionShopId()); |
| | | //经销商存在剩余积分 |
| | | if(Objects.nonNull(shop)&&shop.getIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | //开启了扣除返还经销商积分 |
| | | if(Constants.equalsInteger(afterSaleApplyRequest.getReturnShopIntegralStatus(),Constants.ONE)){ |
| | | //记录扣除经销商积分值 |
| | | aftersale.setReturnShopIntegral(shop.getIntegral().compareTo(goodsorder.getReturnCustomerIntegral())>Constants.ZERO |
| | | ?goodsorder.getReturnCustomerIntegral():shop.getIntegral()); |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(aftersale.getReturnShopIntegral()); |
| | | dealIntegralRequest.setDealType(Constants.ONE); |
| | | dealIntegralRequest.setMemberId(goodsorder.getDistributionShopId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER_REFUND_INTEGRAL); |
| | | integralService.dealShopIntegral(dealIntegralRequest,null); |
| | | } |
| | | //订单退回 扣除已结算 订单赠送积分 - 经销商 |
| | | if(Constants.equalsInteger(afterSaleApplyRequest.getReturnShopIntegralStatus(),Constants.ONE)){ |
| | | //订单退回返回给经销商的积分 |
| | | if(Objects.nonNull(goodsorder.getDistributionShopId())){ |
| | | Shop shop = shopMapper.selectById(goodsorder.getDistributionShopId()); |
| | | //经销商存在剩余积分 |
| | | if(Objects.nonNull(shop)&&shop.getIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | //记录扣除经销商积分值 |
| | | aftersale.setReturnShopIntegral(shop.getIntegral().compareTo(goodsorder.getReturnCustomerIntegral())>Constants.ZERO |
| | | ?goodsorder.getReturnCustomerIntegral():shop.getIntegral()); |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(aftersale.getReturnShopIntegral()); |
| | | dealIntegralRequest.setDealType(Constants.ONE); |
| | | dealIntegralRequest.setMemberId(goodsorder.getDistributionShopId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER_REFUND_INTEGRAL); |
| | | integralService.dealShopIntegral(dealIntegralRequest,null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //订单退回 经销商结算余额 |
| | | if(Objects.nonNull(goodsorder.getDistributionShopId())&&goodsorder.getShopSettlement().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | Shop shop = shopMapper.selectById(goodsorder.getDistributionShopId()); |
| | | //经销商存在剩余积分 |
| | | if(Objects.nonNull(shop)&&shop.getAmount().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | //开启了扣除返还经销商积分 |
| | | if(Constants.equalsInteger(afterSaleApplyRequest.getReturnShopSettlementStatus(),Constants.ONE)){ |
| | | //记录扣除经销商积分值 |
| | | aftersale.setReturnShopSettlement(shop.getAmount().compareTo(goodsorder.getShopSettlement())>Constants.ZERO |
| | | ?goodsorder.getShopSettlement():shop.getAmount()); |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(aftersale.getReturnShopIntegral()); |
| | | dealIntegralRequest.setDealType(Constants.ONE); |
| | | dealIntegralRequest.setMemberId(goodsorder.getDistributionShopId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER_REFUND_CASH); |
| | | integralService.dealShopAmount(dealIntegralRequest); |
| | | |
| | | } |
| | | //订单退回 扣除已结算 结算余额 - 经销商 |
| | | if(Constants.equalsInteger(afterSaleApplyRequest.getReturnShopSettlementStatus(),Constants.ONE)){ |
| | | if(Objects.nonNull(goodsorder.getDistributionShopId())){ |
| | | Shop shop = shopMapper.selectById(goodsorder.getDistributionShopId()); |
| | | //查询订单明细经销商结算金额 |
| | | List<GoodsorderDetail> list = goodsorderDetailMapper.selectList(new QueryWrapper<GoodsorderDetail>().lambda() |
| | | .eq(GoodsorderDetail::getIsdeleted,Constants.ZERO) |
| | | .eq(GoodsorderDetail::getOrderId,goodsorder.getId()) |
| | | .isNotNull(GoodsorderDetail::getShopSettlement) |
| | | ); |
| | | //经销商存在剩余余额 |
| | | if(Objects.nonNull(shop)&&shop.getAmount().compareTo(BigDecimal.ZERO)>Constants.ZERO&&list.size()>Constants.ZERO){ |
| | | BigDecimal total = list.stream().map(i->i.getShopSettlement()).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //记录扣除经销商积分值 |
| | | aftersale.setReturnShopSettlement(shop.getAmount().compareTo(total)>Constants.ZERO |
| | | ?total:shop.getAmount()); |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(aftersale.getReturnShopSettlement()); |
| | | dealIntegralRequest.setDealType(Constants.ONE); |
| | | dealIntegralRequest.setMemberId(goodsorder.getDistributionShopId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER_REFUND_CASH); |
| | | dealIntegralRequest.setParam1(goodsorder.getCode().toString()); |
| | | integralService.dealShopAmount(dealIntegralRequest); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //订单退回 返还给客户的积分 |
| | | if(Objects.nonNull(goodsorder.getDistributionShopId())&&goodsorder.getReturnMemberIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | //扣除已返还用户积分 - 用户 |
| | | if(Constants.equalsInteger(afterSaleApplyRequest.getReturnIntegralStatus(),Constants.ONE)){ |
| | | Member member = memberMapper.selectById(goodsorder.getMemberId()); |
| | | //客户存在剩余积分 |
| | | if(Objects.nonNull(member)&&member.getIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | //开启了扣除返还客户积分 |
| | | if(Constants.equalsInteger(afterSaleApplyRequest.getReturnIntegralStatus(),Constants.ONE)){ |
| | | //记录扣除经销商积分值 |
| | | aftersale.setReturnIntegral(member.getIntegral().compareTo(goodsorder.getReturnCustomerIntegral())>Constants.ZERO |
| | | ?goodsorder.getReturnCustomerIntegral():member.getIntegral()); |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(aftersale.getReturnShopIntegral()); |
| | | dealIntegralRequest.setIntegralNum(aftersale.getReturnIntegral()); |
| | | dealIntegralRequest.setDealType(Constants.ONE); |
| | | dealIntegralRequest.setMemberId(member.getId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.MEMBER_ORDER_REFUND_RETURN); |
| | | integralService.dealIntegral(dealIntegralRequest,null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //订单退款 返还客户使用的积分 |
| | | if(Constants.equalsInteger(afterSaleApplyRequest.getReturnIntegralStatus(),Constants.ONE) |
| | | if(Constants.equalsInteger(afterSaleApplyRequest.getReturnUseIntegralStatus(),Constants.ONE) |
| | | && goodsorder.getUseIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(aftersale.getReturnShopIntegral()); |
| | | dealIntegralRequest.setIntegralNum(goodsorder.getUseIntegral()); |
| | | dealIntegralRequest.setDealType(Constants.ZERO); |
| | | dealIntegralRequest.setMemberId(goodsorder.getMemberId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | |
| | | .set(Goodsorder::getRefundMoney, afterSaleApplyRequest.getMoney()) |
| | | .set(Goodsorder::getRefundUserId, loginUserInfo.getId()) |
| | | .set(Goodsorder::getRefundInfo, afterSaleApplyRequest.getRemark()) |
| | | .set(Goodsorder::getRefundConfigInfo, JSONObject.toJSONString(afterSaleApplyRequest)) |
| | | .eq(Goodsorder::getId, goodsorder.getId()) |
| | | ); |
| | | |