在thinkphp5模型的查询中,一般有两种方式:数组方式和闭包方式,相对于数组方式只能定义查询条件,闭包方式可以支持更多的连贯操作,包括排序、数量限制等。
那么我们在使用闭包方式要怎么传入参数呢?具体代码如下:
//非超级管理员与审核人,不能查考到
$user_id=$_SESSION['fw']['admin_user']['id'];
// $this->_query($this->table_log)
Db::table($this->table_log)
->alias('log')
->leftJoin("$this->table po",'log.pid=po.id')
->field('po.order_no as order_no,po.create_time_auto as create_time_auto,po.producer_name as producer_name,po.purchasing_entity as purchasing_entity,po.scanning_copy as scanning_copy,log.is_result as is_result,po.audit_status as audit_status,po.is_signed as is_signed,log.id as log_id,po.id as po_id')
->where([['log.is_result','eq',0]])
->where(function($query) use ($user_id){
$query->where('log.audit_id',$user_id);
})
->order('po.create_time_auto desc')
->select();
echo Db::name($this->table_log)->getLastSql();die;