企微短剧业务系统

AdminController.php 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. /**
  3. * Created by:PhpStorm
  4. * Author:chenzhiyuan
  5. * Date: 2022/4/19
  6. * Time: 11:32 上午
  7. */
  8. namespace App\Http\Controllers\Api\Admin;
  9. use App\Http\Controllers\Controller;
  10. use App\Models\System\Users;
  11. use App\Service\Admin\AdminService;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Validation\Rule;
  14. /**
  15. * 系统管理员管理相关
  16. * Class AdminController
  17. * @package App\Http\Controllers\Api\Admin
  18. */
  19. class AdminController extends Controller
  20. {
  21. /**
  22. * 角色列表(添加管理员时使用)
  23. * @return array
  24. */
  25. public function role_list(Request $request)
  26. {
  27. $admin_id = $request->input('admin_id');
  28. $sys_group_id = $request->input('sys_group_id');
  29. $is_system_admin = $request->input('is_system_admin');
  30. $errno = 0;
  31. $res = AdminService::all_role_list($admin_id,$sys_group_id,$is_system_admin, $errno);
  32. return self::returnValue($res,$errno);
  33. }
  34. /**
  35. * 主体列表
  36. * @param Request $request
  37. * @return array
  38. */
  39. public function corp_list(Request $request){
  40. $group_admin_id = $request->input("group_admin_id",0);
  41. $admin_id = $request->input("admin_id",0);
  42. $is_system_admin = $request->input("is_system_admin");
  43. $corp_list = AdminService::corp_list($group_admin_id,$admin_id,$is_system_admin);
  44. return self::returnValue($corp_list,0);
  45. }
  46. /**
  47. * 创建管理员
  48. * @param Request $request
  49. */
  50. public function create_admin(Request $request){
  51. $support_view_type = AdminService::VIEW_TYPE;
  52. $validator = \Validator::make($request->all(),[
  53. 'name' => 'required',
  54. 'password' => 'required',
  55. // 'view_type' => Rule::in($support_view_type),
  56. ]);
  57. if ($validator->fails()) {
  58. return self::returnValue($validator->getMessageBag(), 1102);
  59. }
  60. $view_type = $support_view_type[0];
  61. $name = trim($request->input("name"));
  62. $password = $request->input("password");
  63. $role_id = $request->input("role_id");
  64. $corp_id = $request->input("corp_id");
  65. $is_promoter = $request->input("is_promoter", 0);
  66. $is_all_adq = $request->input("is_all_adq", 0);
  67. $adq_account = $request->input("adq_account");
  68. $is_all_mp = $request->input("is_all_mp", 0);
  69. $mp_account = $request->input("mp_account");
  70. $can_export = $request->input("can_export", 0);
  71. $group_admin_id = $request->input("group_admin_id",0);
  72. if(strlen($password)<6 || strlen($password)>18){
  73. return self::returnValue([],4405); //密码不符合要求
  74. }
  75. /**系统管理员创建账号时,为新建分组**/
  76. $is_new_group = $request->input("is_system_admin") == Users::SYSTEM_ADMIN ? 1 : 0;
  77. $ret_code = AdminService::admin_create(
  78. $view_type,$group_admin_id,$name,$password,$role_id,$corp_id,$is_new_group, $is_promoter,
  79. $is_all_adq, $adq_account, $is_all_mp, $mp_account, $can_export
  80. );
  81. return self::returnValue([],$ret_code);
  82. }
  83. /**
  84. * 编辑管理员
  85. * @param Request $request
  86. */
  87. public function edit_admin(Request $request){
  88. $support_view_type = AdminService::VIEW_TYPE;
  89. $validator = \Validator::make($request->all(),[
  90. 'id' => 'required|integer',
  91. // 'is_super_admin' => 'required|integer',
  92. // 'view_type' => Rule::in($support_view_type),
  93. ]);
  94. if ($validator->fails()) {
  95. return self::returnValue($validator->getMessageBag(), 1102);
  96. }
  97. $view_type = $support_view_type[0];
  98. $sys_user_id = $request->input("id");
  99. $password = $request->input("password",'');
  100. $role_id = $request->input("role_id");
  101. $corp_id = $request->input("corp_id");
  102. $is_promoter = $request->input("is_promoter", 0);
  103. $is_all_adq = $request->input("is_all_adq", 0);
  104. $adq_account = $request->input("adq_account");
  105. $is_all_mp = $request->input("is_all_mp", 0);
  106. $mp_account = $request->input("mp_account");
  107. $can_export = $request->input("can_export", 0);
  108. $group_admin_id = $request->input("group_admin_id",0);
  109. if(empty($password)==false && (strlen($password)<6 || strlen($password)>18)){
  110. return self::returnValue([],4405); //密码不符合要求
  111. }
  112. $ret_code = AdminService::admin_edit(
  113. $view_type,$group_admin_id,$sys_user_id,$password,$role_id,$corp_id, $is_promoter,
  114. $is_all_adq, $adq_account, $is_all_mp, $mp_account, $can_export
  115. );
  116. return self::returnValue([],$ret_code);
  117. }
  118. /**
  119. * 删除管理员
  120. * @param Request $request
  121. */
  122. public function delete_admin(Request $request)
  123. {
  124. $validator = \Validator::make($request->all(),[
  125. 'id' => 'required|integer',
  126. ]);
  127. if ($validator->fails()) {
  128. return self::returnValue($validator->getMessageBag(), 1102);
  129. }
  130. $sys_user_id = $request->input("id");
  131. $admin_id = $request->input("admin_id");
  132. $group_admin_id = $request->input("group_admin_id",0);
  133. $sys_group_id = $request->input("sys_group_id");
  134. $is_system_admin = $request->input("is_system_admin",0);
  135. if($sys_user_id==$admin_id){
  136. return self::returnValue([],4407); //不能删除自己账号
  137. }
  138. $ret_code = AdminService::admin_del($is_system_admin,$group_admin_id,$sys_user_id,$sys_group_id, $admin_id);
  139. return self::returnValue([],$ret_code);
  140. }
  141. /**
  142. * 管理员列表
  143. * @param Request $request
  144. */
  145. public function admin_list(Request $request){
  146. $support_view_type = AdminService::VIEW_TYPE;
  147. $view_type = $support_view_type[0];
  148. $admin_id = $request->input("admin_id");
  149. $sys_group_id = $request->input("sys_group_id");
  150. $page = $request->input("page",1);
  151. $page_size = $request->input("page_size",20);
  152. $group_admin_id = $request->input("group_admin_id",0);
  153. $is_system_admin= $request->input("is_system_admin",0);
  154. $errno = 0;
  155. list($total,$list) = AdminService::admin_list($view_type,$is_system_admin,$admin_id,$sys_group_id,$group_admin_id,$page,$page_size, $errno);
  156. if($errno) return self::returnValue([], $errno);
  157. return self::returnPageValue($list,$total,$page_size,$page);
  158. }
  159. /**
  160. * 管理员详情
  161. * @param Request $request
  162. * @return array
  163. */
  164. public function admin_info(Request $request){
  165. $support_view_type = AdminService::VIEW_TYPE;
  166. $validator = \Validator::make($request->all(),[
  167. 'id' => 'required|integer',
  168. ]);
  169. if ($validator->fails()) {
  170. return self::returnValue($validator->getMessageBag(), 1102);
  171. }
  172. $view_type = $support_view_type[0];
  173. $sys_user_id = $request->input("id");
  174. $group_admin_id = $request->input("group_admin_id",0);
  175. $is_system_id = $request->input("is_system_admin",0);
  176. $res = AdminService::admin_info($view_type,$is_system_id,$group_admin_id,$sys_user_id);
  177. if(is_numeric($res)){
  178. return self::returnValue([],$res);
  179. }else{
  180. return self::returnValue($res);
  181. }
  182. }
  183. /**
  184. * 管理的账号组列表
  185. * @param Request $request
  186. */
  187. public function accountGroupList(Request $request){
  188. $group_admin_id = $request->input("group_admin_id");
  189. $is_system_admin = $request->input("is_system_admin");
  190. /**目前仅开放系统管理员查看**/
  191. if($is_system_admin != Users::SYSTEM_ADMIN){
  192. return self::returnValue([],4406); //非系统管理员不能管理账号组
  193. }
  194. $res = AdminService::manage_account_group_list($group_admin_id,$is_system_admin);
  195. return self::returnValue($res,0);
  196. }
  197. # 获取企微已绑定成员
  198. public function getCorpBindUserList(Request $request) {
  199. $validator = \Validator::make($request->all(),[
  200. 'id' => 'required|integer',
  201. ]);
  202. if ($validator->fails()) {
  203. return self::returnValue($validator->getMessageBag(), 1102);
  204. }
  205. $corpId = $request->input('id');
  206. $supportViewType = AdminService::VIEW_TYPE;
  207. $viewType = $supportViewType[0];
  208. $groupAdminId = $request->input("group_admin_id",0);
  209. $isSystemAdmin= $request->input("is_system_admin",0);
  210. $list = AdminService::getCorpBindUserList($corpId, $viewType, $groupAdminId, $isSystemAdmin);
  211. return self::returnValue($list);
  212. }
  213. # 为企微分配成员
  214. public function corpBindMultipleUser(Request $request) {
  215. $validator = \Validator::make($request->all(),[
  216. 'id' => 'required|integer',
  217. 'user_id_list' => 'required',
  218. ]);
  219. if ($validator->fails()) {
  220. return self::returnValue($validator->getMessageBag(), 1102);
  221. }
  222. $corpId = $request->input('id');
  223. $userIdList = $request->input('user_id_list');
  224. $userIdList = json_decode($userIdList);
  225. $supportViewType = AdminService::VIEW_TYPE;
  226. $viewType = $supportViewType[0];
  227. list($res, $code) = AdminService::corpBindMultipleUser($corpId, $userIdList, $viewType);
  228. return self::returnValue($res, $code);
  229. }
  230. }