tp5.1 whereOr查询

发布时间 2023-07-24 09:52:24作者: 萌妹子的vlog
public function workList(Request $request,$limit = 10){
if ($request->isAjax()) {
$status = $request->param('state');
$map[] = ['state','neq',-1];

if($status!='' && in_array($status+1,[1,2,3],true)){//+1为了好判断
unset($map);
}
$status != '' && $map[] = ["state", "eq", $status];
$map[] = ['check_uid','eq',UID];
$map[] = ['type','in',[1,2]];

$status != '' && $whereor[] = ["state", "eq", $status];
$whereor[] = ['replace_uid','eq',UID];
$whereor[] = ['type','in',[1,2]];//只展示1请假 2 工作模版

$list = model('Rest')
->field('id,t_id,type,create_uid,replace_uid,start_time,end_time,desc,check_uid,state,check_time,replace_time')
->where([$map])
->whereOr([$whereor])
->whereIn('type',[1,2])
->order("id desc")
->paginate($limit)
->append(['tidName','createName','replaceName','checkName']);
$data['code'] = 1;
$data['message'] = "数据请求成功!";
$data['count'] = $list->total();
$data['data'] = $list->items();
return json($data);
} else {
return $this->fetch('worklist');
}
}