<?php
/**
* @author 龙虾 <15108148@qq.com>
* @version 2.0 2020-08-06
* @copyright 睿谷信息 <www.rgxx.com>
*/
namespace app\common\model;
use think\Model;

class Cmsmodels extends Model
{
	protected $json = ['config'];
    protected $jsonAssoc = true;
    
    // 类型名称
    public function getTypenameAttr($value,$data) 
    {
        return $this->getattrinfo($data)['typename'];
    }
    // 获取模型属性
    private function getattrinfo($data)
    {
        switch ($data['type']) {
            case '1':
                $prefix = 'diy_';
                $type = '内容';
                break;
            case '2':
                $prefix = 'func_';
                $type = '功能';
                break;
            case '3':
                $prefix = 'form_';
                $type = '表单';
                break;
            default:
                $prefix = 'other_';
                $type = '其他';
                break;
        }
        return ['tablename' => $data['name'].'_model','typename' => $type];
    }

    // 关联字段
    public function cmsfields()
    {
        return $this->hasMany('Cmsfields');
    }
    // 关联栏目
    public function navlist()
    {
        return $this->belongsTo('Navlist','id','typeid');
    }
}