get('type','1'); $member_id = request()->get('m_id', ''); $lists = Notices::select(['id', 'title', 'title_en', 'created_at', 'updated_at']) ->where([['show', '>=', 1]]) // 显示公告 ->orderBy('id', 'DESC') // 最新正序排序 // ->orderBy('sort', 'ASC') // 正序排序 ->get(); $data = array(); $lang=request()->input('lang', 'zh'); foreach ($lists as $key => $list){ $data[$key]['id'] = $list->{'id'}; if ( $lang == 'zh' ) { $data[$key]['title'] = $list->{'title'}; }else{ $data[$key]['title'] = $list->{'title_en'}; } $data[$key]['created_at'] = Carbon::parse($list->{'created_at'}, config('app.timezone'))->format('Y.m.d'); $data[$key]['updated_at'] = Carbon::parse($list->{'updated_at'}, config('app.timezone'))->format('Y.m.d'); if(!empty($member_id)){ $num = NoticeRead::where('member_id', $member_id)->where('n_id', $data[$key]['id'])->count(); $data[$key]['is_read'] =$num>0?1:0; }else{ $data[$key]['is_read'] =0; } } return $this->apiResponseSuccess($data, 'notice.index_title_lists'); } /** * @param int $id ## 会员ID * @return \Illuminate\Http\JsonResponse * * 获取指定公告列表详情 */ public function detail($id = 0) { if ( empty($id) ) { return $this->apiResponseError([], 'notice.detail_error'); } $notice = Notices::select(['id', 'title', 'title_en', 'content', 'content_en', 'created_at', 'updated_at']) ->where('show', '>=', 1) ->where('id', $id) ->first(); if ( empty($notice) ) { return $this->apiResponseError([], 'notice.detail_error'); } $data['id'] = $notice->{'id'}; if ( request()->input('lang', 'zh') == 'zh' ) { $data['title'] = $notice->{'title'}; $data['content'] = $notice->{'content'}; }else{ $data['title'] = $notice->{'title_en'}; $data['content'] = $notice->{'content_en'}; } $data['created_at'] = Carbon::parse($notice->{'created_at'}, config('app.timezone'))->format('Y.m.d'); $data['updated_at'] = Carbon::parse($notice->{'updated_at'}, config('app.timezone'))->format('Y.m.d'); $member_id = request()->get('m_id', ''); if(!empty($member_id)){ $num = NoticeRead::where('member_id', $member_id)->where('n_id',$data['id'])->count(); if($num<=0)NoticeRead::create(['member_id'=> $member_id,'n_id'=> $data['id']]); } return $this->apiResponseSuccess($data, 'notice.detail_success'); } /** * 获取未读数量 * @return \Illuminate\Http\JsonResponse */ function getNotReadNum() { $member_id = request()->get('m_id', ''); if ($member_id) { $n_ids = Notices::where('type', '=', '5')->pluck('id')->toArray(); if (empty($n_ids)) { $num = 0; } else { $num = NoticeRead::where('member_id', $member_id)->whereIn('n_id', $n_ids)->count(); $num = count($n_ids) - $num; if ($num <= 0) $num = 0; } } else { $num = 0; } $msg_num=Message::where('member_id',$member_id)->where('is_new','1')->count(); return $this->apiResponseSuccess(['notice_num'=>$num,'msg_num'=>$msg_num], 'notice.detail_success'); } }