<?php

namespace app\worker\controller;

use app\worker\BaseController;

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()
    {
        $access_worker = session('access_worker');
        $worker_list   = [];
        if (!empty($access_worker['userid'])) {
            $worker_list = WorkerModel::where('userid', $access_worker['userid'])
                ->where('id', '<>', $access_worker['id'])
                ->where('status', '<>', 2)
                ->select();
        }
        return view('index', [
            'access_worker' => $access_worker,
            'worker_list'   => $worker_list,
        ]);
    }

    public function console()
    {
        $workerid = $this->access_worker['id'];
        $where    = [];
        $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,
        ]);
    }


}