CommonController.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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'] == 2){
  126. // 看自己以及组员
  127. // 1. 查看自己是哪个组
  128. $deptId = $user_info['dept_id'];
  129. // 2. 查看组员
  130. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->where('dept_id',$deptId)->select()->toArray();
  131. $deptList = SystemDept::where('id',$deptId)->select()->toArray();
  132. }
  133. if($user_info['ad_permission'] == 1){
  134. // 仅看自己
  135. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->where('id',$user_info['id'])->select()->toArray();
  136. $deptList = SystemDept::where('id',$user_info['dept_id'])->select()->toArray();
  137. }
  138. }
  139. $result = [];
  140. // 将部门列表转为以id为key的数组,便于查找
  141. $deptMap = [];
  142. foreach ($deptList as $dept) {
  143. $dept['children'] = [];
  144. $dept['users'] = [];
  145. $deptMap[$dept['id']] = $dept;
  146. }
  147. // 将用户分配到对应部门的users中
  148. foreach ($data as $user) {
  149. if (isset($deptMap[$user['dept_id']])) {
  150. $deptMap[$user['dept_id']]['users'][] = [
  151. 'id' => $user['value'],
  152. 'name' => $user['label'],
  153. ];
  154. }
  155. }
  156. // 构建部门树
  157. $tree = [];
  158. foreach ($deptMap as $id => &$dept) {
  159. if ($dept['parent_id'] && isset($deptMap[$dept['parent_id']])) {
  160. $deptMap[$dept['parent_id']]['children'][] = &$dept;
  161. } else {
  162. $tree[] = &$dept;
  163. }
  164. }
  165. unset($dept);
  166. // 递归格式化输出
  167. $result = $this->formatDeptTree($tree);
  168. return $this->success($result);
  169. }
  170. public function formatDeptTree($depts) {
  171. $result = [];
  172. foreach ($depts as $dept) {
  173. $item = [
  174. 'id' => 'dept_id_'.$dept['id'],
  175. 'name' => $dept['name'],
  176. ];
  177. // 先加用户
  178. if (!empty($dept['users'])) {
  179. $item['children'] = $dept['users'];
  180. }
  181. // 再加子部门
  182. if (!empty($dept['children'])) {
  183. $children = $this->formatDeptTree($dept['children']);
  184. if (!empty($item['children'])) {
  185. $item['children'] = array_merge($item['children'], $children);
  186. } else {
  187. $item['children'] = $children;
  188. }
  189. }
  190. $result[] = $item;
  191. }
  192. return $result;
  193. }
  194. /**
  195. * 设计归属人列表Options
  196. */
  197. public function getDesignAuthOptions(Request $request): Response
  198. {
  199. $data = $this->systemUserLogic
  200. ->field('sa_system_user.id as "value", sa_system_user.username as label')
  201. ->leftJoin('sa_system_user_role', 'sa_system_user_role.user_id = sa_system_user.id')
  202. ->leftJoin('sa_system_role', 'sa_system_role.id = sa_system_user_role.role_id')
  203. ->whereOr('sa_system_role.code', 'designLeader')
  204. ->whereOr('sa_system_role.code', 'design')
  205. ->where('sa_system_role.status', 1);
  206. $data = $data->select()
  207. ->toArray();
  208. return $this->success($data);
  209. }
  210. /**
  211. * 获取母包列表Options
  212. */
  213. public function getPackageOptions(Request $request): Response
  214. {
  215. $where = $request->get();
  216. $data = $this->gamePackageLogic->getPackageOptions($where);
  217. return $this->success($data);
  218. }
  219. /**
  220. * 获取广告位options
  221. */
  222. public function getAgentSiteOptions(Request $request): Response
  223. {
  224. $data = $this->agentSiteLogic->getAgentSiteOptions();
  225. return $this->success($data);
  226. }
  227. /**
  228. * 获取充值渠道
  229. */
  230. public function getPayChannelOptions(Request $request): Response
  231. {
  232. $data = Db::connect('db_center')->table('pay_channel')->where('status',1)->select()->toArray();
  233. return $this->success($data);
  234. }
  235. /**
  236. * 给游戏分组用的游戏列表
  237. */
  238. public function getGameListOptionsByGroup(Request $request): Response
  239. {
  240. $where = $request->more([
  241. ['game_group_id', '']
  242. ]);
  243. $data = $this->gameGroupLogic->getGameListOptionsByGroup($where);
  244. return $this->success($data);
  245. }
  246. /**
  247. * 获取游戏根据部门ID, 返回根据分组后的游戏列表
  248. */
  249. public function getGameListOptionsByDeptId(Request $request): Response
  250. {
  251. $where = $request->more([
  252. ['dept_id', '']
  253. ]);
  254. $data = $this->gameGroupLogic->getGameListOptionsByDeptId($where);
  255. return $this->success($data);
  256. }
  257. /**
  258. * 获取产品ID, 获取游戏列表
  259. */
  260. public function getAllGameOptions(): Response
  261. {
  262. $data = $this->gameLogic->getAllGameOptions();
  263. return $this->success($data);
  264. }
  265. /**
  266. * 获取系统配置
  267. * group_code: 配置组标识
  268. * key: 配置key
  269. * @param Request $request
  270. * @return Response
  271. */
  272. public function getSystemConfig(Request $request): Response
  273. {
  274. $where = $request->more([
  275. ['group_code', ''],
  276. ['key', '']
  277. ]);
  278. $data = $this->systemConfigLogic->getSystemConfig($where);
  279. return $this->success($data);
  280. }
  281. }