This commit is contained in:
86
app/Controller/AbstractController.php
Normal file
86
app/Controller/AbstractController.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Context\UserContext;
|
||||
use App\Service\OpLogsService;
|
||||
use App\Utils\ApiResponse;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Hyperf\HttpServer\Contract\ResponseInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
abstract class AbstractController
|
||||
{
|
||||
#[Inject]
|
||||
protected ContainerInterface $container;
|
||||
|
||||
#[Inject]
|
||||
protected RequestInterface $request;
|
||||
|
||||
#[Inject]
|
||||
protected ResponseInterface $response;
|
||||
|
||||
#[Inject]
|
||||
protected ApiResponse $apiResponse;
|
||||
|
||||
#[Inject]
|
||||
protected OpLogsService $opLogsService;
|
||||
|
||||
/**
|
||||
* 获取默认分页参数.
|
||||
* @return array
|
||||
*/
|
||||
protected function getPage(): array
|
||||
{
|
||||
$params = $this->request->all();
|
||||
return [$params['page'] ?? 1, $params['pageSize'] ?? 100];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户令牌
|
||||
* @return string|null
|
||||
*/
|
||||
public function token(): ?string
|
||||
{
|
||||
return UserContext::getCurrentToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function user(): array
|
||||
{
|
||||
return UserContext::getCurrentUser() ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前公司信息
|
||||
* @return array
|
||||
*/
|
||||
public function company(): array
|
||||
{
|
||||
return $this->user()['company'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作日志.
|
||||
* @param string $log
|
||||
* @param int $source
|
||||
*/
|
||||
protected function opLogs(string $log, int $source = 0): void
|
||||
{
|
||||
$this->opLogsService->operatorLogs($log, $source);
|
||||
}
|
||||
}
|
43
app/Controller/CompanyController.php
Normal file
43
app/Controller/CompanyController.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/6/5
|
||||
* Time: 下午6:04
|
||||
* Description:
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\Company\CompanyRepository;
|
||||
use App\Request\CompanyRequest;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpMessage\Server\Response;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
class CompanyController extends AbstractController
|
||||
{
|
||||
#[Inject]
|
||||
protected CompanyRepository $companyRepository;
|
||||
|
||||
/**
|
||||
* 添加公司.
|
||||
* @param CompanyRequest $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Scene(scene: 'addCompany', argument: 'request')]
|
||||
public function addCompany(CompanyRequest $request): Response
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
$this->companyRepository->add($data);
|
||||
|
||||
return $this->apiResponse->success();
|
||||
}
|
||||
}
|
45
app/Controller/FirstCompanyController.php
Normal file
45
app/Controller/FirstCompanyController.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/6/5
|
||||
* Time: 下午9:29
|
||||
* Description:
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\Company\FirstCompanyRepository;
|
||||
use App\Request\FirstCompanyRequest;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpMessage\Server\Response;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
class FirstCompanyController extends AbstractController
|
||||
{
|
||||
#[Inject]
|
||||
protected FirstCompanyRepository $firstCompanyRepository;
|
||||
|
||||
/**
|
||||
* 添加公司.
|
||||
* @param FirstCompanyRequest $request
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
#[Scene(scene: 'addFirstCompany', argument: 'request')]
|
||||
public function addFirstCompany(FirstCompanyRequest $request): Response
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
$this->firstCompanyRepository->addCompany($data);
|
||||
|
||||
return $this->apiResponse->success();
|
||||
}
|
||||
}
|
52
app/Controller/PurchaseController.php
Normal file
52
app/Controller/PurchaseController.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/6/5
|
||||
* Time: 下午5:35
|
||||
* Description:
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\Purchase\PurchaseRepository;
|
||||
use App\Request\PurchaseRequest;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpMessage\Server\Response;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/6/5
|
||||
* Time: 下午5:42
|
||||
* Description: 采购单入库管理.
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
class PurchaseController extends AbstractController
|
||||
{
|
||||
#[Inject]
|
||||
protected PurchaseRepository $purchaseRepository;
|
||||
|
||||
/**
|
||||
* 新增采购单入库单
|
||||
* @param PurchaseRequest $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Scene(scene: 'addPurchase', argument: '')]
|
||||
public function addPurchase(PurchaseRequest $request): Response
|
||||
{
|
||||
$this->purchaseRepository->addPurchase($request->all());
|
||||
|
||||
return $this->apiResponse->success();
|
||||
}
|
||||
}
|
51
app/Controller/RoleController.php
Normal file
51
app/Controller/RoleController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/6/4
|
||||
* Time: 下午2:52
|
||||
* Description:
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\JsonRpc\UserAuthServiceInterface;
|
||||
use App\Request\RoleRequest;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpMessage\Server\Response;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
class RoleController extends AbstractController
|
||||
{
|
||||
#[Inject]
|
||||
protected UserAuthServiceInterface $userAuthServiceInterface;
|
||||
|
||||
/**
|
||||
* 添加角色.
|
||||
* @param RoleRequest $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Scene(scene: 'addRole', argument: 'request')]
|
||||
public function addRole(RoleRequest $request): Response
|
||||
{
|
||||
$params = $request->all();
|
||||
|
||||
$data = [
|
||||
'companyInfo' => $this->company(),
|
||||
'id' => $params['id'] ?? null,
|
||||
'role_name' => $params['role_name'],
|
||||
'active_status' => $params['active_status'],
|
||||
'sort' => $params['sort'],
|
||||
];
|
||||
// 添加角色.
|
||||
$this->userAuthServiceInterface->addRole($data);
|
||||
|
||||
return $this->apiResponse->success();
|
||||
}
|
||||
}
|
110
app/Controller/UserController.php
Normal file
110
app/Controller/UserController.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/6/3
|
||||
* Time: 下午8:20
|
||||
* Description:
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Amqp\Producer\UserImportProducer;
|
||||
use App\Constants\UserTypeConst;
|
||||
use App\Context\UserContext;
|
||||
use App\JsonRpc\UserAuthServiceInterface;
|
||||
use App\Request\UserRequest;
|
||||
use Exception;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpMessage\Server\Response;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
#[Inject]
|
||||
protected UserAuthServiceInterface $userAuthService;
|
||||
|
||||
#[Inject]
|
||||
protected Producer $producer;
|
||||
|
||||
/**
|
||||
* 用户登录.
|
||||
* @param UserRequest $request
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
#[Scene(scene: 'userLogin', argument: 'request')]
|
||||
public function userLogin(UserRequest $request): Response
|
||||
{
|
||||
$rpcUser = $this->userAuthService->userLogin([
|
||||
'login_name' => $request->input('login_name'),
|
||||
'password' => $request->input('password'),
|
||||
]);
|
||||
$user = $rpcUser['result'] ?? [];
|
||||
if (empty($user)) {
|
||||
return $this->apiResponse->error('用户名不存在');
|
||||
}
|
||||
|
||||
// 设置用户信息上下文
|
||||
UserContext::setCurrentUser($user['user']);
|
||||
|
||||
$this->opLogs('[用户登录]登录名 ' . $request->input('login_name'));
|
||||
|
||||
return $this->apiResponse->success($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户.
|
||||
* @param UserRequest $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Scene(scene: 'addUser', argument: 'request')]
|
||||
public function addUser(UserRequest $request): Response
|
||||
{
|
||||
$data = $request->all();
|
||||
$data['token'] = $this->token();
|
||||
$data['user_type'] = UserTypeConst::SYSTEM_USER;
|
||||
$data['companyInfo'] = $this->company();
|
||||
$data['role_ids'] = $request->input('role_ids', []); // 角色ID列表
|
||||
|
||||
$this->userAuthService->addUser($data);
|
||||
|
||||
return $this->apiResponse->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表.
|
||||
* @param UserRequest $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Scene(scene: 'getUserList', argument: 'request')]
|
||||
public function getUserList(UserRequest $request): Response
|
||||
{
|
||||
$data = [
|
||||
'companyInfo' => $this->company(),
|
||||
'userInfo' => UserContext::getCurrentUser(),
|
||||
'getPage' => $this->getPage(),
|
||||
'params' => $request->all()
|
||||
];
|
||||
|
||||
$rpcResult = $this->userAuthService->userList($data);
|
||||
|
||||
return $this->apiResponse->success($rpcResult['result']);
|
||||
}
|
||||
|
||||
public function importUser(): Response
|
||||
{
|
||||
$data = [];
|
||||
|
||||
$this->producer->produce(new UserImportProducer($data));
|
||||
|
||||
return $this->apiResponse->success();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user