作者 Your Name

Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev

... ... @@ -13,3 +13,4 @@ npm-debug.log
yarn-error.log
/.idea
/.vscode
composer.lock
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/4/12
* Time: 15:33
*/
namespace App\Console\Commands;
use App\Models\Project;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* Class ProjectInitDatabase
* @package App\Console\Commands
*/
class ProjectInit extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project:init';
/**
* The console command description.
*
* @var string
*/
protected $description = '项目数据库初始化';
protected $connect = null;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
#TODO 通过项目ID获取项目部署数据库配置, 创建数据库, 同步数据表
$project_id = 102;
$project = Project::getProjectById($project_id);
if (empty($project) || empty($project->mysqlConfig()))
return true;
$this->initDatabase($project);
return true;
}
/**
* @param Project $project
* @return bool
*/
public function initDatabase($project)
{
$create_flag = $this->createDatabase($project);
if (!$create_flag) {
// 创建数据库失败 添加通知以及再次处理
}
// 设置 database.connections.custom_mysql 数据
config(['database.connections.custom_mysql.host' => $project->mysqlConfig()->host]);
config(['database.connections.custom_mysql.port' => $project->mysqlConfig()->port]);
config(['database.connections.custom_mysql.database' => $project->databaseName()]);
config(['database.connections.custom_mysql.username' => $project->mysqlConfig()->user]);
config(['database.connections.custom_mysql.password' => $project->mysqlConfig()->password]);
// TODO 创建对应库 初始化数据表
$this->initTable();
return true;
}
/**
* @return bool
*/
public function initTable()
{
// $table = DB::select('show tables');
// $table = array_column($table, 'Tables_in_globalso_dev');
// $table = DB::connection('custom_tmp_mysql')->select('show tables');
// $table_in = DB::connection('custom_tmp_mysql')->getDatabaseName();
// dd($table, $table_in);
$database_name = DB::connection('custom_tmp_mysql')->getDatabaseName();
$table = Schema::connection('custom_tmp_mysql')->getAllTables();
$table = array_column($table, 'Tables_in_' . $database_name);
foreach ($table as $v) {
$has_table = Schema::connection('custom_mysql')->hasTable($v);
if ($has_table)
continue;
$connection = DB::connection('custom_tmp_mysql');
$sql = $connection->getDoctrineSchemaManager()
->getDatabasePlatform()
->getCreateTableSQL($connection->getDoctrineSchemaManager()->listTableDetails($v));
DB::connection('custom_mysql')->select($sql[0]);
}
return true;
}
/**
* 创建数据库
* 链接mysql 查询数据库是否存在 创建数据库
* @param Project $project
* @return bool|\mysqli_result|null
*/
public function createDatabase($project)
{
# 该方法需要:composer require parity-bit/laravel-db-commands
// $result = Artisan::call('db:create', [
// '--database' => $database_name,
// ]);
//
// return $result;
if ($this->connect)
return $this->connect;
//连接到 MySQL 服务器
$servername = $project->mysqlConfig()->host;
$username = $project->mysqlConfig()->user;
$password = $project->mysqlConfig()->password;
$conn = new \mysqli($servername, $username, $password);
//检查连接是否成功
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
$this->connect = $conn;
// $result = $conn->query('SHOW DATABASES LIKE \'' . $database_name . '\';');
// if ($result)
// return true;
$result = $conn->query('CREATE DATABASE ' . $project->databaseName() . ';');
return $result;
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/2/7
* Time: 17:58
*/
namespace App\Console\Commands\Test;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Demo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'demo';
/**
* The console command description.
*
* @var string
*/
protected $description = 'demo';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$sql = 'CREATE DATABASE database_name;';
$results = DB::select($sql);
dd($results);
return true;
}
public function printMessage()
{
$client = new Client();
$headers = [
'Accept-Language' => 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cache-Control' => 'no-cache',
'Content-Type' => 'application/json',
'DNT' => '1',
'Origin' => 'http://openai.waimaoq.com',
'Pragma' => 'no-cache',
'Proxy-Connection' => 'keep-alive',
'Referer' => 'http://openai.waimaoq.com/docs',
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
'accept' => 'application/json',
'Access-Control-Allow-Origin' => '*'
];
$body = '{
"prompt": "Human: 我需要一篇100字的英文原创博客并包含标题,内容结合:“cnc machine”。AI:"
}';
$response = $client->post('http://openai.waimaoq.com/v1/openai_chat_stream', [
'stream' => true,
'headers' => $headers,
'body' => $body
]);
// 获取响应流对象
$stream = $response->getBody();
// 设置输出缓冲区
ob_start();
// 读取流中的数据并输出到页面
while (!$stream->eof()) {
echo $stream->read(4);
ob_flush();
flush();
}
dd(1);
}
}
\ No newline at end of file
... ...
... ... @@ -3,6 +3,18 @@ use Illuminate\Support\Facades\Log;
define('HTTP_OPENAI_URL','http://openai.waimaoq.com');
//ai自动生成文本
function send_openai_msg($url , $command , $param){
$url = HTTP_OPENAI_URL.$url;
$data = [
'messages'=>[
['role'=>$command['key'],'content'=>$command['scene']],
['role'=>$param['key'],'content'=>$param['scene']],
]
];
return http_post($url,json_encode($data));
}
if(!function_exists('http_post')){
/**
* 发送http post请求
... ... @@ -56,6 +68,7 @@ if(!function_exists('http_get')){
}
}
if(!function_exists('_get_child')){
/**
* 菜单权限->得到子级数组
... ...
... ... @@ -4,25 +4,25 @@ namespace App\Http\Controllers\Aside;
use App\Enums\Common\Code;
use App\Http\Controllers\Controller;
use App\Utils\EncryptUtils;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cache;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Session;
class BaseController extends Controller
class BaseController extends Controller
{
protected $param = [];//所有请求参数
protected $token = ''; //token
protected $request = [];//助手函数
protected $p = 1;//当前页
protected $allCount = 0;//总条数
protected $page = 1;//当前页
protected $row = 20;//每页条数
protected $header = [];//设置请求头参数
protected $order = 'id';
protected $map = [];//处理后的参数
protected $uid = 0;
protected $user = [];//当前登录用户详情
/**
* 获取所有参数
*/
... ... @@ -30,32 +30,24 @@ class BaseController extends Controller
{
$this->request = $request;
$this->param = $this->request->all();
$this->token = $this->request->header('token');
$this->get_param();
$this->auth_token();
}
/**
* @name
* @return void
* @author :liyuhang
* @method
* @return mixed
* @author zbj
* @date 2023/4/19
*/
public function auth_token(){
$info = Cache::get($this->token);
if(isset($info) && !empty($info)){
$this->user = $info;
$this->uid = $info['id'];
}
public function manage(){
return Session::get('manage');
}
/**
* 成功返回
* @param array $data
* @param string $code
* @param bool $objectData
* @return JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse
{
... ... @@ -68,16 +60,8 @@ class BaseController extends Controller
'data' => $data,
'msg' => $code->description,
];
//加密-返回数据
if (config('app.params_encrypt')) {
$k = config('app.params_encrypt_key');
$i = config('app.params_encrypt_iv');
$response = [
'p' => (new EncryptUtils())->openssl_en($response, $k, $i)];
}
return response()->json($response,200,$this->header);
}
/**
* @name 参数过滤
* @return void
... ... @@ -94,20 +78,23 @@ class BaseController extends Controller
case "order":
$this->order = $v;
break;
case 'p':
$this->p = $v;
case 'page':
$this->page = $v;
break;
case 'row':
$this->row = $v;
break;
case "created_at":
case "name":
$this->map['name'] = ['like','%'.$v.'%'];
break;
case "start_at":
$this->_btw[0] = $v;
$this->_btw[1] = date('Y-m-d H:i:s',time());
$this->map['create_at'] = ['between', $this->_btw];
$this->map['created_at'] = ['between', $this->_btw];
break;
case "updated_at":
case "end_at":
$this->_btw[1] = $v;
$this->map['update_at'] = ['between', $this->_btw];
$this->map['updated_at'] = ['between', $this->_btw];
break;
default:
if (!empty($v)) {
... ... @@ -116,46 +103,24 @@ class BaseController extends Controller
break;
}
}
}
/**
* @name 统一返回参数
* @return void
* @return JsonResponse
* @author :liyuhang
* @method
*/
public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){
$result_code === null && $result_code = $code;
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
$code = Code::fromValue($code);
$result = [
'msg' =>$msg,
'code'=>$result_code,
'data'=>$data
'msg' => $msg == ' ' ? $code->description : $msg,
'code' => $code->value,
'data' => $data,
];
$this->header['Content-Type'] = $type;
$this->header['token'] = $this->token;
$response = response($result,$result_code,$this->header);;
throw new HttpResponseException($response);
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
*/
public function uploads(){
$files = $this->request->file('file');
if(empty($files)){
return $this->response('没有上传文件',Code::USER_ERROR);
}
$url = './uploads/images/';
$param = $this->request->post();
if($this->request->hasFile('image') && $files->isValid()){
$filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
$this->request->file('image')->move('./uploads/images/',$filename);
}else{
return false;
}
return $url.$filename;
}
}
... ...
<?php
namespace App\Http\Controllers\Aside;
use App\Http\Logic\Aside\DemoLogic;
use App\Http\Requests\Aside\DemoRequest;
class DemoController extends BaseController
{
/**
* Deom控制器
* @param DemoRequest $request
* @param DemoLogic $logic
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function test(DemoRequest $request,DemoLogic $logic)
{
$request->validated();
$data=$logic->testLogic();
return $this->success($data);
}
}
<?php
namespace App\Http\Controllers\Aside;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
/**
* Class IndexController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/19
*/
class IndexController extends Controller
{
/**
* 首页
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{
}
}
... ...
<?php
namespace App\Http\Controllers\Aside;
use App\Http\Logic\Aside\LoginLogic;
use App\Rules\Mobile;
use Illuminate\Http\Request;
/**
* Class LoginController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/19
*/
class LoginController extends BaseController
{
function login(Request $request, LoginLogic $logic)
{
if ($request->isMethod('POST')) {
$request->validate([
'mobile' => ['required', new Mobile()],
'password' => 'required',
], [
'mobile.required' => '请输入手机号',
'password.required' => '请输入密码',
]);
$logic->login();
return $this->success();
}
return view('admin.login');
}
public function logout(LoginLogic $logic)
{
return $logic->logout();
}
}
... ...
<?php
namespace App\Http\Controllers\Aside;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
/**
* Class Menu
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/19
*/
class MenuController extends Controller
{
/**
* 菜单列表
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{
echo 111;
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\Blog;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
class AiCommandController extends BaseController
{
/**
* @name :指令列表
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
$url = 'v2/openai_chat';
$command = ['key'=>'user','scene'=>'system'];
$param = ['key'=>'user','scene'=>'请问你是谁?'];
$data = send_openai_msg($url,$command,$param);
var_dump($data);
die();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function add(){
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function edit(){
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function del(){
}
}
... ...
... ... @@ -23,8 +23,8 @@ class ComController extends BaseController
*/
public function login(Request $request){
$request->validate([
'mobile'=>'required|string|max:12',
'password'=>'required|string',
'mobile'=>['required|string|max:12'],
'password'=>['required|string'],
],[
'mobile.required'=>'标题必须填写',
'mobile.string'=>'标题中含有非法文字',
... ... @@ -87,8 +87,8 @@ class ComController extends BaseController
*/
public function edit_info(Request $request){
$request->validate([
'password'=>'required,string,min:5',
'name'=>'required,max:20',
'password'=>['required,string,min:5'],
'name'=>['required,max:20'],
],[
'password.required'=>'密码必须填写',
'password.string'=>'密码中含有非法文字',
... ...
... ... @@ -2,35 +2,21 @@
namespace App\Http\Logic\Aside;
use App\Enums\Common\Code;
use App\Exceptions\AsideGlobalException;
use App\Http\Logic\Logic;
/**
* @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
* Class BaseLogic
* @package App\Http\Logic\Aside
*/
class BaseLogic
class BaseLogic extends Logic
{
protected $requestAll;
public function __construct()
{
$this->requestAll=request()->all();
}
protected $requestAll;
/**
* @notes: 统一格式化分页返回
* @return array
*/
function getPageData($pagninate): array
public function __construct()
{
$p = $pagninate->toArray();
$result['list'] = $p ['data'];
$result['pager']['total'] = $p ['total'];
$result['pager']['page'] = $p ['current_page'];
$result['pager']['pagesize'] = $p ['per_page'];
return $result;
$this->requestAll = request()->all();
}
}
... ...
<?php
namespace App\Http\Logic\Aside;
use App\Models\Manage;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Session;
/**
* Class LoginLogic
* @package App\Http\Logic\Aside
* @author zbj
* @date 2023/4/19
*/
class LoginLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Manage();
}
public function login()
{
$info = $this->model->where('mobile', $this->requestAll['mobile'])->first();
if (!$info){
$this->fail('登录用户名不存在');
}
if (Manage::STATUS_DISABLE == $info->status) {
$this->fail('帐号已被禁用');
}
if (!Hash::check($this->requestAll['password'], $info->password)) {
$this->fail('登录密码不正确');
}
Session::put('manage', $info->toArray());
return $this->success();
}
public function logout(){
Session::forget('manage');
return redirect(route('admin.login'));
}
}
... ...
<?php
namespace App\Http\Logic\Aside;
namespace App\Http\Logic\Bside;
class DemoLogic extends BaseLogic
class AiCommandLogic extends BaseLogic
{
protected $requestAll;
public function __construct()
{
$this->requestAll=request()->all();
}
public function testLogic():array
{
return $this->success($this->requestAll);
parent::__construct();
$this->model = new Department();
}
}
... ...
... ... @@ -2,27 +2,23 @@
namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Http\Logic\Logic;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
/**
* @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
*/
class BaseLogic
class BaseLogic extends Logic
{
protected $model;
protected $requestAll;
protected $requestAll;
protected $param;
protected $user;
protected $is_cache = true; //是否缓存数据
public function __construct()
{
$this->requestAll = request()->all();
... ... @@ -30,27 +26,6 @@ class BaseLogic
$this->user = Cache::get(request()->header('token'));
}
/**
* @notes: 请简要描述方法功能
* @param array $data
* @return array
*/
public function success(array $data = [])
{
return $data;
}
/**
* @notes: 错误抛出
* @param string $code
* @param string $message
* @throws BsideGlobalException
*/
public function fail(string $message = "", string $code = Code::SYSTEM_ERROR)
{
throw new BsideGlobalException($code, $message);
}
/**
* 列表
... ... @@ -65,41 +40,7 @@ class BaseLogic
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
$map[] = ['project_id' => $this->user['project_id']];
// 闭包查询条件格式化
$query = $this->formatQuery($map);
// 排序(支持多重排序)
$query = $query->when($sort, function ($query, $sort) {
foreach ($sort as $k=>$v) {
$query->orderBy($k, $v);
}
});
// 数据分页设置
if ($limit) {
$result = $query->select($columns)->paginate($limit);
}else{
$result = $query->select($columns)->get();
}
return $this->success($result ? $result->toArray() : []);
}
/**
* 详情
* @param $id
* @return array
* @author zbj
* @date 2023/4/13
*/
public function getInfo($id)
{
$info = $this->getCacheInfo($id);
if(!$info){
$this->fail('数据不存在或者已经删除');
}
return $this->success($info->toArray());
return parent::getList($map, $sort, $columns, $limit);
}
/**
... ... @@ -108,19 +49,10 @@ class BaseLogic
* @author zbj
* @date 2023/4/15
*/
public function getCacheInfo($id){
if($this->is_cache){
$info = Cache::get($this->getInfoCacheKey($id));
if (!$info) {
$info = $this->model->find($id);
if($info){
Cache::put($this->getInfoCacheKey($id), $info);
}
}
}else{
$info = $this->model->find($id);
}
if($info && $info['project_id'] != $this->user['project_id']) {
public function getCacheInfo($id)
{
$info = parent::getCacheInfo($id);
if ($info && $info['project_id'] != $this->user['project_id']) {
$info = null;
}
return $info;
... ... @@ -134,178 +66,24 @@ class BaseLogic
* @author zbj
* @date 2023/4/13
*/
public function save($param){
if(!empty($param['id'])){
$this->model = $this->getCacheInfo($param['id']);
if(!$this->model){
$this->fail('数据不存在或者已经删除');
}
}
public function save($param)
{
$param['project_id'] = $this->user['project_id'];
foreach ($param as $name => $value){
$this->model[$name] = $value;
}
$res = $this->model->save();
if($res){
//清缓存
if($this->is_cache && !empty($param['id'])){
Cache::forget($this->getInfoCacheKey($param['id']));
}
return $this->success(['id' => $this->model->id]); //返回保存的数据id
}else{
$this->fail('保存失败');
}
return parent::save($param);
}
/**
* 批量删除
* @param $ids
* @param array $map
* @return array
* @throws BsideGlobalException
* @author zbj
* @date 2023/4/13
*/
public function delete($ids){
$ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
if(!$ids){
$this->fail('ID不能为空');
}
$map[] = ['id', 'in', $ids];
$map[] = ['project_id' => $this->user['project_id']];
$res = $this->formatQuery($map)->delete();
if($res){
if($this->is_cache){
foreach ($ids as $id){
Cache::forget($this->getInfoCacheKey($id));
}
}
return $this->success();
}else{
$this->fail('删除失败');
}
}
/**
* @param $id
* @return string
* @author zbj
* @date 2023/4/13
*/
public function getInfoCacheKey($id){
return $this->model->getTable() . '_info_' . $id;
}
/**
* 格式化查询条件
* @param $map
* @param $query
* @return mixed
* @author zbj
* @date 2023/4/13
*/
public function formatQuery($map, $query = '')
public function delete($ids, $map = [])
{
$model = $query ?: $this->model;
$query = $model->where(function ($query) use ($map) {
foreach ($map as $v) {
if ($v instanceof \Closure) {
$query = $query->where($v);
continue;
}
// 判断是否是键值对类型
if (key($v) !== 0) {
$key = key($v);
$val = $v[$key];
$v = [$key, is_array($val) ? 'in' : '=', $val];
}
switch ($v[1]) {
case 'like':
// like查询 ['name|title', 'like', '%a%']
if (strpos($v[0], '|') !== false) {
$query->where(function ($query) use ($v) {
$item = explode('|', $v[0]);
foreach ($item as $vo) {
$query->orWhere($vo, $v[1], $v[2]);
}
});
} else {
$query->where($v[0], $v[1], $v[2]);
}
break;
case 'in':
// in查询 ['id', 'in', [1,2,3]]
if (!is_array($v[2])) {
$v[2] = explode(',', $v[2]);
}
$query->whereIn($v[0], $v[2]);
break;
case 'not in':
// not in查询 ['id', 'not in', [1,2,3]]
if (!is_array($v[2])) {
$v[2] = explode(',', $v[2]);
}
$query->whereNotIn($v[0], $v[2]);
break;
case 'between':
// between查询 ['created_at', 'between', ['xxx', 'xxx]]
if (!is_array($v[2])) {
$v[2] = explode(',', $v[2]);
}
$query->whereBetween($v[0], $v[2]);
break;
case 'not between':
// not between查询 ['created_at', 'not between', ['xxx', 'xxx]]
if (!is_array($v[2])) {
$v[2] = explode(',', $v[2]);
}
$query->whereNotBetween($v[0], $v[2]);
break;
case 'null':
// null查询 ['deleted_at', 'null']
$query->whereNull($v[0]);
break;
case "not null":
// not null查询 ['deleted_at', 'not null']
$query->whereNotNull($v[0]);
break;
case "or":
// or查询 [[['status'=>1],['status'=>2]], 'or'];
//格式:or (status=1 and status=2)
$where = $v[0];
$query->orWhere(function ($query) use ($where) {
// 递归解析查询条件
$this->formatQuery($where, $query);
});
break;
case 'xor':
// xor查询 [[['status'=>1],['status'=>2]], 'xor'];
// 格式:and (status=1 or status=2)
$where = $v[0];
$query->where(function ($query) use ($where) {
foreach ($where as $w) {
$query->orWhere(function ($query) use ($w) {
// 递归解析查询条件
$this->formatQuery([$w], $query);
});
}
});
break;
default:
// 常规查询
if (count($v) == 2) {
$query->where($v[0], '=', $v[1]);
} else {
$query->where($v[0], $v[1], $v[2]);
}
break;
}
}
});
return $query;
$map[] = ['project_id' => $this->user['project_id']];
return parent::delete($ids, $map);
}
/**
* @name :上传图片
... ...
... ... @@ -2,7 +2,6 @@
namespace App\Http\Logic\Bside\Product;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Attr;
use App\Models\Product\AttrValue;
... ...
<?php
namespace App\Http\Logic;
use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use Illuminate\Support\Facades\Cache;
/**
* @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
*/
class Logic
{
protected $model;
protected $is_cache = true; //是否缓存数据
/**
* @notes: 请简要描述方法功能
* @param array $data
* @return array
*/
public function success(array $data = [])
{
return $data;
}
/**
* @notes: 错误抛出
* @param string $code
* @param string $message
* @throws AsideGlobalException|BsideGlobalException
*/
public function fail(string $message = "", string $code = Code::SYSTEM_ERROR)
{
if((request()->path()[0]) == Common::B){
throw new BsideGlobalException($code, $message);
}
throw new AsideGlobalException($code, $message);
}
/**
* 列表
* @param array $map
* @param array $sort
* @param array $columns
* @param int $limit
* @return array
* @author zbj
* @date 2023/4/13
*/
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
// 闭包查询条件格式化
$query = $this->formatQuery($map);
// 排序(支持多重排序)
$query = $query->when($sort, function ($query, $sort) {
foreach ($sort as $k=>$v) {
$query->orderBy($k, $v);
}
});
// 数据分页设置
if ($limit) {
$result = $query->select($columns)->paginate($limit);
}else{
$result = $query->select($columns)->get();
}
return $this->success($result ? $result->toArray() : []);
}
/**
* 详情
* @param $id
* @return array
* @throws AsideGlobalException|BsideGlobalException
* @author zbj
* @date 2023/4/13
*/
public function getInfo($id)
{
$info = $this->getCacheInfo($id);
if(!$info){
$this->fail('数据不存在或者已经删除');
}
return $this->success($info->toArray());
}
/**
* @param $id
* @return mixed
* @author zbj
* @date 2023/4/15
*/
public function getCacheInfo($id){
if($this->is_cache){
$info = Cache::get($this->getInfoCacheKey($id));
if (!$info) {
$info = $this->model->find($id);
if($info){
Cache::put($this->getInfoCacheKey($id), $info);
}
}
}else{
$info = $this->model->find($id);
}
return $info;
}
/**
* 保存
* @param $param
* @return array
* @throws BsideGlobalException|AsideGlobalException
* @author zbj
* @date 2023/4/13
*/
public function save($param){
if(!empty($param['id'])){
$this->model = $this->getCacheInfo($param['id']);
if(!$this->model){
$this->fail('数据不存在或者已经删除');
}
}
foreach ($param as $name => $value){
$this->model[$name] = $value;
}
$res = $this->model->save();
if($res){
//清缓存
if($this->is_cache && !empty($param['id'])){
Cache::forget($this->getInfoCacheKey($param['id']));
}
return $this->success(['id' => $this->model->id]); //返回保存的数据id
}else{
$this->fail('保存失败');
}
}
/**
* 批量删除
* @param $ids
* @param array $map
* @return array
* @throws AsideGlobalException|BsideGlobalException
* @author zbj
* @date 2023/4/13
*/
public function delete($ids, $map = []){
$ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
if(!$ids){
$this->fail('ID不能为空');
}
$map[] = ['id', 'in', $ids];
$res = $this->formatQuery($map)->delete();
if($res){
if($this->is_cache){
foreach ($ids as $id){
Cache::forget($this->getInfoCacheKey($id));
}
}
return $this->success();
}else{
$this->fail('删除失败');
}
}
/**
* @param $id
* @return string
* @author zbj
* @date 2023/4/13
*/
public function getInfoCacheKey($id){
return $this->model->getTable() . '_info_' . $id;
}
/**
* 格式化查询条件
* @param $map
* @param $query
* @return mixed
* @author zbj
* @date 2023/4/13
*/
public function formatQuery($map, $query = '')
{
$model = $query ?: $this->model;
$query = $model->where(function ($query) use ($map) {
foreach ($map as $v) {
if ($v instanceof \Closure) {
$query = $query->where($v);
continue;
}
// 判断是否是键值对类型
if (key($v) !== 0) {
$key = key($v);
$val = $v[$key];
$v = [$key, is_array($val) ? 'in' : '=', $val];
}
switch ($v[1]) {
case 'like':
// like查询 ['name|title', 'like', '%a%']
if (strpos($v[0], '|') !== false) {
$query->where(function ($query) use ($v) {
$item = explode('|', $v[0]);
foreach ($item as $vo) {
$query->orWhere($vo, $v[1], $v[2]);
}
});
} else {
$query->where($v[0], $v[1], $v[2]);
}
break;
case 'in':
// in查询 ['id', 'in', [1,2,3]]
if (!is_array($v[2])) {
$v[2] = explode(',', $v[2]);
}
$query->whereIn($v[0], $v[2]);
break;
case 'not in':
// not in查询 ['id', 'not in', [1,2,3]]
if (!is_array($v[2])) {
$v[2] = explode(',', $v[2]);
}
$query->whereNotIn($v[0], $v[2]);
break;
case 'between':
// between查询 ['created_at', 'between', ['xxx', 'xxx]]
if (!is_array($v[2])) {
$v[2] = explode(',', $v[2]);
}
$query->whereBetween($v[0], $v[2]);
break;
case 'not between':
// not between查询 ['created_at', 'not between', ['xxx', 'xxx]]
if (!is_array($v[2])) {
$v[2] = explode(',', $v[2]);
}
$query->whereNotBetween($v[0], $v[2]);
break;
case 'null':
// null查询 ['deleted_at', 'null']
$query->whereNull($v[0]);
break;
case "not null":
// not null查询 ['deleted_at', 'not null']
$query->whereNotNull($v[0]);
break;
case "or":
// or查询 [[['status'=>1],['status'=>2]], 'or'];
//格式:or (status=1 and status=2)
$where = $v[0];
$query->orWhere(function ($query) use ($where) {
// 递归解析查询条件
$this->formatQuery($where, $query);
});
break;
case 'xor':
// xor查询 [[['status'=>1],['status'=>2]], 'xor'];
// 格式:and (status=1 or status=2)
$where = $v[0];
$query->where(function ($query) use ($where) {
foreach ($where as $w) {
$query->orWhere(function ($query) use ($w) {
// 递归解析查询条件
$this->formatQuery([$w], $query);
});
}
});
break;
default:
// 常规查询
if (count($v) == 2) {
$query->where($v[0], '=', $v[1]);
} else {
$query->where($v[0], $v[1], $v[2]);
}
break;
}
}
});
return $query;
}
}
... ...
... ... @@ -2,8 +2,10 @@
namespace App\Http\Middleware\Aside;
use App\Enums\Common\Code;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
class LoginAuthMiddleware
{
... ... @@ -16,6 +18,16 @@ class LoginAuthMiddleware
*/
public function handle(Request $request, Closure $next)
{
$manage = Session::get('manage');
if (!$manage) {
if($request->ajax()){
return response(['status'=> Code::USER_ERROR,'msg'=>'当前用户未登录']);
}else{
return redirect(route('admin.login'));
}
}
return $next($request);
}
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Middleware\Bside;
use App\Enums\Common\Code;
use App\Models\ProjectMenu;
use App\Models\ProjectRole as ProjectRoleModel;
use App\Services\ProjectServer;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
... ... @@ -29,6 +30,9 @@ class LoginAuthMiddleware
if(empty($info)){
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
}
// 设置数据信息
ProjectServer::useProject($info['project_id']);
//操作权限设置
$projectRoleModel = new ProjectRoleModel();
$role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
... ...
<?php
namespace App\Http\Requests\Aside;
use App\Enums\Common\Demo;
use BenSampo\Enum\Rules\EnumValue;
use Illuminate\Foundation\Http\FormRequest;
class DemoRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name'=>['required'],
'status'=>['required','integer',new EnumValue(Demo::class)]
];
}
}
... ... @@ -2,11 +2,10 @@
namespace App\Models;
class Manager extends Base
class AiCommand extends Base
{
//设置关联表名
protected $table = 'gl_manager';
protected $table = 'gl_ai_command';
//自动维护create_at创建时间 updated_at修改时间
public $timestamps = true;
}
... ...
<?php
namespace App\Models;
class Manage extends Base
{
//设置关联表名
protected $table = 'gl_manage';
protected $hidden = ['password'];
const STATUS_ACTIVE = 0;
const STATUS_DISABLE = 1;
}
... ...
... ... @@ -12,6 +12,8 @@ class Project extends Base
public $timestamps = true;
protected $dateFormat = 'Y-m-d';
const DATABASE_NAME_FIX = 'globalso_project_';
/**
* @name:获取当前对象不分页列表
*/
... ... @@ -19,4 +21,52 @@ class Project extends Base
$lists = DB::table($this->table)->select(['*'])->where($this->map)->orderBy($this->order)->get();
return $lists;
}
/**
* 通过ID获取项目信息
* @param $id
* @return self
*/
public static function getProjectById($id)
{
return self::where(['id' => $id])->first();
}
/**
* 项目部署服务器信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function serverConfig()
{
return self::hasOne(ServeConfig::class, 'id', 'serve_id');
}
/**
* 项目部署mysql数据库信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function mysqlConfig()
{
return self::hasOne(ServeConfig::class, 'id', 'mysql_id');
}
/**
* 项目使用Redis服务器信息, 如果没有即使用默认配置
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function redisConfig()
{
return self::hasOne(ServeConfig::class, 'id', 'redis_id');
}
/**
* 获取项目对应数据库名称
* 初始化数据库、数据表迭代等功能使用
* TODO 如果前缀变更,请使用该方法进行处理
* @return string
*/
public function databaseName()
{
return self::DATABASE_NAME_FIX . $this->id;
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/4/17
* Time: 10:04
*/
namespace App\Models;
/**
* 服务账户信息
* Class ServeConfig
* @package App\Models
*/
class ServeConfig extends Base
{
/**
* @var string
*/
protected $table = 'gl_server_config';
/**
* @var array
*/
protected $guarded = ['updated_at'];
/**
* 1:服务器, 2:MySQL, 3:Redis
*/
const TYPE_SERVER = 1;
const TYPE_MYSQL = 2;
const TYPE_REDIS = 3;
/**
* 用户名加密
* @param $value
*/
public function setUserAttribute($value)
{
$this->attributes['user'] = encrypt($value);
}
/**
* 密码加密
* @param $value
*/
public function setPasswordAttribute($value)
{
$this->attributes['password'] = encrypt($value);
}
/**
* 端口加密
* @param $value
*/
public function setPortAttribute($value)
{
$this->attributes['Port'] = encrypt($value);
}
/**
* @return mixed
*/
public function getUserAttribute()
{
return decrypt($this->user);
}
/**
* @return mixed
*/
public function getPasswordAttribute()
{
return decrypt($this->password);
}
/**
* @return mixed
*/
public function getPortAttribute()
{
return decrypt($this->port);
}
}
\ No newline at end of file
... ...
... ... @@ -42,16 +42,16 @@ class RouteServiceProvider extends ServiceProvider
$this->mapBsideRoute();
// 暂时无用
// $this->routes(function () {
// Route::prefix('api')
// ->middleware('api')
// ->namespace($this->namespace)
// ->group(base_path('routes/api.php'));
//
// Route::middleware('web')
// ->namespace($this->namespace)
// ->group(base_path('routes/web.php'));
// });
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}
/**
... ...
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
/**
* 验证手机号
* Class Mobile
* @package App\Rules
* @author zbj
* @date 2023/4/19
*/
class Mobile implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$cardReg = '/^1(3|4|5|7|8)\d{9}$/';
return preg_match($cardReg, $value);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return '手机号码格式不正确';
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/4/17
* Time: 15:16
*/
namespace App\Services;
use App\Models\Project;
/**
* Class ProjectServer
* @package App\Services
*/
class ProjectServer extends BaseService
{
/**
* @param $project_id
* @return bool
*/
public static function useProject($project_id)
{
$project = Project::getProjectById($project_id);
if (empty($project))
return false;
// 设置 database.connections.custom_mysql 配置
config(['database.connections.custom_mysql.host' => $project->mysqlConfig()->host]);
config(['database.connections.custom_mysql.port' => $project->mysqlConfig()->port]);
config(['database.connections.custom_mysql.database' => $project->databaseName()]);
config(['database.connections.custom_mysql.username' => $project->mysqlConfig()->user]);
config(['database.connections.custom_mysql.password' => $project->mysqlConfig()->password]);
// 设置 redis 配置
return true;
}
}
\ No newline at end of file
... ...
... ... @@ -7,6 +7,7 @@
"require": {
"php": "^7.3|^8.0",
"bensampo/laravel-enum": "^4.2",
"doctrine/dbal": "^3.6",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.75",
... ...
... ... @@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "ec0188ad5b235cba39d53baaa3d96767",
"content-hash": "6c3880102ef840b5bed38e672d350800",
"packages": [
{
"name": "asm89/stack-cors",
... ... @@ -305,6 +305,346 @@
"time": "2021-08-13T13:06:58+00:00"
},
{
"name": "doctrine/cache",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
"reference": "1ca8f21980e770095a31456042471a57bc4c68fb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/cache/zipball/1ca8f21980e770095a31456042471a57bc4c68fb",
"reference": "1ca8f21980e770095a31456042471a57bc4c68fb",
"shasum": ""
},
"require": {
"php": "~7.1 || ^8.0"
},
"conflict": {
"doctrine/common": ">2.2,<2.4"
},
"require-dev": {
"cache/integration-tests": "dev-master",
"doctrine/coding-standard": "^9",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"symfony/cache": "^4.4 || ^5.4 || ^6",
"symfony/var-exporter": "^4.4 || ^5.4 || ^6"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
}
],
"description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.",
"homepage": "https://www.doctrine-project.org/projects/cache.html",
"keywords": [
"abstraction",
"apcu",
"cache",
"caching",
"couchdb",
"memcached",
"php",
"redis",
"xcache"
],
"support": {
"issues": "https://github.com/doctrine/cache/issues",
"source": "https://github.com/doctrine/cache/tree/2.2.0"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache",
"type": "tidelift"
}
],
"time": "2022-05-20T20:07:39+00:00"
},
{
"name": "doctrine/dbal",
"version": "3.6.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "57815c7bbcda3cd18871d253c1dd8cbe56f8526e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/57815c7bbcda3cd18871d253c1dd8cbe56f8526e",
"reference": "57815c7bbcda3cd18871d253c1dd8cbe56f8526e",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2",
"doctrine/cache": "^1.11|^2.0",
"doctrine/deprecations": "^0.5.3|^1",
"doctrine/event-manager": "^1|^2",
"php": "^7.4 || ^8.0",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3"
},
"require-dev": {
"doctrine/coding-standard": "11.1.0",
"fig/log-test": "^1",
"jetbrains/phpstorm-stubs": "2022.3",
"phpstan/phpstan": "1.10.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "9.6.4",
"psalm/plugin-phpunit": "0.18.4",
"squizlabs/php_codesniffer": "3.7.2",
"symfony/cache": "^5.4|^6.0",
"symfony/console": "^4.4|^5.4|^6.0",
"vimeo/psalm": "4.30.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": [
"bin/doctrine-dbal"
],
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\DBAL\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
}
],
"description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.",
"homepage": "https://www.doctrine-project.org/projects/dbal.html",
"keywords": [
"abstraction",
"database",
"db2",
"dbal",
"mariadb",
"mssql",
"mysql",
"oci8",
"oracle",
"pdo",
"pgsql",
"postgresql",
"queryobject",
"sasql",
"sql",
"sqlite",
"sqlserver",
"sqlsrv"
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.6.1"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
"type": "tidelift"
}
],
"time": "2023-03-02T19:26:24+00:00"
},
{
"name": "doctrine/deprecations",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/deprecations.git",
"reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de",
"reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de",
"shasum": ""
},
"require": {
"php": "^7.1|^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^9",
"phpunit/phpunit": "^7.5|^8.5|^9.5",
"psr/log": "^1|^2|^3"
},
"suggest": {
"psr/log": "Allows logging deprecations via PSR-3 logger implementation"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.",
"homepage": "https://www.doctrine-project.org/",
"support": {
"issues": "https://github.com/doctrine/deprecations/issues",
"source": "https://github.com/doctrine/deprecations/tree/v1.0.0"
},
"time": "2022-05-02T15:47:09+00:00"
},
{
"name": "doctrine/event-manager",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/event-manager.git",
"reference": "95aa4cb529f1e96576f3fda9f5705ada4056a520"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/event-manager/zipball/95aa4cb529f1e96576f3fda9f5705ada4056a520",
"reference": "95aa4cb529f1e96576f3fda9f5705ada4056a520",
"shasum": ""
},
"require": {
"doctrine/deprecations": "^0.5.3 || ^1",
"php": "^7.1 || ^8.0"
},
"conflict": {
"doctrine/common": "<2.9"
},
"require-dev": {
"doctrine/coding-standard": "^9 || ^10",
"phpstan/phpstan": "~1.4.10 || ^1.8.8",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"vimeo/psalm": "^4.24"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Common\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
},
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
}
],
"description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.",
"homepage": "https://www.doctrine-project.org/projects/event-manager.html",
"keywords": [
"event",
"event dispatcher",
"event manager",
"event system",
"events"
],
"support": {
"issues": "https://github.com/doctrine/event-manager/issues",
"source": "https://github.com/doctrine/event-manager/tree/1.2.0"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager",
"type": "tidelift"
}
],
"time": "2022-10-12T20:51:15+00:00"
},
{
"name": "doctrine/inflector",
"version": "2.0.4",
"source": {
... ... @@ -2597,6 +2937,55 @@
"time": "2023-02-25T19:38:58+00:00"
},
{
"name": "psr/cache",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"support": {
"source": "https://github.com/php-fig/cache/tree/master"
},
"time": "2016-08-06T20:24:11+00:00"
},
{
"name": "psr/container",
"version": "1.1.2",
"source": {
... ... @@ -8574,5 +8963,5 @@
"php": "^7.3|^8.0"
},
"platform-dev": [],
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.1.0"
}
... ...
... ... @@ -63,6 +63,46 @@ return [
]) : [],
],
'custom_tmp_mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE_TMP', 'globalso_project_tmp'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'custom_mysql' => [
'driver' => 'mysql',
'url' => '', // DB_DATABASE_URL
'host' => '', // DB_DATABASE_HOST
'port' => '', // DB_DATABASE_PORT
'database' => '', // DB_DATABASE_CUSTOM
'username' => '', // DB_DATABASE_USER
'password' => '', // DB_DATABASE_PASSWORD
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
... ...
<form method="post" action="">
@csrf
<input type="text" name="mobile" value="15680871314">
<input type="text" name="password" value="123456">
<input type="submit">
</form>
... ...
... ... @@ -5,12 +5,23 @@
use \Illuminate\Support\Facades\Route;
use \App\Http\Controllers\Aside;
//必须登录验证的路由组
Route::middleware(['aloginauth'])->group(function ($route) {
Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上web的中间件
Route::middleware(['aloginauth'])->group(function () {
Route::get('/', [Aside\IndexController::class, 'index'])->name('admin.home');
Route::get('/logout', [Aside\LoginController::class, 'logout'])->name('admin.logout');
});
//菜单
Route::prefix('menu')->group(function () {
Route::get('/', [Aside\MenuController::class, 'index'])->name('admin.menu');
Route::get('/info', [Aside\MenuController::class, 'info'])->name('admin.menu_info');
Route::post('/save', [Aside\MenuController::class, 'save'])->name('admin.menu_save');
Route::any('/delete', [Aside\MenuController::class, 'delete'])->name('admin.menu_delete');
});
});
//无需登录验证的路由组
Route::group([], function ($route) {
//demo
$route->post('/demo', [Aside\DemoController::class, 'test']);
Route::group([], function () {
Route::any('/login', [Aside\LoginController::class, 'login'])->name('admin.login');
});
});
... ...
... ... @@ -82,6 +82,10 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/del', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'del'])->name('blog_del');
Route::any('/status', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'status'])->name('blog_status');
});
//ai指令
Route::prefix('command')->group(function () {
Route::any('/', [\App\Http\Controllers\Bside\Blog\AiCommandController::class, 'lists'])->name('command_lists');
});
//产品
Route::prefix('product')->group(function () {
... ...