|
|
@@ -35,10 +35,10 @@ class GameLogic extends BaseLogic
|
|
|
*/
|
|
|
public function getIndex($where)
|
|
|
{
|
|
|
- $auth_game_list = request()->header('auth_game_list');
|
|
|
+ $authGameList = request()->header('auth_game_list');
|
|
|
$query = $this->search($where);
|
|
|
- if(!empty($auth_game_list)) {
|
|
|
- $authGameList = explode(',', $auth_game_list);
|
|
|
+ if(!empty($authGameList)) {
|
|
|
+ $authGameList = explode(',', $authGameList);
|
|
|
$query->where('id', 'in', $authGameList);
|
|
|
}
|
|
|
$query->order('sort', 'desc');
|
|
|
@@ -53,72 +53,46 @@ class GameLogic extends BaseLogic
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取游戏options列表(有权限)
|
|
|
+ * 获取游戏options列表(有权限限制)
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getGameOptions($where)
|
|
|
+ public function getGameOptions($where): array
|
|
|
{
|
|
|
- $has_package = $where['has_package']??false;
|
|
|
+ $hasPackage = $where['has_package']??false;
|
|
|
unset($where['has_package']);
|
|
|
- $auth_game_list = request()->header('auth_game_list');
|
|
|
+ $authGameList = request()->header('auth_game_list');
|
|
|
$query = $this->search($where);
|
|
|
- if(!empty($auth_game_list)) {
|
|
|
- $authGameList = explode(',', $auth_game_list);
|
|
|
+ if(!empty($authGameList)) {
|
|
|
+ $authGameList = explode(',', $authGameList);
|
|
|
$query->where('id', 'in', $authGameList);
|
|
|
}
|
|
|
+
|
|
|
$query->where('status', 1);
|
|
|
$list = $query->select()->toArray();
|
|
|
|
|
|
- // 携带分组信息
|
|
|
- $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' => $has_package ? $gameInfo['id'].':'.$gameInfo['name'].':'.$gameInfo['package_name'] : '['.$gameInfo['id'].']'.$gameInfo['name'],
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $result[] = [
|
|
|
- 'id' =>'group_id_'.$group['id'],
|
|
|
- 'name' => $group['name'],
|
|
|
- 'children' => $groupGames
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- return $result;
|
|
|
-
|
|
|
-
|
|
|
+ return $this->getGameGroupTree($list, $hasPackage);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取游戏options列表(无权限)
|
|
|
+ * 获取游戏options列表(无权限限制)
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getGameOptionsNoAuth($where)
|
|
|
+ public function getGameOptionsNoAuth($where): array
|
|
|
{
|
|
|
$query = $this->search($where);
|
|
|
$query->where('status', 1);
|
|
|
$list = $query->select()->toArray();
|
|
|
|
|
|
- // 携带分组信息
|
|
|
- $gameGroupList = Db::connect('db_center')->table('game_group')->where('1=1')->select()->toArray();
|
|
|
+ return $this->getGameGroupTree($list);
|
|
|
+ }
|
|
|
|
|
|
- $gameListMap = array_column($list, null, 'id');
|
|
|
+ // 公共方法抽离
|
|
|
+ protected function getGameGroupTree($list, $hasPackage=null): array
|
|
|
+ {
|
|
|
+ $gameListMap = array_column($list, null, 'id');
|
|
|
+
|
|
|
+ // 携带分组信息
|
|
|
+ $gameGroupList = Db::connect('db_center')->table('game_group')->select()->toArray();
|
|
|
|
|
|
// 按照gameGroupList分组输出,组内携带game_list(如2,3,4),并将gameListMap中的游戏信息塞入分组,树形结构输出
|
|
|
$result = [];
|
|
|
@@ -126,6 +100,7 @@ class GameLogic extends BaseLogic
|
|
|
$groupGames = [];
|
|
|
if (!empty($group['game_list'])) {
|
|
|
$gameIds = explode(',', $group['game_list']);
|
|
|
+
|
|
|
foreach ($gameIds as $gid) {
|
|
|
$gid = trim($gid);
|
|
|
if (isset($gameListMap[$gid])) {
|
|
|
@@ -133,7 +108,7 @@ class GameLogic extends BaseLogic
|
|
|
// 兼容输出格式
|
|
|
$groupGames[] = [
|
|
|
'id' => $gameInfo['id'],
|
|
|
- 'name' =>'['.$gameInfo['id'].']'.$gameInfo['name'],
|
|
|
+ 'name' => $hasPackage ? $gameInfo['id'].':'.$gameInfo['name'].':'.$gameInfo['package_name'] : '['.$gameInfo['id'].']'.$gameInfo['name'],
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
@@ -141,7 +116,6 @@ class GameLogic extends BaseLogic
|
|
|
$result[] = [
|
|
|
'id' =>'group_id_'.$group['id'],
|
|
|
'name' => $group['name'],
|
|
|
-
|
|
|
'children' => $groupGames
|
|
|
];
|
|
|
}
|
|
|
@@ -169,10 +143,10 @@ class GameLogic extends BaseLogic
|
|
|
*/
|
|
|
public function getGameListByPermission($where)
|
|
|
{
|
|
|
- $auth_game_list = request()->header('auth_game_list');
|
|
|
+ $authGameList = request()->header('auth_game_list');
|
|
|
$query = $this->search($where);
|
|
|
- if(!empty($auth_game_list)) {
|
|
|
- $authGameList = explode(',', $auth_game_list);
|
|
|
+ if(!empty($authGameList)) {
|
|
|
+ $authGameList = explode(',', $authGameList);
|
|
|
$query->where('id', 'in', $authGameList);
|
|
|
}
|
|
|
$query->where('status', 1);
|
|
|
@@ -206,10 +180,10 @@ class GameLogic extends BaseLogic
|
|
|
*/
|
|
|
public function getGameListTree($where)
|
|
|
{
|
|
|
- $auth_game_list = request()->header('auth_game_list');
|
|
|
+ $authGameList = request()->header('auth_game_list');
|
|
|
$query = $this->search();
|
|
|
- if(!empty($auth_game_list)) {
|
|
|
- $authGameList = explode(',', $auth_game_list);
|
|
|
+ if(!empty($authGameList)) {
|
|
|
+ $authGameList = explode(',', $authGameList);
|
|
|
$query->where('id', 'in', $authGameList);
|
|
|
}
|
|
|
$query->where('status', 1);
|