<?php

namespace app\model\project;

use app\model\system\SystemUploadFile;
use think\Model;

class Business extends Model
{
    protected $name = 'business';

    protected $autoWriteTimestamp = true;

    protected $createTime = 'create_time';

    // 营业执照文件关联
    public function businessQualification()
    {
        return $this->hasOne(SystemUploadFile::class, 'fileid', 'business_qualification_url_id')
            ->where('isdel', 0)
            ->field('fileid,filename,filesize,fileurl,filetype,fileext');
    }

    //行业
    public function businessIndustry()
    {
        return $this->hasOne(SystemUploadFile::class, 'fileid', 'business_industry_url_id')
            ->where('isdel', 0)
            ->field('fileid,filename,filesize,fileurl,filetype,fileext');
    }

    //项目
    public function businessPorject()
    {
        return $this->hasOne(SystemUploadFile::class, 'fileid', 'business_project_url_id')
            ->where('isdel', 0)
            ->field('fileid,filename,filesize,fileurl,filetype,fileext');
    }

    //补充材料
    public function businessMore()
    {
        return $this->hasOne(SystemUploadFile::class, 'fileid', 'more_url_id')
            ->where('isdel', 0)
            ->field('fileid,filename,filesize,fileurl,filetype,fileext');
    }

    //企业logo
    public function businessLogo()
    {
        return $this->hasOne(SystemUploadFile::class, 'fileid', 'business_logo_url_id')
            ->where('isdel', 0)
            ->field('fileid,filename,filesize,fileurl,filetype,fileext');
    }

    //用户信息
    public function getuserdata()
    {
        return $this->belongsTo(User::class, 'user_id')
            ->field('username,mobile,id');
    }

    //详细地址
    public function getAddressxxAttr($value, $data)
    {
        return $data['province'].'-'.$data['city'].'-'.$data['area'];
    }

    public function getStatusTextAttr($value, $data)
    {
        switch ($data['status']) {
            case 1:
                $statustxt = '审核成功';
                break;
            case 2:
                $statustxt = '审核失败';
                break;
            default:
                $statustxt = '待审核';
        }

        return $statustxt;
    }
}