From cc0822a8813d611e43121c840ae1e963436c4360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Sun, 17 Mar 2019 07:00:22 +0900 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/SiteController.php | 6 ++- app/Http/Controllers/UserController.php | 62 ++++++++++++++++++++++++- routes/class/user.php | 7 ++- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php index 9926ad1..f636ef8 100644 --- a/app/Http/Controllers/SiteController.php +++ b/app/Http/Controllers/SiteController.php @@ -571,7 +571,7 @@ class SiteController extends Controller { if ($valid['blg_addcomment'] == 1) { $add = DB::table('blg_comments') - ->insert([ + ->insertGetId([ 'user_id' => $check, 'content_id' => $request->content_id, 'votes' => 0, @@ -582,6 +582,10 @@ class SiteController extends Controller { 'ip_address' => $request->ip_address ]); + $g = DB::table('blg_content')->select('slug', 'user_id')->where('id', $request->content_id)->first(); + + if ($check != $g->user_id) $this->objUser->addNotification($request, $g->user_id, 1, '新規ブログコメント', 'blog/'.$g->slug, 'comment-'.$add); + return \Response::json($add); } else { diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 8fad49f..451ceed 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -754,7 +754,7 @@ class UserController extends Controller { if ($valid['usr_addcomment'] == 1) { $add = DB::table('usr_comments') - ->insert([ + ->insertGetId([ 'user_id' => $check, 'profile_id' => $request->profile_id, 'reply_id' => ($request->reply_id > 0 ? $request->reply_id : 0), @@ -764,6 +764,8 @@ class UserController extends Controller { 'isDel' => 0 ]); + if ($check != $request->profile_id) $this->addNotification($request, $request->profile_id, 2, '新規プロファイルコメント', 'profile/'.$request->profile_id, 'comment-'.$add); + return \Response::json($add); } else { @@ -844,4 +846,62 @@ class UserController extends Controller { } } } + + public function getNotification(Request $r) { // /api/rpc/user/notification/get + $check = $this->objAuth->checkLegit($r->username, $r->password); + + if ($check != 0) { + $get = DB::table('usr_notification') + ->select('id', 'app_id', 'text', 'section', 'goto') + ->where('user_id', $check) + ->get(); + + $res = array(); + + foreach ($get as $g) { + $prot = DB::table('sys_settings')->select('protocol')->first()->protocol; + $goto = DB::table('sys_apps')->select('url')->where('id', $g->app_id)->first()->url; + + $res[] = array( + 'id' => $g->id, + 'text' => $g->text, + 'url' => 'http'.($prot == 1 ? 's' : '').'://'.$goto.'/#/'.$g->section + ); + } + + return $res; + } + + else { + return array(); + } + } + + public function addNotification(Request $r, $uid, $aid, $txt, $sec, $goto) { // /api/rpc/user/notification/add + $check = $this->objAuth->checkLegit($r->username, $r->password); + + if ($check != 0) { + $add = DB::table('usr_notification') + ->insert([ + 'user_id' => $uid, + 'app_id' => $aid, + 'text' => $txt, + 'section' => $sec, + 'goto' => $goto + ]); + + return 1; + } + } + + public function delNotification(Request $r) { // /api/rpc/user/notification/del + $check = $this->objAuth->checkLegit($r->username, $r->password); + + if ($check != 0) { + return DB::table('usr_notification') + ->where('id', $r->id) + ->where('user_id', $check) + ->delete(); + } + } } diff --git a/routes/class/user.php b/routes/class/user.php index 435f903..51ffb9b 100644 --- a/routes/class/user.php +++ b/routes/class/user.php @@ -47,4 +47,9 @@ Route::get('/api/rpc/user/comment/reply/{id}', 'UserController@getReplies'); Route::post('/api/rpc/user/comment/add', 'UserController@addComment'); Route::post('/api/rpc/user/comment/edit', 'UserController@editComment'); Route::post('/api/rpc/user/comment/delete', 'UserController@deleteComment'); -Route::post('/api/rpc/user/comment/undelete', 'UserController@undeleteComment'); \ No newline at end of file +Route::post('/api/rpc/user/comment/undelete', 'UserController@undeleteComment'); + +// Notifications +Route::get('/api/rpc/user/notification/get', 'UserController@getNotification'); + +Route::post('/api/rpc/user/notification/del', 'UserController@delNotification'); \ No newline at end of file