use of cn.lili.modules.system.entity.dto.DistributionSetting in project lilishop by lilishop.
the class DistributionServiceImpl method bindingDistribution.
@Override
public void bindingDistribution(String distributionId) {
// 判断用户是否登录,未登录不能进行绑定
if (UserContext.getCurrentUser() == null) {
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
}
// 储存分销关系时间
Distribution distribution = this.getById(distributionId);
if (distribution != null) {
Setting setting = settingService.get(SettingEnum.DISTRIBUTION_SETTING.name());
DistributionSetting distributionSetting = JSONUtil.toBean(setting.getSettingValue(), DistributionSetting.class);
cache.put(CachePrefix.DISTRIBUTION.getPrefix() + "_" + UserContext.getCurrentUser().getId(), distribution.getId(), distributionSetting.getDistributionDay().longValue(), TimeUnit.DAYS);
}
}
use of cn.lili.modules.system.entity.dto.DistributionSetting in project lilishop by lilishop.
the class DistributionOrderServiceImpl method calculationDistribution.
/**
* 1.查看订单是否为分销订单
* 2.查看店铺流水计算分销总佣金
* 3.修改分销员的分销总金额、冻结金额
*
* @param orderSn 订单编号
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void calculationDistribution(String orderSn) {
// 根据订单编号获取订单数据
Order order = orderService.getBySn(orderSn);
// 判断是否为分销订单,如果为分销订单则获取分销佣金
if (order.getDistributionId() != null) {
// 根据订单编号获取有分销金额的店铺流水记录
List<StoreFlow> storeFlowList = storeFlowService.listStoreFlow(StoreFlowQueryDTO.builder().justDistribution(true).orderSn(orderSn).build());
double rebate = 0.0;
// 包含分销商品则进行记录分销订单、计算分销总额
for (StoreFlow storeFlow : storeFlowList) {
rebate = CurrencyUtil.add(rebate, storeFlow.getDistributionRebate());
DistributionOrder distributionOrder = new DistributionOrder(storeFlow);
distributionOrder.setDistributionId(order.getDistributionId());
// 分销员信息
Distribution distribution = distributionService.getById(order.getDistributionId());
distributionOrder.setDistributionName(distribution.getMemberName());
// 设置结算天数(解冻日期)
Setting setting = settingService.get(SettingEnum.DISTRIBUTION_SETTING.name());
DistributionSetting distributionSetting = JSONUtil.toBean(setting.getSettingValue(), DistributionSetting.class);
// 默认解冻1天
if (distributionSetting.getCashDay().equals(0)) {
distributionOrder.setSettleCycle(new DateTime());
} else {
DateTime dateTime = new DateTime();
dateTime = dateTime.offsetNew(DateField.DAY_OF_MONTH, distributionSetting.getCashDay());
distributionOrder.setSettleCycle(dateTime);
}
// 添加分销订单
this.save(distributionOrder);
// 记录会员的分销总额
if (rebate != 0.0) {
distributionService.addRebate(rebate, order.getDistributionId());
// 如果天数写0则立即进行结算
if (distributionSetting.getCashDay().equals(0)) {
DateTime dateTime = new DateTime();
dateTime = dateTime.offsetNew(DateField.MINUTE, 5);
// 计算分销提佣
this.baseMapper.rebate(DistributionOrderStatusEnum.WAIT_BILL.name(), dateTime);
// 修改分销订单状态
this.update(new LambdaUpdateWrapper<DistributionOrder>().eq(DistributionOrder::getDistributionOrderStatus, DistributionOrderStatusEnum.WAIT_BILL.name()).le(DistributionOrder::getSettleCycle, dateTime).set(DistributionOrder::getDistributionOrderStatus, DistributionOrderStatusEnum.WAIT_CASH.name()));
}
}
}
}
}
use of cn.lili.modules.system.entity.dto.DistributionSetting in project lilishop by lilishop.
the class DistributionServiceImpl method checkDistributionSetting.
/**
* 检查分销设置开关
*/
@Override
public void checkDistributionSetting() {
// 获取分销是否开启
Setting setting = settingService.get(SettingEnum.DISTRIBUTION_SETTING.name());
DistributionSetting distributionSetting = JSONUtil.toBean(setting.getSettingValue(), DistributionSetting.class);
if (Boolean.FALSE.equals(distributionSetting.getIsOpen())) {
throw new ServiceException(ResultCode.DISTRIBUTION_CLOSE);
}
}
Aggregations