| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- // +----------------------------------------------------------------------
- // | saiadmin [ saiadmin快速开发框架 ]
- // +----------------------------------------------------------------------
- // | Author: your name
- // +----------------------------------------------------------------------
- namespace app\v1\logic\center;
- use plugin\saiadmin\basic\BaseLogic;
- use plugin\saiadmin\exception\ApiException;
- use plugin\saiadmin\utils\Helper;
- use app\v1\model\center\GameGroup;
- use support\think\Db;
- /**
- * 游戏分组逻辑层
- */
- class GameGroupLogic extends BaseLogic
- {
- private $gameMainLogic;
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->model = new GameGroup();
- $this->gameMainLogic = new GameMainLogic();
- }
-
- /**
- * 读取数据
- * @param $id
- * @return mixed
- */
- 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] ?? '';
- }
- $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);
- }
-
- }
|