Parcourir la source

Merge commit '9138c571b0bb3a707000de4107e975ad0ab7d826' into dev

ith5 il y a 5 mois
Parent
commit
dc5841317e

+ 0 - 1
app/v1/logic/advert/GamePackageLogic.php

@@ -40,7 +40,6 @@ class GamePackageLogic extends BaseLogic
     {
         $data = $this->model->where('media_id', 1)->select()->toArray();
         $data = $this->trandformListColumn($data, ['game']);
-        // 以game_id为key,value为数组
         $data = array_column($data, null, 'id');
         return $data;
     }

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

@@ -36,67 +36,41 @@ class GameGroupLogic extends BaseLogic
     public function read($id): mixed
     {
         $data = $this->model->where('id', $id)->find();
-        $game_list = explode(',', $data['game_list']);
-        $allGameList =  Db::connect('db_center')->table('pf_game')->field('id,name')->select()->toArray();
-        $allGameList = array_column($allGameList, 'name', 'id');
-        $gameList = [];
-        foreach ($game_list as $game_id) {
-            $gameList[] = '[' . $game_id . ']' . $allGameList[$game_id] ?? '';
+        $gameIds = explode(',', $data['game_list']);
+
+        $gameList =  Db::connect('db_center')->table('pf_game')->where("id", $gameIds)->column('name', 'id');
+        foreach ($gameList as $id => &$name) {
+            $name = '[' . $id . ']' . $name;
         }
         $data['game_list_str'] = $gameList;
         return $data;
     }
 
     /**
-     * 给游戏分组用的游戏列表
+     * 给游戏分组用的游戏列表,主要作用,返回可选或者可编辑的游戏列表
      * $where['game_group_id]
      */
-    public function getGameListOptionsByGroup($where)
+    public function getGameListOptionsByGroup($where): array
     {
-
-        // 获取gameGroupId, 如果存在,则返回的游戏需要加上这个分组的game_list
+        // Todo 获取非自己的已选中
         $gameGroupId = $where['game_group_id'];
-
-
-        // 游戏分组数据
-        $data = $this->model->where('1=1')->order('sort', 'desc')->order('id', 'desc')->select()->toArray();
-
-        // 已经存在分组的game_list
+        $data = $this->model->where('id', '<>', $gameGroupId)->column("game_list");
         $gameIdList = [];
-        foreach ($data as $item) {
-            // 传入的分组,不加入筛选去除筛选,用于编辑回显示
-            if($item['id']!=$gameGroupId){
-                $temGameListArray = explode(',', $item['game_list']);
-                $gameIdList = array_merge($gameIdList, $temGameListArray);
-            }
+        foreach ($data as $gameIds) {
+            $gameIds = explode(',', $gameIds);
+            $gameIdList = array_merge($gameIdList, $gameIds);
         }
 
-        $groupWhere = [];
-        $groupWhere[] = ['status', '=', 1];
-
-
-
+        // Todo 获取游戏分组
+        $groupWhere = [
+            'status'=>1
+        ];
         if (!empty($gameIdList)) {
             $groupWhere[] = [ 'id', 'notin', implode(',', $gameIdList)];
         }
-
         // 平台游戏
         $pfCame = Db::connect('db_center')->table('pf_game')->where($groupWhere)->select()->toArray();
 
-
-        $mainGameMap = $this->gameMainLogic->getMainGameMap();
-        $groupedGames = [];
-        foreach ($pfCame 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);
+        return (new GameLogic())->gameMainTree($pfCame);
     }
-
-  
 }

+ 18 - 27
app/v1/logic/center/GameLogic.php

@@ -166,12 +166,16 @@ class GameLogic extends BaseLogic
         }
         $query->where('status', 1);
         $query->order('sort', 'desc');
-        $game_list = $this->getList($query);
+        $gameList = $this->getList($query);
 
+        return $this->gameMainTree($gameList);
+    }
+
+    public function gameMainTree($gameList): array
+    {
         $mainGameMap = $this->gameMainLogic->getMainGameMap();
-        
-         $groupedGames = [];
-         foreach ($game_list as $game) {
+        $groupedGames = [];
+        foreach ($gameList as $game) {
             $mainId = $game['main_id'];
             $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
             $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
@@ -179,10 +183,9 @@ class GameLogic extends BaseLogic
                 'id' => $game['id'],
                 'name' => '['.$game['id'].']'.$game['name']
             ];
-         }
+        }
         return array_values($groupedGames);
     }
-
     /**
      * 根据权限获取游戏列表
      */
@@ -234,10 +237,10 @@ class GameLogic extends BaseLogic
         }
         $query->where('status', 1);
         $query->order('sort', 'desc');
-        $game_list = $query->select()->toArray();
+        $gameList = $query->select()->toArray();
         $mainGameMap = $this->gameMainLogic->getMainGameMap();
         $groupedGames = [];
-        foreach ($game_list as $game) {
+        foreach ($gameList as $game) {
             $mainId = $game['main_id'];
             $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
             $groupedGames[$mainId]['disabled'] = ($where['single'] ?? false);
@@ -260,36 +263,24 @@ class GameLogic extends BaseLogic
     
     {
         $game_ids = $this->systemDeptLogic->getGameIdsByDeptId($dept_id);
-        $game_list = [];
+
         if($game_ids==='*'){
-            $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
+            $gameList = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
         }else{
-            $game_list = $this->model->where('id', 'in', $game_ids)->where('status', 1)->order('sort', 'desc')->select()->toArray();
+            $gameList = $this->model->where('id', 'in', $game_ids)->where('status', 1)->order('sort', 'desc')->select()->toArray();
         }
-        $mainGameMap = $this->gameMainLogic->getMainGameMap();
-        
-         $groupedGames = [];
-         foreach ($game_list as $game) {
-            $mainId = $game['main_id'];
-            $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
-            $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
-            $groupedGames[$mainId]['children'][] = [
-                'id' => $game['id'],
-                'name' => '['.$game['id'].']'.$game['name']
-            ];
-         }
-        return array_values($groupedGames);
+        return $this->gameMainTree($gameList);
     }
 
     /**
      * 设置部门游戏权限
      * @param array $where
-     * @param array $game_list
+     * @param array $gameList
      * @return void
      */
-    public function setGameListByDeptId($dept_id, $game_list)
+    public function setGameListByDeptId($dept_id, $gameList)
     {
-        $this->systemDeptLogic->setGameListByDeptId($dept_id, $game_list);
+        $this->systemDeptLogic->setGameListByDeptId($dept_id, $gameList);
     }
 
 }