Ver código fonte

游戏分组

ith5 6 meses atrás
pai
commit
defd8e13f6

+ 26 - 0
app/v1/controller/CommonController.php

@@ -5,6 +5,7 @@ use app\v1\logic\advert\AgentListLogic;
 use app\v1\logic\advert\AgentSiteLogic;
 use app\v1\logic\advert\GamePackageLogic;
 use app\v1\logic\advert\MediaListLogic;
+use app\v1\logic\center\GameGroupLogic;
 use app\v1\logic\center\GameLogic;
 use plugin\saiadmin\basic\BaseController;
 use app\v1\logic\center\GameMainLogic;
@@ -25,6 +26,7 @@ class CommonController extends BaseController
     protected $systemUserLogic;
     protected $gamePackageLogic;
     protected $agentSiteLogic;
+    protected $gameGroupLogic;
 
     /**
      * 构造函数
@@ -39,6 +41,19 @@ class CommonController extends BaseController
         $this->systemUserLogic = new SystemUserLogic();
         $this->gamePackageLogic = new GamePackageLogic();
         $this->agentSiteLogic = new AgentSiteLogic();
+        $this->gameGroupLogic = new GameGroupLogic();
+    }
+
+
+
+    /**
+     * 按照权限获取游戏信息,通过游戏分组
+     */
+    public function getGameListOptions(Request $request): Response
+    {
+        $where = $request->get();
+        $data = $this->gameGroupLogic->getGameListOptions($where);
+        return $this->success($data);
     }
     
     /**
@@ -165,4 +180,15 @@ class CommonController extends BaseController
         $data = Db::connect('db_center')->table('pay_channel')->where('status',1)->select()->toArray();
         return $this->success($data);
     }
+
+    /**
+     * 给游戏分组用的游戏列表
+     */
+    public function getGameListOptionsByGroup(Request $request): Response
+    {
+        $data = $this->gameGroupLogic->getGameListOptionsByGroup();
+        return $this->success($data);
+    }
+
+
 }

+ 0 - 9
app/v1/controller/center/GameGroupController.php

@@ -46,15 +46,6 @@ class GameGroupController extends BaseController
         $allGameList =  Db::connect('db_center')->table('pf_game')->field('id,name')->select()->toArray();
         $allGameList = array_column($allGameList, 'name', 'id');
 
-        foreach ($data['data'] as $key => $value) {
-            $gameList = [];
-            $game_list = explode(',', $value['game_list']);
-            foreach ($game_list as $game_id) {
-                $gameList[] = $allGameList[$game_id] ?? '';
-            }
-            $data['data'][$key]['game_list_str'] = $gameList;
-          
-        }
 
         return $this->success($data);
     }

+ 43 - 1
app/v1/logic/center/GameGroupLogic.php

@@ -17,12 +17,15 @@ use support\think\Db;
  */
 class GameGroupLogic extends BaseLogic
 {
+
+    private $gameMainLogic;
     /**
      * 构造函数
      */
     public function __construct()
     {
         $this->model = new GameGroup();
+        $this->gameMainLogic = new GameMainLogic();
     }
     
     /**
@@ -38,10 +41,49 @@ class GameGroupLogic extends BaseLogic
         $allGameList = array_column($allGameList, 'name', 'id');
         $gameList = [];
         foreach ($game_list as $game_id) {
-            $gameList[] = $allGameList[$game_id] ?? '';
+            $gameList[] = '[' . $game_id . ']' . $allGameList[$game_id] ?? '';
         }
         $data['game_list_str'] = $gameList;
         return $data;
     }
 
+    /**
+     * 给游戏分组用的游戏列表
+     */
+    public function getGameListOptionsByGroup()
+    {
+        $data = $this->model->where('1=1')->order('sort', 'desc')->order('id', 'desc')->select()->toArray();
+
+        // 已经存在分组的game_list
+        $gameIdList = [];
+
+        foreach ($data as $item) {
+            $temGameListArray = explode(',', $item['game_list']);
+            $gameIdList = array_merge($gameIdList, $temGameListArray);
+        }
+
+        $where = [];
+        $where[] = ['status', 1];
+
+        if (!empty($gameIdList)) {
+            $where[] = ['id', 'notin', implode(',', $gameIdList)];
+        }
+
+        $game = Db::connect('db_center')->table('pf_game')->where($where)->select()->toArray();
+
+        $mainGameMap = $this->gameMainLogic->getMainGameMap();
+        $groupedGames = [];
+        foreach ($game as $item) {
+            $mainId = $item['main_id'];
+            $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
+            $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
+            $groupedGames[$mainId]['children'][] = [
+                'id' => $item['id'],
+                'name' => '['.$item['id'].']'.$item['name']
+            ];
+        }
+        return array_values($groupedGames);
+    }
+
+  
 }

+ 37 - 1
app/v1/logic/center/GameLogic.php

@@ -9,6 +9,7 @@ namespace app\v1\logic\center;
 use plugin\saiadmin\basic\BaseLogic;
 use app\v1\model\center\Game;
 use plugin\saiadmin\app\logic\system\SystemDeptLogic;
+use support\think\Db;
 
 /**
  * 游戏列表逻辑层
@@ -18,6 +19,7 @@ class GameLogic extends BaseLogic
 
     protected $gameMainLogic;
     protected $systemDeptLogic;
+    protected $gameGroupLogic;
 
     /**
      * 构造函数
@@ -27,6 +29,7 @@ class GameLogic extends BaseLogic
         $this->model = new Game();
         $this->gameMainLogic = new GameMainLogic();
         $this->systemDeptLogic = new SystemDeptLogic();
+        $this->gameGroupLogic = new GameGroupLogic();
     }
 
     /**
@@ -66,7 +69,40 @@ class GameLogic extends BaseLogic
             $query->where('id', 'in', $authGameList);
         }
         $list = $query->select()->toArray();
-        return $list;
+
+        // 携带分组信息
+        $gameGroupList = Db::connect('db_center')->table('game_group')->where('1=1')->select()->toArray();
+
+        $gameListMap = array_column($list, null, 'id'); 
+
+        // 按照gameGroupList分组输出,组内携带game_list(如2,3,4),并将gameListMap中的游戏信息塞入分组,树形结构输出
+        $result = [];
+        foreach ($gameGroupList as $group) {
+            $groupGames = [];
+            if (!empty($group['game_list'])) {
+                $gameIds = explode(',', $group['game_list']);
+                foreach ($gameIds as $gid) {
+                    $gid = trim($gid);
+                    if (isset($gameListMap[$gid])) {
+                        $gameInfo = $gameListMap[$gid];
+                        // 兼容输出格式
+                        $groupGames[] = [
+                            'id' => $gameInfo['id'],
+                            'name' =>'['.$gameInfo['id'].']'.$gameInfo['name'],
+                        ];
+                    }
+                }
+            }
+            $result[] = [
+                'id' =>'group_id_'.$group['id'],
+                'name' => $group['name'],
+                'children' => $groupGames
+            ];
+        }
+
+        return $result;
+
+        
     }
 
     /**