Prechádzať zdrojové kódy

首页列表管理,增加小程序类型支持

liuzejian 1 rok pred
rodič
commit
7b6ce84de6

+ 53 - 0
modules/Common/Services/CommonConfigService.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace Modules\Common\Services;
+
+class CommonConfigService
+{
+    /**
+     * 获取首页列表类型映射
+     * @return mixed[]
+     * <pre>
+     * [
+     *   1 => [
+     *      'label' => 'xxx',
+     *      'value' => 1,
+     *   ],
+     * ]
+     * </pre>
+     */
+    public static function getFirstPageListTypeMap() {
+        return collect(config('common.common.firstPageListType'))->keyBy('value')->toArray();
+    }
+    /**
+     * 获取小程序类型映射
+     * @return mixed[]
+     * <pre>
+     * [
+     *   1 => [
+     *      'label' => 'xxx',
+     *      'value' => 1,
+     *   ],
+     * ]
+     * </pre>
+     */
+    public static function getMiniprogramTypeMap() {
+        return collect(config('common.common.miniprogramType'))->keyBy('value')->toArray();
+    }
+
+    /**
+     * 获取支付类型映射
+     * @return mixed[]
+     * <pre>
+     * [
+     *   1 => [
+     *      'label' => 'xxx',
+     *      'value' => 1,
+     *   ],
+     * ]
+     * </pre>
+     */
+    public static function getPayTypeMap() {
+        return collect(config('common.common.payType'))->keyBy('value')->toArray();
+    }
+}

+ 12 - 12
modules/Common/config/common.php

@@ -22,16 +22,16 @@ return [
      */
     'payType' => [
         [
-            'key' => 1,
-            'val' => '易宝支付',
+            'label' => '易宝支付',
+            'value' => 1,
         ],
         [
-            'key' => 2,
-            'val' => '微信原生支付',
+            'label' => '微信原生支付',
+            'value' => 2,
         ],
         [
-            'key' => 3,
-            'val' => '抖音支付'
+            'label' => '抖音支付',
+            'value' => 2,
         ],
     ],
     /**
@@ -39,12 +39,12 @@ return [
      */
     'miniprogramType' => [
         [
-            'key' => 1,
-            'val' => '微信'
+            'value' => 1,
+            'label' => '微信'
         ],
         [
-            'key' => 2,
-            'val' => '抖音'
+            'value' => 2,
+            'label' => '抖音'
         ]
     ],
     /**
@@ -53,11 +53,11 @@ return [
     'firstPageListType' => [
         [
             'label' => '本周精选',
-            'val' => 1
+            'value' => 1
         ],
         [
             'label' => '优选好剧',
-            'val' => 2
+            'value' => 2
         ],
     ],
 ];

+ 5 - 4
modules/Manage/Http/Controllers/PayConfigController.php

@@ -6,6 +6,7 @@ use Catch\Base\CatchController;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
+use Modules\Common\Services\CommonConfigService;
 
 /**
  * 支付配置管理
@@ -53,11 +54,11 @@ class PayConfigController extends CatchController
             $result =  $sql->paginate($request->input('limit', 15));
         }
 
-        $payTypeMap = collect($commonConfig['payType'])->keyBy('key');
-        $miniprogramTypeMap = collect($commonConfig['miniprogramType'])->keyBy('key');
+        $payTypeMap = CommonConfigService::getPayTypeMap();
+        $miniprogramTypeMap = CommonConfigService::getMiniprogramTypeMap();
         foreach ($result as $item) {
-            $item->pay_type_str = $payTypeMap[$item->pay_type]['val'] ?? '';
-            $item->miniprogram_type_str = $miniprogramTypeMap[$item->miniprogram_type]['val'] ?? '';
+            $item->pay_type_str = $payTypeMap[$item->pay_type]['label'] ?? '';
+            $item->miniprogram_type_str = $miniprogramTypeMap[$item->miniprogram_type]['label'] ?? '';
         }
 
         return $result;

+ 15 - 4
modules/Operation/Http/Controllers/FirstPageController.php

@@ -8,6 +8,7 @@ use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 use Modules\Common\Errors\Errors;
 use Modules\Common\Exceptions\CommonBusinessException;
+use Modules\Common\Services\CommonConfigService;
 use Modules\User\Http\Controllers\UserTrait;
 
 class FirstPageController extends CatchController
@@ -19,13 +20,15 @@ class FirstPageController extends CatchController
      *  首页列表
      */
     public function list(Request $request) {
-        $firstPageListTypeMap = collect(config('common.common.firstPageListType'))->keyBy('val')->toArray();
+        $firstPageListTypeMap = CommonConfigService::getFirstPageListTypeMap();
+        $miniprogramTypeMap = CommonConfigService::getMiniprogramTypeMap();
         $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');
+            $item->miniprogram_type_str = $miniprogramTypeMap[$item->miniprogram_type]['label'] ?? '';
         }
         return $result;
     }
@@ -39,13 +42,17 @@ class FirstPageController extends CatchController
     public function add(Request $request) {
         $this->validate($request, [
             'type' => 'required|in:1,2',
-            'status' => 'required|in:0,1'
+            'status' => 'required|in:0,1',
+            'miniprogram_type' => 'required|in:1,2'
         ]);
 
         $now = date('Y-m-d H:i:s');
         if(1 == $request->input('status')) {
             DB::table('first_pages')
-                ->where('type', $request->input('type'))
+                ->where([
+                    'type' => $request->input('type'),
+                    'miniprogram_type' => $request->input('miniprogram_type')
+                ])
                 ->update(['status' => 0, 'updated_at' => $now]);
         }
 
@@ -53,6 +60,7 @@ class FirstPageController extends CatchController
             ->insert([
                 'type' => $request->input('type'),
                 'status' => $request->input('status'),
+                'miniprogram_type' => $request->input('miniprogram_type'),
                 'created_at' => $now,
                 'updated_at' => $now,
             ]);
@@ -76,7 +84,10 @@ class FirstPageController extends CatchController
 
         $now = date('Y-m-d H:i:s');
         DB::table('first_pages')
-            ->where('type', $info->type)
+            ->where([
+                'type' => $info->type,
+                'miniprogram_type' => $info->miniprogram_type,
+            ])
             ->update(['status' => 0, 'updated_at' => $now]);
         DB::table('first_pages')
             ->where('id', $request->input('id'))

+ 17 - 0
tests/Common/Services/CommonConfigServiceTest.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace Tests\Common\Services;
+
+use Modules\Common\Services\CommonConfigService;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class CommonConfigServiceTest extends UsedTestCase
+{
+
+    public function testGetFirstPageListTypeMap()
+    {
+        $res  = CommonConfigService::getFirstPageListTypeMap();
+        dump($res);
+    }
+}