123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace App\Http\Controllers\Notice\Front;
- use App\Http\Controllers\FrontController;
- use App\Http\Controllers\FrontNotTokenController;
- use App\Models\Message;
- use App\Models\Notice;
- use App\Models\NoticeRead;
- use App\Models\Notices;
- use Carbon\Carbon;
- // 首页公告接口
- class NoticesNotTokenController extends FrontController
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * @return \Illuminate\Http\JsonResponse
- *
- * 首页公告标题
- */
- public function indexTitleLists()
- {
- $type=request()->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');
- }
- }
|