CommonController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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')->select()->toArray();
  115. $deptList = SystemDept::where('1=1')->select()->toArray();
  116. }else{
  117. // 看公司的广告数据权限
  118. if($user_info['ad_permission'] == 1){
  119. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->select()->toArray();
  120. $deptList = SystemDept::where('1=1')->select()->toArray();
  121. }
  122. if($user_info['ad_permission'] == 2){
  123. // 看自己以及组员
  124. // 1. 查看自己是哪个组
  125. $deptId = $user_info['dept_id'];
  126. // 2. 查看组员
  127. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->where('dept_id',$deptId)->select()->toArray();
  128. $deptList = SystemDept::where('id',$deptId)->select()->toArray();
  129. }
  130. if($user_info['ad_permission'] == 0){
  131. // 仅看自己
  132. $data = $this->systemUserLogic->field('id as value, username as label,dept_id')->where('id',$user_info['id'])->select()->toArray();
  133. $deptList = SystemDept::where('id',$user_info['dept_id'])->select()->toArray();
  134. }
  135. }
  136. $result = [];
  137. // 将部门列表转为以id为key的数组,便于查找
  138. $deptMap = [];
  139. foreach ($deptList as $dept) {
  140. $dept['children'] = [];
  141. $dept['users'] = [];
  142. $deptMap[$dept['id']] = $dept;
  143. }
  144. // 将用户分配到对应部门的users中
  145. foreach ($data as $user) {
  146. if (isset($deptMap[$user['dept_id']])) {
  147. $deptMap[$user['dept_id']]['users'][] = [
  148. 'id' => $user['value'],
  149. 'name' => $user['label'],
  150. ];
  151. }
  152. }
  153. // 构建部门树
  154. $tree = [];
  155. foreach ($deptMap as $id => &$dept) {
  156. if ($dept['parent_id'] && isset($deptMap[$dept['parent_id']])) {
  157. $deptMap[$dept['parent_id']]['children'][] = &$dept;
  158. } else {
  159. $tree[] = &$dept;
  160. }
  161. }
  162. unset($dept);
  163. // 递归格式化输出
  164. $result = $this->formatDeptTree($tree);
  165. return $this->success($result);
  166. }
  167. public function formatDeptTree($depts) {
  168. $result = [];
  169. foreach ($depts as $dept) {
  170. $item = [
  171. 'id' => 'dept_id_'.$dept['id'],
  172. 'name' => $dept['name'],
  173. ];
  174. // 先加用户
  175. if (!empty($dept['users'])) {
  176. $item['children'] = $dept['users'];
  177. }
  178. // 再加子部门
  179. if (!empty($dept['children'])) {
  180. $children = $this->formatDeptTree($dept['children']);
  181. if (!empty($item['children'])) {
  182. $item['children'] = array_merge($item['children'], $children);
  183. } else {
  184. $item['children'] = $children;
  185. }
  186. }
  187. $result[] = $item;
  188. }
  189. return $result;
  190. }
  191. /**
  192. * 设计归属人列表Options
  193. */
  194. public function getDesignAuthOptions(Request $request): Response
  195. {
  196. $data = $this->systemUserLogic->field('id as value, username as label')->where('dept_id',11)->select()->toArray();
  197. return $this->success($data);
  198. }
  199. /**
  200. * 获取母包列表Options
  201. */
  202. public function getPackageOptions(Request $request): Response
  203. {
  204. $where = $request->get();
  205. $data = $this->gamePackageLogic->getPackageOptions($where);
  206. return $this->success($data);
  207. }
  208. /**
  209. * 获取广告位options
  210. */
  211. public function getAgentSiteOptions(Request $request): Response
  212. {
  213. $data = $this->agentSiteLogic->getAgentSiteOptions();
  214. return $this->success($data);
  215. }
  216. /**
  217. * 获取充值渠道
  218. */
  219. public function getPayChannelOptions(Request $request): Response
  220. {
  221. $data = Db::connect('db_center')->table('pay_channel')->where('status',1)->select()->toArray();
  222. return $this->success($data);
  223. }
  224. /**
  225. * 给游戏分组用的游戏列表
  226. */
  227. public function getGameListOptionsByGroup(Request $request): Response
  228. {
  229. $where = $request->more([
  230. ['game_group_id', '']
  231. ]);
  232. $data = $this->gameGroupLogic->getGameListOptionsByGroup($where);
  233. return $this->success($data);
  234. }
  235. /**
  236. * 获取游戏根据部门ID, 返回根据分组后的游戏列表
  237. */
  238. public function getGameListOptionsByDeptId(Request $request): Response
  239. {
  240. $where = $request->more([
  241. ['dept_id', '']
  242. ]);
  243. $data = $this->gameGroupLogic->getGameListOptionsByDeptId($where);
  244. return $this->success($data);
  245. }
  246. }