/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.comment.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.distribution.comment.dao.DistributionLevelAuditingMapper;
import com.yami.shop.distribution.comment.dao.DistributionUserMapper;
import com.yami.shop.distribution.comment.model.DistributionLevelAuditing;
import com.yami.shop.distribution.comment.model.DistributionUser;
import com.yami.shop.distribution.comment.service.DistributionLevelAuditingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 等级申请
 *
 * @author xwc
 * @date 2019-04-16 11:46:09
 */
@Service
public class DistributionLevelAuditingServiceImpl extends ServiceImpl<DistributionLevelAuditingMapper, DistributionLevelAuditing> implements DistributionLevelAuditingService {

    @Autowired
    DistributionLevelAuditingMapper distributionLevelAuditingMapper;

    @Autowired
    DistributionUserMapper distributionUserMapper;

    @Override
    public IPage<DistributionLevelAuditing> distributionLevelAuditingPage(Page page, String userMobile, Long shopId, DistributionLevelAuditing distributionLevelAuditing) {
        return distributionLevelAuditingMapper.distributionLevelAuditingPage(page, userMobile, shopId, distributionLevelAuditing);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void auditing(DistributionLevelAuditing distributionLevelAuditing) {
        DistributionUser distributionUser = new DistributionUser();
        // 判断是否审核通过
        if (distributionLevelAuditing.getState() == 1) {
            distributionUser.setDistributionUserId(distributionLevelAuditing.getDistributionUserId());
            distributionUser.setLevel(distributionLevelAuditing.getLevel());
            distributionUserMapper.updateById(distributionUser);
        }
        distributionLevelAuditingMapper.updateById(distributionLevelAuditing);
    }


}
