<?php

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class WorkerResume extends Model
{
    use SoftDelete;
    protected $deleteTime = 'deletetime';
    protected $defaultSoftDelete = 0;

    // 设置字段信息
    protected $schema = [
        'id'             => 'int',
        'workerid'       => 'int',
        'groupsid'       => 'int',
        'nickname'       => 'string',
        'avatar'         => 'string',
        'mobile'         => 'string',
        'status'         => 'tinyint',
        'idcardzpic'     => 'string',
        'idcardfpic'     => 'string',
        'idcard'         => 'string',
        'gender'         => 'tinyint',
        'birthday'       => 'string',
        'address'        => 'string',
        'education'      => 'string',
        'createtime'     => 'int',
        'jobintention'   => 'string',
        'workexperience' => 'string',
        'eduexperience'  => 'string',
        'followstatus'   => 'tinyint',
        'wxampcode'      => 'string',
        'bankcard'       => 'string',
        'emp_time'       => 'string',
        'user_tags'      => 'string',
        'com_cate'       => 'string',
        'volume'         => 'int',
        'deletetime'     => 'int',
        'work_place'     => 'string',
        'com_cate_type'  => 'int',
        'com_cate_other' => 'string',
        'comment'        => 'string',
    ];

    // 设置字段自动转换类型
    protected $type = [
        'bankcard'   => 'json',
        'createtime' => 'timestamp:Y-m-d H:i:s',
        'emp_time'   => 'json',
        'com_cate'   => 'json',
        'work_place' => 'json',
        'user_tags'  => 'json',
    ];
    protected $jsonAssoc = true;

    public function getFollowstatusTextAttr($value, $data)
    {
        $followstatus = [1 => '未跟进', 2 => '未面试', 3 => '面试通过', 4 => '面试未通过', 5 => '用户放弃', 6 => '已入职', 7 => '已离职'];
        return $followstatus[$data['followstatus']];
    }

    public function getEducationTextAttr($value, $data)
    {
        $education = ['' => '', 1 => '初中及以下', 2 => '高中', 3 => '中技', 4 => '中专', 5 => '大专', 6 => '本科', 7 => '硕士', 8 => '博士'];
        return $education[$data['education']];
    }

    public function getWorkerTextAttr($value, $data)
    {
        $experience = ['' => '', 1 => '无经验', 2 => '一年以下', 3 => '1-3年', 4 => '3-5年', 5 => '5-10年', 6 => '10年以上'];
        return $experience[$data['workexperience']];
    }

    public function getJobintentionTextAttr($value, $data)
    {
        $title = '';
        if ($data['jobintention']) {
            $title = UserWill::where('id', $data['jobintention'])->value('title');
        }
        return $title;
    }

    // 关联UserGroups
    public function userGroups()
    {
        return $this->hasOne(UserGroups::class, "id", "groupsid");
    }

    // 关联WorkerGroups
    public function workerGroup()
    {
        return $this->hasOne(WorkerGroup::class, "id", "groupid");
    }

    // 关联Worker
    public function worker()
    {
        return $this->hasOne(Worker::class, "id", "workerid");
    }
}