<?php

namespace app\common\model\odd_job;

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

class JobModel extends Model
{
    protected $connection = 'odd_job';

    use SoftDelete;
    protected $deleteTime = 'deletetime';
    protected $defaultSoftDelete = 0;

    //设置表名
    protected $name = 'comjobs';

    // 设置字段自动转换类型
    protected $type = [
        'tags'       => 'json',
        'picall'     => 'json',
        'emp_time'   => 'json',
        'enddate'    => 'timestamp:Y-m-d',
        'updatetime' => 'timestamp:Y-m-d H:i:s',
        'createtime' => 'timestamp:Y-m-d H:i:s',
    ];

    // 设置JSON数据返回数组
    protected $jsonAssoc = true;

    public function getWtypeTextAttr($value, $data)
    {
        $wtype = [1 => '按月', 2 => '按时', 3 => '按件', 4 => '按项目', 5 => '其他'];
        return $wtype[$data['wtype']];
    }

    public function getSexTextAttr($value, $data)
    {
        $sex = ['不限', '男', '女'];
        return $sex[$data['sex']];
    }

    public function getRecruitmentCateTextAttr($value, $data)
    {
        $recruitment_cate = [1 => '普通招聘', 2 => '悬赏聘'];
        return $recruitment_cate[$data['recruitment_cate']];
    }

    public function getStatusTextAttr($value, $data)
    {
        $status = [1 => '待修改', 2 => '待审核', 3 => '已上架', 4 => '已停招', 5 => '已下架'];
        return $status[$data['status']];
    }

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