junghwi 6 years ago
parent
commit
02f39e3a6f
3 changed files with 72 additions and 11 deletions
  1. 56 0
      app/Http/Controllers/Admin/MessageController.php
  2. 9 8
      app/Http/Models/Common.php
  3. 7 3
      routes/admin.php

+ 56 - 0
app/Http/Controllers/Admin/MessageController.php

@@ -6,6 +6,7 @@ use App\Models\Member;
 use App\Models\Message;
 use App\Models\Message;
 use App\Models\User;
 use App\Models\User;
 use App\Models\Notice;
 use App\Models\Notice;
+use App\Http\Models\Common;
 use App\Traits\PushMessage;
 use App\Traits\PushMessage;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 use App\Http\Controllers\Controller;
 use App\Http\Controllers\Controller;
@@ -343,4 +344,59 @@ class MessageController extends Controller
 
 
     }
     }
 
 
+    public function inform(Request $request){
+        if ($request->ajax()){
+            $model = new Notice();
+            $title = $request->only(['title']);
+            if (!empty($title)){
+                $model = $model->where('title','like','%'.$title.'%');
+            }
+            $res = $model::orderBy('create_at','asc')->get();
+            $data = [
+                'code' => 0,
+                'msg'   => '正在请求中...',
+                'count' => '',
+                'data'  => $res
+            ];
+            return response()->json($data);
+        }
+
+        return view('admin.message.notice');
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function informDel(Request $request)
+    {
+        $ids = $request->get('ids');
+        if (empty($ids)){
+            return response()->json(['code'=>1,'msg'=>'请选择删除项']);
+        }
+        if (Notice::destroy($ids)){
+            return response()->json(['code'=>0,'msg'=>'删除成功']);
+        }
+        return response()->json(['code'=>1,'msg'=>'删除失败']);
+    }
+
+    public function informAdd()
+    {
+        return view('admin.message.noticeadd');
+    }
+
+    public function informStore(Request $request)
+    {
+        $title = $request->post('title');
+        $content = $request->post('content');
+        $data = ['content'=>$content,'title'=>$title,'create_at'=>date('Y-m-d H:i:s',time())];
+        $res = Notice::insert($data);
+        if(!$res){
+            return back()->with(['status'=>'添加失败!']);
+        }
+        return redirect()->to(route('admin.message.notice'))->with(['status'=>'添加成功!']);
+
+    }
 }
 }

+ 9 - 8
app/Http/Models/Common.php

@@ -97,25 +97,26 @@ class Common extends Model
      * 添加系统通知
      * 添加系统通知
      *
      *
      * @access public
      * @access public
+     * @param  key $key redis键名
      * @param array $msg 通知内容
      * @param array $msg 通知内容
      * @return
      * @return
      */
      */
-    static public function addNotification(array $msg){
-        foreach($msg as $k => $v){
-           Redis::rpush('MSG_INDEX_QIPAI',$v);
-        }
+     public function addNotification($key,array $msg){
+        $msg = json_encode($msg,true);
+        Redis::rpush($key,$msg);
     }
     }
 
 
     /**
     /**
-     * 获取后删除栈内系统通知
+     * 获取栈内系统通知
      * @access public
      * @access public
+     * @param  key $key redis键名
      * @param array $msg 通知内容
      * @param array $msg 通知内容
      * @return
      * @return
      */
      */
-    static public function getNotification(){
-        $msg = Redis::lrange('MSG_INDEX_QIPAI',0,-1);
+     public function getNotification($key){
+        $msg = Redis::lrange($key,0,-1);
         if(!empty($msg)){
         if(!empty($msg)){
-            Redis::ltrim('MSG_INDEX_QIPAI',1,0);
+            $msg = json_decode($msg,true);
             return $msg;
             return $msg;
         }
         }
         return [];
         return [];

+ 7 - 3
routes/admin.php

@@ -256,10 +256,15 @@ Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['aut
     Route::delete('message/noticeDel', 'MessageController@noticeDel')->name('admin.message.noticeDel')->middleware('permission:message.message.noticeDel');
     Route::delete('message/noticeDel', 'MessageController@noticeDel')->name('admin.message.noticeDel')->middleware('permission:message.message.noticeDel');
     //添加
     //添加
     Route::get('message/noticeAdd', 'MessageController@noticeAdd')->name('admin.message.noticeAdd')->middleware('permission:message.message.noticeAdd');
     Route::get('message/noticeAdd', 'MessageController@noticeAdd')->name('admin.message.noticeAdd')->middleware('permission:message.message.noticeAdd');
-    //添加
-    Route::get('message/noticeAdd', 'MessageController@noticeAdd')->name('admin.message.noticeAdd')->middleware('permission:message.message.noticeAdd');
     Route::post('message/noticeStore', 'MessageController@noticeStore')->name('admin.message.noticeStore')->middleware('permission:message.message.noticeStore');
     Route::post('message/noticeStore', 'MessageController@noticeStore')->name('admin.message.noticeStore')->middleware('permission:message.message.noticeStore');
 
 
+    //系统通知
+    Route::get('inform/message', 'MessageController@inform')->name('admin.message.inform')->middleware('permission:message.message.inform');
+    //删除
+    Route::delete('message/informDel', 'MessageController@informDel')->name('admin.message.noticeDel')->middleware('permission:message.message.informDel');
+    //添加
+    Route::get('message/informAdd', 'MessageController@informAdd')->name('admin.message.informAdd')->middleware('permission:message.message.informAdd');
+    Route::post('message/informStore', 'MessageController@informStore')->name('admin.message.ninformStore')->middleware('permission:message.message.informStore');
 
 
     //活动
     //活动
     Route::group(['middleware' => 'permission:message.activity'], function () {
     Route::group(['middleware' => 'permission:message.activity'], function () {
@@ -275,6 +280,5 @@ Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['aut
         //删除
         //删除
         Route::delete('activity/destroy', 'ActivityController@destroy')->name('admin.activity.destroy')->middleware('permission:message.activity.destroy');
         Route::delete('activity/destroy', 'ActivityController@destroy')->name('admin.activity.destroy')->middleware('permission:message.activity.destroy');
 
 
-
     });
     });
 });
 });