root 5 years ago
parent
commit
a78f6178bd

+ 28 - 0
app/Http/Controllers/Admin/NoticeController.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use App\Http\Requests\Admin\NoticeSave;
+use Illuminate\Http\Request;
+use App\Http\Controllers\Controller;
+use App\Models\Notice;
+use Illuminate\Support\Facades\Redis;
+
+class NoticeController extends Controller
+{
+    public function index (Request $request) {
+        return response([
+            'data' => Notice::get()
+        ]);
+    }
+
+    public function save (NoticeSave $request) {
+        $data = $request->only([
+            'title',
+            'content'
+        ]);
+        return response([
+            'data' => Notice::create($data)
+        ]);
+    }
+}

+ 17 - 0
app/Http/Controllers/NoticeController.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use App\Http\Controllers\Controller;
+use App\Models\Notice;
+use App\Utils\Helper;
+
+class NoticeController extends Controller
+{
+    public function index (Request $request) {
+        return response([
+            'data' => Notice::orderBy('created_at', 'DESC')->first()
+        ]);
+    }
+}

+ 29 - 0
app/Http/Requests/Admin/NoticeSave.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Http\Requests\Admin;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class NoticeSave extends FormRequest
+{
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            'title' => 'required',
+            'content' => 'required'
+        ];
+    }
+    
+    public function messages()
+    {
+        return [
+            'title.required' => '标题不能为空',
+            'content.required' => '内容不能为空'
+        ];
+    }
+}

+ 12 - 0
app/Models/Notice.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Notice extends Model
+{
+    protected $table = 'v2_notice';
+    protected $dateFormat = 'U';
+    protected $guarded = ['id'];
+}

+ 13 - 4
install.sql

@@ -17,6 +17,17 @@ CREATE TABLE `v2_invite_code` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
+DROP TABLE IF EXISTS `v2_notice`;
+CREATE TABLE `v2_notice` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `title` varchar(255) NOT NULL,
+  `content` text NOT NULL,
+  `created_at` int(11) NOT NULL,
+  `updated_at` int(11) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
 DROP TABLE IF EXISTS `v2_order`;
 CREATE TABLE `v2_order` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
@@ -56,13 +67,11 @@ CREATE TABLE `v2_plan` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
-SET NAMES utf8mb4;
-
 DROP TABLE IF EXISTS `v2_server`;
 CREATE TABLE `v2_server` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `group_id` varchar(255) NOT NULL,
-  `name` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
+  `name` varchar(255) NOT NULL,
   `host` varchar(255) NOT NULL,
   `port` int(11) NOT NULL,
   `server_port` int(11) NOT NULL,
@@ -135,4 +144,4 @@ CREATE TABLE `v2_user` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
--- 2019-12-03 05:04:44
+-- 2019-12-12 05:40:39

+ 5 - 0
routes/api.php

@@ -44,6 +44,9 @@ Route::prefix('v1')
                 Route::post('user/update', 'Admin\\UserController@update');
                 // Stat
                 Route::get ('stat/dashboard', 'Admin\\StatController@dashboard');
+                // Notice
+                Route::get ('notice', 'Admin\\NoticeController@index');
+                Route::post('notice/save', 'Admin\\NoticeController@save');
             });
         // User
         Route::prefix('user')
@@ -73,6 +76,8 @@ Route::prefix('v1')
                 // Tutorial
                 Route::get ('tutorial/getSubscribeUrl', 'TutorialController@getSubscribeUrl');
                 Route::get ('tutorial/getAppleID', 'TutorialController@getAppleID');
+                // Notice
+                Route::get ('notice', 'NoticeController@index');
             });
 
         // Passport

+ 9 - 1
update.sql

@@ -17,4 +17,12 @@ ADD `type` int(11) NOT NULL COMMENT '1新购2续费3升级' AFTER `plan_id`;
 ALTER TABLE `v2_user`
 ADD `commission_rate` int(11) NULL AFTER `password`;
 ALTER TABLE `v2_user`
-ADD `balance` int(11) NOT NULL DEFAULT '0' AFTER `password`;
+ADD `balance` int(11) NOT NULL DEFAULT '0' AFTER `password`;
+
+CREATE TABLE `v2_notice` (
+  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+  `title` varchar(255) NOT NULL,
+  `content` text NOT NULL,
+  `created_at` int(11) NOT NULL,
+  `updated_at` int(11) NOT NULL
+);