Ken před 1 dnem
rodič
revize
0a689a821c
2 změnil soubory, kde provedl 49 přidání a 8 odebrání
  1. 46 8
      app/Http/Controllers/admin/Config.php
  2. 3 0
      routes/admin.php

+ 46 - 8
app/Http/Controllers/admin/Config.php

@@ -6,6 +6,7 @@ use Illuminate\Http\JsonResponse;
 use App\Constants\HttpStatus;
 use App\Http\Controllers\Controller;
 use App\Models\Config as ConfigModel;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Validation\ValidationException;
 use Exception;
@@ -16,18 +17,58 @@ use App\Services\ConfigService;
 
 class Config extends Controller
 {
+
+    /**
+     * @api {post} /admin/config/pc28Switch 游戏切换(0:pc28 1:急速28)
+     * @apiGroup 配置
+     * @apiUse result
+     * @apiUse header
+     * @apiVersion 1.0.0
+     *
+     * @apiParam {int=0,1} val  (0:pc28 1:极速28)
+     */
+    public function pc28Switch()
+    {
+        try {
+            $params = request()->validate([
+                'val' => ['required', 'integer', 'min:0', 'in:0,1']
+            ]);
+            Cache::put('pc28_switch', $params['val']);
+        } catch (ValidationException $e) {
+            return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
+        } catch (Exception $e) {
+            return $this->error(intval($e->getCode()));
+        }
+        return $this->success();
+    }
+
+    /**
+     * @api {get} /admin/config/pcConfig 极速PC28相关配置
+     * @apiGroup 配置
+     * @apiUse result
+     * @apiUse header
+     * @apiVersion 1.0.0
+     *
+     * @apiParam {int} [page=1]
+     * @apiParam {int} [limit=15]
+     */
     public function pcConfig(): JsonResponse
     {
         try {
             $search['group_id'] = 4;
             $result = ConfigService::paginate($search);
+            foreach ($result['data'] as $item) {
+                if ($item['field'] == 'pc28_switch') {
+                    $item['val'] = Cache::get('pc28_switch', $item['val']);
+                }
+            }
         } catch (ValidationException $e) {
             return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
-        } catch (Exception $e) {
+        } catch
+        (Exception $e) {
             return $this->error(intval($e->getCode()));
         }
         return $this->success($result);
-
     }
 
     /**
@@ -165,8 +206,7 @@ class Config extends Controller
      * ]
      *
      */
-    public
-    function get()
+    public function get()
     {
         try {
             request()->validate([
@@ -268,8 +308,7 @@ class Config extends Controller
      *   //更多行...
      * ]
      */
-    public
-    function sendChannelMessage()
+    public function sendChannelMessage()
     {
         set_time_limit(0);
         DB::beginTransaction();
@@ -418,8 +457,7 @@ class Config extends Controller
      * @apiParam {string} receiving_type 收款方式 1-自动 2-手动
      *
      */
-    public
-    function set()
+    public function set()
     {
         DB::beginTransaction();
         try {

+ 3 - 0
routes/admin.php

@@ -118,6 +118,9 @@ Route::middleware(['admin.jwt'])->group(function () {
 
         Route::prefix('/config')->group(function () {
             Route::get('/pcConfig', [Config::class, 'pcConfig']);
+            Route::post('/pc28Switch', [Config::class, 'pc28Switch']);
+
+
 
 
             Route::get('/getAll', [Config::class, 'getAll']);