<?php

namespace app\admin\controller;

use app\admin\common\AdminController;
use app\common\api\TalentState;
use app\enterprise\model\Talent;

/**
 * Description of Login
 *
 * @author sgq
 */
class Index extends AdminController {

    public function index() {
        $vars["user"] = [
            "name" => $this->user["name"],
            "rolename" => $this->user["rolename"],
            "avatar" => $this->user["avatar"],
            "sex" => $this->user["sex"]
        ];
        $menus = \app\common\api\MenuApi::getMenuListByRoleid($this->user["roleid"]);
        $vars["menus"] = $menus;

        $codes = \app\common\api\MenuApi::getCodesByRoleId($this->user["roleid"]);
        $backLogCount = 0;
        if (in_array("talentInfo_first", $codes)) {
            $where[] = ["e.type", "=", session("user")["type"]];
            $where[] = ["ti.checkState", "=", TalentState::SCND_SUBMIT];
            $where[] = ["tl.state", "in", [TalentState::SCND_SUBMIT, TalentState::DEPT_VERIFY_REJECT, TalentState::REVERIFY_REJECT]];
            $count = Talent::alias("ti")
                            ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")
                            ->leftJoin("(select mainId,last_state,new_state,state,createTime from new_talent_checklog where md5(concat(createTime,mainId,`type`)) in (select md5(concat(max(createTime),mainId,`type`)) from `new_talent_checklog` where `type`=1 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ti.id")
                            ->where($where)->count();
            $backlog = ["title" => "【人才认定申报】待初审", "url" => "$('a.J_menuItem[href=\"/admin/talent/fst_verify\"]').click()", "count" => $count];
            $vars["backlog"][] = $backlog;
            $backLogCount += $count;
        }
        $vars["backLogCount"] = $backLogCount;
        return view("", $vars);
    }

}
