<?php

namespace app\common\model;

use think\model\concern\SoftDelete;

class RecruitModel extends BaseModel
{
    use SoftDelete;

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

    //自动完成
    protected $autoWriteTimestamp = true;

    // 设置字段自动转换类型
    protected $type = [
        'forms'                 => 'array',
        'step'                  => 'array',
        'pen_ticket_field'      => 'array',
        'computer_ticket_field' => 'array',
        'face_ticket_field'     => 'array',
        'reexamine_field'       => 'array',
        /*'apply_start'           => 'timestamp:Y-m-d H:i:s',
        'apply_end'             => 'timestamp:Y-m-d H:i:s',
        'audit_start'           => 'timestamp:Y-m-d H:i:s',
        'audit_end'             => 'timestamp:Y-m-d H:i:s',
        'preliminary_start'     => 'timestamp:Y-m-d H:i:s',
        'preliminary_end'       => 'timestamp:Y-m-d H:i:s',
        'computer_start'        => 'timestamp:Y-m-d H:i:s',
        'computer_end'          => 'timestamp:Y-m-d H:i:s',
        'interview_start'       => 'timestamp:Y-m-d H:i:s',
        'interview_end'         => 'timestamp:Y-m-d H:i:s',
        'reexamine_start'       => 'timestamp:Y-m-d H:i:s',
        'reexamine_end'         => 'timestamp:Y-m-d H:i:s',
        'health_start'          => 'timestamp:Y-m-d H:i:s',
        'health_end'            => 'timestamp:Y-m-d H:i:s',
        'political_start'       => 'timestamp:Y-m-d H:i:s',
        'political_end'         => 'timestamp:Y-m-d H:i:s',
        'publicity_start'       => 'timestamp:Y-m-d H:i:s',
        'publicity_end'         => 'timestamp:Y-m-d H:i:s',
        'supplement_start'      => 'timestamp:Y-m-d H:i:s',
        'supplement_end'        => 'timestamp:Y-m-d H:i:s',
        'pen_confirm_start'     => 'timestamp:Y-m-d H:i:s',
        'pen_confirm_end'       => 'timestamp:Y-m-d H:i:s',*/
    ];

    // 常量
    const STATUS_INT = [1 => '是', 2 => '否'];
    const STATUS_STEP = [1 => '报名', 2 => '审核', 3 => '笔试', 4 => '上机', 5 => '面试', 6 => '复试', 7 => '体检', 8 => '政审', 9 => '公示'];
//    const STATUS_TICKET_TYPE = [-1 => '不需要', 1 => '纸质', 2 => '短信', 3 => '模板'];
    const STATUS_TICKET_TYPE = [-1 => '不需要', 1 => '纸质'];
    const STATUS_TICKET_STATUS = [-1 => '未生成', 1 => '生成中', 2 => '已生成'];
    const STATUS_SCORE = [1 => '已上传', 2 => '未上传'];
    const FORMS = ['basic' => '基础信息模块', 'expand_special' => '扩展模块-加分', 'detail' => '详情介绍模块', 'identification' => '身份证明上传模块', 'education_certification' => '学历证明上传模块', 'other_certification' => '其他证明上传模块', 'hj_certification' => '户籍证明上传模块', 'remark' => '备注模块', 'chengnuoshu' => '诚信承诺书', 'shixin' => '失信被执行人查询信息页扫描件', 'baokaoshengming' => '报考声明书'];

    //状态
    const STATUS_YES = 1;
    const STATUS_NO = 2;

    //流程
    const STEP_SIGN = 1;
    const STEP_EXAMINE = 2;
    const STEP_WRITE = 3;
    const STEP_COMPUTER = 4;
    const STEP_FACE = 5;
    const STEP_RETEST = 6;
    const STEP_HEALTH = 7;
    const STEP_POLITICS = 8;
    const STEP_PUBLICITY = 9;

    //准考证类型
    const TICKET_TYPE_NO = -1;
    const TICKET_TYPE_PAPER = 1;
    const TICKET_TYPE_MESSAGE = 2;

    //准考证状态
    const TICKET_STATUS_No = -1;
    const TICKET_STATUS_PROGRESS = 1;
    const TICKET_STATUS_FINISH = 2;

    //是否上传成绩
    const TICKET_SCORE_YES = 1;
    const TICKET_SCORE_NO = 2;

    public function getStatusTextAttr($value, $data)
    {
        return self::STATUS_INT[$data['status']];
    }

    public function getCurrentTextAttr($value, $data)
    {
        return self::STATUS_STEP[$data['current']];
    }

    public function getStepArrAttr($value, $data)
    {
        $arr  = [];
        $step = $data['step'];
        if (is_string($step)) {
            $step = explode('-', $step);
        }
        foreach ($step as $v) {
            $arr[] = self::STATUS_STEP[$v];
        }
        return $arr;
    }

    public function getPredeterminedStatusTextAttr($value, $data)
    {
        return self::STATUS_INT[$data['predetermined_status']];
    }

    public function getShowReportTextAttr($value, $data)
    {
        return self::STATUS_INT[$data['show_report']];
    }

    public function getPenTicketTypeTextAttr($value, $data)
    {
        return self::STATUS_TICKET_TYPE[$data['pen_ticket_type']];
    }

    public function getPenTicketStatusTextAttr($value, $data)
    {
        return self::STATUS_TICKET_STATUS[$data['pen_ticket_status']];
    }

    public function getPenStatusTextAttr($value, $data)
    {
        return self::STATUS_SCORE[$data['pen_status']];
    }

    public function getPenConfirmTextAttr($value, $data)
    {
        return self::STATUS_INT[$data['pen_confirm']];
    }

    public function getComputerTypeTextAttr($value, $data)
    {
        return self::STATUS_TICKET_TYPE[$data['computer_ticket_type']];
    }

    public function getComputerTicketStatusTextAttr($value, $data)
    {
        return self::STATUS_TICKET_STATUS[$data['computer_ticket_status']];
    }

    public function getComputerStatusTextAttr($value, $data)
    {
        return self::STATUS_SCORE[$data['computer_status']];
    }

    public function getFaceTypeTextAttr($value, $data)
    {
        return self::STATUS_TICKET_TYPE[$data['face_ticket_type']];
    }

    public function getFaceTicketStatusTextAttr($value, $data)
    {
        return self::STATUS_TICKET_STATUS[$data['face_ticket_status']];
    }

    public function getFaceStatusTextAttr($value, $data)
    {
        return self::STATUS_SCORE[$data['face_status']];
    }

    public function getReexamineTypeTextAttr($value, $data)
    {
        return self::STATUS_TICKET_TYPE[$data['reexamine_ticket_type']];
    }

    public function getReexamineTicketStatusTextAttr($value, $data)
    {
        return self::STATUS_TICKET_STATUS[$data['reexamine_ticket_status']];
    }

    public function getReexamineStatusTextAttr($value, $data)
    {
        return self::STATUS_SCORE[$data['reexamine_status']];
    }

    public function getApplyTimeAttr($value, $data)
    {
        $start_time = date('Y-m-d', strtotime($data['apply_start']));
        $end_time   = date('Y-m-d', strtotime($data['apply_end']));
        return [$start_time, $end_time];
    }
}