CommonController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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\SystemUserLogic;
  13. use plugin\saiadmin\app\model\system\SystemDept;
  14. use support\Request;
  15. use support\Response;
  16. use support\think\Db;
  17. /**
  18. * 公共接口管理控制器
  19. */
  20. class CommonController extends BaseController
  21. {
  22. protected $gameMainLogic;
  23. protected $gameLogic;
  24. protected $mediaListLogic;
  25. protected $agentListLogic;
  26. protected $systemUserLogic;
  27. protected $gamePackageLogic;
  28. protected $agentSiteLogic;
  29. protected $gameGroupLogic;
  30. /**
  31. * 构造函数
  32. */
  33. public function __construct()
  34. {
  35. parent::__construct();
  36. $this->gameMainLogic = new GameMainLogic();
  37. $this->gameLogic = new GameLogic();
  38. $this->mediaListLogic = new MediaListLogic();
  39. $this->agentListLogic = new AgentListLogic();
  40. $this->systemUserLogic = new SystemUserLogic();
  41. $this->gamePackageLogic = new GamePackageLogic();
  42. $this->agentSiteLogic = new AgentSiteLogic();
  43. $this->gameGroupLogic = new GameGroupLogic();
  44. }
  45. // /**
  46. // * 按照权限获取游戏信息,通过游戏分组
  47. // */
  48. // public function getGameListOptions(Request $request): Response
  49. // {
  50. // $where = $request->get();
  51. // $data = $this->gameGroupLogic->getGameListOptions($where);
  52. // return $this->success($data);
  53. // }
  54. /**
  55. * 获取主游戏options列表
  56. * @return Response
  57. */
  58. public function getMainGameOptions(Request $request): Response
  59. {
  60. $data = $this->gameMainLogic->getMainGameOptions();
  61. return $this->success($data);
  62. }
  63. /**
  64. * 获取子游戏options列表(有权限)
  65. * @return Response
  66. */
  67. public function getGameOptions(Request $request): Response
  68. {
  69. $where = $request->get();
  70. $data = $this->gameLogic->getGameOptions($where);
  71. return $this->success($data);
  72. }
  73. /**
  74. * 获取子游戏options列表(无权限)
  75. * @return Response
  76. */
  77. public function getGameOptionsNoAuth(Request $request): Response
  78. {
  79. $where = $request->get();
  80. $data = $this->gameLogic->getGameOptionsNoAuth($where);
  81. return $this->success($data);
  82. }
  83. /**
  84. * 查询媒体列表Options
  85. */
  86. public function getMediaOptions(Request $request): Response
  87. {
  88. $data = $this->mediaListLogic->getMediaOptions();
  89. $data = $data->toArray();
  90. return $this->success($data);
  91. }
  92. /**
  93. * 查询渠道列表Options
  94. */
  95. public function getAgentOptions(Request $request): Response
  96. {
  97. $data = $this->agentListLogic->getAgentOptions();
  98. return $this->success($data);
  99. }
  100. /**
  101. * 后台归属人列表Options
  102. */
  103. public function getAuthOptions(Request $request): Response
  104. {
  105. // 根据用户id获取用户权限
  106. $token = getCurrentInfo();
  107. // 用户权限缓存
  108. $userAuthCache = new UserInfoCache($token['id']);
  109. $user_info = $userAuthCache->getUserInfo();
  110. $currentUserRoleList = $user_info['roleList'];
  111. $currentUserRoleList = array_column($currentUserRoleList, 'id');
  112. // 管理员角色ID:1, 则不限制权限
  113. if(in_array(1,$currentUserRoleList)){
  114. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->group('dept_id')->select()->toArray();
  115. $deptList = SystemDept::where('1=1')->select()->toArray();
  116. }else{
  117. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->where('id',$user_info['id'])->group('dept_id')->select()->toArray();
  118. $deptList = SystemDept::where('id',$user_info['dept_id'])->select()->toArray();
  119. }
  120. $result = [];
  121. // 将部门列表转为以id为key的数组,便于查找
  122. $deptMap = [];
  123. foreach ($deptList as $dept) {
  124. $dept['children'] = [];
  125. $dept['users'] = [];
  126. $deptMap[$dept['id']] = $dept;
  127. }
  128. // 将用户分配到对应部门的users中
  129. foreach ($data as $user) {
  130. if (isset($deptMap[$user['dept_id']])) {
  131. $deptMap[$user['dept_id']]['users'][] = [
  132. 'id' => $user['value'],
  133. 'name' => $user['label'],
  134. ];
  135. }
  136. }
  137. // 构建部门树
  138. $tree = [];
  139. foreach ($deptMap as $id => &$dept) {
  140. if ($dept['parent_id'] && isset($deptMap[$dept['parent_id']])) {
  141. $deptMap[$dept['parent_id']]['children'][] = &$dept;
  142. } else {
  143. $tree[] = &$dept;
  144. }
  145. }
  146. unset($dept);
  147. // 递归格式化输出
  148. $result = $this->formatDeptTree($tree);
  149. return $this->success($result);
  150. }
  151. public function formatDeptTree($depts) {
  152. $result = [];
  153. foreach ($depts as $dept) {
  154. $item = [
  155. 'id' => 'dept_id_'.$dept['id'],
  156. 'name' => $dept['name'],
  157. ];
  158. // 先加用户
  159. if (!empty($dept['users'])) {
  160. $item['children'] = $dept['users'];
  161. }
  162. // 再加子部门
  163. if (!empty($dept['children'])) {
  164. $children = $this->formatDeptTree($dept['children']);
  165. if (!empty($item['children'])) {
  166. $item['children'] = array_merge($item['children'], $children);
  167. } else {
  168. $item['children'] = $children;
  169. }
  170. }
  171. $result[] = $item;
  172. }
  173. return $result;
  174. }
  175. /**
  176. * 设计归属人列表Options
  177. */
  178. public function getDesignAuthOptions(Request $request): Response
  179. {
  180. $data = $this->systemUserLogic->field('id as value, username as label')->where('dept_id',11)->select()->toArray();
  181. return $this->success($data);
  182. }
  183. /**
  184. * 获取母包列表Options
  185. */
  186. public function getPackageOptions(Request $request): Response
  187. {
  188. $where = $request->get();
  189. $data = $this->gamePackageLogic->getPackageOptions($where);
  190. return $this->success($data);
  191. }
  192. /**
  193. * 获取广告位options
  194. */
  195. public function getAgentSiteOptions(Request $request): Response
  196. {
  197. $data = $this->agentSiteLogic->getAgentSiteOptions();
  198. return $this->success($data);
  199. }
  200. /**
  201. * 获取充值渠道
  202. */
  203. public function getPayChannelOptions(Request $request): Response
  204. {
  205. $data = Db::connect('db_center')->table('pay_channel')->where('status',1)->select()->toArray();
  206. return $this->success($data);
  207. }
  208. /**
  209. * 给游戏分组用的游戏列表
  210. */
  211. public function getGameListOptionsByGroup(Request $request): Response
  212. {
  213. $where = $request->more([
  214. ['game_group_id', '']
  215. ]);
  216. $data = $this->gameGroupLogic->getGameListOptionsByGroup($where);
  217. return $this->success($data);
  218. }
  219. }