Parcourir la source

首页列表配置

liuzejian il y a 1 an
Parent
commit
8ef6ea9af6

+ 1 - 0
modules/Common/Errors/Errors.php

@@ -27,4 +27,5 @@ class Errors
     public const  BANK_CARD_STATUS_ERROR = [500202, '银行卡不存在或当前状态不可提现'];
     public const  TIXIAN_RECORD_NOT_EXISTS = [500203, '提现记录不存在'];
     public const  TIXIAN_ONLY_ONCE_EVERY_DAY = [500204, '每天只能提现一次'];
+    public const  OPERATION_FIRST_PAGE_LIST_NOT_EXISTS = [500301, '首页列表配置项不存在'];
 }

+ 4 - 0
modules/Common/Repository/Options/CommonParams.php

@@ -21,6 +21,10 @@ class CommonParams implements OptionInterface
              * 小程序类型
              */
             'miniprogramType' => $commonConfig['miniprogramType'],
+            /**
+             * 首页列表类型
+             */
+            'firstPageListType' => $commonConfig['firstPageListType'],
         ];
     }
 }

+ 13 - 0
modules/Common/config/common.php

@@ -47,4 +47,17 @@ return [
             'val' => '抖音'
         ]
     ],
+    /**
+     * 首页列表分类
+     */
+    'firstPageListType' => [
+        [
+            'label' => '本周精选',
+            'val' => 1
+        ],
+        [
+            'label' => '优选好剧',
+            'val' => 2
+        ],
+    ],
 ];

+ 1 - 1
modules/Manage/routes/route.php

@@ -33,7 +33,7 @@ Route::prefix('manage')->group(function(){
         ->withoutMiddleware(config('catch.route.middlewares'));
 
     });
-    
+
     Route::prefix('payConfig')->group(function(){
        Route::get('list', [PayConfigController::class, 'list']);
        Route::post('remark', [PayConfigController::class, 'remark']);

+ 73 - 2
modules/Operation/Http/Controllers/FirstPageController.php

@@ -6,6 +6,8 @@ use Catch\Base\CatchController;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
+use Modules\Common\Errors\Errors;
+use Modules\Common\Exceptions\CommonBusinessException;
 use Modules\User\Http\Controllers\UserTrait;
 
 class FirstPageController extends CatchController
@@ -17,21 +19,90 @@ class FirstPageController extends CatchController
      *  首页列表
      */
     public function list(Request $request) {
+        $firstPageListTypeMap = collect(config('common.common.firstPageListType'))->keyBy('val')->toArray();
         $result = DB::table('first_pages')
             ->orderBy('id', 'desc')
             ->paginate($request->input('limit', 15));
+        foreach ($result as $item) {
+            $item->type_str = $firstPageListTypeMap[$item->type]['label'] ?? '';
+            $item->duanjus = collect(\json_decode($item->duanjus, true))->sortBy('sort');
+        }
+        return $result;
     }
 
+    /**
+     * 添加配置
+     * @param Request $request
+     * @return string
+     * @throws \Illuminate\Validation\ValidationException
+     */
     public function add(Request $request) {
+        $this->validate($request, [
+            'type' => 'required|in:1,2',
+            'status' => 'required|in:0,1'
+        ]);
 
+        $now = date('Y-m-d H:i:s');
+        if(1 == $request->input('status')) {
+            DB::table('first_pages')
+                ->where('type', $request->input('type'))
+                ->update(['status' => 0, 'updated_at' => $now]);
+        }
+
+        DB::table('first_pages')
+            ->insert([
+                'type' => $request->input('type'),
+                'status' => $request->input('status'),
+                'created_at' => $now,
+                'updated_at' => $now,
+            ]);
+        return 'ok';
     }
 
-    public function changeStatus(Request $request) {
+    /**
+     * 开启配置,一个列表类型中只允许一个配置开启
+     * @param Request $request
+     * @return string
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function enableStatus(Request $request) {
+        $this->validate($request, ['id' => 'required']);
+        $info = DB::table('first_pages')
+            ->where('id', $request->input('id'))
+            ->first();
+        if(!$info) {
+            CommonBusinessException::throwError(Errors::OPERATION_FIRST_PAGE_LIST_NOT_EXISTS);
+        }
 
+        $now = date('Y-m-d H:i:s');
+        DB::table('first_pages')
+            ->where('type', $info->type)
+            ->update(['status' => 0, 'updated_at' => $now]);
+        DB::table('first_pages')
+            ->where('id', $request->input('id'))
+            ->update(['status' => 1, 'updated_at' => $now]);
+        return 'ok';
     }
 
-    public function config(Request $request) {
+    /**
+     * 配置剧集
+     * @param Request $request
+     * @return string
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function setConfig(Request $request) {
+        $this->validate($request, [
+            'id' => 'required',
+            'duanjus' => 'nullable|array',
+        ]);
+
+        $now = date('Y-m-d H:i:s');
+        DB::table('first_pages')
+            ->where('id', $request->input('id'))
+            ->update(['duanjus' => \json_encode($request->input('duanjus', [])),
+                'updated_at' => $now]);
 
+        return 'ok';
     }
 }
 

+ 7 - 1
modules/Operation/routes/route.php

@@ -1,8 +1,14 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
+use Modules\Operation\Http\Controllers\FirstPageController;
 
 Route::prefix('operationManage')->group(function () {
-
+    Route::prefix('firstPage')->group(function(){
+        Route::post('add', [FirstPageController::class, 'add']);
+        Route::post('enableStatus', [FirstPageController::class, 'enableStatus']);
+        Route::post('setConfig', [FirstPageController::class, 'setConfig']);
+        Route::get('list', [FirstPageController::class, 'list']);
+    });
 });
 

+ 55 - 0
tests/Operation/Http/Controllers/FirstPageControllerTest.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace Tests\Operation\Http\Controllers;
+
+use Modules\Operation\Http\Controllers\FirstPageController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class FirstPageControllerTest extends UsedTestCase
+{
+
+    public function testAdd()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/operationManage/firstPage/add', [
+            'type' => 1,
+            'status' => 0,
+        ]);
+        $this->dumpJson($res);
+    }
+    public function testList()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/operationManage/firstPage/list');
+        $res->dump();
+        $this->dumpJson($res);
+    }
+
+    public function testEnableStatus()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/operationManage/firstPage/enableStatus', [
+            'id' => 4,
+        ]);
+        $res->dump();
+        $this->dumpJson($res);
+    }
+
+    public function testsetConfig()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/operationManage/firstPage/setConfig', [
+            'id' => 4,
+            'duanjus' => []
+        ]);
+        $res->dump();
+        $this->dumpJson($res);
+    }
+
+
+}