Search in sources :

Example 1 with DistributionOrder

use of cn.lili.modules.distribution.entity.dos.DistributionOrder in project lilishop by lilishop.

the class DistributionOrderExecute method execute.

@Override
public void execute() {
    // 计算分销提佣
    distributionOrderMapper.rebate(DistributionOrderStatusEnum.WAIT_BILL.name(), new DateTime());
    // 修改分销订单状态
    distributionOrderService.update(new LambdaUpdateWrapper<DistributionOrder>().eq(DistributionOrder::getDistributionOrderStatus, DistributionOrderStatusEnum.WAIT_BILL.name()).le(DistributionOrder::getSettleCycle, new DateTime()).set(DistributionOrder::getDistributionOrderStatus, DistributionOrderStatusEnum.WAIT_CASH.name()));
}
Also used : LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) DistributionOrder(cn.lili.modules.distribution.entity.dos.DistributionOrder) DateTime(cn.hutool.core.date.DateTime)

Example 2 with DistributionOrder

use of cn.lili.modules.distribution.entity.dos.DistributionOrder in project lilishop by lilishop.

the class DistributionOrderServiceImpl method cancelOrder.

/**
 * 1.获取订单判断是否为已付款的分销订单
 * 2.查看店铺流水记录分销佣金
 * 3.修改分销员的分销总金额、可提现金额
 *
 * @param orderSn 订单编号
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void cancelOrder(String orderSn) {
    // 根据订单编号获取订单数据
    Order order = orderService.getBySn(orderSn);
    // 判断是否为已付款的分销订单,则获取分销佣金
    if (order.getDistributionId() != null && order.getPayStatus().equals(PayStatusEnum.PAID.name())) {
        // 根据订单编号获取有分销金额的店铺流水记录
        List<DistributionOrder> distributionOrderList = this.list(new LambdaQueryWrapper<DistributionOrder>().eq(DistributionOrder::getOrderSn, orderSn));
        // 如果没有分销定单,则直接返回
        if (distributionOrderList.isEmpty()) {
            return;
        }
        // 分销金额
        double rebate = 0.0;
        // 包含分销商品则进行记录分销订单、计算分销总额
        for (DistributionOrder distributionOrder : distributionOrderList) {
            rebate = CurrencyUtil.add(rebate, distributionOrder.getRebate());
        }
        // 如果包含分销商品则记录会员的分销总额
        if (rebate != 0.0) {
            distributionService.subCanRebate(CurrencyUtil.sub(0, rebate), order.getDistributionId());
        }
    }
    // 修改分销订单的状态
    this.update(new LambdaUpdateWrapper<DistributionOrder>().eq(DistributionOrder::getOrderSn, orderSn).set(DistributionOrder::getDistributionOrderStatus, DistributionOrderStatusEnum.CANCEL.name()));
}
Also used : DistributionOrder(cn.lili.modules.distribution.entity.dos.DistributionOrder) Order(cn.lili.modules.order.order.entity.dos.Order) DistributionOrder(cn.lili.modules.distribution.entity.dos.DistributionOrder) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DistributionOrder

use of cn.lili.modules.distribution.entity.dos.DistributionOrder 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()));
                }
            }
        }
    }
}
Also used : DistributionOrder(cn.lili.modules.distribution.entity.dos.DistributionOrder) Order(cn.lili.modules.order.order.entity.dos.Order) DistributionOrder(cn.lili.modules.distribution.entity.dos.DistributionOrder) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) DistributionSetting(cn.lili.modules.system.entity.dto.DistributionSetting) Distribution(cn.lili.modules.distribution.entity.dos.Distribution) DistributionSetting(cn.lili.modules.system.entity.dto.DistributionSetting) Setting(cn.lili.modules.system.entity.dos.Setting) StoreFlow(cn.lili.modules.order.order.entity.dos.StoreFlow) DateTime(cn.hutool.core.date.DateTime) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DistributionOrder (cn.lili.modules.distribution.entity.dos.DistributionOrder)3 DateTime (cn.hutool.core.date.DateTime)2 Order (cn.lili.modules.order.order.entity.dos.Order)2 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Distribution (cn.lili.modules.distribution.entity.dos.Distribution)1 StoreFlow (cn.lili.modules.order.order.entity.dos.StoreFlow)1 Setting (cn.lili.modules.system.entity.dos.Setting)1 DistributionSetting (cn.lili.modules.system.entity.dto.DistributionSetting)1 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1