123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <?php
- /**
- * Created by:PhpStorm
- * Author:chenzhiyuan
- * Date: 2022/4/19
- * Time: 11:32 上午
- */
- namespace App\Http\Controllers\Api\Admin;
- use App\Http\Controllers\Controller;
- use App\Models\System\Users;
- use App\Service\Admin\AdminService;
- use Illuminate\Http\Request;
- use Illuminate\Validation\Rule;
- /**
- * 系统管理员管理相关
- * Class AdminController
- * @package App\Http\Controllers\Api\Admin
- */
- class AdminController extends Controller
- {
- /**
- * 角色列表(添加管理员时使用)
- * @return array
- */
- public function role_list(Request $request)
- {
- $admin_id = $request->input('admin_id');
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input('is_system_admin');
- $errno = 0;
- $res = AdminService::all_role_list($admin_id,$sys_group_id,$is_system_admin, $errno);
- return self::returnValue($res,$errno);
- }
- /**
- * 主体列表
- * @param Request $request
- * @return array
- */
- public function corp_list(Request $request){
- $group_admin_id = $request->input("group_admin_id",0);
- $admin_id = $request->input("admin_id",0);
- $is_system_admin = $request->input("is_system_admin");
- $corp_list = AdminService::corp_list($group_admin_id,$admin_id,$is_system_admin);
- return self::returnValue($corp_list,0);
- }
- /**
- * 创建管理员
- * @param Request $request
- */
- public function create_admin(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'name' => 'required',
- 'password' => 'required',
- // 'view_type' => Rule::in($support_view_type),
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $support_view_type[0];
- $name = trim($request->input("name"));
- $password = $request->input("password");
- $role_id = $request->input("role_id");
- $corp_id = $request->input("corp_id");
- $is_promoter = $request->input("is_promoter", 0);
- $is_all_adq = $request->input("is_all_adq", 0);
- $adq_account = $request->input("adq_account");
- $is_all_mp = $request->input("is_all_mp", 0);
- $mp_account = $request->input("mp_account");
- $can_export = $request->input("can_export", 0);
- $group_admin_id = $request->input("group_admin_id",0);
- if(strlen($password)<6 || strlen($password)>18){
- return self::returnValue([],4405); //密码不符合要求
- }
- /**系统管理员创建账号时,为新建分组**/
- $is_new_group = $request->input("is_system_admin") == Users::SYSTEM_ADMIN ? 1 : 0;
- $ret_code = AdminService::admin_create(
- $view_type,$group_admin_id,$name,$password,$role_id,$corp_id,$is_new_group, $is_promoter,
- $is_all_adq, $adq_account, $is_all_mp, $mp_account, $can_export
- );
- return self::returnValue([],$ret_code);
- }
- /**
- * 编辑管理员
- * @param Request $request
- */
- public function edit_admin(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'id' => 'required|integer',
- // 'is_super_admin' => 'required|integer',
- // 'view_type' => Rule::in($support_view_type),
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $support_view_type[0];
- $sys_user_id = $request->input("id");
- $password = $request->input("password",'');
- $role_id = $request->input("role_id");
- $corp_id = $request->input("corp_id");
- $is_promoter = $request->input("is_promoter", 0);
- $is_all_adq = $request->input("is_all_adq", 0);
- $adq_account = $request->input("adq_account");
- $is_all_mp = $request->input("is_all_mp", 0);
- $mp_account = $request->input("mp_account");
- $can_export = $request->input("can_export", 0);
- $group_admin_id = $request->input("group_admin_id",0);
- if(empty($password)==false && (strlen($password)<6 || strlen($password)>18)){
- return self::returnValue([],4405); //密码不符合要求
- }
- $ret_code = AdminService::admin_edit(
- $view_type,$group_admin_id,$sys_user_id,$password,$role_id,$corp_id, $is_promoter,
- $is_all_adq, $adq_account, $is_all_mp, $mp_account, $can_export
- );
- return self::returnValue([],$ret_code);
- }
- /**
- * 删除管理员
- * @param Request $request
- */
- public function delete_admin(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $sys_user_id = $request->input("id");
- $admin_id = $request->input("admin_id");
- $group_admin_id = $request->input("group_admin_id",0);
- $sys_group_id = $request->input("sys_group_id");
- $is_system_admin = $request->input("is_system_admin",0);
- if($sys_user_id==$admin_id){
- return self::returnValue([],4407); //不能删除自己账号
- }
- $ret_code = AdminService::admin_del($is_system_admin,$group_admin_id,$sys_user_id,$sys_group_id, $admin_id);
- return self::returnValue([],$ret_code);
- }
- /**
- * 管理员列表
- * @param Request $request
- */
- public function admin_list(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $view_type = $support_view_type[0];
- $admin_id = $request->input("admin_id");
- $sys_group_id = $request->input("sys_group_id");
- $page = $request->input("page",1);
- $page_size = $request->input("page_size",20);
- $group_admin_id = $request->input("group_admin_id",0);
- $is_system_admin= $request->input("is_system_admin",0);
- $errno = 0;
- list($total,$list) = AdminService::admin_list($view_type,$is_system_admin,$admin_id,$sys_group_id,$group_admin_id,$page,$page_size, $errno);
- if($errno) return self::returnValue([], $errno);
- return self::returnPageValue($list,$total,$page_size,$page);
- }
- /**
- * 管理员详情
- * @param Request $request
- * @return array
- */
- public function admin_info(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $support_view_type[0];
- $sys_user_id = $request->input("id");
- $group_admin_id = $request->input("group_admin_id",0);
- $is_system_id = $request->input("is_system_admin",0);
- $res = AdminService::admin_info($view_type,$is_system_id,$group_admin_id,$sys_user_id);
- if(is_numeric($res)){
- return self::returnValue([],$res);
- }else{
- return self::returnValue($res);
- }
- }
- /**
- * 管理的账号组列表
- * @param Request $request
- */
- public function accountGroupList(Request $request){
- $group_admin_id = $request->input("group_admin_id");
- $is_system_admin = $request->input("is_system_admin");
- /**目前仅开放系统管理员查看**/
- if($is_system_admin != Users::SYSTEM_ADMIN){
- return self::returnValue([],4406); //非系统管理员不能管理账号组
- }
- $res = AdminService::manage_account_group_list($group_admin_id,$is_system_admin);
- return self::returnValue($res,0);
- }
- # 获取企微已绑定成员
- public function getCorpBindUserList(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpId = $request->input('id');
- $supportViewType = AdminService::VIEW_TYPE;
- $viewType = $supportViewType[0];
- $groupAdminId = $request->input("group_admin_id",0);
- $isSystemAdmin= $request->input("is_system_admin",0);
- $list = AdminService::getCorpBindUserList($corpId, $viewType, $groupAdminId, $isSystemAdmin);
- return self::returnValue($list);
- }
- # 为企微分配成员
- public function corpBindMultipleUser(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'id' => 'required|integer',
- 'user_id_list' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpId = $request->input('id');
- $userIdList = $request->input('user_id_list');
- $userIdList = json_decode($userIdList);
- $supportViewType = AdminService::VIEW_TYPE;
- $viewType = $supportViewType[0];
- list($res, $code) = AdminService::corpBindMultipleUser($corpId, $userIdList, $viewType);
- return self::returnValue($res, $code);
- }
- }
|