ZBLOG

$where = []; if($data['nickname'] != ""){ array_push($where, ['recv.nickname', 'like', '%'.$data['receivers'].'%']); } array_push($where,['recv.delete_time', '=',0]); ...

你可以使用以下代码实现所描述的功能:

$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助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:

上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?