<?php
namespace app\worker\controller;

use think\facade\Session;
use app\worker\BaseController;

use app\common\model\User as UserModel;
use app\common\model\Agent as AgentModel;
use app\common\model\Broker as BrokerModel;

use app\common\model\ReportEntry as ReportEntryModel;

use app\common\model\Admin as AdminModel;
use app\common\model\Menu as MenuModel;

use app\common\model\Worker as WorkerModel;
use app\common\model\Comjobs as ComjobsModel;
use app\common\model\Demand as DemandModel;
use app\common\model\Supply as SupplyModel;

class Home extends BaseController
{
	
	public function index()
	{
		return view('index', [
			'access_worker'  => session('access_worker')
		]);
	}

    public function console()
    {
        $workerid = $this->access_worker['id'];
        $where = array();
        $where[] = ['workerid', '=', $workerid];

        $comjobstol['today'] = ComjobsModel::whereDay('createtime')->where($where)->count();
        $comjobstol['yesterday'] = ComjobsModel::whereDay('createtime', 'yesterday')->where($where)->count();
        $comjobstol['week'] = ComjobsModel::whereWeek('createtime')->where($where)->count();
        $comjobstol['month'] = ComjobsModel::whereMonth('createtime')->where($where)->count();

        $demandtol['today'] = DemandModel::whereDay('createtime')->where($where)->count();
        $demandtol['yesterday'] = DemandModel::whereDay('createtime', 'yesterday')->where($where)->count();
        $demandtol['week'] = DemandModel::whereWeek('createtime')->where($where)->count();
        $demandtol['month'] = DemandModel::whereMonth('createtime')->where($where)->count();

        $supplytol['today'] = SupplyModel::whereDay('createtime')->where($where)->count();
        $supplytol['yesterday'] = SupplyModel::whereDay('createtime', 'yesterday')->where($where)->count();
        $supplytol['week'] = SupplyModel::whereWeek('createtime')->where($where)->count();
        $supplytol['month'] = SupplyModel::whereMonth('createtime')->where($where)->count();


        return view('home/console',[
            'domain' 			=> request()->domain(),
            'access_admin'  	=> session('access_admin'),
            'comjobstol'		=> $comjobstol,
            'demandtol'			=> $demandtol,
            'supplytol'			=> $supplytol
        ]);
    }
	

}