<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2017/11/21
 * Time: 10:42
 */

namespace App\Modules\Trade\Services;

use App\Modules\Trade\Models\Order;
use Redis;

class OrderService
{
    /**
     * 查询订单
     * @param  array $params [distribution_channel_id、begin_time、end_time、uid(用户ID)、send_order_id(派单ID)、trade_no(订单号)]
     * @param  boolean $is_all [是否返回全部，默认否]
     * @return [type]          [description]
     */
    static function search($params = [], $is_all = false)
    {
        return Order::search($params, $is_all);
    }

    /**
     * 查询订单
     * @param  array $params [distribution_channel_id、begin_time、end_time、uid(用户ID)、send_order_id(派单ID)、trade_no(订单号)]
     */
    static function searchObj($params = [])
    {
        return Order::searchObj($params);
    }

    /**
     * 获取订单总额
     * @param  array $params [distribution_channel_id、begin_time、end_time、uid、send_order_id]
     */
    static function getAmount($params = [])
    {
        return Order::getAmount($params);
    }

    /**
     * 获取付费用户数
     * @param  array $params [send_order_id]
     */
    static function getPayUserNum($send_order_id)
    {
        return Order::getPayUserNum($send_order_id);
    }

    /**
     * 获取VIP付费用户数
     * @param  array $params [send_order_id]
     */
    static function getVipPayUserNum($send_order_id)
    {
        return Order::getVipPayUserNum($send_order_id);
    }

    /**
     * 获取普通付费用户数
     * @param  array $params [send_order_id]
     */
    static function getNormaPayUserNum($send_order_id)
    {
        return Order::getNormalPayUserNum($send_order_id);
    }

    /**
     *获取派单下的订单总数
     * @param  array $params [send_order_id]
     */
    static function getOrderCount($send_order_id)
    {
        return Order::getOrderCount($send_order_id);
    }

    /**
     *获取活动下的订单数
     * @param  array $params [$activity_id]
     */
    static function getActivityOrderNum($params = [])
    {
        return Order::getActivityOrderNum($params);
    }

    /**
     *获取派单下的普通用户的订单总数
     * @param  array $params [send_order_id]
     */
    static function getNormalOrderCount($send_order_id)
    {
        return Order::getNormalOrderCount($send_order_id);
    }

    /**
     *获取派单下的VIP用户的订单总数
     * @param  array $params [send_order_id]
     */
    static function getVipOrderCount($send_order_id)
    {
        return Order::getVipOrderCount($send_order_id);
    }

    /**
     * 获取渠道当日数据
     * @param  $distribution_channel_id 分销渠道ID
     * @return [成功订单总额、成功订单数]
     */
    static function getChannelToday($distribution_channel_id)
    {
        $data = Order::getChannelToday($distribution_channel_id);
        $data['total_num'] = Redis::hget('order_stat:' . $distribution_channel_id, 'order_num_' . date('Y-m-d'));
        return $data;
    }

    /**
     * 获取渠道当日数据  new
     * @param  $distribution_channel_id 分销渠道ID
     * @return [成功订单总额、成功订单数]
     */
    static function getChannelTodayData($distribution_channel_id)
    {
        $data = Order::getChannelTodayData($distribution_channel_id);
        return $data;
    }

    /**
     * 获取渠道当日数据
     * @param  $distribution_channel_id 分销渠道ID
     * @return [成功订单总额、成功订单数、总订单数]
     */
    static function getChannelDateOrderInfo($distribution_channel_id, $date)
    {
        $data = Order::getChannelDateOrderInfo($distribution_channel_id, $date);
        $data['total_num'] = Redis::hget('order_stat:' . $distribution_channel_id, 'order_num_' . $date);
        return $data;
    }

    /**
     * 获取渠道对应支付通道总额
     * @param  array $params [distribution_channel_id、begin_time、end_time]
     * @return array
     * [
     *     'ALIPAY'=>121,
     *     'OFFICIAL'=2323
     * ]
     */
    static function getPayMerchantSourceAmount($params = [])
    {
        return Order::getPayMerchantSourceAmount($params);
    }

    //获取渠道日付费用户数
    static function getDayPayUserNumByChannelId($distribution_channel_id, $date)
    {
        return Order::getDayPayUserNumByChannelId($distribution_channel_id, $date);
    }

    //获取渠道日包年vip付费用户数
    static function getDayVipPayUserNumByChannelId($distribution_channel_id, $date)
    {
        return Order::getDayVipPayUserNumByChannelId($distribution_channel_id, $date);
    }

    //获取渠道日普通充值付费用户数
    static function getDayRechargePayUserNumByChannelId($distribution_channel_id, $date)
    {
        return Order::getDayRechargePayUserNumByChannelId($distribution_channel_id, $date);
    }

    //获取指定日期普通充值未支付订单数、支付订单数、总额
    static function getChannelDayTicketRechargeData($distribution_channel_id, $date)
    {
        return Order::getChannelDayTicketRechargeData($distribution_channel_id, $date);
    }

    //获取指定日期包年充值未支付订单数、支付订单数、总额
    static function getChannelDayYearRechargeData($distribution_channel_id, $date)
    {
        return Order::getChannelDayYearRechargeData($distribution_channel_id, $date);
    }

    //获取渠道日首充数据
    static function getChannelDayFirstRechargeData($distribution_channel_id, $date)
    {
        return Order::getChannelDayFirstRechargeData($distribution_channel_id, $date);
    }

    //获取派单累计充值（追踪用户）
    static function getPromotionRegUserRechargeAmount($params)
    {
        return Order::getPromotionRegUserRechargeAmount($params);
    }

    /**
     * 获取服务号下面的充值金额
     * @param $start_time 开始时间
     * @param $end_time 结束时间
     */
    static function getRechargeAmountGroupByOfficial($date){
        return Order::getRechargeAmountGroupByOfficialAccount($date);
    }
}
