first commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use GatewayWorker\BusinessWorker;
|
||||
use GatewayWorker\Gateway;
|
||||
use GatewayWorker\Register;
|
||||
use Workerman\Worker;
|
||||
use App\Events\WorkermanEvent;
|
||||
|
||||
class Workerman extends Command {
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'work {action} {--d}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Start a Workerman server.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle() {
|
||||
global $argv;
|
||||
$action = $this->argument('action');
|
||||
|
||||
$argv[0] = 'work';
|
||||
$argv[1] = $action;
|
||||
$argv[2] = $this->option('d') ? '-d' : '';
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
public function start() {
|
||||
$this->startGateWay();
|
||||
$this->startBusinessWorker();
|
||||
$this->startRegister();
|
||||
|
||||
$workerPath = storage_path('workerman/');
|
||||
if (!is_dir($workerPath))
|
||||
mkdir($workerPath, 0755, true);
|
||||
Worker::$pidFile = $workerPath . config('app.name') . '_workman.pid';
|
||||
$logPath = $workerPath . date('Ym') . '/';
|
||||
if (!is_dir($logPath))
|
||||
mkdir($logPath, 0755, true);
|
||||
Worker::$logFile = $logPath . date('d') . '.log';
|
||||
|
||||
Worker::runAll();
|
||||
}
|
||||
|
||||
public function startGateWay() {
|
||||
$gateway = new Gateway("websocket://0.0.0.0:2346");
|
||||
$gateway->name = 'Gateway';
|
||||
$gateway->count = 4;
|
||||
$gateway->lanIp = '127.0.0.1';
|
||||
$gateway->startPort = 2900;
|
||||
$gateway->pingInterval = 10;
|
||||
$gateway->pingNotResponseLimit = 1;
|
||||
$gateway->pingData = '{"type":"pong"}';
|
||||
$gateway->registerAddress = '127.0.0.1:1236';
|
||||
}
|
||||
|
||||
public function startBusinessWorker() {
|
||||
$worker = new BusinessWorker();
|
||||
$worker->name = 'BusinessWorker';
|
||||
$worker->count = 3;
|
||||
$worker->registerAddress = '127.0.0.1:1236';
|
||||
$worker->eventHandler = WorkermanEvent::class;
|
||||
}
|
||||
|
||||
public function startRegister() {
|
||||
$register = new Register('text://0.0.0.0:1236');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use GatewayWorker\BusinessWorker;
|
||||
use GatewayWorker\Gateway;
|
||||
use GatewayWorker\Register;
|
||||
use Workerman\Worker;
|
||||
use App\Events\WorkermanEvent;
|
||||
|
||||
class WorkermanWin extends Command {
|
||||
|
||||
// 兼容windows
|
||||
protected $signature = 'wk {action : action} {--start=all : start} {--d : daemon mode}';
|
||||
|
||||
protected $description = 'Start a Workerman server.';
|
||||
|
||||
public function handle() {
|
||||
global $argv;
|
||||
$action = $this->argument('action');
|
||||
|
||||
|
||||
//针对 Windows 一次执行,无法注册多个协议的特殊处理
|
||||
if ($action === 'single') {
|
||||
$start = $this->option('start');
|
||||
if ($start === 'register') {
|
||||
$this->startRegister();
|
||||
} elseif ($start === 'gateway') {
|
||||
$this->startGateWay();
|
||||
} elseif ($start === 'worker') {
|
||||
$this->startBusinessWorker();
|
||||
}
|
||||
Worker::runAll();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$argv[1] = $action;
|
||||
$argv[2] = $this->option('d') ? '-d' : '';
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
public function start() {
|
||||
$this->startGateWay();
|
||||
$this->startBusinessWorker();
|
||||
$this->startRegister();
|
||||
Worker::runAll();
|
||||
}
|
||||
|
||||
public function startGateWay() {
|
||||
$gateway = new Gateway("websocket://0.0.0.0:2346");
|
||||
$gateway->name = 'Gateway';
|
||||
$gateway->count = 4;
|
||||
$gateway->lanIp = '127.0.0.1';
|
||||
$gateway->startPort = 2900;
|
||||
$gateway->pingInterval = 10;
|
||||
$gateway->pingNotResponseLimit = 1;
|
||||
$gateway->pingData = '{"type":"pong"}';
|
||||
$gateway->registerAddress = '127.0.0.1:1236';
|
||||
}
|
||||
|
||||
public function startBusinessWorker() {
|
||||
$worker = new BusinessWorker();
|
||||
$worker->name = 'BusinessWorker';
|
||||
$worker->count = 3;
|
||||
$worker->registerAddress = '127.0.0.1:1236';
|
||||
$worker->eventHandler = WorkermanEvent::class;
|
||||
}
|
||||
|
||||
public function startRegister() {
|
||||
$register = new Register('text://0.0.0.0:1236');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Events;
|
||||
|
||||
use GatewayWorker\BusinessWorker;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Workerman\Lib\Timer;
|
||||
|
||||
class WorkermanEvent {
|
||||
|
||||
/**
|
||||
* @title worker 启动时触发
|
||||
*
|
||||
* @param BusinessWorker $businessWorker
|
||||
* @return void
|
||||
*/
|
||||
public static function onWorkerStart(BusinessWorker $businessWorker) {
|
||||
|
||||
self::log(__FUNCTION__, $businessWorker->workerId);
|
||||
// 向所有客户端连接发送数据
|
||||
// Gateway::sendToAll("worker started");
|
||||
// 定时向所有客户端连接发送数据
|
||||
Timer::add(1, function() use ($businessWorker) {
|
||||
$time_now = time();
|
||||
foreach ($businessWorker->connections as $connection) {
|
||||
if (empty($connection->lastMessageTime)){
|
||||
$connection->lastMessageTime = $time_now;
|
||||
continue;
|
||||
}
|
||||
if ($time_now - $connection->lastMessageTime > 10) {
|
||||
$connection->lastMessageTime = $time_now;
|
||||
Gateway::sendToClient($connection->id, 'pong');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 当客户端连接时触发
|
||||
*
|
||||
* @param int $client_id 连接id
|
||||
* @return void
|
||||
*/
|
||||
public static function onConnect($client_id) {
|
||||
self::log(__FUNCTION__, $client_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 客户端连接时触发
|
||||
*
|
||||
* @param int $client_id 连接id
|
||||
* @param mixed $message 具体消息
|
||||
* @return void
|
||||
*/
|
||||
public static function onWebSocketConnect($client_id, $data) {
|
||||
self::log(__FUNCTION__, $client_id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 当客户端发来消息时触发
|
||||
*
|
||||
* @param int $client_id 连接id
|
||||
* @param mixed $message 具体消息
|
||||
* @return void
|
||||
*/
|
||||
public static function onMessage(string $client_id, string $message) {
|
||||
self::log(__FUNCTION__, $client_id, $message);
|
||||
|
||||
if (empty($message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Gateway::sendToAll($message);
|
||||
if ($message == 'ping') {
|
||||
Gateway::sendToClient($client_id, 'pong');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 当用户断开连接时触发
|
||||
*
|
||||
* @param int $client_id 连接id
|
||||
* @return void
|
||||
*/
|
||||
public static function onClose(string $client_id) {
|
||||
self::log(__FUNCTION__, $client_id);
|
||||
Gateway::destoryClient($client_id);
|
||||
}
|
||||
|
||||
protected static function log(string $title, ...$data): void{
|
||||
if (config('app.debug')) {
|
||||
Log::info("{$title} | " . json_encode($data, 256));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\Auth;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\Auth\DepartmentService;
|
||||
|
||||
class Department extends BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* @title 部门列表
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request, DepartmentService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加部门
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Department $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request, DepartmentService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->create($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改部门
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DepartmentService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(Request $request, DepartmentService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->update($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除部门
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DepartmentService $service
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Request $request, DepartmentService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->delete($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\Auth;
|
||||
|
||||
use App\Http\Controllers\BaseController;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Auth\Events\Login;
|
||||
|
||||
class Index extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 用户登录
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function login() {
|
||||
$credentials = request(['username', 'password']);
|
||||
|
||||
$token = auth('admin')->attempt($credentials);
|
||||
|
||||
if (!$token) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = '登录失败!';
|
||||
}else{
|
||||
$this->data['code'] = 1;
|
||||
$this->data['message'] = '登录成功!';
|
||||
$this->data['data'] = [
|
||||
'access_token' => $token,
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => auth('admin')->factory()->getTTL() * 60
|
||||
];
|
||||
event(new Login('admin', auth('admin')->user(), false));
|
||||
}
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取用户信息
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function user() {
|
||||
try {
|
||||
$user = auth('admin')->userOrFail();
|
||||
$user->roles = $user->roles()->get();
|
||||
$this->data['data'] = $user;
|
||||
} catch (\Tymon\JWTAuth\Exceptions\UserNotDefinedException $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 退出
|
||||
* @desc 退出
|
||||
* @method POST
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function logout() {
|
||||
auth('admin')->logout();
|
||||
$this->data['message'] = '退出成功';
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 刷新token
|
||||
* @desc 刷新token
|
||||
* @method POST
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function refresh() {
|
||||
$this->data['data'] = auth('admin')->refresh();
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\Auth;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\Auth\MenuService;
|
||||
|
||||
class Menu extends BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* @title 权限节点列表
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request, MenuService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取我的权限节点
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function my(Request $request, MenuService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getMyMenuList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加权限节点
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Department $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request, MenuService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->create($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改权限节点
|
||||
*
|
||||
* @param Request $request
|
||||
* @param MenuService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(Request $request, MenuService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->update($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除权限节点
|
||||
*
|
||||
* @param Request $request
|
||||
* @param MenuService $service
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Request $request, MenuService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->delete($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\Auth;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\Auth\RoleService;
|
||||
|
||||
class Role extends BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* @title 角色列表
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request, RoleService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加角色
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Department $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request, RoleService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->create($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改角色
|
||||
*
|
||||
* @param Request $request
|
||||
* @param RoleService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(Request $request, RoleService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->update($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除角色
|
||||
*
|
||||
* @param Request $request
|
||||
* @param RoleService $service
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Request $request, RoleService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->delete($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 角色权限
|
||||
*
|
||||
* @param Request $request
|
||||
* @param RoleService $service
|
||||
* @return void
|
||||
*/
|
||||
public function auth(Request $request, RoleService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->auth($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\Auth;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\Auth\UsersService;
|
||||
|
||||
class Users extends BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* @title 用户列表
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request, UsersService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加用户
|
||||
*
|
||||
* @param Request $request
|
||||
* @param UsersService $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request, UsersService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->create($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改用户
|
||||
*
|
||||
* @param Request $request
|
||||
* @param UsersService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(Request $request, UsersService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->update($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除用户
|
||||
*
|
||||
* @param Request $request
|
||||
* @param UsersService $service
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Request $request, UsersService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->delete($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改密码
|
||||
*
|
||||
* @param Request $request
|
||||
* @param UsersService $service
|
||||
* @return void
|
||||
*/
|
||||
public function passwd(Request $request, UsersService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->upPassword($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 角色分配
|
||||
*
|
||||
* @param Request $request
|
||||
* @param UsersService $service
|
||||
* @return void
|
||||
*/
|
||||
public function uprole(Request $request, UsersService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->uprole($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\System\AreaService;
|
||||
|
||||
class Area extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 地区列表
|
||||
*
|
||||
* @param Request $request
|
||||
* @param AreaService $service
|
||||
* @return void
|
||||
*/
|
||||
public function index(Request $request, AreaService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getAreaList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加地区
|
||||
*
|
||||
* @param Request $request
|
||||
* @param AreaService $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request, AreaService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->create($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 编辑地区
|
||||
*
|
||||
* @param Request $request
|
||||
* @param AreaService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(Request $request, AreaService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->update($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Traits\AdminController;
|
||||
use App\Services\System\ClientService;
|
||||
|
||||
class Client extends BaseController {
|
||||
|
||||
use AdminController;
|
||||
protected $service = null;
|
||||
|
||||
public function __construct(ClientService $service) {
|
||||
$this->service = $service;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Traits\AdminController;
|
||||
use App\Services\System\CrontabService;
|
||||
|
||||
class Crontab extends BaseController {
|
||||
|
||||
use AdminController;
|
||||
protected $service = null;
|
||||
|
||||
public function __construct(CrontabService $service) {
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
public function reload(Request $request){
|
||||
try {
|
||||
$this->data['data'] = $this->service->reload($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\System\DictService;
|
||||
|
||||
class Dict extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 字典列表
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function all(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDictionaryAll($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 字典列表
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DictService $service
|
||||
* @return void
|
||||
*/
|
||||
public function lists(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 字段分类
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DictService $service
|
||||
* @return void
|
||||
*/
|
||||
public function category(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getCategoryList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加字典
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DictService $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->create($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改字典
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DictService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->update($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除字典
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DictService $service
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->delete($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加字典分类
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DictService $service
|
||||
* @return void
|
||||
*/
|
||||
public function addcate(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->createCategory($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改字典分类
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DictService $service
|
||||
* @return void
|
||||
*/
|
||||
public function editcate(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->updateCategory($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除字典分类
|
||||
*
|
||||
* @param Request $request
|
||||
* @param DictService $service
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCate(Request $request, DictService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->deleteCategory($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Http\Controllers\BaseController;
|
||||
|
||||
class File extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 上传文件
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function upload(Request $request){
|
||||
$type = $request->input('type', 'images');
|
||||
|
||||
try {
|
||||
switch ($type) {
|
||||
case 'avatar':
|
||||
$this->data['data'] = $this->avatar($request);
|
||||
break;
|
||||
case 'images':
|
||||
$this->data['data'] = $this->images($request);
|
||||
break;
|
||||
case 'files':
|
||||
$this->data['data'] = $this->files($request);
|
||||
break;
|
||||
default:
|
||||
$this->data['data'] = $this->images($request);
|
||||
break;
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $th->getMessage();
|
||||
}
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 文件列表
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function lists(Request $request){
|
||||
$path = $request->input('groupId', 'images');
|
||||
|
||||
$files = Storage::allFiles($path);
|
||||
|
||||
$data = [];
|
||||
foreach ($files as $key => $value) {
|
||||
$data[] = [
|
||||
'path' => $value,
|
||||
'url' => Storage::disk()->url($path),
|
||||
'name'=> explode('/', $value)[2],
|
||||
];
|
||||
}
|
||||
$this->data['data'] = ['data' => $data];
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 列表菜单
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function menu(Request $request){
|
||||
$file = [
|
||||
['id'=> 'images','title'=>'图片', 'children' => []],
|
||||
['id'=> 'files','title'=>'文件', 'children' => []],
|
||||
['id'=> 'videos','title'=>'视频', 'children' => []],
|
||||
['id'=> 'audios','title'=>'音频', 'children' => []],
|
||||
];
|
||||
|
||||
foreach ($file as $key => $value) {
|
||||
$paths = Storage::disk()->allDirectories($value['id']);
|
||||
foreach ($paths as $key => $value) {
|
||||
$file[$key]['children'][] = ['id'=> $value, 'title'=>explode('/', $value)[1]];
|
||||
}
|
||||
}
|
||||
|
||||
$this->data['data'] = $file;
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除文件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Request $request){
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 上传头像
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
protected function avatar(Request $request){
|
||||
$file = $request->file('file');
|
||||
|
||||
if ($file->isValid()) {
|
||||
$ext = $file->extension();
|
||||
$name = $file->hashName();
|
||||
|
||||
$path = $file->store('avatar/'.date('Ymd'));
|
||||
|
||||
$data = [
|
||||
'path' => $path,
|
||||
'url' => Storage::disk()->url($path),
|
||||
'src' => Storage::disk()->url($path),
|
||||
'name'=> $name,
|
||||
'size'=> $file->getSize(),
|
||||
'ext' => $ext,
|
||||
];
|
||||
return $data;
|
||||
}else{
|
||||
throw new \Exception('上传失败');
|
||||
}
|
||||
}
|
||||
|
||||
protected function images(Request $request){
|
||||
$file = $request->file('file');
|
||||
|
||||
if ($file->isValid()) {
|
||||
$ext = $file->extension();
|
||||
$name = $file->hashName();
|
||||
|
||||
$path = $file->store('images/'.date('Ymd'));
|
||||
|
||||
$data = [
|
||||
'path' => $path,
|
||||
'url' => Storage::disk()->url($path),
|
||||
'src' => Storage::disk()->url($path),
|
||||
'name'=> $name,
|
||||
'size'=> $file->getSize(),
|
||||
'ext' => $ext,
|
||||
];
|
||||
return $data;
|
||||
}else{
|
||||
throw new \Exception('上传失败');
|
||||
}
|
||||
}
|
||||
|
||||
protected function files(Request $request){
|
||||
$file = $request->file('file');
|
||||
|
||||
if ($file->isValid()) {
|
||||
$ext = $file->extension();
|
||||
$name = $file->hashName();
|
||||
|
||||
$path = $file->store('files/'.date('Ymd'));
|
||||
|
||||
$data = [
|
||||
'path' => $path,
|
||||
'url' => Storage::disk()->url($path),
|
||||
'src' => Storage::disk()->url($path),
|
||||
'name'=> $name,
|
||||
'size'=> $file->getSize(),
|
||||
'ext' => $ext,
|
||||
];
|
||||
return $data;
|
||||
}else{
|
||||
throw new \Exception('上传失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
|
||||
class Index extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 系统信息
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function version(Request $request){
|
||||
$system_info_mysql = \Illuminate\Support\Facades\DB::select("select version() as v;");
|
||||
|
||||
$this->data['data'] = [
|
||||
['label' => '系统核心版本', 'values' => env('VERSION', '0.0.1')],
|
||||
['label' => '服务器操作系统', 'values' => PHP_OS],
|
||||
['label' => '运行环境', 'values' => $_SERVER['SERVER_SOFTWARE']],
|
||||
['label' => 'MYSQL版本', 'values' => $system_info_mysql[0]->v],
|
||||
['label' => '上传限制', 'values' => '10']
|
||||
];
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 系统信息
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function info(Request $request){
|
||||
$this->data['data'] = [
|
||||
['label' => '系统名称', 'values' => env('APP_NAME', 'LarAdmin')],
|
||||
['label' => '后端框架', 'values' => 'PHP8 + Laravel ' . \Illuminate\Foundation\Application::VERSION],
|
||||
['label' => '前端框架', 'values' => 'VITE + VUE3 + Element Plus'],
|
||||
['label' => '系统后台UI', 'values' => 'SentUI 1.0.0'],
|
||||
['label' => 'Development', 'values' => 'molong']
|
||||
];
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 清理缓存
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearcache(Request $request){
|
||||
$this->data['data'] = cache()->flush();
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\System\LogService;
|
||||
|
||||
class Log extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 日志列表
|
||||
* @param Request $request
|
||||
* @param LogService $service
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request, LogService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 我的日志列表
|
||||
* @param Request $request
|
||||
* @param LogService $service
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function my(Request $request, LogService $service){
|
||||
try {
|
||||
$request->merge(['is_my' => 1]);
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除日志
|
||||
* @param Request $request
|
||||
* @param LogService $service
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function delete(Request $request, LogService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->delete($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Traits\AdminController;
|
||||
use App\Services\System\ClientMenuService;
|
||||
|
||||
class Menu extends BaseController {
|
||||
|
||||
use AdminController;
|
||||
protected $service = null;
|
||||
|
||||
public function __construct(ClientMenuService $service) {
|
||||
$this->service = $service;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2025 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Traits\AdminController;
|
||||
use App\Services\System\ModulesService;
|
||||
|
||||
class Modules extends BaseController {
|
||||
|
||||
use AdminController;
|
||||
protected $service = null;
|
||||
|
||||
public function __construct(ModulesService $service) {
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try {
|
||||
$this->data['data'] = $this->service->update($request);
|
||||
} catch (\Throwable $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\System\SettingService;
|
||||
|
||||
class Setting extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 获取配置列表
|
||||
*
|
||||
* @param Request $request
|
||||
* @param SettingService $service
|
||||
* @return void
|
||||
*/
|
||||
public function index(Request $request, SettingService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 创建配置
|
||||
*
|
||||
* @param Request $request
|
||||
* @param SettingService $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request, SettingService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->create($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
public function edit(Request $request, SettingService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->update($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 更新配置
|
||||
*
|
||||
* @param Request $request
|
||||
* @param SettingService $service
|
||||
* @return void
|
||||
*/
|
||||
public function save(Request $request, SettingService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->saveSetting($request);
|
||||
$this->data['message'] = "保存成功!";
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取配置字段
|
||||
*
|
||||
* @param Request $request
|
||||
* @param SettingService $service
|
||||
* @return void
|
||||
*/
|
||||
public function fields(Request $request, SettingService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getFields($request);
|
||||
} catch (\Throwable $th) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $th->getMessage();
|
||||
}
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Admin\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\System\TasksService;
|
||||
|
||||
class Tasks extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 任务列表
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TasksService $service
|
||||
* @return void
|
||||
*/
|
||||
public function index(Request $request, TasksService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加任务
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TasksService $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request, TasksService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->create($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 编辑任务
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TasksService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(Request $request, TasksService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->update($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除任务
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TasksService $service
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Request $request, TasksService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->delete($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Api\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\System\AreaService;
|
||||
|
||||
class Area extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 获取地区数据
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function index(Request $request, AreaService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getDataList($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Api\System;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Services\System\QrcodeService;
|
||||
|
||||
class Index extends BaseController {
|
||||
|
||||
/**
|
||||
* @title 生成二维码
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function qrcode(Request $request, QrcodeService $service){
|
||||
try {
|
||||
$this->data['data'] = $service->getQrcode($request);
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
|
||||
class BaseController {
|
||||
|
||||
protected $data = ['code' => 1, 'message' => 'success', 'data' => []];
|
||||
|
||||
public function __construct(Request $request){
|
||||
if ($request->filled('page')) {
|
||||
$offset = ($request->input('page', 1) - 1) * $request->input('limit', 30);
|
||||
$request->mergeIfMissing(['offset' => $offset]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Services\System\LogService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AuthCheckMiddleware {
|
||||
|
||||
public function handle(Request $request, Closure $next, string $guard = 'admin'): Response {
|
||||
$response = $next($request);
|
||||
if (auth($guard)->check()) {
|
||||
if($guard == 'admin'){
|
||||
app(LogService::class)->createLog($request);
|
||||
}
|
||||
return $response;
|
||||
}else{
|
||||
return response()->json(['code' => 2000, 'message' => '未登录,请重新登录!']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use App\Models\Auth\Admin;
|
||||
|
||||
class AdminLogin {
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct() {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(Login $event): void {
|
||||
$admin = $event->user;
|
||||
|
||||
$admin->last_login_ip = request()->ip();
|
||||
$admin->last_login_at = date('Y-m-d H:i:s');
|
||||
$admin->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
class Admin extends Authenticatable implements JWTSubject {
|
||||
use Notifiable, ModelTrait;
|
||||
|
||||
protected $table = 'auth_admins';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $fillable = ['username', 'nickname', 'email', 'mobile', 'password', 'department_id', 'status', 'last_login_at', 'last_login_ip'];
|
||||
protected $hidden = ['password', 'deleted_at'];
|
||||
protected $with = ['department', 'roles'];
|
||||
|
||||
// Rest omitted for brevity
|
||||
|
||||
/**
|
||||
* Get the identifier that will be stored in the subject claim of the JWT.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJWTIdentifier() {
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a key value array, containing any custom claims to be added to the JWT.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJWTCustomClaims() {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function password() : Attribute {
|
||||
return new Attribute(
|
||||
set: fn ($value) => Hash::make($value),
|
||||
);
|
||||
}
|
||||
|
||||
public function department(){
|
||||
return $this->belongsTo(Department::class, 'department_id', 'id');
|
||||
}
|
||||
|
||||
public function roles(){
|
||||
return $this->belongsToMany(Role::class, 'auth_admins_roles', 'uid', 'role_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
class Department extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_departments';
|
||||
protected $fillable = ['title', 'name', 'parent_id', 'status', 'sort'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'parent_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function members(){
|
||||
return $this->hasMany(Admin::class, 'department_id', 'uid');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Permission extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_permissions';
|
||||
protected $fillable = ['title', 'name', 'parent_id', 'hiddenBreadcrumb', 'hidden', 'affix', 'color', 'fullpage', 'icon', 'status', 'sort'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function meta() : Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => [
|
||||
'id' => $data['id'],
|
||||
'parent_id' => $data['parent_id'],
|
||||
'title' => $data['title'],
|
||||
'hiddenBreadcrumb' => $data['hiddenBreadcrumb'],
|
||||
'hidden' => $data['hidden'],
|
||||
'affix' => $data['affix'],
|
||||
'color' => $data['color'],
|
||||
'fullpage' => $data['fullpage'],
|
||||
'icon' => isset($data['icon']) && $data['icon'] ? $data['icon'] : 'el-icon-document',
|
||||
// 'icon' => isset($data['icon']) && $data['icon'] ? $data['icon'] : 'AIconFileTextOutlined',
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function roles(){
|
||||
return $this->belongsToMany(Role::class, 'auth_roles_permissions', 'permission_id', 'role_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
class Role extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_roles';
|
||||
protected $fillable = ['title', 'name', 'data_range', 'sort', 'status', 'description'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function admins(){
|
||||
return $this->belongsToMany(Admin::class, 'auth_admins_roles', 'role_id', 'uid');
|
||||
}
|
||||
public function permissions(){
|
||||
return $this->belongsToMany(Permission::class, 'auth_roles_permissions', 'role_id', 'permission_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class BaseModel extends Model {
|
||||
|
||||
protected $dateFormat = 'Y-m-d H:i:s';
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'deleted_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
}
|
||||
|
||||
protected function serializeDate($data){
|
||||
return $data->timezone('Asia/Shanghai')->format('Y-m-d H:i:s');
|
||||
}
|
||||
/**
|
||||
* 过滤移除非当前表的字段参数
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setFilterFields(array $params) : array {
|
||||
$fields = Schema::getColumnListing($this->getTable());
|
||||
foreach ($params as $key => $param) {
|
||||
if ( !in_array($key, $fields) ) unset($params[$key]);
|
||||
}
|
||||
// 同时过滤时间戳字段【时间戳只允许自动更改,不允许手动设置】
|
||||
if ( $this->timestamps === true && isset($params[self::CREATED_AT]) ) unset($params[self::CREATED_AT]);
|
||||
if ( $this->timestamps === true && isset($params[self::UPDATED_AT]) ) unset($params[self::UPDATED_AT]);
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
class Area extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_areas';
|
||||
protected $fillable = ['title', 'parent_id', 'status'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Client extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_client';
|
||||
protected $fillable = ['title', 'app_id', 'secret', 'redirect', 'status'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'status' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function appId() : Attribute {
|
||||
return Attribute::make(
|
||||
set: function (mixed $value, array $data){
|
||||
return uniqid();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function secret() : Attribute {
|
||||
return Attribute::make(
|
||||
set: function (mixed $value, array $data){
|
||||
return md5(uniqid());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class ClientMenu extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_client_menu';
|
||||
protected $with = ['client'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'status' => 'integer',
|
||||
'sort' => 'integer',
|
||||
];
|
||||
}
|
||||
public function client(){
|
||||
return $this->belongsTo(Client::class, 'client_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Config extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_configs';
|
||||
protected $fillable = ['values', 'name', 'title', 'group', 'remark', 'type', 'status', 'sort'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'option' => 'json',
|
||||
];
|
||||
}
|
||||
|
||||
public function options(): Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => [
|
||||
'placeholder' => $data['title'],
|
||||
'options' => $data['option'] ? json_decode($data['option'], true) : [],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function label() : Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => $data['title'],
|
||||
);
|
||||
}
|
||||
|
||||
public function prop() : Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => $data['title'],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Crontab extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_crontabs';
|
||||
protected $fillable = [];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'status' => 'integer',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Dict extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_dicts';
|
||||
protected $fillable = ['title', 'values', 'group_id', 'group_name', 'sort', 'status'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function group(){
|
||||
return $this->belongsTo(DictGroup::class, 'group_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
class DictGroup extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_dict_groups';
|
||||
protected $fillable = ['title', 'name', 'parent_id', 'sort', 'status'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'parent_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
'sort' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use App\Models\Auth\Admin;
|
||||
|
||||
class Log extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_logs';
|
||||
protected $fillable = ['title', 'name', 'url', 'method', 'client_ip', 'browser', 'user_id', 'data', 'remark', 'status'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo(Admin::class, 'user_id', 'uid');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
class Modules extends \App\Models\BaseModel {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\Auth\Admin;
|
||||
|
||||
class Tasks extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_tasks';
|
||||
protected $fillable = [];
|
||||
protected $hidden = ['deleted_at'];
|
||||
protected $append = ['url'];
|
||||
|
||||
public function url(): Attribute{
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => Storage::disk('public')->url($data['file']),
|
||||
);
|
||||
}
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo(Admin::class, 'user_id', 'uid');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
|
||||
$loader->alias('Debugbar', \Barryvdh\Debugbar\Facades\Debugbar::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\Auth\Department;
|
||||
use App\Support\Tree;
|
||||
|
||||
class DepartmentService {
|
||||
|
||||
/**
|
||||
* @title 获取部门列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$map[] = ['name', 'like', '%' . $request->input('name') . '%'];
|
||||
}
|
||||
if ($request->filled('pid')) {
|
||||
$map[] = ['parent_id', '=', $request->input('pid')];
|
||||
}
|
||||
|
||||
$query = Department::where($map)->orderBy('id', 'desc');
|
||||
|
||||
if($request->filled('is_tree') && $request->filled('is_tree') == 1){
|
||||
$query = $query->get()->toArray();
|
||||
$tree = new Tree();
|
||||
$data = $tree->list_to_tree($query, 0, 'id', 'parent_id');
|
||||
}else{
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加部门
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function create($request) {
|
||||
$request->validate([
|
||||
'title' => 'required|unique:auth_departments',
|
||||
'name' => 'required|unique:auth_departments',
|
||||
]);
|
||||
$data = $request->all();
|
||||
$data['status'] = 1;
|
||||
|
||||
return Department::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改部门
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function update($request) {
|
||||
try {
|
||||
$department = Department::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("部门不存在!", 1);
|
||||
}
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$department->title = $request->input('title');
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$department->name = $request->input('name');
|
||||
}
|
||||
if ($request->filled('parent_id')) {
|
||||
$department->parent_id = $request->input('parent_id');
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$department->status = $request->input('status');
|
||||
}
|
||||
if ($request->filled('sort')) {
|
||||
$department->sort = $request->input('sort');
|
||||
}
|
||||
|
||||
$department->save();
|
||||
return $department;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除部门
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function delete($request) {
|
||||
if($request->filled('id')){
|
||||
try {
|
||||
$department = Department::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("角色不存在!", 1);
|
||||
}
|
||||
$department->delete();
|
||||
}
|
||||
if($request->filled('ids')){
|
||||
try {
|
||||
$ids = $request->input('ids');
|
||||
$department = Department::whereIn('id', $ids)->delete();
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception($th->getMessage(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $department;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\Auth\Permission;
|
||||
use App\Models\Auth\Admin;
|
||||
use App\Support\Tree;
|
||||
|
||||
class MenuService {
|
||||
|
||||
/**
|
||||
* @title 获取权限节点列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$map[] = ['name', 'like', '%' . $request->input('name') . '%'];
|
||||
}
|
||||
if ($request->filled('pid')) {
|
||||
$map[] = ['parent_id', '=', $request->input('pid')];
|
||||
}
|
||||
|
||||
$query = Permission::where($map)->orderBy('sort', 'asc')->orderBy('id', 'desc');
|
||||
|
||||
|
||||
if($request->filled('is_tree') && $request->filled('is_tree') == 1){
|
||||
$query = $query->get()->toArray();
|
||||
$tree = new Tree();
|
||||
$data = $tree->list_to_tree($query, 0, 'id', 'parent_id');
|
||||
}else{
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取我的权限节点
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getMyMenuList($request){
|
||||
$map = [];
|
||||
$data = [];
|
||||
$uid = auth('admin')->user()['uid'];
|
||||
|
||||
$tree = new Tree();
|
||||
if($uid != env('ADMIN_ID', 1)){
|
||||
$map[] = ['uid', '=', $uid];
|
||||
|
||||
$admin = Admin::with(['roles'])->where($map)->first();
|
||||
$permission = [];
|
||||
$menu = [];
|
||||
foreach ($admin->roles as $key => $role) {
|
||||
$menu = array_merge($menu, $role->permissions->append(['meta'])->toArray());
|
||||
$permission = array_merge($permission, $role->permissions->pluck('name')->toArray());
|
||||
}
|
||||
$data = [
|
||||
'menu' => $tree->list_to_tree($menu, 0, 'id', 'parent_id'),
|
||||
'permissions' => $permission
|
||||
];
|
||||
}else{
|
||||
$query = Permission::where($map)->orderBy('sort', 'asc');
|
||||
|
||||
$data = [
|
||||
'menu' => $tree->list_to_tree($query->where('type', '=', 'menu')->get()->append(['meta'])->toArray(), 0, 'id', 'parent_id'),
|
||||
'permissions' => $query->pluck('name')
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加权限节点
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function create($request) {
|
||||
$request->validate([
|
||||
'title' => 'required|unique:auth_permissions',
|
||||
'name' => 'required|unique:auth_permissions',
|
||||
]);
|
||||
$data = $request->all();
|
||||
$data['status'] = 1;
|
||||
|
||||
return Permission::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改权限节点
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function update($request) {
|
||||
try {
|
||||
$permission = Permission::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("权限节点不存在!", 1);
|
||||
}
|
||||
|
||||
$data = $request->all();
|
||||
foreach ($data as $key => $value) {
|
||||
if (in_array($key, ['affix', 'color', 'component', 'fullpage', 'hidden', 'hiddenBreadcrumb', 'icon', 'name', 'parent_id', 'redirect', 'sort', 'title', 'type', 'path', 'status'])) {
|
||||
$permission->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$permission->save();
|
||||
return $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除权限节点
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function delete($request) {
|
||||
if($request->filled('id')){
|
||||
try {
|
||||
$permission = Permission::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("权限节点不存在!", 1);
|
||||
}
|
||||
|
||||
$permission->roles()->detach();
|
||||
$permission->delete();
|
||||
}
|
||||
if($request->filled('ids')){
|
||||
try {
|
||||
$permission = Permission::whereIn('id', $request->input('ids'));
|
||||
foreach ($permission->get() as $item) {
|
||||
$item->roles()->detach();
|
||||
}
|
||||
$permission->delete();
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception($th->getMessage(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 批量导入
|
||||
*
|
||||
* @param [array] $data
|
||||
* @return void
|
||||
*/
|
||||
public function importMenu($data, $parent_id = 0){
|
||||
foreach ($data as $key => $value) {
|
||||
$save = [
|
||||
'title' => $value['title'],
|
||||
'name' => $value['name'],
|
||||
'path' => $value['path'],
|
||||
'component' => $value['component'],
|
||||
'type' => $value['type'],
|
||||
'affix' => isset($value['affix']) ? $value['affix'] : 0,
|
||||
'parent_id' => $parent_id,
|
||||
'status' => 1,
|
||||
'sort' => isset($value['sort']) ? $value['sort'] : $key,
|
||||
'icon' => isset($value['icon']) ? $value['icon'] : '',
|
||||
'hidden' => isset($value['hidden']) ? $value['hidden'] : 0,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
$res = Permission::insertGetId($save);
|
||||
if (isset($value['children']) && !empty($value['children'])) {
|
||||
$this->importMenu($value['children'], $res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\Auth\Role;
|
||||
use App\Support\Tree;
|
||||
|
||||
class RoleService {
|
||||
|
||||
/**
|
||||
* @title 获取角色列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$map[] = ['name', 'like', '%' . $request->input('name') . '%'];
|
||||
}
|
||||
|
||||
$query = Role::with(['permissions'])->where($map)->orderBy('id', 'desc');
|
||||
|
||||
if($request->filled('is_tree') && $request->filled('is_tree') == 1){
|
||||
$query = $query->get()->toArray();
|
||||
$tree = new Tree();
|
||||
$data = $tree->list_to_tree($query, 0, 'id', 'parent_id');
|
||||
}else{
|
||||
if ($request->filled('page')){
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}else{
|
||||
$data = $query->get();
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加角色
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function create($request) {
|
||||
$request->validate([
|
||||
'title' => 'required|unique:auth_roles',
|
||||
'name' => 'required|alpha_dash:ascii|unique:auth_roles',
|
||||
]);
|
||||
$data = $request->all();
|
||||
$data['status'] = 1;
|
||||
|
||||
return Role::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改角色
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function update($request) {
|
||||
$request->validate([
|
||||
'title' => 'required|unique:auth_roles,title,' . $request->input('id'),
|
||||
'name' => 'required|alpha_dash:ascii|unique:auth_roles,name,' . $request->input('id'),
|
||||
]);
|
||||
try {
|
||||
$role = Role::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("角色不存在!", 1);
|
||||
}
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$role->title = $request->input('title');
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$role->name = $request->input('name');
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$role->status = $request->input('status');
|
||||
}
|
||||
if ($request->filled('sort')) {
|
||||
$role->sort = $request->input('sort');
|
||||
}
|
||||
|
||||
$role->save();
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除角色
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function delete($request) {
|
||||
if($request->filled('id')){
|
||||
try {
|
||||
$role = Role::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("角色不存在!", 1);
|
||||
}
|
||||
$role->permissions()->detach();
|
||||
$role->admins()->detach();
|
||||
$role->delete();
|
||||
}
|
||||
if($request->filled('ids')){
|
||||
try {
|
||||
$role = Role::whereIn('id', $request->input('ids'));
|
||||
foreach ($role->get() as $item) {
|
||||
$item->permissions()->detach(); //删除关联
|
||||
$item->admins()->detach(); //删除关联
|
||||
}
|
||||
|
||||
$role->delete();
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception($th->getMessage(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 角色授权
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function auth($request){
|
||||
try {
|
||||
$role = Role::with(['permissions'])->findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("角色不存在!", 1);
|
||||
}
|
||||
|
||||
|
||||
if($request->filled('data_range')){
|
||||
$role->data_range = $request->input('data_range');
|
||||
}
|
||||
|
||||
$role->permissions()->sync($request->input('permissions'));
|
||||
$role->save();
|
||||
return $role;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\Auth\Admin;
|
||||
|
||||
class UsersService {
|
||||
|
||||
/**
|
||||
* @title 获取用户列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('username')) {
|
||||
$map[] = ['username', 'like', '%' . $request->input('username') . '%'];
|
||||
}
|
||||
if ($request->filled('mobile')) {
|
||||
$map[] = ['mobile', 'like', '%' . $request->input('mobile') . '%'];
|
||||
}
|
||||
if ($request->filled('email')) {
|
||||
$map[] = ['email', 'like', '%' . $request->input('email') . '%'];
|
||||
}
|
||||
if ($request->filled('department_id')) {
|
||||
$map[] = ['department_id', '=', $request->input('department_id')];
|
||||
}
|
||||
|
||||
$query = Admin::where($map)->orderBy('uid', 'desc');
|
||||
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加用户
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function create($request) {
|
||||
$request->validate([
|
||||
'username' => 'required|unique:auth_admins,username',
|
||||
// 'email' => 'required|unique:auth_admins',
|
||||
// 'mobile' => 'required|unique:auth_admins',
|
||||
'password' => 'required|min:8',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
$data['status'] = 1;
|
||||
$data['last_login_at'] = date('Y-m-d H:i:s');
|
||||
$data['last_login_ip'] = $request->ip();
|
||||
|
||||
$admins = Admin::create($data);
|
||||
$request->whenFilled('roles_id', function ($value) use ($admins) {
|
||||
$admins->roles()->sync($value);
|
||||
});
|
||||
return $admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改用户
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function update($request) {
|
||||
$request->validate([
|
||||
'username' => 'required|unique:auth_admins,username,' . $request->input('uid').',uid',
|
||||
]);
|
||||
try {
|
||||
$admins = Admin::findOrFail($request->input('uid'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("用户不存在!", 1);
|
||||
}
|
||||
|
||||
if ($request->filled('username')) {
|
||||
$admins->username = $request->input('username');
|
||||
}
|
||||
if ($request->filled('email')) {
|
||||
$admins->email = $request->input('email');
|
||||
}
|
||||
if ($request->filled('mobile')) {
|
||||
$admins->mobile = $request->input('mobile');
|
||||
}
|
||||
if ($request->filled('nickname')) {
|
||||
$admins->nickname = $request->input('nickname');
|
||||
}
|
||||
if ($request->filled('department_id')) {
|
||||
$admins->department_id = $request->input('department_id');
|
||||
}
|
||||
if ($request->filled('avatar')) {
|
||||
$admins->avatar = $request->input('avatar');
|
||||
}
|
||||
if ($request->filled('remark')) {
|
||||
$admins->remark = $request->input('remark');
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$admins->status = $request->input('status');
|
||||
}
|
||||
if ($request->filled('password')) {
|
||||
$admins->password = $request->input('password');
|
||||
}
|
||||
$request->whenFilled('roles_id', function ($value) use ($admins) {
|
||||
$admins->roles()->sync($value);
|
||||
});
|
||||
|
||||
$admins->save();
|
||||
return $admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除用户
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function delete($request) {
|
||||
if($request->filled('id')){
|
||||
if($request->input('id') == env('ADMIN_ID', 1)){
|
||||
throw new \Exception("超级管理员不能删除!", 1);
|
||||
}
|
||||
try {
|
||||
$admins = Admin::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("角色不存在!", 1);
|
||||
}
|
||||
$admins->roles()->detach();
|
||||
$admins->delete();
|
||||
}
|
||||
if($request->filled('ids')){
|
||||
if(in_array(env('ADMIN_ID', 1), $request->input('ids'))){
|
||||
throw new \Exception("超级管理员不能删除!", 1);
|
||||
}
|
||||
try {
|
||||
$admins = Admin::whereIn('uid', $request->input('ids'));
|
||||
foreach ($admins->get() as $item) {
|
||||
$item->roles()->detach(); //删除关联
|
||||
}
|
||||
$admins = $admins->delete();
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception($th->getMessage(), 1);
|
||||
}
|
||||
}
|
||||
return $admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改密码
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function upPassword($request) {
|
||||
try {
|
||||
$admins = Admin::findOrFail($request->input('uid'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("用户不存在!", 1);
|
||||
}
|
||||
|
||||
$admins->password = $request->input('password');
|
||||
$admins->save();
|
||||
return $admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 设置角色
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function uprole($request){
|
||||
try {
|
||||
$admins = Admin::with(['roles'])->findOrFail($request->input('uid'));
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $th) {
|
||||
throw new \Exception($th->getMessage(), 1);
|
||||
}
|
||||
|
||||
$admins->roles()->sync($request->input('roles'));
|
||||
return $admins;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use App\Models\System\Area;
|
||||
use App\Support\Tree;
|
||||
|
||||
class AreaService {
|
||||
|
||||
/**
|
||||
* @title 区域列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getAreaList($request){
|
||||
$map = [];
|
||||
if($request->filled('title')){
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if($request->filled('id')){
|
||||
$map[] = ['id', '=', $request->input('id')];
|
||||
}
|
||||
if($request->filled('parent_code')){
|
||||
$map[] = ['parent_code', '=', $request->input('parent_code')];
|
||||
}
|
||||
|
||||
$query = Area::where($map)->orderBy('id', 'asc');
|
||||
|
||||
if($request->filled('page')){
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}else{
|
||||
if($request->filled('is_tree') && $request->filled('is_tree') == 1){
|
||||
$query = $query->get()->toArray();
|
||||
$tree = new Tree();
|
||||
$data = $tree->list_to_tree($query, 0, 'code', 'parent_code');
|
||||
}else{
|
||||
$data = $query->get();
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加区域
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function create($request){
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
'code' => 'required|unique:system_areas',
|
||||
], [
|
||||
'code.unique' => '编码已存在',
|
||||
'title.required' => '请输入标题',
|
||||
'code.required' => '请输入编码',
|
||||
]);
|
||||
|
||||
$area = new Area;
|
||||
|
||||
foreach ($area->setFilterFields($request->all()) as $key => $value) {
|
||||
$area->$key = $value;
|
||||
}
|
||||
|
||||
$area->save();
|
||||
return $area;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 编辑区域
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function update($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
'title' => 'required',
|
||||
'code' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
'title.required' => '请输入标题',
|
||||
'code.required' => '请输入编码',
|
||||
]);
|
||||
|
||||
$area = Area::where('id', '=', $request->input('id'))->first();
|
||||
|
||||
foreach ($area->setFilterFields($request->all()) as $key => $value) {
|
||||
$area->$key = $value;
|
||||
}
|
||||
|
||||
$area->save();
|
||||
return $area;
|
||||
}
|
||||
|
||||
public function delete($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
]);
|
||||
|
||||
$area = Area::where('id', '=', $request->input('id'))->first();
|
||||
$area->delete();
|
||||
return $area;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use App\Models\System\ClientMenu;
|
||||
use App\Support\Tree;
|
||||
|
||||
class ClientMenuService {
|
||||
|
||||
public function getDataList($request){
|
||||
$map = [];
|
||||
|
||||
if($request->filled('title')){
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
|
||||
$query = ClientMenu::where($map)->orderBy('id', 'asc');
|
||||
|
||||
if($request->filled('page')){
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}else{
|
||||
if($request->filled('is_tree') && $request->filled('is_tree') == 1){
|
||||
$query = $query->get()->toArray();
|
||||
$tree = new Tree();
|
||||
$data = $tree->list_to_tree($query, 0, 'id', 'parent_id');
|
||||
}else{
|
||||
$data = $query->get();
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function create($request){
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
]);
|
||||
$menu = new ClientMenu();
|
||||
|
||||
foreach ($menu->setFilterFields($request->all()) as $key => $value) {
|
||||
$menu->$key = $value;
|
||||
}
|
||||
$menu->save();
|
||||
|
||||
return $menu;
|
||||
}
|
||||
|
||||
public function update($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
'title' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
'title.required' => '请输入标题',
|
||||
]);
|
||||
|
||||
$menu = ClientMenu::where('id', $request->input('id'))->first();
|
||||
|
||||
foreach ($menu->setFilterFields($request->all()) as $key => $value) {
|
||||
$menu->$key = $value;
|
||||
}
|
||||
|
||||
$menu->save();
|
||||
return $menu;
|
||||
}
|
||||
|
||||
public function delete($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
]);
|
||||
|
||||
$menu = ClientMenu::where('id', $request->input('id'))->first();
|
||||
|
||||
$menu->delete();
|
||||
return $menu;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use App\Models\System\Client;
|
||||
|
||||
class ClientService {
|
||||
|
||||
public function getDataList($request){
|
||||
$map = [];
|
||||
|
||||
if($request->filled('title')){
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
|
||||
$query = Client::where($map)->orderBy('id', 'asc');
|
||||
|
||||
if($request->filled('page')){
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}else{
|
||||
$data = $query->get();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function create($request){
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
]);
|
||||
$client = new Client();
|
||||
|
||||
foreach ($client->setFilterFields($request->all()) as $key => $value) {
|
||||
$client->$key = $value;
|
||||
}
|
||||
|
||||
$client->app_id = '';
|
||||
$client->secret = '';
|
||||
$client->redirect = '';
|
||||
$client->save();
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
public function update($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
'title' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
'title.required' => '请输入标题',
|
||||
]);
|
||||
|
||||
$client = Client::where('id', $request->input('id'))->first();
|
||||
|
||||
$client->title = $request->input('title');
|
||||
$client->status = $request->input('status', 0);
|
||||
|
||||
$client->save();
|
||||
return $client;
|
||||
}
|
||||
|
||||
public function delete($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
]);
|
||||
|
||||
$client = Client::where('id', $request->input('id'))->first();
|
||||
|
||||
$client->delete();
|
||||
return $client;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use App\Models\System\Crontab;
|
||||
|
||||
class CrontabService {
|
||||
|
||||
public function getDataList($request){
|
||||
$map = [];
|
||||
|
||||
if($request->filled('title')){
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if($request->filled('type')){
|
||||
$map[] = ['type', '=', $request->input('type')];
|
||||
}
|
||||
|
||||
$query = Crontab::where($map)->orderBy('id', 'asc');
|
||||
|
||||
if($request->filled('page')){
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}else{
|
||||
$data = $query->get();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function create($request){
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
'type' => 'required',
|
||||
'expression' => 'required',
|
||||
'command' => 'required',
|
||||
], [
|
||||
'title.required' => '请输入标题',
|
||||
'type.required' => '请选择类型',
|
||||
'expression.required' => '请输入表达式',
|
||||
'command.required' => '请输入命令',
|
||||
]);
|
||||
|
||||
$crontab = new Crontab;
|
||||
|
||||
foreach ($crontab->setFilterFields($request->all()) as $key => $value) {
|
||||
$crontab->$key = $value;
|
||||
}
|
||||
|
||||
$crontab->save();
|
||||
|
||||
return $crontab;
|
||||
}
|
||||
|
||||
public function update($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
'title' => 'required',
|
||||
'type' => 'required',
|
||||
'expression' => 'required',
|
||||
'command' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
'title.required' => '请输入标题',
|
||||
'type.required' => '请选择类型',
|
||||
'expression.required' => '请输入表达式',
|
||||
'command.required' => '请输入命令',
|
||||
]);
|
||||
|
||||
$crontab = Crontab::where('id', $request->input('id'))->first();
|
||||
|
||||
foreach ($crontab->setFilterFields($request->all()) as $key => $value) {
|
||||
$crontab->$key = $value;
|
||||
}
|
||||
|
||||
$crontab->save();
|
||||
|
||||
return $crontab;
|
||||
}
|
||||
|
||||
public function delete($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
]);
|
||||
|
||||
$crontab = Crontab::where('id', $request->input('id'))->first();
|
||||
|
||||
$crontab->delete();
|
||||
return $crontab;
|
||||
}
|
||||
|
||||
public function reload($request){
|
||||
$request->validate([
|
||||
'id' => 'required',
|
||||
'status' => 'required',
|
||||
], [
|
||||
'id.required' => '参数错误',
|
||||
'status.required' => '参数错误',
|
||||
]);
|
||||
|
||||
$crontab = Crontab::where('id', $request->input('id'))->first();
|
||||
|
||||
$crontab->status = $request->input('status');
|
||||
|
||||
$crontab->save();
|
||||
return $crontab;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use App\Models\System\Dict;
|
||||
use App\Models\System\DictGroup;
|
||||
use App\Support\Tree;
|
||||
|
||||
class DictService {
|
||||
|
||||
/**
|
||||
* @title 获取列表数据
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$map[] = ['group_name', '=', $request->input('name')];
|
||||
}
|
||||
if ($request->filled('group_id')) {
|
||||
$map[] = ['group_id', '=', $request->input('group_id')];
|
||||
}
|
||||
|
||||
$query = Dict::where($map)->orderBy('sort', 'asc')->orderBy('id', 'desc');
|
||||
|
||||
if($request->filled('page')){
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}else{
|
||||
$data = $query->get();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 字段分类数据
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getCategoryList($request){
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$map[] = ['name', 'like', '%' . $request->input('name') . '%'];
|
||||
}
|
||||
|
||||
$query = DictGroup::where($map)->orderBy('id', 'desc');
|
||||
|
||||
|
||||
if($request->filled('is_tree') && $request->filled('is_tree') == 1){
|
||||
$query = $query->get()->toArray();
|
||||
$tree = new Tree();
|
||||
$data = $tree->list_to_tree($query, 0, 'id', 'parent_id');
|
||||
}else{
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->limit($request->input('limit', 10))->offset($request->input('page', 1) - 1)->get(),
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 创建字典
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function create($request){
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
'values' => 'required',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
$data['group_name'] = DictGroup::where('id', '=', $data['group_id'])->value('name');
|
||||
|
||||
$dict = Dict::create($data);
|
||||
|
||||
if($dict->values == ''){
|
||||
$dict->values = $dict->id;
|
||||
$dict->save();
|
||||
}
|
||||
$this->setDictCache(true);
|
||||
return $dict;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 更新字典
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function update($request){
|
||||
try {
|
||||
$dict = Dict::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("改字典不存在", 1);
|
||||
}
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$dict->title = $request->input('title');
|
||||
}
|
||||
if ($request->filled('values')) {
|
||||
$dict->values = $request->input('values');
|
||||
}
|
||||
if ($request->filled('sort')) {
|
||||
$dict->sort = $request->input('sort');
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$dict->status = $request->input('status');
|
||||
}
|
||||
if ($request->filled('group_id')) {
|
||||
$dict->group_id = $request->input('group_id');
|
||||
$dict->group_name = DictGroup::where('id', '=', $request->input('group_id'))->value('name');
|
||||
}
|
||||
|
||||
$dict->save();
|
||||
$this->setDictCache(true);
|
||||
return $dict;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除字典
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function delete($request){
|
||||
try {
|
||||
$dict = Dict::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("改字典不存在", 1);
|
||||
}
|
||||
|
||||
$dict->delete();
|
||||
$this->setDictCache(true);
|
||||
return $dict;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 创建字典分类
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function createCategory($request){
|
||||
$request->validate([
|
||||
'title' => 'required|unique:system_dict_groups',
|
||||
'name' => 'required|unique:system_dict_groups',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
$data['status'] = 1;
|
||||
$group = DictGroup::create($data);
|
||||
|
||||
$this->setDictCache(true);
|
||||
return $group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 更新字典分类
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function updateCategory($request){
|
||||
try {
|
||||
$dict = DictGroup::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("改字典不存在", 1);
|
||||
}
|
||||
|
||||
if ($request->filled('parent_id')) {
|
||||
$dict->parent_id = $request->input('parent_id');
|
||||
}
|
||||
if ($request->filled('title')) {
|
||||
$dict->title = $request->input('title');
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$dict->name = $request->input('name');
|
||||
}
|
||||
if ($request->filled('sort')) {
|
||||
$dict->sort = $request->input('sort');
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$dict->status = $request->input('status');
|
||||
}
|
||||
|
||||
$dict->save();
|
||||
$this->setDictCache(true);
|
||||
return $dict;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除字典
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCategory($request){
|
||||
try {
|
||||
$dict = DictGroup::findOrFail($request->input('id'));
|
||||
} catch (\Throwable $th) {
|
||||
throw new \Exception("改字典不存在", 1);
|
||||
}
|
||||
|
||||
$dict->delete();
|
||||
$this->setDictCache(true);
|
||||
return $dict;
|
||||
}
|
||||
|
||||
public function getDictionaryAll(){
|
||||
$map = [];
|
||||
|
||||
$map[] = ['status', '=', 1];
|
||||
|
||||
$list = Dict::where($map)->get();
|
||||
|
||||
$data = [];
|
||||
foreach ($list as $key => $value) {
|
||||
$data[$value['group_name']][] = $value;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function setDictCache($refresh = false){
|
||||
if (!cache('dict') || $refresh){
|
||||
$data = $this->getDictionaryAll();
|
||||
cache('dict', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use App\Models\System\Log;
|
||||
|
||||
class LogService {
|
||||
|
||||
/**
|
||||
* @title 获取日志列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$map[] = ['name', 'like', '%' . $request->input('name') . '%'];
|
||||
}
|
||||
if ($request->filled('url')) {
|
||||
$map[] = ['url', 'like', '%' . $request->input('url') . '%'];
|
||||
}
|
||||
if ($request->filled('method')) {
|
||||
$map[] = ['method', 'like', '%' . $request->input('method') . '%'];
|
||||
}
|
||||
if ($request->filled('ip')) {
|
||||
$map[] = ['ip', 'like', '%' . $request->input('ip') . '%'];
|
||||
}
|
||||
if ($request->filled('user_id')) {
|
||||
$map[] = ['user_id', '=', $request->input('user_id')];
|
||||
}
|
||||
if ($request->filled('remark')) {
|
||||
$map[] = ['remark', 'like', '%' . $request->input('remark') . '%'];
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$map[] = ['status', '=', $request->input('status')];
|
||||
}
|
||||
if ($request->filled('is_my')) {
|
||||
$user = auth('admin')->user();
|
||||
$map[] = ['user_id', '=', $user->uid];
|
||||
}
|
||||
|
||||
$query = Log::with(['user:nickname,username,uid'])->where($map)->orderBy('id', 'desc');
|
||||
|
||||
if ($request->filled('date')) {
|
||||
$query->whereBetween('created_at', $request->input('date'));
|
||||
}
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function createLog($request){
|
||||
list($class, $method) = explode('@', $request->route()->getActionName());
|
||||
$reflection = new \ReflectionMethod("\\" . $class, $method);
|
||||
$docComment = $reflection->getDocComment();
|
||||
$matches = [];
|
||||
preg_match("/@title(.*)(\\r\\n|\\r|\\n)/U", $docComment, $matches);
|
||||
|
||||
$data = [
|
||||
'user_id' => auth('admin')->user()->uid,
|
||||
'title' => isset($matches[1]) ? trim($matches[1]) : '',
|
||||
'name' => $request->route()->getName() ?? '',
|
||||
'client_ip' => $request->ip(),
|
||||
'url' => $request->path(),
|
||||
'method' => $request->method(),
|
||||
'data' => json_encode($request->all()),
|
||||
'browser' => $request->userAgent(),
|
||||
'remark' => $request->input('remark', ''),
|
||||
'status' => 1,
|
||||
];
|
||||
$log = Log::create($data);
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除日志
|
||||
* @param Request $request
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($request){
|
||||
$map = [];
|
||||
if($request->filled('id')){
|
||||
$map[] = ['id', '=', $request->input('id')];
|
||||
}
|
||||
if($request->filled('ids')){
|
||||
$map[] = ['id', 'IN', $request->input('ids')];
|
||||
}
|
||||
|
||||
$query = Log::where($map);
|
||||
|
||||
if($request->filled('date')){
|
||||
$query->whereBetween('created_at', $request->input('date'));
|
||||
}
|
||||
|
||||
$query->delete();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2025 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use Nwidart\Modules\Contracts\ActivatorInterface;
|
||||
use Nwidart\Modules\Module;
|
||||
use Nwidart\Modules\Facades\Module as ModuleFacade;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Models\System\Modules;
|
||||
|
||||
class ModulesService implements ActivatorInterface {
|
||||
|
||||
/**
|
||||
* 模块管理的模型
|
||||
* @var class-string<Model> $modelClass
|
||||
*/
|
||||
private string $modelClass;
|
||||
/**
|
||||
* Laravel Filesystem instance
|
||||
*
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $files;
|
||||
|
||||
public function __construct(Container $app) {
|
||||
$this->modelClass = $app['config']['modules.activators.database.model'];
|
||||
$this->files = $app['files'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a module
|
||||
*/
|
||||
public function enable(Module $module): void {
|
||||
$this->setActiveByName($module->getName(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables a module
|
||||
*/
|
||||
public function disable(Module $module): void {
|
||||
$this->setActiveByName($module->getName(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the given status same with a module status.
|
||||
*/
|
||||
public function hasStatus(Module|string $module, bool $status): bool {
|
||||
$name = $module instanceof Module ? $module->getName() : $module;
|
||||
$moduleRecord = $this->modelClass::where('name', $name)->first();
|
||||
if ($moduleRecord) {
|
||||
return boolval($moduleRecord['status']) === $status;
|
||||
} else {
|
||||
return $status === false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set active state for a module.
|
||||
*/
|
||||
public function setActive(Module $module, bool $active): void {
|
||||
$this->setActiveByName($module->getName(), $active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a module status by its name
|
||||
*/
|
||||
public function setActiveByName(string $name, bool $active): void {
|
||||
$module = ModuleFacade::getModulePath($name);
|
||||
$json = $this->readJson($module . 'module.json');
|
||||
$this->modelClass::upsert(['name' => $name, 'status' => $active, 'title' => $json['alias']], ['name'], ['status', 'title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a module activation status
|
||||
*/
|
||||
public function delete(Module $module): void {
|
||||
$moduleRecord = $this->modelClass::where('name', $module->getName())->first();
|
||||
if ($moduleRecord) {
|
||||
$moduleRecord->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes any module activation statuses created by this class.
|
||||
*/
|
||||
public function reset(): void {
|
||||
$this->modelClass::truncate();
|
||||
}
|
||||
|
||||
|
||||
public function getDataList($request){
|
||||
$map = [];
|
||||
|
||||
if($request->filled('title')){
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
|
||||
$query = Modules::where($map)->orderBy('id', 'asc');
|
||||
|
||||
if($request->filled('page')){
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get(),
|
||||
];
|
||||
}else{
|
||||
$data = $query->get();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function update($request){
|
||||
if($request->filled('name')){
|
||||
$name = $request->input('name');
|
||||
$module = ModuleFacade::getModulePath($name);
|
||||
$json = $this->readJson($module . 'module.json');
|
||||
|
||||
$module = Modules::where('name', $name)->first();
|
||||
|
||||
$module->title = $json['alias'];
|
||||
|
||||
$module->save();
|
||||
return $module;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the json file that contains the activation statuses.
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private function readJson($file): array {
|
||||
if (! $this->files->exists($file)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->files->json($file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use App\Models\System\Config;
|
||||
|
||||
class SettingService {
|
||||
|
||||
/**
|
||||
* @title 获取配置列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getDataList($request){
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('group_name')) {
|
||||
$map[] = ['group', '=', $request->input('group_name')];
|
||||
}
|
||||
|
||||
$data = Config::where($map)->orderBy('sort', 'asc')->pluck('values', 'name');
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function create($request){
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
'name' => 'required',
|
||||
'values' => 'required',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
$config = Config::create($data);
|
||||
|
||||
$this->setConfigCache(true);
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function update($request){
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
'name' => 'required',
|
||||
]);
|
||||
$config = Config::where('id', $request->input('id'))->first();
|
||||
|
||||
|
||||
foreach ($config->setFilterFields($request->all()) as $key => $value) {
|
||||
$config->$key = $value;
|
||||
}
|
||||
$config->save();
|
||||
|
||||
$this->setConfigCache(true);
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function saveSetting($request){
|
||||
$data = $request->all();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
Config::where('name', $key)->update(['values' => $value]);
|
||||
}
|
||||
|
||||
$this->setConfigCache(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($request){
|
||||
$data = $request->all();
|
||||
$config = Config::find($data['id']);
|
||||
$config->delete();
|
||||
|
||||
$this->setConfigCache(true);
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function getFields($request){
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('group_name')) {
|
||||
$map[] = ['group', '=', $request->input('group_name')];
|
||||
}
|
||||
|
||||
$config = Config::where($map)->orderBy('sort', 'asc')->get()->append(['options', 'label']);
|
||||
return $config;
|
||||
}
|
||||
|
||||
public static function setConfigCache($refresh = false){
|
||||
if (!cache('config') || $refresh){
|
||||
$config = Config::orderBy('sort', 'asc')->pluck('values', 'name');
|
||||
cache('config', $config);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\System;
|
||||
|
||||
use App\Models\System\Tasks;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class TasksService {
|
||||
|
||||
public function getDataList($request){
|
||||
$map = [];
|
||||
|
||||
if ($request->filled('title')) {
|
||||
$map[] = ['title', 'like', '%' . $request->input('title') . '%'];
|
||||
}
|
||||
if ($request->filled('name')) {
|
||||
$map[] = ['name', 'like', '%' . $request->input('name') . '%'];
|
||||
}
|
||||
if ($request->filled('url')) {
|
||||
$map[] = ['url', 'like', '%' . $request->input('url') . '%'];
|
||||
}
|
||||
if ($request->filled('method')) {
|
||||
$map[] = ['method', 'like', '%' . $request->input('method') . '%'];
|
||||
}
|
||||
if ($request->filled('ip')) {
|
||||
$map[] = ['ip', 'like', '%' . $request->input('ip') . '%'];
|
||||
}
|
||||
if ($request->filled('user_id')) {
|
||||
$map[] = ['user_id', '=', $request->input('user_id')];
|
||||
}
|
||||
if ($request->filled('data')) {
|
||||
$map[] = ['data', 'like', '%' . $request->input('data') . '%'];
|
||||
}
|
||||
if ($request->filled('remark')) {
|
||||
$map[] = ['remark', 'like', '%' . $request->input('remark') . '%'];
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$map[] = ['status', '=', $request->input('status')];
|
||||
}
|
||||
if ($request->filled('is_my')) {
|
||||
$user = auth('admin')->user();
|
||||
$map[] = ['user_id', '=', $user->uid];
|
||||
}
|
||||
|
||||
$query = Tasks::with(['user:nickname,username,uid'])->where($map)->orderBy('id', 'desc');
|
||||
|
||||
if ($request->filled('page')) {
|
||||
$data = [
|
||||
'total' => $query->count(),
|
||||
'page' => $request->input('page', 1),
|
||||
'data' => $query->offset($request->input('offset', 0))->limit($request->input('limit', 10))->get()->append(['url']),
|
||||
];
|
||||
}else{
|
||||
$data = $query->get()->append(['url']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
$task = new Tasks();
|
||||
|
||||
$task->type = $data['type'] ? $data['type'] : 'export';
|
||||
$task->title = $data['title'] ? $data['title'] : $task->type . '任务';
|
||||
$task->file = $data['file'] ? $data['file'] : '';
|
||||
$task->status = $data['status'] ? $data['status'] : 0;
|
||||
$task->user_id = auth('admin')->user()->uid;
|
||||
|
||||
$task->save();
|
||||
return $task;
|
||||
}
|
||||
|
||||
public function update($data){
|
||||
$task = Tasks::where('id', $data['id'])->first();
|
||||
|
||||
if ($data['status'] != '') {
|
||||
$task->status = $data['status'];
|
||||
}
|
||||
if ($data['file'] != '') {
|
||||
$task->file = $data['file'];
|
||||
}
|
||||
if (in_array($data['type'], ['import', 'export'])) {
|
||||
$task->type = $data['type'];
|
||||
}
|
||||
if ($data['title'] != '') {
|
||||
$task->title = $data['title'];
|
||||
}
|
||||
|
||||
$task->save();
|
||||
}
|
||||
|
||||
public function delete($data){
|
||||
$task = Tasks::where('id', $data['id'])->first();
|
||||
|
||||
if ($task->status == 0) {
|
||||
throw new \Exception("该任务正在执行中,无法删除");
|
||||
}
|
||||
|
||||
if ($task->file) {
|
||||
Storage::disk('public')->delete($task->file);
|
||||
}
|
||||
|
||||
$task->delete();
|
||||
return $task;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Support;
|
||||
|
||||
class Regex {
|
||||
|
||||
|
||||
/**
|
||||
* 验证用户名
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @param int $minLen 最小长度
|
||||
* @param int $maxLen 最大长度
|
||||
* @param string $type 验证类型,默认‘ALL’,EN.验证英文,CN.验证中文,ALL.验证中文和英文
|
||||
* @return bool
|
||||
*/
|
||||
public static function isUsername($value, $minLen = 2, $maxLen = 48, $type = 'ALL')
|
||||
{
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'EN' :
|
||||
$match = '/^[_\w\d]{' . $minLen . ',' . $maxLen . '}$/iu';
|
||||
break;
|
||||
case 'CN' :
|
||||
$match = '/^[_\x{4e00}-\x{9fa5}\d]{' . $minLen . ',' . $maxLen . '}$/iu';
|
||||
break;
|
||||
default :
|
||||
$match = '/^[_\w\d\x{4e00}-\x{9fa5}]{' . $minLen . ',' . $maxLen . '}$/iu';
|
||||
}
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证密码
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @param int $minLen 最小长度
|
||||
* @param int $maxLen 最大长度
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPassword($value, $minLen = 6, $maxLen = 16)
|
||||
{
|
||||
$value = trim($value);
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = '/^[\\~!@#$%^&*()-_=+|{}\[\],.?\/:;\'\"\d\w]{' . $minLen . ',' . $maxLen . '}$/';
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证eamil
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEmail($value)
|
||||
{
|
||||
$value = trim($value);
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = '/^[\w\d]+[\w\d-.]*@[\w\d-.]+\.[\w\d]{2,10}$/i';
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证电话号码
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return bool
|
||||
*/
|
||||
public static function isTelephone($value)
|
||||
{
|
||||
$value = trim($value);
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = '/^0[0-9]{2,3}[-]?\d{7,8}$/';
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证手机
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return bool
|
||||
*/
|
||||
public static function isMobile($value)
|
||||
{
|
||||
$value = trim($value);
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = '/^[(86)|0]?(1\d{10})$/';
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证邮政编码
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPostCode($value)
|
||||
{
|
||||
$value = trim($value);
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = '/\d{6}/';
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证IP
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isIp($value)
|
||||
{
|
||||
$value = trim($value);
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = '/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])' .
|
||||
'\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)' .
|
||||
'\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)' .
|
||||
'\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/';
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证身份证号码
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isIDCard($value)
|
||||
{
|
||||
$value = trim($value);
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strlen($value) > 18) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$match = '/^\d{6}((1[89])|(2\d))\d{2}((0\d)|(1[0-2]))((3[01])|([0-2]\d))\d{3}(\d|X)$/i';
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证URL
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isUrl($value)
|
||||
{
|
||||
$value = strtolower(trim($value));
|
||||
if (empty ($value)) {
|
||||
return false;
|
||||
}
|
||||
$match = '/^(http:\/\/)?(https:\/\/)?([\w\d-]+\.)+[\w-]+(\/[\d\w-.\/?%&=]*)?$/';
|
||||
|
||||
return preg_match($match, $value) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有数字
|
||||
* 说明:如果字符串中含有非法字符返回假,没有返回真
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return int
|
||||
*/
|
||||
public static function hasNumber($value)
|
||||
{
|
||||
return preg_match("/[0-9]/", $value) != false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否含有英文
|
||||
* 说明:如果字符串中含有非法字符返回假,没有返回真
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasEnglish($value)
|
||||
{
|
||||
return preg_match("/[a-zA-Z]/", $value) != false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有中文
|
||||
* 说明:如果字符串中含有非法字符返回假,没有返回真
|
||||
*
|
||||
* @param string $value 验证的值
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasChinese($value)
|
||||
{
|
||||
return preg_match("/[\x7f-\xff]/", $value) != false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Time {
|
||||
|
||||
/**
|
||||
* 返回今日开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function today($data = '') {
|
||||
[$y, $m, $d] = explode('-', $data ? $data : date('Y-m-d'));
|
||||
|
||||
return [
|
||||
mktime(0, 0, 0, $m, $d, $y),
|
||||
mktime(23, 59, 59, $m, $d, $y),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回昨日开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yesterday() {
|
||||
$yesterday = date('d') - 1;
|
||||
|
||||
return [
|
||||
mktime(0, 0, 0, date('m'), $yesterday, date('Y')),
|
||||
mktime(23, 59, 59, date('m'), $yesterday, date('Y')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回本周开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function week() {
|
||||
[$y, $m, $d, $w] = explode('-', date('Y-m-d-w'));
|
||||
if ($w == 0) $w = 7; //修正周日的问题
|
||||
|
||||
return [
|
||||
mktime(0, 0, 0, $m, $d - $w + 1, $y), mktime(23, 59, 59, $m, $d - $w + 7, $y),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回上周开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function lastWeek() {
|
||||
$timestamp = time();
|
||||
|
||||
return [
|
||||
strtotime(date('Y-m-d', strtotime("last week Monday", $timestamp))),
|
||||
strtotime(date('Y-m-d', strtotime("last week Sunday", $timestamp))) + 24 * 3600 - 1,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回本月开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function month($data = '') {
|
||||
$res = [];
|
||||
$data = $data ? $data : date('Y-m-d');
|
||||
$nextMoth = date('Y-m-d', strtotime($data . ' +1 month'));
|
||||
|
||||
return [
|
||||
mktime(0, 0, 0, date('m', strtotime($data)), 1, date('Y', strtotime($data))),
|
||||
mktime(0, 0, 0, date('m', strtotime($nextMoth)), 1, date('Y', strtotime($nextMoth))),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回上个月开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function lastMonth() {
|
||||
$y = date('Y');
|
||||
$m = date('m');
|
||||
$begin = mktime(0, 0, 0, $m - 1, 1, $y);
|
||||
$end = mktime(23, 59, 59, $m - 1, date('t', $begin), $y);
|
||||
|
||||
return [$begin, $end];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回今年开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function year() {
|
||||
$y = date('Y');
|
||||
|
||||
return [
|
||||
mktime(0, 0, 0, 1, 1, $y),
|
||||
mktime(23, 59, 59, 12, 31, $y),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回去年开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function lastYear() {
|
||||
$year = date('Y') - 1;
|
||||
|
||||
return [
|
||||
mktime(0, 0, 0, 1, 1, $year),
|
||||
mktime(23, 59, 59, 12, 31, $year),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取几天前零点到现在/昨日结束的时间戳
|
||||
*
|
||||
* @param int $day 天数
|
||||
* @param bool $now 返回现在或者昨天结束时间戳
|
||||
* @return array
|
||||
*/
|
||||
public static function dayToNow($day = 1, $now = true) {
|
||||
$end = time();
|
||||
if (!$now) {
|
||||
[$foo, $end] = self::yesterday();
|
||||
}
|
||||
|
||||
return [
|
||||
mktime(0, 0, 0, date('m'), date('d') - $day, date('Y')),
|
||||
$end,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回几天前的时间戳
|
||||
*
|
||||
* @param int $day
|
||||
* @return int
|
||||
*/
|
||||
public static function daysAgo($day = 1) {
|
||||
$nowTime = time();
|
||||
|
||||
return $nowTime - self::daysToSecond($day);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回几天后的时间戳
|
||||
*
|
||||
* @param int $day
|
||||
* @return int
|
||||
*/
|
||||
public static function daysAfter($day = 1) {
|
||||
$nowTime = time();
|
||||
|
||||
return $nowTime + self::daysToSecond($day);
|
||||
}
|
||||
|
||||
/**
|
||||
* 天数转换成秒数
|
||||
*
|
||||
* @param int $day
|
||||
* @return int
|
||||
*/
|
||||
public static function daysToSecond($day = 1) {
|
||||
return $day * 86400;
|
||||
}
|
||||
|
||||
/**
|
||||
* 周数转换成秒数
|
||||
*
|
||||
* @param int $week
|
||||
* @return int
|
||||
*/
|
||||
public static function weekToSecond($week = 1) {
|
||||
return self::daysToSecond() * 7 * $week;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取毫秒级别的时间戳
|
||||
*/
|
||||
public static function getMillisecond() {
|
||||
$time = explode(" ", microtime());
|
||||
$time = $time[1] . ($time[0] * 1000);
|
||||
$time2 = explode(".", $time);
|
||||
$time = $time2[0];
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相对时间
|
||||
*
|
||||
* @param int $timeStamp
|
||||
* @return string
|
||||
*/
|
||||
public static function formatRelative($timeStamp) {
|
||||
$currentTime = time();
|
||||
|
||||
// 判断传入时间戳是否早于当前时间戳
|
||||
$isEarly = $timeStamp <= $currentTime;
|
||||
|
||||
// 获取两个时间戳差值
|
||||
$diff = abs($currentTime - $timeStamp);
|
||||
|
||||
$dirStr = $isEarly ? '前' : '后';
|
||||
|
||||
if ($diff < 60) { // 一分钟之内
|
||||
$resStr = $diff . '秒' . $dirStr;
|
||||
} elseif ($diff >= 60 && $diff < 3600) { // 多于59秒,少于等于59分钟59秒
|
||||
$resStr = floor($diff / 60) . '分钟' . $dirStr;
|
||||
} elseif ($diff >= 3600 && $diff < 86400) { // 多于59分钟59秒,少于等于23小时59分钟59秒
|
||||
$resStr = floor($diff / 3600) . '小时' . $dirStr;
|
||||
} elseif ($diff >= 86400 && $diff < 2623860) { // 多于23小时59分钟59秒,少于等于29天59分钟59秒
|
||||
$resStr = floor($diff / 86400) . '天' . $dirStr;
|
||||
} elseif ($diff >= 2623860 && $diff <= 31567860 && $isEarly) { // 多于29天59分钟59秒,少于364天23小时59分钟59秒,且传入的时间戳早于当前
|
||||
$resStr = date('m-d H:i', $timeStamp);
|
||||
} else {
|
||||
$resStr = date('Y-m-d', $timeStamp);
|
||||
}
|
||||
|
||||
return $resStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 范围日期转换时间戳
|
||||
*
|
||||
* @param string $rangeDatetime
|
||||
* @param int $maxRange 最大时间间隔
|
||||
* @param string $delimiter
|
||||
* @return array
|
||||
*/
|
||||
public static function parseRange($rangeDatetime, $maxRange = 0, $delimiter = ' - ') {
|
||||
$rangeDatetime = explode($delimiter, $rangeDatetime, 2);
|
||||
$rangeDatetime[0] = strtotime($rangeDatetime[0]);
|
||||
$rangeDatetime[1] = isset($rangeDatetime[1]) ? strtotime($rangeDatetime[1]) : time();
|
||||
$rangeDatetime = [
|
||||
min($rangeDatetime[0], $rangeDatetime[1]),
|
||||
max($rangeDatetime[0], $rangeDatetime[1]),
|
||||
];
|
||||
|
||||
// 如果结束时间小于或等于开始时间 直接返回null
|
||||
// if ($rangeDatetime[1] < $rangeDatetime[0]) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// 如果大于最大时间间隔 则用结束时间减去最大时间间隔获得开始时间
|
||||
if ($maxRange > 0 && $rangeDatetime[1] - $rangeDatetime[0] > $maxRange) {
|
||||
$rangeDatetime[0] = $rangeDatetime[1] - $maxRange;
|
||||
}
|
||||
|
||||
return $rangeDatetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定时间范围内的日期数组
|
||||
* @param int $startTime
|
||||
* @param int $endTime
|
||||
* @return \Carbon\CarbonPeriod
|
||||
*/
|
||||
public static function daysUntilOfTimestamp($startTime, $endTime) {
|
||||
$startTime = Carbon::createFromTimestamp($startTime);
|
||||
$endTime = Carbon::createFromTimestamp($endTime);
|
||||
|
||||
return $startTime->daysUntil($endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间排序
|
||||
*
|
||||
* @param array $times
|
||||
* @return array
|
||||
*/
|
||||
public static function sort($times) {
|
||||
usort($times, function ($com1, $com2) {
|
||||
$com1 = strtotime($com1);
|
||||
$com2 = strtotime($com2);
|
||||
|
||||
return $com1 < $com2 ? -1 : 1;
|
||||
});
|
||||
|
||||
return $times;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Support;
|
||||
|
||||
class Tree {
|
||||
|
||||
public static function list_to_tree($list, $root = 0, $pk = 'id', $pid = 'parent_id', $children = 'children') {
|
||||
// 创建Tree
|
||||
$tree = array();
|
||||
if (is_array($list)) {
|
||||
// 创建基于主键的数组引用
|
||||
$refer = array();
|
||||
foreach ($list as $key => $data) {
|
||||
$refer[$data[$pk]] = &$list[$key];
|
||||
}
|
||||
foreach ($list as $key => $data) {
|
||||
// 判断是否存在parent
|
||||
$parentId = 0;
|
||||
if (isset($data[$pid])) {
|
||||
$parentId = $data[$pid];
|
||||
}
|
||||
if ((string)$root == $parentId) {
|
||||
$tree[] = &$list[$key];
|
||||
} else {
|
||||
if (isset($refer[$parentId])) {
|
||||
$parent = &$refer[$parentId];
|
||||
$parent[$children][] = &$list[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
public static function tree_to_list($tree = [], $children = 'children') {
|
||||
if (empty($tree) || !is_array($tree)) {
|
||||
return $tree;
|
||||
}
|
||||
$arrRes = [];
|
||||
foreach ($tree as $k => $v) {
|
||||
$arrTmp = $v;
|
||||
unset($arrTmp[$children]);
|
||||
$arrRes[] = $arrTmp;
|
||||
if (!empty($v[$children])) {
|
||||
$arrTmp = self::tree_to_list($v[$children], $children);
|
||||
$arrRes = array_merge($arrRes, $arrTmp);
|
||||
}
|
||||
}
|
||||
return $arrRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得所有的子
|
||||
*/
|
||||
public static function get_children($data, $id = 0, $pk = 'id', $pid = 'parent_id') {
|
||||
$array = [];
|
||||
foreach ($data as $k => $v) {
|
||||
if ($v[$pid] == $id) {
|
||||
$array[] = $v[$pk];
|
||||
array_merge($array, self::get_children($data, $v[$pk], $pk, $pid));
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取id的所有父,包含自己
|
||||
*/
|
||||
public static function get_parents($data, $id = 0, $pk = 'id', $pid = 'parent_id', $field = '') {
|
||||
$temp = [];
|
||||
foreach ($data as $k => $v) {
|
||||
if ($v[$pk] == $id) {
|
||||
$temp[] = $v;
|
||||
$temp = array_merge($temp, self::get_parents($data, $v[$pid]), $pk, $pid, $field);
|
||||
}
|
||||
}
|
||||
if($field){
|
||||
$temp = array_column($temp, $field);
|
||||
}
|
||||
return $temp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
trait AdminController {
|
||||
|
||||
protected $service = null;
|
||||
|
||||
/**
|
||||
* @title 列表
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $service
|
||||
* @return void
|
||||
*/
|
||||
public function index(Request $request){
|
||||
try {
|
||||
$this->data['data'] = $this->service->getDataList($request);
|
||||
} catch (\Throwable $th) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $th->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(Request $request){
|
||||
try {
|
||||
$this->data['data'] = $this->service->create($request);
|
||||
} catch (\Throwable $th) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $th->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 编辑
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(Request $request){
|
||||
try {
|
||||
$this->data['data'] = $this->service->update($request);
|
||||
} catch (\Throwable $th) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $th->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $service
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Request $request){
|
||||
try {
|
||||
$this->data['data'] = $this->service->delete($request);
|
||||
} catch (\Throwable $th) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $th->getMessage();
|
||||
}
|
||||
|
||||
return response()->json($this->data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
trait ModelTrait {
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'deleted_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
}
|
||||
|
||||
protected function serializeDate($data){
|
||||
return $data->timezone('Asia/Shanghai')->format('Y-m-d H:i:s');
|
||||
}
|
||||
/**
|
||||
* 过滤移除非当前表的字段参数
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setFilterFields(array $params) : array {
|
||||
$fields = Schema::getColumnListing($this->getTable());
|
||||
foreach ($params as $key => $param) {
|
||||
if ( !in_array($key, $fields) ) unset($params[$key]);
|
||||
}
|
||||
// 同时过滤时间戳字段【时间戳只允许自动更改,不允许手动设置】
|
||||
if ( $this->timestamps === true && isset($params[self::CREATED_AT]) ) unset($params[self::CREATED_AT]);
|
||||
if ( $this->timestamps === true && isset($params[self::UPDATED_AT]) ) unset($params[self::UPDATED_AT]);
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user