你可以使用以下代码实现所描述的功能:
$where = [];
if ($data['nickname'] != "") {
$receiverIds = Db::name('notification_receiver')
->where('nickname', 'like', '%' . $data['nickname'] . '%')
->column('id');
if (!empty($receiverIds)) {
array_push($where, ['recv.id', 'in', $receiverIds]);
}
}
array_push($where, ['recv.delete_time', '=', 0]);
$curdepartment_childrens = $tree->findMeAndAllChilds($data['department_id'], $departments);
$log_list = Db::name('notification_strategy')
->alias('stra')
->join('notification_receiver recv', 'FIND_IN_SET(recv.id, stra.receivers)', 'LEFT')
->whereIn('stra.department_id', $curdepartment_childrens)
->where($where)
->field('stra.*, GROUP_CONCAT(recv.nickname) as receiver_nicknames')
->order('stra.create_time desc')
->group('stra.id')
->paginate($data['limit']);
$this->success('Success', $log_list);
这段代码首先根据输入的nickname在notification_receiver表中查询对应的id。然后通过JOIN操作将notification_strategy表与notification_receiver表关联,并使用FIND_IN_SET函数来模糊匹配receivers字段中的id。最后,使用GROUP_CONCAT函数将对应的nickname进行聚合,并返回结果。
请注意,以上代码仅为示例,具体实现可能需要根据你的数据结构和业务逻辑进行调整。
内容由零声教学AI助手提供,问题来源于学员提问




