| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- // +----------------------------------------------------------------------
- // | saiadmin [ saiadmin快速开发框架 ]
- // +----------------------------------------------------------------------
- // | Author: your name
- // +----------------------------------------------------------------------
- namespace app\v1\logic\center;
- use plugin\saiadmin\basic\BaseLogic;
- use app\v1\model\center\Game;
- use plugin\saiadmin\app\logic\system\SystemDeptLogic;
- /**
- * 游戏列表逻辑层
- */
- class GameLogic extends BaseLogic
- {
- protected $gameMainLogic;
- protected $systemDeptLogic;
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->model = new Game();
- $this->gameMainLogic = new GameMainLogic();
- $this->systemDeptLogic = new SystemDeptLogic();
- }
- /**
- * 获取游戏列表
- * @param array $where
- * @return array
- */
- public function getIndex($where)
- {
- $query = $this->search($where);
- $query->order('sort', 'desc');
- $data = $this->getList($query);
- foreach ($data['data'] as $key => $value) {
- $data['data'][$key]['main_game_name'] = $this->gameMainLogic->getMainGameNameById($value['main_id']);
- }
- return $data;
- }
- /**
- * 获取游戏options列表
- * @return array
- */
- public function getGameOptions()
- {
- $list = $this->model->field('id,name')->where('status', 1)->order('sort', 'desc')->select()->toArray();
- $list = array_map(function ($item) {
- return [
- 'label' => $item['name'],
- 'value' => $item['id']
- ];
- }, $list);
- return $list;
- }
- /**
- * 处理游戏tree数据
- * @return array
- */
- public function getGameTree($game_list)
- {
- $mainGameMap = $this->gameMainLogic->getMainGameMap();
-
- $groupedGames = [];
- foreach ($game_list as $game) {
- $mainId = $game['main_id'];
- $groupedGames[$mainId]['id'] = $mainId;
- $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
- $groupedGames[$mainId]['children'][] = [
- 'id' => $game['id'],
- 'name' => $game['name']
- ];
- }
- $game_list = array_values($groupedGames);
- return $game_list;
- }
- /**
- * 获取所有的游戏数据
- */
- public function getAllGameData()
- {
- $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
- return $this->getGameTree($game_list);
- }
- /**
- * 根据部门ID获取游戏列表
- * @param array $where
- * @return array
- */
- public function getGameListByDeptId($dept_id)
- {
- $game_ids = $this->systemDeptLogic->getGameListByDeptId($dept_id);
- // if($game_ids==='*'){
- // $game_list = $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();
- // }
- return $game_ids;
- }
- /**
- * 设置部门游戏权限
- * @param array $where
- * @param array $game_list
- * @return void
- */
- public function setGameListByDeptId($dept_id, $game_list)
- {
- $this->systemDeptLogic->setGameListByDeptId($dept_id, $game_list);
- }
- }
|