Ver código fonte

新增启动页字段

wzq 5 anos atrás
pai
commit
6e9c15c15b

+ 111 - 0
app/Http/Controllers/V3/StartupController.php

@@ -0,0 +1,111 @@
+<?php
+
+namespace App\Http\Controllers\V3;
+
+use App\Http\Controllers\Controller;
+use App\Repositories\NoticeRuleRepository;
+use App\Transformers\MessageRuleDetailTransformer;
+use App\Transformers\NoticeRuleDetailTransformer;
+use App\Transformers\NoticeRuleListTransformer;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Validation\Rule;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+use League\Fractal\Resource\Item;
+
+class StartupController extends Controller
+{
+    public function __construct(NoticeRuleRepository $noticeRuleRepository)
+    {
+        $this->noticeRuleRepository = $noticeRuleRepository;
+    }
+
+    /**
+     * 启动页列表
+     */
+    public function index(Request $request)
+    {
+        $productList = $this->noticeRuleRepository->lists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($productList, new NoticeRuleListTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($productList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'title',
+            ],
+            'columns' => [
+                'id',
+                'title',
+                'cover',
+                'updated_at',
+                'send_count',
+                'notice_user_type',
+                'notice_status'
+            ]
+        ];
+        return $data;
+    }
+
+    /**
+     * 创建启动页
+     */
+    public function create(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'title' => 'required|string|max:12',
+            'img' => 'required|url',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->noticeRuleRepository->create($request->all());
+    }
+
+
+    /**
+     * 启动页详情
+     */
+    public function detail(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:notice_rule'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+
+        $post = $this->noticeRuleRepository->detail($request->all());
+        return $this->response->item($post, new NoticeRuleDetailTransformer());
+    }
+
+    /**
+     * 发送启动页
+     */
+    public function send(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:notice_rule'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->noticeRuleRepository->send($request->all());
+    }
+
+    /**
+     * 删除通知
+     */
+    public function delete(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:notice_rule'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->noticeRuleRepository->delete($request->all());
+    }
+}

+ 50 - 0
database/migrations/2019_09_17_151927_create_table_startup.php

@@ -0,0 +1,50 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableStartup extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('startup', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->string('title', 32)
+                ->default('')
+                ->comment('标题');
+
+            $table->tinyInteger('is_open')
+                ->default(0)
+                ->comment('是否开启:0否,1是');
+
+            $table->string('img', 255)
+                ->default('')
+                ->comment('图片');
+
+            $table->string('url', 255)
+                ->default('')
+                ->comment('跳转地址');
+            
+            $table->softDeletes();
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('startup');
+    }
+}

+ 24 - 0
routes/api.php

@@ -143,4 +143,28 @@ $api->version('v1', [
             $api->get('/complaintSuggestions/lists', 'ComplaintSuggestionsController@index');
         });
     });
+});
+
+$api->version('v1', [
+    'namespace' => 'App\Http\Controllers\V3',
+], function ($api) {
+
+    $api->group([
+        'prefix' => 'v3'
+    ], function ($api) {
+        $api->group(['middleware' => 'jwt.chxq_auth'], function ($api) {
+            //启动页列表
+            $api->get('startup', 'StartupController@lists');
+            //新增启动页
+            $api->post('startup', 'StartupController@create');
+            //编辑启动页
+            $api->put('startup', 'StartupController@update');
+            //删除启动页
+            $api->delete('startup', 'StartupController@delete');
+            //修改启动页状态
+            $api->put('startup/status', 'StartupController@updateStatus');
+            //启动页详情
+            $api->get('startup/detail', 'StartupController@detail');
+        });
+    });
 });