1]; getWhereUserByParam($where, 'id'); $userList = UserModel::where($where) ->field(['id','username','realname']) ->select(); foreach ($userList as $k=>$v) { $log_list = []; $count = 0; //填写数 $unReadCont = 0; //接收人未读数 $unCommentCount = 0; //未评论数 $commentCount = 0; //已评论数 $log_list = $this->where(['create_time' => $create_time,'create_user_id' => $v['id']])->field('send_user_ids,read_user_ids,log_id')->select(); $count = count($log_list); if ($log_list) { //获取评论过的日志id集合 $w_c['ac.type'] = 'oa_log'; $log_ids = $this->alias('l') ->join('AdminComment ac', 'ac.type_id = l.log_id', 'LEFT') ->where($w_c) ->group('l.log_id') ->column('log_id'); foreach ($log_list as $key=>$val) { if (stringToArray($val['send_user_ids']) && !array_intersect(stringToArray($val['send_user_ids']),stringToArray($val['read_user_ids']))) { $unReadCont += 1; } //判断日志id是否在评论过的id集合内 if (in_array($val['log_id'], $log_ids) ) { $commentCount += 1; } else { $unCommentCount += 1; } } } $userList[$k]['count'] = $count; $userList[$k]['unReadCont'] = $unReadCont; $userList[$k]['unCommentCount'] = $unCommentCount; $userList[$k]['commentCount'] = $commentCount; } return $userList ? : []; } }