<?php
namespace app\model;

use think\facade\Db;
use think\Model;

class CdssDisease extends Model
{

    protected $table = "jm_cdss_xy_disease";


    /**
     * 组装知识库详情返回
     */
    public static function jointZskDetailFieds($table , $model  , $field  , $value)
    {
        /**
         * 获取表结构
         */
        $sql ="show full columns from {$table}";
        $res = Db::query($sql);
	
	if (is_array($value)){
		$detail=[];
	    foreach ($value as $k=>$v){
                $detail[] = $model::where($field , $v)->find();
            }

	if (!empty($detail)){
                foreach ($res as $val) {
                    foreach ($detail as $k=>$v){
                        $v[$val['Field']] = [
                            'name' => $val['Comment'] ,
                            'text' => $v[$val['Field']] ?? ''
                        ];
                        unset($v['id']);
                        unset($v['productionEnterprise']);
                    }

                }
            }

	return $detail;
        }else{

		if ($field == 'zhonglian_name'){
	
		$detail = $model::whereRaw('FIND_IN_SET(?, zhonglian_name)', [$value])->find();
                //$detail = $model::where($field ,'like' ,"%$value%")->find();
            }else{
                $detail = $model::where($field , $value)->find();
            }

        }
	
        /**
         * 组装返回格式
         */
        foreach ($res as $val) {
            $detail[$val['Field']] = [
                'name' => $val['Comment'] ,
                'text' => $detail[$val['Field']] ?? ''
            ];
        }
        unset($detail['id']);
        return $detail;
    }

}
