<?php
namespace app\admin\controller;

use app\common\model\ComjobsLog;
use think\facade\Session;
use app\admin\BaseController;
use app\common\model\Admin as AdminModel;
use app\common\model\Menu as MenuModel;

use app\common\model\User as UserModel;
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;

use app\common\model\ArticleComment as ArticleCommentModel;

use think\facade\Env;

class Home extends BaseController
{
	
	public function index()
	{
		$access_admin = session('access_admin');
		$admin = AdminModel::findOrEmpty($access_admin['id']);
		$menulist = MenuModel::where(['mtype'=>'admin','status'=>1])->where('id','in',$admin->powerids)->order(['pid'=>'asc','priority'=>'asc','id'=>'asc'])->select()->toArray();
		$powerarr = array();
		$poweridsarr = ($admin->powerids==null||empty($admin->powerids)) ? [] : explode(",", $admin->powerids);
		if (!empty($menulist)){
			foreach ($menulist as $k=>$v){
				if ($v['pid']==0){
					$v['children'] = array();
					$powerarr[$v['id']] = $v;
				}else {
					$powerarr[$v['pid']]['children'][] = $v;
				}
			}
		}
		return view('index', [
			'access_admin'	=> $access_admin,
			'powerarr'		=> $powerarr
		]);
	}
	
	public function console()
	{
		
		$usertol['today'] = UserModel::whereDay('createtime')->count();
		$usertol['yesterday'] = UserModel::whereDay('createtime', 'yesterday')->count();
		$usertol['week'] = UserModel::whereWeek('createtime')->count();
		$usertol['month'] = UserModel::whereMonth('createtime')->count();
		
		$workertol['today'] = WorkerModel::whereDay('createtime')->count();
		$workertol['yesterday'] = WorkerModel::whereDay('createtime', 'yesterday')->count();
		$workertol['week'] = WorkerModel::whereWeek('createtime')->count();
		$workertol['month'] = WorkerModel::whereMonth('createtime')->count();
		
		$comjobstol['today'] = ComjobsModel::whereDay('createtime')->count();
		$comjobstol['yesterday'] = ComjobsModel::whereDay('createtime', 'yesterday')->count();
		$comjobstol['week'] = ComjobsModel::whereWeek('createtime')->count();
		$comjobstol['month'] = ComjobsModel::whereMonth('createtime')->count();
		
		$demandtol['today'] = DemandModel::whereDay('createtime')->count();
		$demandtol['yesterday'] = DemandModel::whereDay('createtime', 'yesterday')->count();
		$demandtol['week'] = DemandModel::whereWeek('createtime')->count();
		$demandtol['month'] = DemandModel::whereMonth('createtime')->count();
		
		$supplytol['today'] = SupplyModel::whereDay('createtime')->count();
		$supplytol['yesterday'] = SupplyModel::whereDay('createtime', 'yesterday')->count();
		$supplytol['week'] = SupplyModel::whereWeek('createtime')->count();
		$supplytol['month'] = SupplyModel::whereMonth('createtime')->count();

		//企业入住量
        $workercount = WorkerModel::where(["deletetime"=>0])->count();
        //岗位数量
        $comjobscount = ComjobsModel::where(["deletetime"=>0])->count();
        //个人进驻量
        $usercount = UserModel::where(["deletetime"=>0])->count();
        //求职成功量
        $comjobssuccesscount = ComjobsLog::where(["status"=>6,"del_status"=>0])->count();

        //按分类统计个人
        $catedata[0] = UserModel::where(["deletetime"=>0,"groupsid"=>7])->count();
        $catedata[1] = UserModel::where(["deletetime"=>0,"groupsid"=>8])->count();
        $catedata[2] = UserModel::where(["deletetime"=>0,"groupsid"=>9])->count();
        $catedata[3] = UserModel::where(["deletetime"=>0,"groupsid"=>10])->count();
        $catedata[4] = UserModel::where(["deletetime"=>0,"groupsid"=>11])->count();
        $catedata[5] = UserModel::where(["deletetime"=>0,"groupsid"=>12])->count();
		
		// var_dump($_SERVER);die;
		
		
		return view('home/console',[
			'domain' 			=> request()->domain(),
			'access_admin'  	=> session('access_admin'),
			'usertol'			=> $usertol,
			'workertol'			=> $workertol,
			'comjobstol'		=> $comjobstol,
			'demandtol'			=> $demandtol,
			'supplytol'			=> $supplytol,
            'catedata'			=> $catedata,
            'workercount'		=> $workercount,
            'comjobscount'			=> $comjobscount,
            'usercount'			=> $usercount,
            'comjobssuccesscount'			=> $comjobssuccesscount
		]);
	}
	

}