CommonController.php 6.7 KB

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