package cn.pluss.platform.merchantOrder;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.dto.MemberRechargeDTO;
import cn.pluss.platform.dto.MemberScanPayDTO;
import cn.pluss.platform.dto.MerChantOrderDTO;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.mapper.MerchantOrderMapper;
import cn.pluss.platform.vo.*;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author admin
 */
public interface MerchantOrderService extends IService<MerchantOrder> {

    default MerchantOrder queryMerchantOrder(MerchantOrder merchantOrder) {
        return getBaseMapper().selectOne(new QueryWrapper<>(merchantOrder));
    }

    /**
     * 统计账单信息，其中包含账单记录，账单笔数，以及账单总额
     *
     * @return 账单信息
     */
    Map<String, Object> billCollect(MerchantOrder merchantOrder);

    default List<MerchantOrder> queryMerchantOrderPage(Map<String, Object> map) {
        return ((MerchantOrderMapper) getBaseMapper()).queryMerchantOrderPage(map);
    }

    default Integer queryMerchantOrderPageCount(Map<String, Object> map) {
        return ((MerchantOrderMapper) getBaseMapper()).queryMerchantOrderPageCount(map);
    }

    default Integer queryMerchantOrderPageCountByTime(Map<String, Object> map) {
        Integer count = ((MerchantOrderMapper) getBaseMapper()).queryMerchantOrderPageCountByTime(map);
        return count == null ? 0 : count;
    }

    default Double queryMerchantOrderFeeByTime(Map<String, Object> map) {
        return ((MerchantOrderMapper) getBaseMapper()).queryMerchantOrdeFeeByTime(map) == null ? 0
                : ((MerchantOrderMapper) getBaseMapper()).queryMerchantOrdeFeeByTime(map);
    }

    default List<MerchantOrder> queryMerchantOrderPageByTime(Map<String, Object> map) {
        return ((MerchantOrderMapper) getBaseMapper()).queryMerchantOrderPageByTime(map);
    }

    /**
     * 供 商户推广- 交易明细 接口使用
     *
     * @param map 参数
     * @return  结果
     */
    default List<MerchantOrder> queryMerchantOrderPageApp(Map<String, Object> map) {
        return ((MerchantOrderMapper) getBaseMapper()).queryMerchantOrderPageApp(map);
    }

    /**
     * 供 商户推广- 交易明细 接口使用
     *
     * @param map 参数
     * @return 结果
     */
    Integer queryMerchantOrderPageCountApp(Map<String, Object> map);

    /**
     * 汇总流水（manage）
     */
    SummaryOfWaterVO querySummaryOfWater(Map<String, Object> map);

    /**
     * 订单退款信息
     *
     * @param map ignored
     * @return ignored
     */
    List<MerchantOrder> queryMerchantOrderRefundPage(Map<String, Object> map);

    /**
     * 订单退款统计
     *
     * @param map ignored
     * @return ignored
     */
    Integer queryMerchantOrderRefundPageCount(Map<String, Object> map);

    /**
     * 7日交易数统计
     *
     * @param s ignored
     */
    List<OrderStatisticsVO> queryOrderStatistics(MerchantOrder s);

    /**
     * 支付通道统计
     *
     * @param s ignored
     */
    List<PayTypeStatisticsVO> queryPayTypeStatistics(MerchantOrder s);


    /**
     * queryMerchantOrderPageShuju:(最新统计订单方法). <br/>
     *
     * @param map ignored
     * @return ignored
     *
     * @author Administrator
     * @since JDK 1.8
     */
    List<MerchantMangeOrderVO> queryMerchantOrderPageShuju(Map<String, Object> map);

//    /**
//     * 最新统计订单方法，商户
//     * @param map ignored
//     * @return ignored
//     */
//    default List<MerchantMangeOrderVO> queryMerchantOrderNoPageShuju(Map<String, Object> map) {
//        return ((MerchantOrderMapper)getBaseMapper()).queryMerchantOrderNoPageShuju(map);
//    }

    /**
     * queryMerchantOrderPageCountShuju:(最新统计订单方法). <br/>
     *
     * @param map ignored
     * @return ignored
     *
     * @author Administrator
     * @since JDK 1.8
     */
    Integer queryMerchantOrderPageCountShuju(Map<String, Object> map);

//    default Integer queryMerchantOrderNoPageCountShuju(Map<String, Object> map) {
//        return ((MerchantOrderMapper)getBaseMapper()).queryMerchantOrderNoPageCountShuju(map);
//    }

    /**
     * PlatformSum:(统计平台大屏的门店数量 商户数量 交易总额 交易笔数 会员数量 推广员数量 推广分润总额 粉丝奖励总额 收益总计). <br/>
     *
     * @return ignored
     *
     * @author Administrator
     * @since JDK 1.8
     */
    Map<String, Object> platformSum();


    /**
     * app 首页数据
     *
     * @param userApp ignored
     * @return ignored
     */
    Map<String, Object> queryHomePageData(UserApp userApp);

    /**
     * app对账页面
     *
     * @param merchantOrder ignored
     * @return ignored
     */
    Map<String, Object> queryCheckOrderData(MerchantOrder merchantOrder);

    /**
     * 查询订单页面统计数据
     *
     * @param params ignored
     * @return ignored
     */
    Map<String, Object> querySumCount(Map<String, Object> params);

    /**
     * 获取真实的营业额，收款 - 退款
     *
     * @return ignored
     */
    default BigDecimal getRealConsume(List<Map<String, Object>> sumList) {
        BigDecimal result = BigDecimal.ZERO;
        for (Map<String, Object> consumeSum : sumList) {
			Object status = consumeSum.get("status");
			if (status != null && "1".equals(status.toString())) {
				result = result.add(new BigDecimal(consumeSum.get("fee").toString()));
			}

			if (status != null && "2".equals(status.toString())) {
				result = result.subtract(new BigDecimal(consumeSum.get("fee").toString()));
			}
        }

		return result;
    }

    /**
     * //查询自己和子属下级商户成功订单金额
     * @param merchantNoList ignored
     * @return ignored
     */
    Double queryNextMercTransAmtCount(List<String> merchantNoList);


    MerchantOrder saveMerchantOrderStatus(String outTradeNo, MerchantOrder merchantOrder);

    /**
     * 获取超级代理商下级商户当月交易额
     * @param params ignored
     * @return ignored
     */
    List<Map<String, Object>> getSuperMerchantToDayTradeMoneyCount(Map<String, Object> params);

    /**
     * 订单分润明细分页查询
     * @param map ignored
     * @return ignored
     */
    List<MerchantOrderProfitVO> pageData(Map<String,Object> map);

    Integer pageDataCount(Map<String, Object> map);


    /**
     * 统计营销活动奖励金
     * @return ignored
     */
//    Map<String, BigDecimal> getCountMaketAmt(Long userId,String date,String auditDate);

    /**
     * 获取商户当前已经积累的交易额度
     * @param merchantCode ignored
     * @return ignored
     */
    Map<String,Double> getCountTradeAmt(String merchantCode,String date,String startDate,String endDate);


    /**
     * 分页查询
     * @param page ignored
     * @param order ignored
     * @return ignored
     */
    Page<MerchantOrder> pageWapInfo(Page<MerchantOrder> page, MerchantOrder order);

    /**
     * 计算累计省钱金额和今日省钱金额
     * @param merchantCode ignored
     * @param nowDate ignored
     * @return ignored
     */
    Map<String, BigDecimal> getSaveMoneyCount(String merchantCode, String nowDate,String startDate,String endDate);

    /**
     * 扫用户二维码支付
     * @param merchantOrderDTO ignored
     * @return ignored
     */
    Result<Object> toActivePay(MerChantOrderDTO merchantOrderDTO);

    /**
     * 主扫会员卡支付
     * @param memberScanPayDTO ignored
     * @return ignored
     */
    Result<MemberScanVO> toMemberScanPay(MemberScanPayDTO memberScanPayDTO);

    /**
     * 主扫会员卡充值
     * @param memberRechargeDTO ignored
     * @return ignored
     */
    Result<Map<String, Object>> toMemberRecharge(MemberRechargeDTO memberRechargeDTO);

    /**
     * 退款
     * @param orderNumber 退款单号
     * @param refundReason 退款原因
     * @param type 退款类型
     * @param noticeCode 通知code值
     */
    void returnOrder(String orderNumber,String refundReason,String type, String noticeCode);

    /**
     * 退款
     * @param orderNumber 退款单号
     * @param refundReason 退款原因
     * @param type 退款类型
     * @param noticeCode 通知code值
     */
    void apiReturnOrderV2(String orderNumber,String refundReason,String type, String noticeCode, String payPassword);


    void setMemberRechargeOrder(MemberRechargeDTO dto, MerchantMenber menber, MemberOrder memberOrder,MerchantMenberRecharge recharge,MerchantOrder order);

    /**
     * 订单补单操作
     * @param id ignored
     * @return ignored
     */
    Result<Object> suppleOrder(Integer id);

    /**
     * 分页查询订单信息
     * @param page ignored
     * @param query ignored
     * @return ignored
     */
    Page<MerchantOrder> pageInfo(Page<MerchantOrder> page, MerchantOrder query);


    /**
     * 解析CSV文件
     * @param path 文件路径
     */
    void readCSV(String path);

    List<Map<String, Object>> getCouponList(String orderNumber);


    Result updateOrderStatus(JSONObject result,MerchantOrder order);

    /**
     * @description:订单列表根据查询条件统计数据
     * @date: 2021/8/5 16:49
     * @param map:
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    Map<String, Object> getOrderCountData(Map<String, Object> map);

    /**
     * @description:更改订单支付状态以及创建分润
     * @date: 2021/8/19 18:49
     * @param order:
     */
    void updateOrderAndCreateProfit(MerchantOrder order);


    /**
     * @description:更新支付失败的订单
     * @date: 2021/8/20 10:57
     * @param order:
     * @param channelStatus:
     * @param channelMsg:
     */
    void updateFailOrder(MerchantOrder order,String channelStatus,String channelMsg);

    /**
     * @description:设置订单相关参数
     * @date: 2021/8/25 11:16
     * @param order:
     * @param params:
     * @param channel:
     */
    void constOrderPayCodeAndName(MerchantOrder order, Map<String, Object> params, MerchantChannelStatus channel);

    /**
     * @description:获取获取订单信息
     * @date: 2021/8/31 14:53
     * @param orderNumber:
     * @return cn.pluss.platform.entity.MerchantOrder
     */
    MerchantOrder getLockByOrderNumber(String orderNumber);

    /**
     * @description:获取订单首页数据
     * @date: 2021/10/19 14:54
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    Map<String, Object> getPlatformOrderData();

    /**
     * @description:统计累计金额数据
     * @date: 2021/10/19 17:52
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    Map<String, Object> getPlatformAmtData();

    /**
     * 设置活动积分
     * @date: 2021/11/29 10:40
     * @param order:  当前订单
     */
    void setActivityMarketAmt(MerchantOrder order,MerchantStore store);

    List<UserProfit> getOrderFlow(String date,Integer sort);

    Integer getOrderMaxSort(String date);

    Map<String, String> getPlatformTransData();

    /**
     * 根据商户号和时间获取流水
     * @date: 2022/3/1 16:59
     * @param mercList:
     * @param date:
     * @param flag:
     * @return java.math.BigDecimal
     */
    BigDecimal getAreaOrderCount(List<String> mercList, String date, Integer flag);

    /**
     * 获取通道对账文件地址
     * @param accountDate
     * @param channel
     * @param type
     * @return
     */
    Result<Object> getChannelFileUrl(String accountDate, Integer channel, Integer type);

    BigDecimal getPlatformAmtYestNowData(String date,String yestStartDate, String yestEndDate);

    void sendPayCallBackArrival(MerchantOrder order);

    /**
     * 获取有效交易笔数
     * @param merchantCode
     * @return
     */
    Integer getValidNumByMerchantCode(String merchantCode);

//    void sendPayCallBackArrival(String userId,String orderNumber,Double consumeFee);
}

