184 lines
5.6 KiB
PHP
184 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\System;
|
|
|
|
use App\Http\Controllers\BaseController;
|
|
use App\Http\Requests\Admin\System\SystemUserSchoolCampusRequest;
|
|
use App\Services\System\SystemUserSchoolCampusService;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
/**
|
|
* 系统用户校区关联控制器
|
|
*/
|
|
class SystemUserSchoolCampusController extends BaseController
|
|
{
|
|
public function __construct(
|
|
private SystemUserSchoolCampusService $systemUserSchoolCampusService
|
|
) {}
|
|
|
|
/**
|
|
* 获取用户校区关联列表
|
|
*/
|
|
public function list(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->getList($params);
|
|
|
|
return $this->SuccessPage($result->items(), $result->total());
|
|
}
|
|
|
|
/**
|
|
* 获取用户校区关联详情
|
|
*/
|
|
public function detail(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->detail($params['id']);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 创建用户校区关联
|
|
*/
|
|
public function create(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$data = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->create($data);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 更新用户校区关联
|
|
*/
|
|
public function update(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->update($params['id'], $params);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 删除用户校区关联
|
|
*/
|
|
public function delete(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$this->systemUserSchoolCampusService->delete($params['id']);
|
|
return $this->Success();
|
|
}
|
|
|
|
/**
|
|
* 批量删除用户校区关联
|
|
*/
|
|
public function batchDelete(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$this->systemUserSchoolCampusService->batchDelete($params['ids']);
|
|
return $this->Success();
|
|
}
|
|
|
|
/**
|
|
* 获取用户的学校校区列表
|
|
*/
|
|
public function userSchoolCampuses(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->getUserSchoolCampuses($params['userid']);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取当前用户的学校校区列表
|
|
*/
|
|
public function mySchoolCampuses(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$userId = $request->user()->id;
|
|
$result = $this->systemUserSchoolCampusService->getUserSchoolCampuses($userId);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取学校的用户列表
|
|
*/
|
|
public function schoolUsers(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->getSchoolUsers($params['schoolid']);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取校区的用户列表
|
|
*/
|
|
public function campusUsers(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->getCampusUsers($params['campusid']);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 批量分配用户到学校校区
|
|
*/
|
|
public function batchAssign(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->batchAssignUsersToSchoolCampus(
|
|
$params['userids'],
|
|
$params['schoolid'],
|
|
$params['campusid'] ?? null
|
|
);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 批量移除用户学校校区关联
|
|
*/
|
|
public function batchRemove(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->batchRemoveUsersFromSchoolCampus(
|
|
$params['userids'],
|
|
$params['schoolid'],
|
|
$params['campusid'] ?? null
|
|
);
|
|
return $this->Success(['removed_count' => $result]);
|
|
}
|
|
|
|
/**
|
|
* 转移用户到新的学校校区
|
|
*/
|
|
public function transfer(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->transferUserToSchoolCampus(
|
|
$params['userid'],
|
|
$params['old_schoolid'],
|
|
$params['new_schoolid'],
|
|
$params['old_campusid'] ?? null,
|
|
$params['new_campusid'] ?? null
|
|
);
|
|
return $this->Success(['transferred' => $result]);
|
|
}
|
|
|
|
/**
|
|
* 获取用户校区统计信息
|
|
*/
|
|
public function stats(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemUserSchoolCampusService->getUserSchoolCampusStats($params['userid']);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取当前用户校区统计信息
|
|
*/
|
|
public function myStats(SystemUserSchoolCampusRequest $request): JsonResponse
|
|
{
|
|
$userId = $request->user()->id;
|
|
$result = $this->systemUserSchoolCampusService->getUserSchoolCampusStats($userId);
|
|
return $this->Success($result);
|
|
}
|
|
}
|