| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- namespace app\v1\controller;
- use app\v1\logic\advert\AgentListLogic;
- use app\v1\logic\advert\AgentSiteLogic;
- use app\v1\logic\advert\GamePackageLogic;
- use app\v1\logic\advert\MediaListLogic;
- use app\v1\logic\center\GameGroupLogic;
- use app\v1\logic\center\GameLogic;
- use plugin\saiadmin\basic\BaseController;
- use app\v1\logic\center\GameMainLogic;
- use plugin\saiadmin\app\cache\UserInfoCache;
- use plugin\saiadmin\app\logic\system\SystemUserLogic;
- use plugin\saiadmin\app\model\system\SystemDept;
- use support\Request;
- use support\Response;
- use support\think\Db;
- /**
- * 公共接口管理控制器
- */
- class CommonController extends BaseController
- {
- protected $gameMainLogic;
- protected $gameLogic;
- protected $mediaListLogic;
- protected $agentListLogic;
- protected $systemUserLogic;
- protected $gamePackageLogic;
- protected $agentSiteLogic;
- protected $gameGroupLogic;
- /**
- * 构造函数
- */
- public function __construct()
- {
- parent::__construct();
- $this->gameMainLogic = new GameMainLogic();
- $this->gameLogic = new GameLogic();
- $this->mediaListLogic = new MediaListLogic();
- $this->agentListLogic = new AgentListLogic();
- $this->systemUserLogic = new SystemUserLogic();
- $this->gamePackageLogic = new GamePackageLogic();
- $this->agentSiteLogic = new AgentSiteLogic();
- $this->gameGroupLogic = new GameGroupLogic();
- }
- // /**
- // * 按照权限获取游戏信息,通过游戏分组
- // */
- // public function getGameListOptions(Request $request): Response
- // {
- // $where = $request->get();
- // $data = $this->gameGroupLogic->getGameListOptions($where);
- // return $this->success($data);
- // }
-
- /**
- * 获取主游戏options列表
- * @return Response
- */
- public function getMainGameOptions(Request $request): Response
- {
- $data = $this->gameMainLogic->getMainGameOptions();
- return $this->success($data);
- }
- /**
- * 获取子游戏options列表(有权限)
- * @return Response
- */
- public function getGameOptions(Request $request): Response
- {
- $where = $request->get();
- $data = $this->gameLogic->getGameOptions($where);
- return $this->success($data);
- }
- /**
- * 获取子游戏options列表(无权限)
- * @return Response
- */
- public function getGameOptionsNoAuth(Request $request): Response
- {
- $where = $request->get();
- $data = $this->gameLogic->getGameOptionsNoAuth($where);
- return $this->success($data);
- }
- /**
- * 查询媒体列表Options
- */
- public function getMediaOptions(Request $request): Response
- {
- $data = $this->mediaListLogic->getMediaOptions();
- $data = $data->toArray();
-
- return $this->success($data);
- }
- /**
- * 查询渠道列表Options
- */
- public function getAgentOptions(Request $request): Response
- {
- $data = $this->agentListLogic->getAgentOptions();
- return $this->success($data);
- }
- /**
- * 后台归属人列表Options
- */
- public function getAuthOptions(Request $request): Response
- {
- // 根据用户id获取用户权限
- $token = getCurrentInfo();
- // 用户权限缓存
- $userAuthCache = new UserInfoCache($token['id']);
- $user_info = $userAuthCache->getUserInfo();
- $currentUserRoleList = $user_info['roleList'];
- $currentUserRoleList = array_column($currentUserRoleList, 'id');
- // 管理员角色ID:1, 则不限制权限
- if(in_array(1,$currentUserRoleList)){
- $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->group('dept_id')->select()->toArray();
- $deptList = SystemDept::where('1=1')->select()->toArray();
- }else{
- $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->where('id',$user_info['id'])->group('dept_id')->select()->toArray();
- $deptList = SystemDept::where('id',$user_info['dept_id'])->select()->toArray();
- }
- $result = [];
- // 将部门列表转为以id为key的数组,便于查找
- $deptMap = [];
- foreach ($deptList as $dept) {
- $dept['children'] = [];
- $dept['users'] = [];
- $deptMap[$dept['id']] = $dept;
- }
- // 将用户分配到对应部门的users中
- foreach ($data as $user) {
- if (isset($deptMap[$user['dept_id']])) {
- $deptMap[$user['dept_id']]['users'][] = [
- 'id' => $user['value'],
- 'name' => $user['label'],
- ];
- }
- }
- // 构建部门树
- $tree = [];
- foreach ($deptMap as $id => &$dept) {
- if ($dept['parent_id'] && isset($deptMap[$dept['parent_id']])) {
- $deptMap[$dept['parent_id']]['children'][] = &$dept;
- } else {
- $tree[] = &$dept;
- }
- }
- unset($dept);
- // 递归格式化输出
- $result = $this->formatDeptTree($tree);
-
-
- return $this->success($result);
- }
- public function formatDeptTree($depts) {
- $result = [];
- foreach ($depts as $dept) {
- $item = [
- 'id' => 'dept_id_'.$dept['id'],
- 'name' => $dept['name'],
- ];
- // 先加用户
- if (!empty($dept['users'])) {
- $item['children'] = $dept['users'];
- }
- // 再加子部门
- if (!empty($dept['children'])) {
- $children = $this->formatDeptTree($dept['children']);
- if (!empty($item['children'])) {
- $item['children'] = array_merge($item['children'], $children);
- } else {
- $item['children'] = $children;
- }
- }
- $result[] = $item;
- }
- return $result;
- }
- /**
- * 设计归属人列表Options
- */
- public function getDesignAuthOptions(Request $request): Response
- {
- $data = $this->systemUserLogic->field('id as value, username as label')->where('dept_id',11)->select()->toArray();
- return $this->success($data);
- }
- /**
- * 获取母包列表Options
- */
- public function getPackageOptions(Request $request): Response
- {
- $where = $request->get();
- $data = $this->gamePackageLogic->getPackageOptions($where);
- return $this->success($data);
- }
- /**
- * 获取广告位options
- */
- public function getAgentSiteOptions(Request $request): Response
- {
- $data = $this->agentSiteLogic->getAgentSiteOptions();
- return $this->success($data);
- }
- /**
- * 获取充值渠道
- */
- public function getPayChannelOptions(Request $request): Response
- {
- $data = Db::connect('db_center')->table('pay_channel')->where('status',1)->select()->toArray();
- return $this->success($data);
- }
- /**
- * 给游戏分组用的游戏列表
- */
- public function getGameListOptionsByGroup(Request $request): Response
- {
- $where = $request->more([
- ['game_group_id', '']
- ]);
- $data = $this->gameGroupLogic->getGameListOptionsByGroup($where);
- return $this->success($data);
- }
- }
|