组装查询条件条件 注意这里store_ids是数组格式
if(isset($params['store_ids'])&&!empty($params['store_ids'])) { $store_ids=$params['store_ids']; $sql_where=''; foreach($store_ids as $v){ $sql_where .= "FIND_IN_SET('{$v}',t1.store_ids) or "; } $sql_where = rtrim($sql_where," or "); $map=Db::raw($sql_where); $where[]=['','exp',$map]; }
查询关联语句
public function getStoreGuidePlanList($where=[],$page,$limit)
{
$result=$this->db->name('store_guide_plan')
->alias('t1')
->field('t1.plan_id,t1.plan_name,t1.status,t1.store_ids,GROUP_CONCAT(t2.store_name) store_name,t1.create_time')
->leftJoin('store t2', 'FIND_IN_SET(t2.store_id,t1.store_ids)')
->where('t1.delete_time',0)
->where($where)
->order(['t1.plan_id' => 'desc'])
->group('t1.plan_id');
$result->page($page, $limit);
$count = $result->count();
$list = $result->select()->toArray();
return compact('list','count');
}
这样就实现了关联多个id的查询语句!!!
