一个需求里面要求一个关键字输入匹配多个字段模糊查询结果,多次验证后最终需要如下操作才能正确返回
public function getList($keyword="",$page=1,$limit=30)
{
$supliper = new Supplier();
$wheres["isdel"] = 0;
if($keyword!=""){
$wheres["sname|numbers|contactuser|tel"] = array("like","%".$keyword."%");
}
$list = $supliper->where($wheres)
->order("id",'desc')
->paginate($limit,false,['query' => array('keyword'=>$keyword,'limit'=>$limit,
'page'=>$page)]);
return $list;
}
生成的sql为
SELECT * FROM `hc_supplier` WHERE `isdel` = 0 AND ( `sname` LIKE '%关键字%' OR `numbers` LIKE '%关键字%' OR `contactuser` LIKE '%关键字%' OR `tel` LIKE '%关键字%' ) ORDER BY `id` desc LIMIT 0,30
网友评论