<?
trait DdExtend {
   function get_field($table,$id,$field="title"){
   	return $this->select($table,$field,"id=$id");
   }
   function changefield($data){

      $table=$data['table']?$data['table']:MOD;
      $notable=["menu","duoduo2020","role"];
      if (in_array($table, $notable)){
         json(1,"你不能这样做");
      }
        $numfield=["sort","hits","value"];
        if (in_array($data['field'], $numfield)){

            if (!is_numeric($data['value'])){
            
               json(1,"须输入数字");
            }
        }
      $udata[$data['field']]=$data['value'];

      if ($table=="company" and empty($data['id'])){
           $company_id=db()->select("visit","company_id","id=".$data['vid']);
           if (empty($company_id))
               json(1,"修改无效,请先填写公司名称再来编辑此项");
             else
              $data['id']=$company_id;
      }
      $this->update($table,$udata,"id=".$data['id']);

       if ($data['field']=="expenses"){
          app("order")->profit($data['id']);
      }
      json(0);

   }

  function get_table($table,$id,$field="*"){

     $rows=$this->select($table,$field,"id=$id");

     return $rows;

   }
/**
 * [TableField 检查某表是否存在某一字段]
 * @Author   huangxiaojian
 * @DateTime 2021-04-03T19:59:55+0800
 * @param    [type]                   $table [description]
 * @param    [type]                   $field [description]
 */
   function TableField($table,$field){
     $field = mysqli_query($this->link,"Describe ".BIAOTOU.$table." ".$field);
     $field = mysqli_fetch_array($field);//得到返回结果
      if($field[0]){ //判断返回结果
          return true;
      }else{
          return false;
      }
   }
}
?>