角色相关(列表和下拉框)、用户查询、项目部分API
This commit is contained in:
@@ -147,7 +147,7 @@ class BaseController
|
||||
if (mb_strlen(strval($checkValue)) <= 0 && !in_array($fieldName, $this->notRequest)) {
|
||||
$requiredFields[] = $fieldName;
|
||||
} else {
|
||||
if (!empty($checkValue)) {
|
||||
if (!empty($checkValue) || $checkValue === 0) {
|
||||
$result[$fieldName] = $checkValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,11 @@ class BaseService
|
||||
*/
|
||||
protected array $optionField = ['id', 'name'];
|
||||
|
||||
/**
|
||||
* @var array 下拉列表字段
|
||||
*/
|
||||
protected array $queryField = [];
|
||||
|
||||
/**
|
||||
* @var array 关联加载
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ class LoginController extends BaseController
|
||||
public function login()
|
||||
{
|
||||
$this->insertField = [
|
||||
'account', 'password', 'is_remember'
|
||||
'account', 'password', 'remember'
|
||||
];
|
||||
$param = $this->checkRequiredFields(request()->post());
|
||||
|
||||
|
||||
19
app/Http/Controllers/ProjectController.php
Normal file
19
app/Http/Controllers/ProjectController.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\ProjectService;
|
||||
|
||||
class ProjectController extends BaseController
|
||||
{
|
||||
//
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = ProjectService::getInstance();
|
||||
$this->insertField = [ 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status'];
|
||||
$this->updateField = [ 'id', 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status'];
|
||||
}
|
||||
}
|
||||
20
app/Http/Controllers/RoleController.php
Normal file
20
app/Http/Controllers/RoleController.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\ProjectService;
|
||||
use App\Service\RoleService;
|
||||
|
||||
class RoleController extends BaseController
|
||||
{
|
||||
//
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = RoleService::getInstance();
|
||||
$this->insertField = [ 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status'];
|
||||
$this->updateField = [ 'id', 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status'];
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class LoginService
|
||||
*/
|
||||
public function login($account, $password)
|
||||
{
|
||||
$userModel = UserModel::where('account', $account)->first();
|
||||
$userModel = UserModel::with(['roles:id,name,value'])->where('account', $account)->first();
|
||||
if (empty($userModel)) {
|
||||
UtilsService::getInstance()->errorThrow('用户或密码错误!');
|
||||
// return $this->register($account, $password);
|
||||
@@ -72,6 +72,8 @@ class LoginService
|
||||
'nick_name' => $userModel->nick_name,
|
||||
'avatar' => $userModel->avatar,
|
||||
'email' => $userModel->email,
|
||||
'role_name' => $userModel->roles->name,
|
||||
'role_value' => $userModel->roles->value,
|
||||
'ip' => $userModel->ip,
|
||||
'ip_table' => $userModel->ip_table,
|
||||
];
|
||||
@@ -99,6 +101,7 @@ class LoginService
|
||||
'password' => password_hash($password, PASSWORD_DEFAULT),
|
||||
'nick_name' => '新用户'. Str::random(),
|
||||
'avatar' => 'https://pic.rmb.bdstatic.com/bjh/80852bfe7c321988191838517ba64e309354.jpeg@h_1280',
|
||||
'role_id' => 2,
|
||||
'ip' => get_ip(),
|
||||
'ip_table' => json_encode([get_ip()]),
|
||||
'created_at' => get_time()
|
||||
@@ -114,6 +117,8 @@ class LoginService
|
||||
'nick_name' => $createModel->nick_name,
|
||||
'avatar' => $createModel->avatar,
|
||||
'email' => $userModel->email?? '',
|
||||
'role_name' => $userModel->roles->name,
|
||||
'role_value' => $userModel->roles->value,
|
||||
'ip' => $createModel->ip,
|
||||
'ip_table' => $createModel->ip_table,
|
||||
];
|
||||
|
||||
93
app/Service/ProjectService.php
Normal file
93
app/Service/ProjectService.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Models\ProjectModel;
|
||||
use App\Models\UserModel;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class ProjectService extends BaseService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->selectField = [ 'id', 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status', 'created_at', 'updated_at', 'deleted_at', ];
|
||||
$this->model = ProjectModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目列表
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function list(): array
|
||||
{
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
// 'features:id,project_id,name'
|
||||
];
|
||||
return $this->getPageList();
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
'features:id,project_id,name'
|
||||
];
|
||||
return $this->getDetail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目下拉列表
|
||||
* @return mixed
|
||||
*/
|
||||
public function option()
|
||||
{
|
||||
$this->optionField = ['id', 'title'];
|
||||
return $this->getOption();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建项目
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create($params): mixed
|
||||
{
|
||||
$params['user_id'] = $this->userId;
|
||||
$params['author_id'] = $params['author_id']?? $this->userId;
|
||||
return $this->insert($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑项目
|
||||
* @param $id
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($id, $params): mixed
|
||||
{
|
||||
return $this->save($id, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除项目
|
||||
* @param $ids
|
||||
* @return mixed|true
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete($ids): mixed
|
||||
{
|
||||
return $this->del($ids);
|
||||
}
|
||||
|
||||
}
|
||||
82
app/Service/RoleService.php
Normal file
82
app/Service/RoleService.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Models\ProjectModel;
|
||||
use App\Models\RoleModel;
|
||||
use App\Models\UserModel;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class RoleService extends BaseService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->selectField = ['id', 'name', 'value', 'pid', 'desc', 'created_at', 'updated_at', 'deleted_at'];
|
||||
$this->model = RoleModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目列表
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function list(): array
|
||||
{
|
||||
return $this->getPageList();
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
return $this->getDetail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目下拉列表
|
||||
* @return mixed
|
||||
*/
|
||||
public function option()
|
||||
{
|
||||
$this->optionField = ['id', 'name'];
|
||||
return $this->getOption();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建项目
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create($params): mixed
|
||||
{
|
||||
return $this->insert($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑项目
|
||||
* @param $id
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($id, $params): mixed
|
||||
{
|
||||
return $this->save($id, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除项目
|
||||
* @param $ids
|
||||
* @return mixed|true
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete($ids): mixed
|
||||
{
|
||||
return $this->del($ids);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,13 @@ class UserService extends BaseService
|
||||
parent::__construct();
|
||||
$this->selectField = [ 'id', 'account', 'nick_name', 'avatar', 'email', 'balance', 'qr_code', 'role_id', 'ip', 'ip_table', 'status', 'last_reset_password_at', 'created_at', 'updated_at', 'deleted_at', ];
|
||||
$this->model = UserModel::class;
|
||||
$this->queryField = [
|
||||
'account' => 'like',
|
||||
'nick_name' => 'like',
|
||||
'email' => 'like',
|
||||
'role_id' => '=',
|
||||
'status' => '=',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,11 +33,15 @@ class UserService extends BaseService
|
||||
*/
|
||||
public function list(): array
|
||||
{
|
||||
$this->with = [
|
||||
'roles'
|
||||
];
|
||||
$result = $this->getPageList();
|
||||
|
||||
foreach ($result['items'] as &$v) {
|
||||
$v['ip_table'] = json_decode($v['ip_table'], true);
|
||||
$v['status_text'] = UserStatusEnum::from($v['status'])->description();
|
||||
$v['last_reset_password_at'] = format_time($v['last_reset_password_at']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -490,3 +490,15 @@ if (!function_exists('get_time')) {
|
||||
return $isString === true ? date($format) : time();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
if (!function_exists('format_time')) {
|
||||
function format_time($time, $format = 'Y-m-d H:i:s'): string
|
||||
{
|
||||
return !empty($time)? date($format, $time) : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,7 @@ UtilsService::class::getInstance()->autoRouteRegister([
|
||||
Route::group([], function () {
|
||||
UtilsService::class::getInstance()->autoRouteRegister([
|
||||
'user' => \App\Http\Controllers\UserController::class, // 用户控制器
|
||||
'project' => \App\Http\Controllers\ProjectController::class, // 项目控制器
|
||||
'role' => \App\Http\Controllers\RoleController::class, // 角色控制器
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -3,12 +3,5 @@
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/', function () {
|
||||
//
|
||||
// $framework = \App\Models\ProjectModel::with([
|
||||
// 'frameworks',
|
||||
// 'labels',
|
||||
// 'technologyStacks',
|
||||
// ])->get();
|
||||
// ds($framework);
|
||||
return view('welcome');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user