💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 封装函数 ``` if (!function_exists('apibuildparams')) { //post https请求,CURLOPT_POSTFIELDS xml格式 function apibuildparams($data=[],$select_datt) { $where=[]; foreach ($select_datt as $key => $value) { if(isset($select_datt[$key])&&!empty($select_datt[$key])&&isset($data[$key])){ if(is_array($value) ){ if(trim(strtoupper($value["exp"])," ")=="BETWEEN"||trim(strtoupper($value["exp"])," ")=="NOTBETWEEN" ){ if(isset($data[$value["start"]])&&!empty($data[$value["start"]]) && isset($data[$value["end"]])&&!empty($data[$value["end"]]) ){ if(isset($value["name"])&&!empty($value["name"])){ $where[$value["name"]]=[$value["exp"],[$data[$value["start"]],$data[$value["end"]]]]; }else{ $where[$key]=[$value["exp"],[$data[$value["start"]],$data[$value["end"]]]]; } }else if(isset($data[$value["start"]])&&!empty($data[$value["start"]]) ){ $where["createtime"]= [">", $data[$value["start"]]]; //start,end }else if( isset($data[$value["end"]])&&!empty($data[$value["end"]]) ){ $where["createtime"]= ["<", $data[$value["end"]]]; } }else if(trim(strtoupper($value["exp"])," ")=="BETWEENTIME"||trim(strtoupper($value["exp"])," ")=="NOTBETWEENTIME" ){ if(isset($data[$value["start"]])&&!empty($data[$value["start"]]) && isset($data[$value["end"]])&&!empty($data[$value["end"]]) ){ if(isset($value["name"])&&!empty($value["name"])){ $where[$value["name"]]=[$value["exp"],[strtotime($data[$value["start"]]),strtotime($data[$value["end"]])]]; }else{ $where[$key]=[$value["exp"],[strtotime($data[$value["start"]]),strtotime($data[$value["end"]])]]; } }else if(isset($data[$value["start"]])&&!empty($data[$value["start"]]) ){ $where["createtime"]= [">", strtotime($data[$value["start"]])]; //start,end }else if( isset($data[$value["end"]])&&!empty($data[$value["end"]]) ){ $where["createtime"]= ["<", strtotime($data[$value["end"]])]; } }else if(trim(strtoupper($value["exp"])," ")=="LIKE"){ $where[$value["name"]]=[$value["exp"],"%".$data[$key]."%"]; } else if(trim(strtoupper($value["exp"])," ")=="IN"||trim(strtoupper($value["exp"])," ")=="NOTIN"){ $where[$value["name"]]=[$value["exp"],$data[$key]]; }else if(isset($key)){ $where[$value["name"]]=$data[$key]; } }else if(trim(strtoupper($value)," ")=="LIKE"){ $where[$key]=[$value,"%".$data[$key]."%"]; } else if(trim(strtoupper($value)," ")=="IN"||trim(strtoupper($value)," ")=="NOTIN"){ $where[$key]=[$value,$data[$key]]; }else{ $where[$key]=$data[$key]; } } } $page=(isset($data["page"])&&!empty($data["page"]))?$data["page"]:1; $limit=isset($data["limit"])&&!empty($data["limit"])?$data["limit"]:10; return [$where,$page,$limit]; } } ``` # 使用方法 ## 当前区间查询 ``` $select_datt["time"]=[ "exp"=>"BETWEEN", "start"=>"start_class_id", //获取开始参数名 "end"=>"start_class_id" //获取结束参数名 ]; ``` ## //数据表有别名的区间查询 ``` $select_datt["time"]=[ "exp"=>"BETWEEN", "name"=>"gghmartialart.name", //组成where的时候的键名 "start"=>"start_class_id", //获取开始参数名 "end"=>"start_class_id" //获取结束参数名 ]; ``` ## //其他查询 ``` $select_datt["name"]= "LIKE"; $select_datt["id"]= "="; ``` ## //数据表有别名的区间查询 ``` $select_datt["zid"]=[ "exp"=>"=", "name"=>"gghmartialart.id", //组成where的时候的键名 ]; list($where,$page, $limit)= apibuildparams($_POST,$select_datt); ``` ## 使用实例: ``` //当前区间查询 $select_datt["time"]=[ "exp"=>"BETWEEN", "start"=>"start_class_id", //获取开始参数名 "end"=>"start_class_id" //获取结束参数名 ]; //数据表有别名的区间查询 $select_datt["time"]=[ "exp"=>"BETWEEN", "name"=>"gghmartialart.name", //组成where的时候的键名 "start"=>"start_class_id", //获取开始参数名 "end"=>"start_class_id" //获取结束参数名 ]; //其他查询 $select_datt["name"]= "LIKE"; $select_datt["id"]= "="; //数据表有别名的区间查询 $select_datt["zid"]=[ "exp"=>"=", "name"=>"gghmartialart.id", //组成where的时候的键名 ]; list($where,$page, $limit)= apibuildparams($_POST,$select_datt); $order=[]; $total = $this->model ->with(['gghmartialarts']) ->where($where) ->order($order) ->count(); $list = $this->model ->with(['gghmartialarts']) ->where($where) ->order($order) ->page($page, $limit) ->select(); foreach ($list as $row) { $row->visible(['id','name','state','force_value','pay_state']); $row->visible(['gghmartialarts']); $row->getRelation('gghmartialarts')->visible(['name','img']); } $list = collection($list)->toArray(); $result = array("total" => $total, "rows" => $list); $this->success('请求成功',$result); ```