diff --git a/src/main/java/com/sczx/order/service/impl/OrderDistribServiceImpl.java b/src/main/java/com/sczx/order/service/impl/OrderDistribServiceImpl.java index cf7694b..29b50e6 100644 --- a/src/main/java/com/sczx/order/service/impl/OrderDistribServiceImpl.java +++ b/src/main/java/com/sczx/order/service/impl/OrderDistribServiceImpl.java @@ -5,16 +5,18 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.google.common.collect.Lists; import com.sczx.order.common.enums.DistribTypeEnum; -import com.sczx.order.common.enums.WalletChangeTypeEnum; import com.sczx.order.dto.OrderDistribDTO; import com.sczx.order.dto.OrderDistribQueryReq; import com.sczx.order.exception.BizException; -import com.sczx.order.po.*; +import com.sczx.order.po.BaseUserReferralPO; +import com.sczx.order.po.OrderDistribPO; +import com.sczx.order.po.OrderMainPO; import com.sczx.order.repository.*; import com.sczx.order.service.OrderDistribService; import com.sczx.order.thirdpart.dto.CompanyDTO; import com.sczx.order.thirdpart.dto.CompanyStoreDTO; import com.sczx.order.thirdpart.dto.SysConfigDTO; +import com.sczx.order.thirdpart.dto.req.DistibIncomeReq; import com.sczx.order.thirdpart.integration.StoreInteg; import com.sczx.order.thirdpart.integration.UserInteg; import lombok.extern.slf4j.Slf4j; @@ -24,7 +26,6 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.List; import java.util.Objects; @@ -115,30 +116,39 @@ public class OrderDistribServiceImpl implements OrderDistribService { .set(OrderMainPO::getDistribed, 1); orderMainRepo.update(updateMainWrapper); + //更新推荐信息,防止重复分润 + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(BaseUserReferralPO::getUserId, orderMainPO.getCustomerId()) + .set(BaseUserReferralPO::getReferralOrderNo, storeDistribPO.getOrderNo()); + baseUserReferralRepo.update(updateWrapper); + //门店钱包入账 - LambdaQueryWrapper queryWalletWrapper = new LambdaQueryWrapper<>(); - queryWalletWrapper.eq(BaseWalletPO::getUserId, orderMainPO.getOperatorId()).last(" limit 1"); - BaseWalletPO baseWalletPO = baseWalletRepo.getOne(queryWalletWrapper); - if(baseWalletPO != null){ - LambdaUpdateWrapper updateWalletWrapper = new LambdaUpdateWrapper<>(); - updateWalletWrapper.eq(BaseWalletPO::getUserId, orderMainPO.getOperatorId()) - .set(BaseWalletPO::getBalance, baseWalletPO.getBalance().add(storeDistribPO.getDistribAmount())); - baseWalletRepo.update(updateWalletWrapper); + DistibIncomeReq distibIncomeReq = new DistibIncomeReq(); + distibIncomeReq.setStoreId(orderMainPO.getStoreId()); + distibIncomeReq.setAmount(storeDistribPO.getDistribAmount()); + storeInteg.distibIncome(distibIncomeReq); - BaseWalletChangePO baseWalletChangePO = new BaseWalletChangePO(); - baseWalletChangePO.setUserId(orderMainPO.getOperatorId()); - baseWalletChangePO.setChangeType(WalletChangeTypeEnum.REFERRAL.getCode()); - baseWalletChangePO.setChangeTime(LocalDateTime.now()); - baseWalletChangePO.setChangeAmount(storeDistribPO.getDistribAmount()); - baseWalletChangePO.setReferralOrderNo(orderMainPO.getOrderNo()); - baseWalletChangeRepo.save(baseWalletChangePO); +// LambdaQueryWrapper queryWalletWrapper = new LambdaQueryWrapper<>(); +// queryWalletWrapper.eq(BaseWalletPO::getUserId, orderMainPO.getStoreId()).last(" limit 1"); +// BaseWalletPO baseWalletPO = baseWalletRepo.getOne(queryWalletWrapper); +// if(baseWalletPO != null){ +// LambdaUpdateWrapper updateWalletWrapper = new LambdaUpdateWrapper<>(); +// updateWalletWrapper.eq(BaseWalletPO::getUserId, orderMainPO.getOperatorId()) +// .set(BaseWalletPO::getBalance, baseWalletPO.getBalance().add(storeDistribPO.getDistribAmount())); +// baseWalletRepo.update(updateWalletWrapper); +// }else { +// baseWalletPO = new BaseWalletPO(); +// baseWalletPO.setUserId(Long.valueOf(companyStoreDTO.getId())); +// baseWalletPO.setUserName(companyStoreDTO.getName()); +// } +// BaseWalletChangePO baseWalletChangePO = new BaseWalletChangePO(); +// baseWalletChangePO.setUserId(orderMainPO.getOperatorId()); +// baseWalletChangePO.setChangeType(WalletChangeTypeEnum.REFERRAL.getCode()); +// baseWalletChangePO.setChangeTime(LocalDateTime.now()); +// baseWalletChangePO.setChangeAmount(storeDistribPO.getDistribAmount()); +// baseWalletChangePO.setReferralOrderNo(orderMainPO.getOrderNo()); +// baseWalletChangeRepo.save(baseWalletChangePO); - //更新推荐信息,防止重复分润 - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(BaseUserReferralPO::getUserId, orderMainPO.getCustomerId()) - .set(BaseUserReferralPO::getReferralOrderNo, storeDistribPO.getOrderNo()); - baseUserReferralRepo.update(updateWrapper); - } diff --git a/src/main/java/com/sczx/order/thirdpart/dto/req/DistibIncomeReq.java b/src/main/java/com/sczx/order/thirdpart/dto/req/DistibIncomeReq.java new file mode 100644 index 0000000..3b722c6 --- /dev/null +++ b/src/main/java/com/sczx/order/thirdpart/dto/req/DistibIncomeReq.java @@ -0,0 +1,18 @@ +package com.sczx.order.thirdpart.dto.req; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +@ApiModel(value = "分润收入查询参数") +@Data +public class DistibIncomeReq { + + @ApiModelProperty("门店id") + private Long storeId; + + @ApiModelProperty("金额") + private BigDecimal amount ; +} diff --git a/src/main/java/com/sczx/order/thirdpart/facade/StoreFacade.java b/src/main/java/com/sczx/order/thirdpart/facade/StoreFacade.java index 263a596..4604433 100644 --- a/src/main/java/com/sczx/order/thirdpart/facade/StoreFacade.java +++ b/src/main/java/com/sczx/order/thirdpart/facade/StoreFacade.java @@ -5,6 +5,7 @@ import com.sczx.order.thirdpart.dto.CompanyDTO; import com.sczx.order.thirdpart.dto.CompanyStoreDTO; import com.sczx.order.thirdpart.dto.SysConfigDTO; import com.sczx.order.thirdpart.dto.SysDictDataDTO; +import com.sczx.order.thirdpart.dto.req.DistibIncomeReq; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -32,4 +33,7 @@ public interface StoreFacade { @GetMapping("/sys/getConfigByConfigKey") Result getConfigByConfigKey(@RequestParam(name = "configKey") String configKey); + + @PostMapping("/wallet/distibIncome") + Result distibIncome(@RequestBody DistibIncomeReq distibIncomeReq); } diff --git a/src/main/java/com/sczx/order/thirdpart/integration/StoreInteg.java b/src/main/java/com/sczx/order/thirdpart/integration/StoreInteg.java index 148544c..8bf93c4 100644 --- a/src/main/java/com/sczx/order/thirdpart/integration/StoreInteg.java +++ b/src/main/java/com/sczx/order/thirdpart/integration/StoreInteg.java @@ -6,6 +6,7 @@ import com.sczx.order.thirdpart.dto.CompanyDTO; import com.sczx.order.thirdpart.dto.CompanyStoreDTO; import com.sczx.order.thirdpart.dto.SysConfigDTO; import com.sczx.order.thirdpart.dto.SysDictDataDTO; +import com.sczx.order.thirdpart.dto.req.DistibIncomeReq; import com.sczx.order.thirdpart.facade.StoreFacade; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -86,4 +87,23 @@ public class StoreInteg { } return null; } + + /** + * 分润收入 + * @param distibIncomeReq + * @return + */ + public boolean distibIncome(DistibIncomeReq distibIncomeReq){ + + try{ + Result result = storeFacade.distibIncome(distibIncomeReq); + if(result.isSuccess()){ + return result.getData(); + } + } catch (Exception e){ + log.error("分润收入失败",e); + throw new InnerException("分润收入失败"); + } + return false; + } }