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

package com.yami.shop.distribution.comment.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.dto.DistributionOrderDto;
import com.yami.shop.distribution.comment.dto.DistributionUserIncomeDto;
import com.yami.shop.distribution.comment.dto.DistributionUserIncomeOrderDto;
import com.yami.shop.distribution.comment.model.DistributionUserIncome;
import com.yami.shop.distribution.comment.param.RangeTimeParam;
import com.yami.shop.distribution.comment.vo.DistributionAmountAndWalletVO;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

public interface DistributionUserIncomeMapper extends BaseMapper<DistributionUserIncome> {

    IPage<DistributionUserIncome> incomeAndDistributionUserPage(Page page, @Param("shopId") Long shopId, @Param("rangeTimeParam") RangeTimeParam rangeTimeParam,
                                                                @Param("userMobile") String userMobile, @Param("orderNumber") String orderNumber, @Param("state") Integer state);

    IPage<DistributionOrderDto> getDistributionOrderDtoByDistributionUserId(Page page, @Param("distributionUserId") Long distributionUserId);

    void updateStateByOrderNumber(@Param("state") Integer state, @Param("orderNumber") String orderNumber);

//    /**
//     * 根据订单流水号 获取相应的分销员钱包
//     * @param orderNumber
//     * @return
//     */
//    DistributionUserWallet getWalletByOrderNumberAndIncomeType(@Param("orderNumber") String orderNumber,@Param("incomeType") Integer incomeType);
//
//    /**
//     * 根据订单号获取佣金总和
//     * @return
//     */
//    Double getIncomeAmountByOrderNumber(@Param("orderNumber") String orderNumber);

//    /**
//     * 根据订单流水号分别获取上下级的钱包对象和佣金
//     */
//    DistributionAmountAndWalletVO distributionUser(@Param("orderNumber") String orderNumber);

    void updateStateByDistributionUserId(@Param("distributionUserId") Long distributionUserId, @Param("state") Integer state);

    /**
     * 通过订单项、订单编号修改订单状态
     *
     * @param state
     * @param orderNumber
     * @param orderItemId
     */
    void updateStateByOrderNumberAndOrderItem(@Param("orderNumber") String orderNumber, @Param("orderItemId") Long orderItemId, @Param("state") int state);

    /**
     * 统计分销员某时间段收入
     */
    Double statisticsDisUserIncome(@Param("distributionUserId") Long distributionUserId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    IPage<DistributionUserIncomeDto> getDistributionUserIncomePage(@Param("page") PageParam<DistributionUserIncome> page, @Param("distributionUserId") Long distributionUserId);

    IPage<DistributionUserIncomeOrderDto> getMyPromotionOrderByState(@Param("page") PageParam<DistributionUserIncomeOrderDto> page, @Param("distributionUserId") Long distributionUserId, @Param("state") Integer state);

    DistributionAmountAndWalletVO getDistributionAmountAndWalletVOByOrderNumber(String orderNumber);

    /**
     * 未结算的收益记录
     */
    List<DistributionUserIncome> listWaitCommissionSettlement(@Param("date") Date date);

    /**
     * 批量更新收入记录
     */
    int updateBatchState(@Param("distributionUserIncomeList") List<DistributionUserIncome> distributionUserIncomeList, @Param("state") Integer state);

}
