<?php
namespace app\web\controller;


use app\common\model\ComjobsLog;
use think\facade\Session;
use app\web\BaseController;
use app\common\model\Comjobs as ComjobsModel;
use app\common\model\Worker as WorkerModel;
use app\common\model\Article as ArticleModel;
use app\common\model\ComjobsCate;

class Page extends BaseController
{
    public function index(){
        $cmap = array();
        $cmap[] = ['createtime','<=',time()];
        $cmap[] = ['status','in','3,4'];
        $comjobslist = ComjobsModel::where($cmap)->order(['status'=>'asc','priority'=>'desc','updatetime'=>'desc','id'=>'desc'])->limit(9)->select();

        $articleonelist = ArticleModel::where(["cateid"=>5])->limit(5)->select();
        foreach($articleonelist as $k=>$v){
            if($v['createtime']){
                $articleonelist[$k]['showtime'] = date('m-d',strtotime($v['createtime']));
            }
        }
        $jobslog = ComjobsLog::where('del_status',0)->count();
        return view('page/index', [
            'time'     => date('Y-m-d H:i:s',time()),
            'jobscount'    =>  count($comjobslist),
            'usercount'    =>  $jobslog,
            'comjobslist'	=> $comjobslist,
            'articleonelist'	=> $articleonelist
        ]);
    }

    public function comjobs(){
        $page = input('page/d', 1);
        $cateid = input('cateid/d', 0);
        if (!empty($cateid)){
            $map[] = ['cateid', '=', $cateid];
        }
        $map = [];
//        $map[] = ['status','in','3,4'];
        $comjobslist = ComjobsModel::with(['comjobsCate'])->where($map)->order(['status'=>'asc','priority'=>'desc','updatetime'=>'desc','id'=>'desc'])->page($page)->paginate(8);
        $comjobscate = ComjobsCate::where('id','>',45)->order(['priority'=>'desc','id'=>'desc'])->select();
        return view('page/comjobs', [
            'last_page'    =>  $comjobslist->toArray()['last_page'],
            'page'    =>  $page,
            'comjobslist'	=> $comjobslist->toArray()['data'],
            'comjobscate'	=> $comjobscate,
        ]);
    }

    public function comjobsajax(){
        $page = input('page/d', 1);
        $cateid = input('cateids/s', '');
        $map = [];
        if (!empty($cateid)){
            $catearr = explode(',',$cateid);
            $map[] = ['cateid', 'in', $catearr];
        }

//        $map[] = ['status','in','3,4'];
        $comjobslist = ComjobsModel::with(['comjobsCate'])->where($map)->order(['status'=>'asc','priority'=>'desc','updatetime'=>'desc','id'=>'desc'])->page($page)->paginate(8);
        return json(['data'=>$comjobslist->toArray()['data'],'current_page'=>$comjobslist->toArray()['current_page'],'last_page'=>$comjobslist->toArray()['last_page']]);
    }

    public function comjobsinfo(){
        $id = input('id/d', 0);
        $comjobsinfo = ComjobsModel::with(['worker'])->where('id',$id)->find();
//        dd($comjobsinfo->toArray());
        return json($comjobsinfo);
    }


	
}