Search in sources :

Example 1 with Distribution

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

the class DistributionServiceImpl method audit.

@Override
public boolean audit(String id, String status) {
    // 检查分销开关
    checkDistributionSetting();
    // 根据id获取分销员
    Distribution distribution = this.getById(id);
    if (Optional.ofNullable(distribution).isPresent()) {
        if (status.equals(DistributionStatusEnum.PASS.name())) {
            distribution.setDistributionStatus(DistributionStatusEnum.PASS.name());
        } else {
            distribution.setDistributionStatus(DistributionStatusEnum.REFUSE.name());
        }
        return this.updateById(distribution);
    }
    return false;
}
Also used : Distribution(cn.lili.modules.distribution.entity.dos.Distribution)

Example 2 with Distribution

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

the class DistributionServiceImpl method resume.

@Override
public boolean resume(String id) {
    // 检查分销开关
    checkDistributionSetting();
    // 根据id获取分销员
    Distribution distribution = this.getById(id);
    if (Optional.ofNullable(distribution).isPresent()) {
        distribution.setDistributionStatus(DistributionStatusEnum.PASS.name());
        return this.updateById(distribution);
    }
    return false;
}
Also used : Distribution(cn.lili.modules.distribution.entity.dos.Distribution)

Example 3 with Distribution

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

the class DistributionServiceImpl method applyDistribution.

@Override
@Transactional(rollbackFor = Exception.class)
public Distribution applyDistribution(DistributionApplyDTO distributionApplyDTO) {
    // 检查分销开关
    checkDistributionSetting();
    // 判断用户是否申请过分销
    Distribution distribution = getDistribution();
    // 如果分销员非空并未审核则提示用户请等待,如果分销员为拒绝状态则重新提交申请
    if (Optional.ofNullable(distribution).isPresent()) {
        if (distribution.getDistributionStatus().equals(DistributionStatusEnum.APPLY.name())) {
            throw new ServiceException(ResultCode.DISTRIBUTION_IS_APPLY);
        } else if (distribution.getDistributionStatus().equals(DistributionStatusEnum.REFUSE.name())) {
            distribution.setDistributionStatus(DistributionStatusEnum.APPLY.name());
            BeanUtil.copyProperties(distributionApplyDTO, distribution);
            this.updateById(distribution);
            return distribution;
        }
    }
    // 如果未申请分销员则新增进行申请
    // 获取当前登录用户
    Member member = memberService.getUserInfo();
    // 新建分销员
    distribution = new Distribution(member.getId(), member.getNickName(), distributionApplyDTO);
    // 添加分销员
    this.save(distribution);
    return distribution;
}
Also used : ServiceException(cn.lili.common.exception.ServiceException) Distribution(cn.lili.modules.distribution.entity.dos.Distribution) Member(cn.lili.modules.member.entity.dos.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Distribution

use of cn.lili.modules.distribution.entity.dos.Distribution 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);
    }
}
Also used : ServiceException(cn.lili.common.exception.ServiceException) 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)

Example 5 with Distribution

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

the class DistributionCashServiceImpl method audit.

@Override
@Transactional(rollbackFor = Exception.class)
public DistributionCash audit(String id, String result) {
    // 检查分销功能开关
    distributionService.checkDistributionSetting();
    // 获取分销佣金信息
    DistributionCash distributorCash = this.getById(id);
    // 只有分销员和分销佣金记录存在的情况才可以审核
    if (distributorCash != null) {
        // 获取分销员
        Distribution distribution = distributionService.getById(distributorCash.getDistributionId());
        if (distribution != null && distribution.getDistributionStatus().equals(DistributionStatusEnum.PASS.name())) {
            MemberWithdrawalMessage memberWithdrawalMessage = new MemberWithdrawalMessage();
            // 审核通过
            if (result.equals(WithdrawStatusEnum.VIA_AUDITING.name())) {
                memberWithdrawalMessage.setStatus(WithdrawStatusEnum.VIA_AUDITING.name());
                // 分销记录操作
                distributorCash.setDistributionCashStatus(WithdrawStatusEnum.VIA_AUDITING.name());
                distributorCash.setPayTime(new Date());
                // 提现到余额
                memberWalletService.increase(new MemberWalletUpdateDTO(distributorCash.getPrice(), distribution.getMemberId(), "分销[" + distributorCash.getSn() + "]佣金提现到余额[" + distributorCash.getPrice() + "]", DepositServiceTypeEnum.WALLET_COMMISSION.name()));
            } else {
                memberWithdrawalMessage.setStatus(WithdrawStatusEnum.FAIL_AUDITING.name());
                // 分销员可提现金额退回
                distribution.setCanRebate(CurrencyUtil.add(distribution.getCanRebate(), distributorCash.getPrice()));
                distributorCash.setDistributionCashStatus(WithdrawStatusEnum.FAIL_AUDITING.name());
            }
            // 分销员金额相关处理
            distributionService.updateById(distribution);
            // 修改分销提现申请
            boolean bool = this.updateById(distributorCash);
            if (bool) {
                // 组织会员提现审核消息
                memberWithdrawalMessage.setMemberId(distribution.getMemberId());
                memberWithdrawalMessage.setPrice(distributorCash.getPrice());
                memberWithdrawalMessage.setDestination(MemberWithdrawalDestinationEnum.WALLET.name());
                String destination = rocketmqCustomProperties.getMemberTopic() + ":" + MemberTagsEnum.MEMBER_WITHDRAWAL.name();
                rocketMQTemplate.asyncSend(destination, memberWithdrawalMessage, RocketmqSendCallbackBuilder.commonCallback());
            }
            return distributorCash;
        }
        throw new ServiceException(ResultCode.DISTRIBUTION_NOT_EXIST);
    }
    throw new ServiceException(ResultCode.DISTRIBUTION_CASH_NOT_EXIST);
}
Also used : MemberWalletUpdateDTO(cn.lili.modules.wallet.entity.dto.MemberWalletUpdateDTO) MemberWithdrawalMessage(cn.lili.modules.wallet.entity.dto.MemberWithdrawalMessage) ServiceException(cn.lili.common.exception.ServiceException) Distribution(cn.lili.modules.distribution.entity.dos.Distribution) DistributionCash(cn.lili.modules.distribution.entity.dos.DistributionCash) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Distribution (cn.lili.modules.distribution.entity.dos.Distribution)9 ServiceException (cn.lili.common.exception.ServiceException)4 Transactional (org.springframework.transaction.annotation.Transactional)4 DistributionCash (cn.lili.modules.distribution.entity.dos.DistributionCash)3 Setting (cn.lili.modules.system.entity.dos.Setting)2 DistributionSetting (cn.lili.modules.system.entity.dto.DistributionSetting)2 MemberWithdrawalMessage (cn.lili.modules.wallet.entity.dto.MemberWithdrawalMessage)2 DateTime (cn.hutool.core.date.DateTime)1 DistributionOrder (cn.lili.modules.distribution.entity.dos.DistributionOrder)1 Member (cn.lili.modules.member.entity.dos.Member)1 Order (cn.lili.modules.order.order.entity.dos.Order)1 StoreFlow (cn.lili.modules.order.order.entity.dos.StoreFlow)1 MemberWalletUpdateDTO (cn.lili.modules.wallet.entity.dto.MemberWalletUpdateDTO)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)1 Date (java.util.Date)1