<?php
/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 2017/5/25
 * Time: 上午9:30
 */

require_once (BASE_ROOT_PATH . '/helper/statistics/stat_base.php');
require_once (BASE_ROOT_PATH . '/helper/statistics/stbonus.php');
require_once (BASE_ROOT_PATH . '/helper/statistics/stmember.php');
require_once (BASE_ROOT_PATH . '/helper/statistics/statorder.php');
require_once (BASE_ROOT_PATH . '/helper/statistics/statcall.php');

class stat_helper
{
    const cur_date_type    = 1;
    const last_week_type   = 2;
    const last_hmonth_type = 3;
    const last_month_type  = 4;

    //['time' => time(),'use_type' => $this->mUsedType,'rate' => $rate,'amount' => $used / 100,'member_id' => $this->member_id]
    public static function onUseBonus($param)
    {
        if(empty($param) || is_array($param) == false) {
            return false;
        }
        try
        {
            $time = intval($param['time']);
            $stat = new statistics\stbonus($time);
            $use_type = intval($param['use_type']);
            $rate = intval($param['rate']);
            $amount = $param['amount'];

            if($use_type == bonus_helper::pay_order_withold) {
                $stat->add_paied($rate,$amount);
            }
            elseif (($use_type == bonus_helper::send_bonus_withold)) {
                $stat->add_send($rate,$amount);
            }
        }
        catch (Exception $ex) {
            Log::record($ex->getMessage(),Log::ERR);
        }

        return true;
    }
    public static function onDaiyBonus($time)
    {
        try
        {
            $stat = new statistics\stbonus($time);
            $stat->daily();
        }
        catch(Exception $ex)
        {
            Log::record($ex->getMessage(),Log::ERR);
        }
    }

    public static function onInitSelfDiscount()
    {
        try
        {
            $stat = new statistics\stbonus(time());
            $stat->init_discount_self();
        }
        catch(Exception $ex)
        {
            Log::record($ex->getMessage(),Log::ERR);
        }
    }

    public static function onInitInviteesDiscount()
    {
        try
        {
            $stat = new statistics\stbonus(time());
            $stat->init_discount_invitee();
        }
        catch(Exception $ex)
        {
            Log::record($ex->getMessage(),Log::ERR);
        }
    }

    public static function onDailySelfDiscount($time)
    {
        try
        {
            $stat = new statistics\stbonus($time);
            $stat->discount_self();
        }
        catch(Exception $ex)
        {
            Log::record($ex->getMessage(),Log::ERR);
        }
    }

    public static function onDailyInviteeDiscount($time)
    {
        try
        {
            $stat = new statistics\stbonus($time);
            $stat->discount_invitee();
        }
        catch(Exception $ex)
        {
            Log::record($ex->getMessage(),Log::ERR);
        }
    }

    public static function onInvite()
    {
        try
        {
            $stat = new statistics\stmember(time());
            $stat->onInvite();
        }
        catch(Exception $ex)
        {
            Log::record($ex->getMessage(),Log::ERR);
        }
    }
    public static function onDaiyMember($time)
    {
        try
        {
            $stat = new statistics\stmember($time);
            $stat->daily();
        }
        catch(Exception $ex)
        {
            Log::record($ex->getMessage(),Log::ERR);
        }
    }
    public static function onDaiyOrder($time)
    {
        try
        {
            $stat = new statistics\statorder($time);
            $stat->daily();
        }
        catch(Exception $ex)
        {
            Log::record($ex->getMessage(),Log::ERR);
        }
    }
}
