概述
1、运行原生sql
ublic function getList($data){
//获取前端传过来的参数
$user = $data['userId'];
$office = $data['officeId'];
$key = $data['oneKeySearch'];
//进行模糊搜索和联合查询
$where = 'and 1=1 ';
if($key!=null) {
$where.= ' and ( a.code like "%' . $key . '%"';
$where.= ' or b.name like "%' . $key . '%"';
$where.= ' or c.name like "%' . $key . '%")';
}
//对前端传回的字段进行判断,如果不为空则执行条件查询
if($user!=null){
$user='and a.userId='.$user;
}
if($office!=null){
$office='and a.officeId='.$office;
}
//自定义原生sql语句,%s可以传参数到sql语句中,格式如下:
$sqlTmp=sprintf('select a.id,a.code,a.attendanceRate,a.statisticTime,
b.`realName` as userName,c.`name` as officeName
from xxxa1
LEFT JOIN xxx2 b ON