| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 | <?phpnamespace app\common\api;use app\common\model\TalentLog;/** * Description of TalentLogApi * * @author sgq */class TalentLogApi {    public static function getList($type, $mainId, $active = 1) {        $where[] = ["type", "=", $type];        $where[] = ["mainId", "=", $mainId];        $where[] = ["active", "=", $active];        $whr[] = ["step", "=", 3];        $whr[] = ["type", "=", $type];        $whr[] = ["mainId", "=", $mainId];        return $list = TalentLog::whereOr([$where, $whr])->order("createTime desc")->select()->toArray();    }    public static function getPassDepts($mainId, $fst_dept_check_time = null) {        $dept_pass_state = TalentState::DEPT_VERIFY_PASS;        $where[] = ["type", "=", 1];        $where[] = ["mainId", "=", $mainId];        $where[] = ["step", "=", 3];        if ($fst_dept_check_time) {            $where[] = ["createTime", ">=", $fst_dept_check_time];        }        $dept_logs = TalentLog::where($where)->order("createTime desc")->select();        $check_depts = [];        $pass_depts = [];        foreach ($dept_logs as $dept_log) {            if (!in_array($dept_log["companyId"], $check_depts)) {                $check_depts[] = $dept_log["companyId"];                if ($dept_log["new_state"] == $dept_pass_state && $dept_log["active"] == 1) {                    $pass_depts[] = $dept_log["companyId"];                }            }        }        return array_unique($pass_depts);    }    public static function getUnCheckDepts($mainId) {        $where[] = ["type", "=", 1];        $where[] = ["mainId", "=", $mainId];        $where[] = ["active", "=", 0];        $where[] = ["step", "=", 3];        //$where[] = ["new_state", "in", [TalentState::DEPT_VERIFY_PASS, TalentState::FST_VERIFY_PASS]];        return TalentLog::where($where)->column("companyId");    }    public static function getFstLog($mainId, $type) {        $where = [];        $where[] = ["mainId", "=", $mainId];        $where[] = ["type", "=", $type];        $where[] = ["active", "=", 1];        $where[] = ["typeFileId", "null"];        $log = TalentLog::where($where)->order("createTime asc")->findOrEmpty()->toArray();        return $log;    }    public static function getLastLog($mainId, $type, $companyId = 0, $extra_where = []) {        $where = [];        $where[] = ["mainId", "=", $mainId];        $where[] = ["type", "=", $type];        $where[] = ["typeFileId", "null"];        if ($companyId) {            $where[] = ["companyId", "=", $companyId];        }        if ($extra_where) {            $where[] = $extra_where;        }        $last_log = TalentLog::where($where)->order("createTime desc")->findOrEmpty()->toArray();        return $last_log;    }    public static function getLastLogEx($mainId, $type, $companyId = 0, $extra_where = []) {        $where = [];        $where[] = ["mainId", "=", $mainId];        $where[] = ["type", "=", $type];        $where[] = ["typeFileId", "null"];        if ($companyId) {            $where[] = ["companyId", "=", $companyId];        }        if ($extra_where) {            $where = array_merge($where, (array) $extra_where);        }        $last_log = TalentLog::where($where)->order("createTime desc")->findOrEmpty()->toArray();        return $last_log;    }    public static function getCompanyNewestCheckedLog($mainId, $companyId) {        $where = [];        $where[] = ["mainId", "=", $mainId];        $where[] = ["step", "=", 3];        $where[] = ["companyId", "=", $companyId];        //$where[] = ["active", "=", 1];        $one = TalentLog::where($where)->order("createTime desc")->find();        return $one;    }    public static function getLogByCompanyId($mainId, $companyId, $fst_dept_check_time) {        $where = [];        $where[] = ["mainId", "=", $mainId];        $where[] = ["companyId", "=", $companyId];        $where[] = ["createTime", ">=", $fst_dept_check_time];        $one = TalentLog::where($where)->find();        return $one;    }    public static function getListLogByTime($id, $time, $type = 1) {        $where = [];        $where[] = ["mainId", "=", $id];        $where[] = ["type", "=", $type];        $where[] = ["createTime", ">=", $time];        $where[] = ["typeFileId", "null"];        $list = TalentLog::where($where)->order("createTime desc")->select()->toArray();        return $list;    }    public static function getLastLogByStep($id, $type, $step, $active = 2) {        $where = [];        $where[] = ["mainId", "=", $id];        $where[] = ["type", "=", $type];        $where[] = ["active", "=", $active];        $where[] = ["step", "=", $step];        $last = TalentLog::where($where)->order("createTime desc")->find();        return $last;    }    public static function writeDeptLogs($mainId, $companyIds, $state = []) {        $user = session("user");        $last_log = self::getLastLog($mainId, 1, 0, ["active", "=", 1]);        for ($i = 0; $i < count($companyIds); $i++) {            $log["last_state"] = $last_log["state"] ?: 0;            $log["id"] = getStringId();            if (is_array($state)) {                $log["state"] = $state[0];                $log["new_state"] = $state[1];            } else {                $log["state"] = $log["new_state"] = $state;            }            $log["type"] = 1;            $log["mainId"] = $mainId;            $log["companyId"] = $companyIds[$i];            $log["description"] = "等待部门审核";            $log["step"] = 3; //部门审核阶段            $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);            $log["createTime"] = date("Y-m-d H:i:s");            TalentLog::create($log);        }    }    public static function write($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null, $companyId = null, $user = null) {        $user = $user ? $user : session("user");        $last_log = self::getLastLog($mainId, $type, 0, ["active", "=", 1]);        $log["last_state"] = $last_log["state"] ?: 0;        $log["id"] = getStringId();        if (is_array($state)) {            $log["state"] = $state[0];            $log["new_state"] = $state[1];            if ($state[2]) {                $log["step"] = $state[2];            }        } else {            $log["state"] = $log["new_state"] = $state;        }        $log["type"] = $type;        $log["mainId"] = $mainId;        $log["typeFileId"] = $fileType;        $log["fileId"] = $fileId;        if ($user) {            $log["companyId"] = $user["companyId"];        }        if ($companyId) {            $log["companyId"] = $companyId;        }        $log["active"] = $active;        $log["description"] = $description;        $log["createUser"] = $user ? ($user["userType"] == 3 ? "申报用户" : sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"])) : "系统";        $log["createTime"] = date("Y-m-d H:i:s");        return TalentLog::create($log);    }    public static function rewrite($id, $state = [], $description = "", $active = 0, $user = null) {        $user = $user ? $user : session("user");        if (is_array($state)) {            $log["state"] = $state[0];            $log["new_state"] = $state[1];        } else {            $log["state"] = $log["new_state"] = $state;        }        $log["id"] = $id;        if ($user) {            $log["companyId"] = $user["companyId"];        }        $log["active"] = $active;        $log["description"] = $description;        $log["updateUser"] = $user ? ($user["userType"] == 3 ? "申报用户" : sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"])) : "系统";        $log["updateTime"] = date("Y-m-d H:i:s");        return TalentLog::update($log);    }    public static function setActive($id, $value) {        $user = session("user");        $data["id"] = $id;        $data["active"] = $value;        $data["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);        $data["updateTime"] = date("Y-m-d H:i:s");        return TalentLog::update($data);    }    public static function system($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null) {        $last_log = self::getLastLog($mainId, $type, 0, ["active", "=", 1]);        $log["last_state"] = $last_log["state"] ?: 0;        $log["id"] = getStringId();        if (is_array($state)) {            $log["state"] = $state[0];            $log["new_state"] = $state[1];            if ($state[2]) {                $log["step"] = $state[2];            }        } else {            $log["state"] = $log["new_state"] = $state;        }        $log["type"] = $type;        $log["mainId"] = $mainId;        $log["typeFileId"] = $fileType;        $log["fileId"] = $fileId;        $log["active"] = $active;        $log["description"] = $description;        $log["createUser"] = '系统';        $log["createTime"] = date("Y-m-d H:i:s");        return TalentLog::create($log);    }}
 |