CommonController.php 9.9 KB

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