<?php


namespace App\Admin\Controllers;


use App\Http\Controllers\Controller;
use App\Models\Order;

class Sta extends Controller
{

    /*
     *
     * 获取今日预约订单数目
     *@param
     * $type int 订单类型
     */
    public static function getOrderCount($type,$day=1)
    {
//        产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
//        订单状态(1.未支付 2.待接单 3.进行中 4.已完成 5.已取消 6.已超时)
          if($type == 0) return Order::count();
        if($type != 7)
            return Order::where(['product_type'=>$type])
                ->where('order_status','>=',2)
                ->where('created_at','>=',date('Y-m-d H:i:s',strtotime('today')))
                ->count();
          if($day == 1)
          return Order::where('order_status','>=',2)
                        ->where('created_at','>=',date('Y-m-d H:i:s',strtotime('today')))
                        ->count();
          if($day == -1)
//              echo date('Y-m-d H:i:s',strtotime('-2 days')).'--'.date('Y-m-d H:i:s',strtotime('-1 days'));
              return Order::where('order_status','>=',2)
                  ->whereBetween('created_at',[date('Y-m-d H:i:s',strtotime('-2 days')),date('Y-m-d H:i:s',strtotime('-1 days'))])
                  ->count();
          if($day > 1)
              return Order::where('order_status','>=',2)
                  ->whereBetween('created_at',[date('Y-m-d H:i:s',strtotime('-'.$day.' days')),date('Y-m-d H:i:s',strtotime('today'))])
                  ->count();
    }
}
