Explorar el Código

游戏下拉列表

aiden hace 3 meses
padre
commit
9187c58f7d
Se han modificado 3 ficheros con 27 adiciones y 0 borrados
  1. 15 0
      app/controller/Game.php
  2. 11 0
      app/model/GameModel.php
  3. 1 0
      route/app.php

+ 15 - 0
app/controller/Game.php

@@ -201,6 +201,21 @@ class Game extends BaseController
             return json_error([], '获取游戏平台失败:' . $e->getMessage());
         }
     }
+
+    /**
+     * 获取所有游戏
+     */
+    public function getGames()
+    {
+        $userInfo = $this->getUserInfo();
+
+        try {
+            $platforms = GameModel::getGames($userInfo['merchant_id']);
+            return json_success($platforms, '获取成功');
+        } catch (\Exception $e) {
+            return json_error([], '获取游戏平台失败:' . $e->getMessage());
+        }
+    }
     
 
     /**

+ 11 - 0
app/model/GameModel.php

@@ -169,6 +169,17 @@ class GameModel extends Model
         ];
     }
 
+    public static function getGames($merchantId, $filters = [])
+    {
+        $query = self::where('merchant_id', $merchantId);
+        // 排序
+        $order = $filters['order'] ?? 'id';
+        $sort = $filters['sort'] ?? 'desc';
+        $query->order($order, $sort);
+
+        return $query->field(['id', 'game_id', 'title'])->select()->toArray();
+    }    
+
     /**
      * 获取游戏详情
      */

+ 1 - 0
route/app.php

@@ -49,6 +49,7 @@ Route::group('player', function () {
 // 游戏相关路由
 Route::group('game', function () {
     Route::get('list', 'Game/list');
+    Route::get('get_games', 'Game/getGames');
     Route::get('detail', 'Game/detail');
     Route::post('update', 'Game/update');
     Route::post('update_status', 'Game/updateStatus');