//注意 field查询字段要指定,不然报 xxx.(表不存在
$sql1 = Db::name('user')->field('id,username')->where('id <=10')->buildSql();
$sql2 = Db::name('user')->field('id,username')->where('id >20 and id<=30')->buildSql();
$sql3 = Db::name('user')->field('id,username')->where('id >40 and id<=50')->union([$sql1,$sql2])->buildSql();
//a是指定一个临时表名,给后面做条件筛选用户
//另外可以使用Db::table() ,但是我使用了报错
$list = Db::name(strtolower($sql3) . ' a')->order('a.id asc')->paginate(每页几条, false, ['page' => 第几页]);
其他参考:https://blog.jkloozx.com/?id=163
$m_acc = model('...');
$a = $m_acc->field('... as a,...')->where(...)->group('...')->buildSql();
$b = $m_acc->field('... as a,...')->where(...)->group('...')->buildSql();
$c = $m_acc->field('... as a,...')->where(...)->group('...')->buildSql();
$d = $m_acc->field('... as a,...')->where(...)->group('...')->buildSql();
$e = $m_acc->field('... as a,...')->where(...)->group('...')->union([$a,$b,$c,$d])->buildSql();
//到这里,已经可以把$e当做一个正常表来进行操作了,什么分页、group by、where随便用,使用"DB::table($e . ' a')"即可
$res = Db::table($e.' a')->field('...')->group('...')->paginate(5);
return json($res);