
package com.tmerclub.cloud.multishop.service;

import com.tmerclub.cloud.api.multishop.bo.OrderChangeShopWalletAmountBO;
import com.tmerclub.cloud.api.multishop.bo.ShopWalletBO;
import com.tmerclub.cloud.api.user.bo.RechargeNotifyBO;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.order.bo.PayNotifyBO;
import com.tmerclub.cloud.common.order.vo.OrderSimpleAmountInfoBO;
import com.tmerclub.cloud.multishop.dto.ShopWalletLogSearchDTO;
import com.tmerclub.cloud.multishop.model.ShopWallet;
import com.tmerclub.cloud.multishop.mongo.MongoShopWalletLogBO;
import com.tmerclub.cloud.multishop.vo.ShopWalletVO;

import java.util.List;
import java.util.Map;

/**
 * 商家钱包信息
 *
 * @author tmerclub
 * @date 2021-01-07 16:41:03
 */
public interface ShopWalletService {

    /**
     * 保存商家钱包信息
     * @param shopWallet 商家钱包信息
     */
    void save(ShopWallet shopWallet);

    /**
     * 更新商家钱包信息
     * @param shopWallet 商家钱包信息
     */
    void update(ShopWallet shopWallet);

    /**
     * 通过下单添加商家待结算金额，确认收货后进行结算
     * @param orderSimpleAmountInfos 订单id和店铺id关联信息
     * @param message 订单id和店铺id关联信息
     * @param settledAmountMap 店铺已结算金额map
     * @param salesMap 商家的代销配置
     */
    void addAmountByOrder(List<OrderSimpleAmountInfoBO> orderSimpleAmountInfos, PayNotifyBO message, Map<String, Long> settledAmountMap, Map<Long, Integer> salesMap);

    /**
     * 结算给商家增加结算金额
     * @param orderId 订单id
     */
    void addAmountBySettledOrder(OrderChangeShopWalletAmountBO orderId);

    /**
     * 通联结算给商家
     * @param orderChangeShopWalletAmountBO 订单
     */
    void addAmountSettlementOrderByAllinPay(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO);

    /**
     * 通过退款，锁定商家钱包金额
     * @param orderChangeShopWalletAmountBO 金额相关信息
     * @return
     */
    void refundShopAmountByRefund(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO);

    /**
     * 通过退款，锁定商家钱包金额，待采购
     * @param orderChangeShopWalletAmountBO 金额相关信息
     * @return
     */
    void refundShopAmountByRefundAndWaitPur(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO);

    /**
     * 根据店铺id查询店铺钱包信息
     * @param shopId 店铺id
     * @return 店铺钱包信息
     */
    ShopWalletVO getByShopId(Long shopId);

    /**
     * 获取所有店铺的钱包信息
     * @param shopWalletLogSearchDTO
     * @return 钱包信息
     */
    ShopWalletVO getAllShop(ShopWalletLogSearchDTO shopWalletLogSearchDTO);

    /**
     * 分页获取店铺钱包信息
     * @param pageDTO
     * @param shopWalletLogSearchDTO
     * @return
     */
    PageVO<ShopWalletVO> pageShopWalletByTime(PageDTO pageDTO, ShopWalletLogSearchDTO shopWalletLogSearchDTO);

    /**
     * 订单部分退款导致订单关闭 商家结算操作
     * @param orderChangeShopWalletAmountBO 金额相关信息
     */
    void settlementShopAmountByRefund(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO);

    /**
     * 订单超时未支付尾款 商家结算操作
     * @param orderChangeShopWalletAmountBO 金额相关信息
     */
    void settlementShopAmountByPreSaleFail(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO);

    /**
     * 订单部分退款导致订单关闭 商家结算操作,待采购时的金额处理
     * @param orderChangeShopWalletAmountBO 金额相关信息
     */
    void settlementShopAmountByRefundAndWaitPur(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO);

    /**
     * 修改店铺钱包的待结算金额
     * @param message 分销产生的待结算金额
     */
    void updateByDistributionAmount(List<ShopWalletBO> message);

    /**
     * 根据店铺ids获取商家钱包信息列表
     * @param shopIds 店铺ids
     * @param paySysType 支付系统类型0默认1通联
     * @return 商家钱包信息列表
     */
    List<ShopWalletVO> listByShopIds(List<Long> shopIds, Integer paySysType);

    /**
     * 获取店铺余额
     * @param shopId 店铺id
     * @param paySysType 支付系统类型0默认1通联
     * @return
     */
    Long getSettlementAmountByShopId(Long shopId, Integer paySysType);

    /**
     * 充值成功
     * @param message
     */
    void rechargeSuccess(RechargeNotifyBO message);

    /**
     * 商家减少结算金额
     * @param shopId
     * @param changeAmount
     * @param paySysType
     * @return
     */
    boolean subSettledAmount(Long shopId, Long changeAmount, Integer paySysType);

    /**
     * 商家自行处理供应商订单，减少商家结算金额
     * @param supplierRealRefundAmount 减少金额
     * @param orderChangeShopWalletAmountBO 退款信息
     * @param shopWalletLogList 退款信息
     * @param isNowSave 是否立即保存
     */
    void subSettlementAmount(Long supplierRealRefundAmount, OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO, List<MongoShopWalletLogBO> shopWalletLogList, Boolean isNowSave);

    /**
     * 订单部分退款导致订单关闭 商家结算操作(通联支付结算)
     * @param orderChangeShopWalletAmountBO 金额相关信息
     */
    void settlementByRefundAndWaitPurAndAllinpay(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO);
}
