瀏覽代碼

游戏分组

ith5 3 月之前
父節點
當前提交
aa8d72b8e2
共有 1 個文件被更改,包括 44 次插入0 次删除
  1. 44 0
      app/v1/logic/center/GameGroupLogic.php

+ 44 - 0
app/v1/logic/center/GameGroupLogic.php

@@ -19,6 +19,50 @@ class GameGroupLogic extends BaseLogic
         $this->model = new GameGroup();
     }
     
+    /**
+     * 读取列表
+     */
+    public function getList($query): mixed
+    {
+        $page = request()->input('page') ? request()->input('page') : 1;
+        $limit = request()->input('limit') ? request()->input('limit') : 10;
+
+
+        $list = $this->model->order('sort', 'desc')->paginate($limit, false, ['page' => $page])->toArray();
+
+        $gameList = Db::connect('db_center')->table('pf_game')->column('name', 'id');
+        foreach ($gameList as $id => &$name) {
+            $name = '[' . $id . ']' . $name;
+        }
+        $gameList = array_column($gameList, null, 'id');
+   
+        
+        foreach ($list['data'] as $key => $value) {
+             $gameIds = explode(',', $value['game_list']);
+             foreach ($gameIds as $gameId) {
+                $list['data'][$key]['children'][] = [
+                    'id' => $gameId,
+                    'name' => $gameList[$gameId],
+                ];
+             }
+        }
+
+         $total = $this->model->count();
+         $last_page = ceil($total/$limit);
+         $startIndex = ($page - 1) * $limit;
+         $pageData = array_slice($list['data'], $startIndex, $limit);
+
+        return [
+            'data' => $pageData,
+            'current_page' => $page,
+            'per_page' => $limit,
+            'last_page' => $last_page,
+            'total' => $total,
+        ];
+
+        // return $this->model->order('sort', 'desc')->paginate($limit, false, ['page' => $page])->toArray();
+    }
+
     /**
      * 读取数据
      * @param $id