修复任务列表多条件搜索 or、 and 联合查询的语法错误

This commit is contained in:
hdm 2023-02-07 11:02:42 +08:00
parent 4cbea37397
commit 0ff2d82126
4 changed files with 35 additions and 14 deletions

View File

@ -91,6 +91,7 @@ class api extends BaseController
$res['data'] = []; $res['data'] = [];
if($exist){ if($exist){
$where = array(); $where = array();
$whereOr = array();
$map1 = []; $map1 = [];
$map2 = []; $map2 = [];
$map3 = []; $map3 = [];
@ -98,11 +99,14 @@ class api extends BaseController
$map2[] = ['director_uid', '=', $this->uid]; $map2[] = ['director_uid', '=', $this->uid];
$map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$this->uid},assist_admin_ids)")]; $map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$this->uid},assist_admin_ids)")];
$whereOr =[$map1,$map2,$map3];
$where[] = ['delete_time', '=', 0]; $where[] = ['delete_time', '=', 0];
$list = Db::name('ProjectTask')->where($where) $list = Db::name('ProjectTask')
->where(function ($query) use ($map1, $map2, $map3) { ->where(function ($query) use ($whereOr) {
$query->where($map1)->whereor($map2)->whereor($map3); if (!empty($whereOr))
}) $query->whereOr($whereOr);
})
->where($where)
->withoutField('content,md_content') ->withoutField('content,md_content')
->order('flow_status asc') ->order('flow_status asc')
->order('id desc') ->order('id desc')

View File

@ -86,7 +86,7 @@ class Index extends BaseController
$v = explode(',', $v); $v = explode(',', $v);
$adminMenus = array_merge($adminMenus, $v); $adminMenus = array_merge($adminMenus, $v);
} }
$menu = Db::name('AdminRule')->where(['menu' => 1, 'status' => 1])->where('id', 'in', $adminMenus)->order('sort asc')->select()->toArray(); $menu = Db::name('AdminRule')->where(['menu' => 1, 'status' => 1])->where('id', 'in', $adminMenus)->order('sort asc,id asc')->select()->toArray();
$list = list_to_tree($menu); $list = list_to_tree($menu);
\think\facade\Cache::tag('adminMenu')->set('menu' . $admin['id'], $list); \think\facade\Cache::tag('adminMenu')->set('menu' . $admin['id'], $list);
} }
@ -198,6 +198,7 @@ class Index extends BaseController
$whereProject[] = ['id', 'in', $project_ids]; $whereProject[] = ['id', 'in', $project_ids];
$projectCount = Db::name('Project')->where($whereProject)->count(); $projectCount = Db::name('Project')->where($whereProject)->count();
$whereOr = array();
$map1 = []; $map1 = [];
$map2 = []; $map2 = [];
$map3 = []; $map3 = [];
@ -207,9 +208,14 @@ class Index extends BaseController
$map2[] = ['director_uid', '=', $uid]; $map2[] = ['director_uid', '=', $uid];
$map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$uid},assist_admin_ids)")]; $map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$uid},assist_admin_ids)")];
$map4[] = ['project_id', 'in', $project_ids]; $map4[] = ['project_id', 'in', $project_ids];
$taskCount = Db::name('ProjectTask')->where([['delete_time', '=', 0]])->where(function ($query) use ($map1, $map2, $map3, $map4) {
$query->where($map1)->whereor($map2)->whereor($map3)->whereor($map4); $whereOr =[$map1,$map2,$map3,$map4];
})->count(); $taskCount = Db::name('ProjectTask')
->where(function ($query) use ($whereOr) {
if (!empty($whereOr))
$query->whereOr($whereOr);
})
->where([['delete_time', '=', 0]])->count();
$total[] = array( $total[] = array(
'name' => '项目', 'name' => '项目',

View File

@ -28,10 +28,15 @@ class ProjectDocument extends Model
$where[] = ['title|content', 'like', '%' . $param['keywords'] . '%']; $where[] = ['title|content', 'like', '%' . $param['keywords'] . '%'];
} }
$where[] = ['delete_time', '=', 0]; $where[] = ['delete_time', '=', 0];
$whereOr =[$map1,$map2];
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = Db::name('ProjectDocument')->where(function ($query) use ($map1, $map2) { $list = Db::name('ProjectDocument')
$query->where($map1)->whereor($map2); ->where(function ($query) use ($whereOr) {
})->where($where) if (!empty($whereOr))
$query->whereOr($whereOr);
})
->where($where)
->withoutField('content,md_content') ->withoutField('content,md_content')
->order('id desc') ->order('id desc')
->paginate($rows, false, ['query' => $param]) ->paginate($rows, false, ['query' => $param])

View File

@ -44,6 +44,7 @@ class ProjectTask extends Model
//列表 //列表
function list($param) { function list($param) {
$where = array(); $where = array();
$whereOr = array();
$map1 = []; $map1 = [];
$map2 = []; $map2 = [];
$map3 = []; $map3 = [];
@ -56,6 +57,7 @@ class ProjectTask extends Model
$map2[] = ['director_uid', '=', $param['uid']]; $map2[] = ['director_uid', '=', $param['uid']];
$map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$param['uid']},assist_admin_ids)")]; $map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$param['uid']},assist_admin_ids)")];
$map4[] = ['project_id', 'in', $project_ids]; $map4[] = ['project_id', 'in', $project_ids];
$whereOr =[$map1,$map2,$map3,$map4];
} }
if (!empty($param['type'])) { if (!empty($param['type'])) {
$where[] = ['type', '=', $param['type']]; $where[] = ['type', '=', $param['type']];
@ -76,10 +78,14 @@ class ProjectTask extends Model
$where[] = ['title|content', 'like', '%' . $param['keywords'] . '%']; $where[] = ['title|content', 'like', '%' . $param['keywords'] . '%'];
} }
$where[] = ['delete_time', '=', 0]; $where[] = ['delete_time', '=', 0];
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = Db::name('ProjectTask')->where(function ($query) use ($map1, $map2, $map3, $map4) { $list = Db::name('ProjectTask')
$query->where($map1)->whereor($map2)->whereor($map3)->whereor($map4); ->where(function ($query) use ($whereOr) {
})->where($where) if (!empty($whereOr))
$query->whereOr($whereOr);
})
->where($where)
->withoutField('content,md_content') ->withoutField('content,md_content')
->order('flow_status asc') ->order('flow_status asc')
->order('id desc') ->order('id desc')