1,第一步获取前端页面传过来的数据
2,编写where条件数组
$input=input(“name”);
2,编写where条件数组 编写的时候注意数组格式 ,这里就直接上图了
数组条件可以替换成自己需要的条件,我这里用的都是模糊查询
3, 使用 多条件whereOr 进行查询
$ list=Db::table(‘company_account’)->whereOr($where) ->select();
4,获取数据查询长度
$ count=count($list);
5,返回数据
return json([‘code’=>200,‘data’ => $list,‘count’ => $count]);
上原图
后续修改 为了应对不同方式的搜索
public function getByInputSelectAccount(){
$name=Request::instance()->post('name'); //姓名
$startTime=strtotime(input('startTime')); //$startTime开始时间
$endTime=strtotime(input('endTime'))+86400-1; //$endTime结束时间
$contract_number=Request::instance()->post('contractNum'); //合同编号
$voucher_number=Request::instance()->post('voucherNum'); //凭证号
$core=Request::instance()->post('core'); //中心
$abstract=Request::instance()->post('abstract'); //摘要
$money_type=Request::instance()->post('moneyType'); //费用类别
$where=[];
if ($name!=null){
array_push($where, ['username','=',$name]);
}
if ($startTime!=null){
array_push($where, ['data','>=',$startTime]);
array_push($where, ['data','<=',$endTime]);
}
if ($contract_number!=null){
array_push($where, ['contract_number','=',$contract_number]);
}
if ($voucher_number!=null){
array_push($where, ['voucher_number','=',$voucher_number]);
}
if ($core!=null){
array_push($where, ['core','=',$core]);
}
if ($abstract!=null){
array_push($where, ['abstract','=',$abstract]);
}
if ($money_type!=null){
array_push($where, ['money_type','=',$money_type]);
}
$list=Db::name('account')->where($where)->select();
if ($list){
return json(['code'=>200,'data'=>$list]);
}else{
return json(['code'=>400,'msg'=>'没有该数据']);
}
}