CommonController.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. namespace app\v1\controller;
  3. use app\v1\logic\advert\AgentListLogic;
  4. use app\v1\logic\advert\AgentSiteLogic;
  5. use app\v1\logic\advert\GamePackageLogic;
  6. use app\v1\logic\advert\MediaListLogic;
  7. use app\v1\logic\center\GameGroupLogic;
  8. use app\v1\logic\center\GameLogic;
  9. use plugin\saiadmin\basic\BaseController;
  10. use app\v1\logic\center\GameMainLogic;
  11. use plugin\saiadmin\app\cache\UserInfoCache;
  12. use plugin\saiadmin\app\logic\system\SystemConfigLogic;
  13. use plugin\saiadmin\app\logic\system\SystemUserLogic;
  14. use plugin\saiadmin\app\model\system\SystemDept;
  15. use support\Request;
  16. use support\Response;
  17. use support\think\Db;
  18. /**
  19. * 公共接口管理控制器
  20. */
  21. class CommonController extends BaseController
  22. {
  23. /**
  24. * 不需要登录的方法
  25. */
  26. protected array $noNeedLogin = ['getSystemConfig'];
  27. protected $gameMainLogic;
  28. protected $gameLogic;
  29. protected $mediaListLogic;
  30. protected $agentListLogic;
  31. protected $systemUserLogic;
  32. protected $gamePackageLogic;
  33. protected $agentSiteLogic;
  34. protected $gameGroupLogic;
  35. protected $systemConfigLogic;
  36. /**
  37. * 构造函数
  38. */
  39. public function __construct()
  40. {
  41. parent::__construct();
  42. $this->gameMainLogic = new GameMainLogic();
  43. $this->gameLogic = new GameLogic();
  44. $this->mediaListLogic = new MediaListLogic();
  45. $this->agentListLogic = new AgentListLogic();
  46. $this->systemUserLogic = new SystemUserLogic();
  47. $this->gamePackageLogic = new GamePackageLogic();
  48. $this->agentSiteLogic = new AgentSiteLogic();
  49. $this->gameGroupLogic = new GameGroupLogic();
  50. $this->systemConfigLogic = new SystemConfigLogic();
  51. }
  52. // /**
  53. // * 按照权限获取游戏信息,通过游戏分组
  54. // */
  55. // public function getGameListOptions(Request $request): Response
  56. // {
  57. // $where = $request->get();
  58. // $data = $this->gameGroupLogic->getGameListOptions($where);
  59. // return $this->success($data);
  60. // }
  61. /**
  62. * 获取主游戏options列表
  63. * @return Response
  64. */
  65. public function getMainGameOptions(Request $request): Response
  66. {
  67. $data = $this->gameMainLogic->getMainGameOptions();
  68. return $this->success($data);
  69. }
  70. /**
  71. * 获取子游戏options列表(有权限)
  72. * @return Response
  73. */
  74. public function getGameOptions(Request $request): Response
  75. {
  76. $where = $request->get();
  77. $data = $this->gameLogic->getGameOptions($where);
  78. return $this->success($data);
  79. }
  80. /**
  81. * 获取子游戏options列表(无权限)
  82. * @return Response
  83. */
  84. public function getGameOptionsNoAuth(Request $request): Response
  85. {
  86. $where = $request->get();
  87. $data = $this->gameLogic->getGameOptionsNoAuth($where);
  88. return $this->success($data);
  89. }
  90. /**
  91. * 查询媒体列表Options
  92. */
  93. public function getMediaOptions(Request $request): Response
  94. {
  95. $data = $this->mediaListLogic->getMediaOptions();
  96. $data = $data->toArray();
  97. return $this->success($data);
  98. }
  99. /**
  100. * 查询渠道列表Options
  101. */
  102. public function getAgentOptions(Request $request): Response
  103. {
  104. $data = $this->agentListLogic->getAgentOptions();
  105. return $this->success($data);
  106. }
  107. /**
  108. * 后台归属人列表Options
  109. */
  110. public function getAuthOptions(Request $request): Response
  111. {
  112. // 根据用户id获取用户权限
  113. $token = getCurrentInfo();
  114. // 用户权限缓存
  115. $userAuthCache = new UserInfoCache($token['id']);
  116. $user_info = $userAuthCache->getUserInfo();
  117. $currentUserRoleList = $user_info['roleList'];
  118. $currentUserRoleList = array_column($currentUserRoleList, 'id');
  119. // 管理员角色ID:1, 则不限制权限
  120. if(in_array(1,$currentUserRoleList)){
  121. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->select()->toArray();
  122. $deptList = SystemDept::where('1=1')->select()->toArray();
  123. }else{
  124. // 看公司的广告数据权限
  125. if($user_info['ad_permission'] == 1){
  126. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->select()->toArray();
  127. $deptList = SystemDept::where('1=1')->select()->toArray();
  128. }
  129. if($user_info['ad_permission'] == 2){
  130. // 看自己以及组员
  131. // 1. 查看自己是哪个组
  132. $deptId = $user_info['dept_id'];
  133. // 2. 查看组员
  134. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->where('dept_id',$deptId)->select()->toArray();
  135. $deptList = SystemDept::where('id',$deptId)->select()->toArray();
  136. }
  137. if($user_info['ad_permission'] == 0){
  138. // 仅看自己
  139. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->where('id',$user_info['id'])->select()->toArray();
  140. $deptList = SystemDept::where('id',$user_info['dept_id'])->select()->toArray();
  141. }
  142. }
  143. $result = [];
  144. // 将部门列表转为以id为key的数组,便于查找
  145. $deptMap = [];
  146. foreach ($deptList as $dept) {
  147. $dept['children'] = [];
  148. $dept['users'] = [];
  149. $deptMap[$dept['id']] = $dept;
  150. }
  151. // 将用户分配到对应部门的users中
  152. foreach ($data as $user) {
  153. if (isset($deptMap[$user['dept_id']])) {
  154. $deptMap[$user['dept_id']]['users'][] = [
  155. 'id' => $user['value'],
  156. 'name' => $user['label'],
  157. ];
  158. }
  159. }
  160. // 构建部门树
  161. $tree = [];
  162. foreach ($deptMap as $id => &$dept) {
  163. if ($dept['parent_id'] && isset($deptMap[$dept['parent_id']])) {
  164. $deptMap[$dept['parent_id']]['children'][] = &$dept;
  165. } else {
  166. $tree[] = &$dept;
  167. }
  168. }
  169. unset($dept);
  170. // 递归格式化输出
  171. $result = $this->formatDeptTree($tree);
  172. return $this->success($result);
  173. }
  174. public function formatDeptTree($depts) {
  175. $result = [];
  176. foreach ($depts as $dept) {
  177. $item = [
  178. 'id' => 'dept_id_'.$dept['id'],
  179. 'name' => $dept['name'],
  180. ];
  181. // 先加用户
  182. if (!empty($dept['users'])) {
  183. $item['children'] = $dept['users'];
  184. }
  185. // 再加子部门
  186. if (!empty($dept['children'])) {
  187. $children = $this->formatDeptTree($dept['children']);
  188. if (!empty($item['children'])) {
  189. $item['children'] = array_merge($item['children'], $children);
  190. } else {
  191. $item['children'] = $children;
  192. }
  193. }
  194. $result[] = $item;
  195. }
  196. return $result;
  197. }
  198. /**
  199. * 设计归属人列表Options
  200. */
  201. public function getDesignAuthOptions(Request $request): Response
  202. {
  203. $data = $this->systemUserLogic
  204. ->field('sa_system_user.id as "value", sa_system_user.username as label')
  205. ->leftJoin('sa_system_user_role', 'sa_system_user_role.user_id = sa_system_user.id')
  206. ->leftJoin('sa_system_role', 'sa_system_role.id = sa_system_user_role.role_id')
  207. ->whereOr('sa_system_role.code', 'designLeader')
  208. ->whereOr('sa_system_role.code', 'design')
  209. ->where('sa_system_role.status', 1);
  210. $data = $data->select()
  211. ->toArray();
  212. return $this->success($data);
  213. }
  214. /**
  215. * 获取母包列表Options
  216. */
  217. public function getPackageOptions(Request $request): Response
  218. {
  219. $where = $request->get();
  220. $data = $this->gamePackageLogic->getPackageOptions($where);
  221. return $this->success($data);
  222. }
  223. /**
  224. * 获取广告位options
  225. */
  226. public function getAgentSiteOptions(Request $request): Response
  227. {
  228. $data = $this->agentSiteLogic->getAgentSiteOptions();
  229. return $this->success($data);
  230. }
  231. /**
  232. * 获取充值渠道
  233. */
  234. public function getPayChannelOptions(Request $request): Response
  235. {
  236. $data = Db::connect('db_center')->table('pay_channel')->where('status',1)->select()->toArray();
  237. return $this->success($data);
  238. }
  239. /**
  240. * 给游戏分组用的游戏列表
  241. */
  242. public function getGameListOptionsByGroup(Request $request): Response
  243. {
  244. $where = $request->more([
  245. ['game_group_id', '']
  246. ]);
  247. $data = $this->gameGroupLogic->getGameListOptionsByGroup($where);
  248. return $this->success($data);
  249. }
  250. /**
  251. * 获取游戏根据部门ID, 返回根据分组后的游戏列表
  252. */
  253. public function getGameListOptionsByDeptId(Request $request): Response
  254. {
  255. $where = $request->more([
  256. ['dept_id', '']
  257. ]);
  258. $data = $this->gameGroupLogic->getGameListOptionsByDeptId($where);
  259. return $this->success($data);
  260. }
  261. /**
  262. * 获取产品ID, 获取游戏列表
  263. */
  264. public function getAllGameOptions(): Response
  265. {
  266. $data = $this->gameLogic->getAllGameOptions();
  267. return $this->success($data);
  268. }
  269. /**
  270. * 获取系统配置
  271. * group_code: 配置组标识
  272. * key: 配置key
  273. * @param Request $request
  274. * @return Response
  275. */
  276. public function getSystemConfig(Request $request): Response
  277. {
  278. $where = $request->more([
  279. ['group_code', ''],
  280. ['key', '']
  281. ]);
  282. $data = $this->systemConfigLogic->getSystemConfig($where);
  283. return $this->success($data);
  284. }
  285. }