$contract_types = "2,1,3"; $exp = new \think\Db\Expression('field(contract_type,'.$contract_types.')'); $tpl = Db::name('contract')->order($exp)->select()
//SELECT * FROM `ct_contract` ORDER BY field(contract_type,2,1,3)
$contract_types = "2,1,3"; $exp = new \think\Db\Expression('field(contract_type,'.$contract_types.'),create_time DESC'); $tpl = Db::name('contract')->order($exp)->select();
//SELECT * FROM `ct_contract` ORDER BY field(contract_type,2,1,3),create_time DESC
其他情况的多条件排序,一样的操作,例:
$tpl = Db::name('contract')->order('contract_type DESC,create_time DESC')->select();
//SELECT * FROM `ct_contract` ORDER BY `contract_type` DESC,`create_time` DESC