门店分润入账

This commit is contained in:
2025-09-29 00:21:13 +08:00
parent 1f06e34d99
commit 60defa3bb4
4 changed files with 76 additions and 24 deletions

View File

@ -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<BaseUserReferralPO> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(BaseUserReferralPO::getUserId, orderMainPO.getCustomerId())
.set(BaseUserReferralPO::getReferralOrderNo, storeDistribPO.getOrderNo());
baseUserReferralRepo.update(updateWrapper);
//门店钱包入账
LambdaQueryWrapper<BaseWalletPO> queryWalletWrapper = new LambdaQueryWrapper<>();
queryWalletWrapper.eq(BaseWalletPO::getUserId, orderMainPO.getOperatorId()).last(" limit 1");
BaseWalletPO baseWalletPO = baseWalletRepo.getOne(queryWalletWrapper);
if(baseWalletPO != null){
LambdaUpdateWrapper<BaseWalletPO> 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<BaseWalletPO> queryWalletWrapper = new LambdaQueryWrapper<>();
// queryWalletWrapper.eq(BaseWalletPO::getUserId, orderMainPO.getStoreId()).last(" limit 1");
// BaseWalletPO baseWalletPO = baseWalletRepo.getOne(queryWalletWrapper);
// if(baseWalletPO != null){
// LambdaUpdateWrapper<BaseWalletPO> 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<BaseUserReferralPO> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(BaseUserReferralPO::getUserId, orderMainPO.getCustomerId())
.set(BaseUserReferralPO::getReferralOrderNo, storeDistribPO.getOrderNo());
baseUserReferralRepo.update(updateWrapper);
}

View File

@ -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 ;
}

View File

@ -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<SysConfigDTO> getConfigByConfigKey(@RequestParam(name = "configKey") String configKey);
@PostMapping("/wallet/distibIncome")
Result<Boolean> distibIncome(@RequestBody DistibIncomeReq distibIncomeReq);
}

View File

@ -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<Boolean> result = storeFacade.distibIncome(distibIncomeReq);
if(result.isSuccess()){
return result.getData();
}
} catch (Exception e){
log.error("分润收入失败",e);
throw new InnerException("分润收入失败");
}
return false;
}
}