ManageHr.php 5.8 KB
<?php

namespace App\Models\Manage;
use App\Models\Base;
use Illuminate\Support\Facades\Cache;

class ManageHr extends Base
{
    protected $table = 'gl_manage_hr';

    const GID_ZERO = 0;//超级管理员

    const STATUS_ONE = 1;

    const IS_LEADER = 1;//组长
    /**
     * 特殊字段
     * @return string[]
     * @author zgj
     * @date 2023/5/31
     */
    public static function specieField(){
        return ['photo_gallery','id_card_gallery','certificate_gallery','career_history','learning_history'];
    }
    /**
     * 归属小组
     * @return string[]
     * @author zgj
     * @date 2023/5/31
     */
    public static function belongGroup()
    {
        return [
            1 => 'KA组',
            2 => 'A组',
            3 => 'B组',
            4 => 'C组',
            5 => 'D组',
            6 => 'E组',
            7 => 'F组',
            8 => 'G组',
            9 => 'H组',
            10 => 'GA组',
            11=> 'GB组',
            12 => 'GC组',
            13 => '前端组',
            14 => '后端组',
            15 => '黑格组',
            16 => '售后组',
            0 => '其他',
        ];
    }

    /**
     * 学历
     * @return string[]
     * @author zgj
     * @date 2023/5/31
     */
    public static function education()
    {
        return [
            1 => '专科',
            2 => '本科',
            3 => '研究生及以上',
            0 => '其他',
        ];
    }
    /**
     * 入职岗位
     * @return string[]
     * @author zgj
     * @date 2023/5/31
     */
    public static function entryPosition()
    {
        return [
            1 => '优化师',
            2 => '优化师助理',
            3 => '优化顾问',
            4 => '项目经理',
            5 => '平面设计',
            6 => '技术经理',
            7 => '技术主管',
            8 => '技术总监',
            9 => '渠道经理',
            10 => '前端研发',
            11=> '后端研发',
            12 => '行政财务',
            13 => '品牌营销',
            14 => '销售经理',
            15 => '销售主管',
            16 => '售后技术',
            17 => '售后服务',
            18 => '外贸销售',
            19 => '渠道助理',
            20 => '黑格运营',
            21 => '运营',
            22 => '短视频剪辑师',
            23 => '人事',
            24 => '采购',
            0 => '其他',
        ];
    }

    /**
     * 级别序列
     * @return string[]
     * @author zgj
     * @date 2023/5/31
     */
    public static function pLevel()
    {
        return [
            0 => '实习期/试用期(P0)',
            1 => '初级(P1)',
            2 => '初级(P2)',
            3 => '初级(P3)',
            4 => '中级(P4)',
            5 => '中级(P5)',
            6 => '中级(P6)',
            7 => '高级(P7)',
            8 => '高级(P8)',
            9 => '高级(P9)',
            10 => '高级(P10)',
            11=> '职务初级(M1)',
            12 => '职务初级(M2)',
            13 => '职务初级(M3)',
            14 => '职务中级(M4)',
            15 => '职务中级(M5)',
            16 => '职务中级(M6)',
            17 => '职务高级(M7)',
            18 => '职务高级(M8)',
            19 => '职务高级(M9)',
            20 => '职务高级(M10)',
        ];
    }
    /**
     * 是否党员
     * @return string[]
     * @author zgj
     * @date 2023/5/31
     */
    public static function dangyuan()
    {
        return [
            0 => '群众',
            1 => '预备党员',
            2 => '正式党员',
        ];
    }

    /**
     * 是否有党支部
     * @return string[]
     * @author zgj
     * @date 2023/5/31
     */
    public static function dangzhibu()
    {
        return [
            0 => '无',
            1 => '是',
            2 => '否',
        ];
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function dept()
    {
        return $this->hasOne(Dept::class, 'id', 'dept_id');
    }

    public function position()
    {
        return $this->hasOne(EntryPosition::class, 'id', 'entry_position');
    }

    public function getDeptNameAttribute()
    {
        return $this->dept->name;
    }

    /**
     * @remark :获取用户名称
     * @name   :getName
     * @author :lyh
     * @method :post
     * @time   :2023/8/18 14:41
     */
    public function getName($id){
        $name = '未分配';
        if(!empty($id)){
            $name = Cache::get('manager_hr_'.$id);
            if(empty($name)){
                $info = $this->read(['id'=>$id],['id','name']);
                if($info !== false){
                    $name = $info['name'];
                    Cache::put('manager_hr_'.$id,$name,24 * 3600);
                }
            }
        }
        return $name;
    }

    /**
     * @remark :根据当前用户登录的id获取当前用户的组长
     * @name   :accordIdGetLeader
     * @author :lyh
     * @method :post
     * @time   :2025/7/22 9:42
     * @param  :id->当前用户的人事id
     */
    public function accordIdGetLeader($id = 0){
        if(empty($id)){
            return 0;
        }
        //查看当前用户是否为组长
        $info = $this->read(['id'=>$id],['belong_group','is_leader','dept_id']);
        if($info === false){
            return 0;
        }
        //不是组长:根据小组获取组长
        if($info['is_leader'] != self::IS_LEADER){
            $id = $this->getValue(['belong_group'=>$info['belong_group'],'is_leader'=> self::IS_LEADER]);
            if(empty($id)){
                //未获取到时,根据当前大组去随机获取一个组长
                $id = $this->getValue(['dept_id'=>$info['dept_id'],'is_leader'=> self::IS_LEADER]);
            }
        }
        return $id;
    }
}