<?php
/**
 * Created by PhpStorm.
 * User: 陈武杰
 * Date: 2021/1/14
 * Time: 9:37
 */

namespace App\Admin\Controllers\DataCenter;
use App\Http\Controllers\Controller;
use App\Models\Order;
use App\Models\User;


class FinancialSta
{
    //获取平台的收入总金额
    public static function getTotalIncome(){
        $data = Order::where('payment_status',2)->where('is_faster',0)->pluck('payment_amount')->sum();
        $data /=100;
       return $data;
    }
    //获取用户充值总金额
    public static function getTotalRecharge(){
        $data = Order::where('payment_status',2)->where('product_type',7)->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
    //获取平台用户所有的余额
    public static function getTotalUserBalance(){
        $data = User::where('is_docter',0)->pluck('balance')->sum();
        $data /= 100;
        return $data;
    }
    public static function getTotalRefund(){
        $data = Order::where('payment_status',4)->where('is_faster',0)->where('is_faster',0)->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
    /*
     * 充值记录
     * */
    //获取当日充值金额
    public static function getTodayReCharge(){
        $data = Order::where('payment_status',2)
                        ->where('product_type',7)
                        ->where('created_at','>=',date('Y-m-d 00:00:00',strtotime('today')))
                        ->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
    //获取最近7天的充值金额
    public static function getSevenDayReCharge(){
        $data = Order::where('payment_status',2)
            ->where('product_type',7)
            ->whereBetween('created_at',[date('Y-m-d 00:00:00',strtotime('-6 days')),date('Y-m-d H:i:s',time())])
            ->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
    //获取最近30天的充值金额
    public static function getOneMonthReCharge(){
        $data = Order::where('payment_status',2)
            ->where('product_type',7)
            ->whereBetween('created_at',[date('Y-m-d 00:00:00',strtotime('-29 days')),date('Y-m-d H:i:s',time())])
            ->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
    //获取今天的支付金额
    public static function getTodayPay(){
        $data = Order::where('payment_status',2)
            ->where('is_faster',0)
            ->where('created_at','>=',date('Y-m-d 00:00:00',strtotime('today')))
            ->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
    //获取昨天的支付金额
    public static function getYesterdayPay(){
        $data = Order::where('payment_status',2)
            ->where('is_faster',0)
            ->whereBetween('created_at',[date('Y-m-d 00:00:00',strtotime('-1 days')),date('Y-m-d 23:59:59',strtotime('-1 days'))])
            ->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
    //获取近七日的支付金额
    public static function getSevenDayPay(){
        $data = Order::where('payment_status',2)
            ->where('is_faster',0)
            ->whereBetween('created_at',[date('Y-m-d 00:00:00',strtotime('-6 days')),date('Y-m-d H:i:s',time())])
            ->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
    //获取三十日的支付金额
    public static function getOneMonthPay(){
        $data = Order::where('payment_status',2)
            ->where('is_faster',0)
            ->whereBetween('created_at',[date('Y-m-d 00:00:00',strtotime('-29 days')),date('Y-m-d H:i:s',time())])
            ->pluck('payment_amount')->sum();
        $data /= 100;
        return $data;
    }
}