作者 lyh

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

... ... @@ -7,6 +7,8 @@
*/
namespace App\Console\Commands\Test;
use App\Models\Devops\ServerConfig;
use App\Services\ProjectServer;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
... ... @@ -42,6 +44,15 @@ class Demo extends Command
*/
public function handle()
{
//切换数据库配置
$project = ProjectServer::useProject(1);
//创建数据库
ProjectServer::createDatabase($project);
//创建表
ProjectServer::initTable($project);
dd(1);
$sql = 'CREATE DATABASE database_name;';
$results = DB::select($sql);
dd($results);
... ...
... ... @@ -200,4 +200,16 @@ class BaseController extends Controller
}
return true;
}
/**
* 是否post请求
* @return bool
*/
protected final function isPost()
{
return \Illuminate\Support\Facades\Request::isMethod('post');
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\BCustom;
/**
* 自定义 页面
* @author:dc
* @time 2023/5/9 10:08
* Class CustomController
* @package App\Http\Controllers\Bside
*/
class CustomController extends BaseController
{
/**
* 验证规则
* @var array[]
*/
private $verify = [
'role' => [
'name' => ['required','max:100'],
'title' => ['required','max:200'],
'keywords' => ['required','max:200'],
'description' => ['required','max:250'],
'html' => ['required'],
'url' => ['required','max:200'],
'status' => ['required','in:0,1'],
],
'message' => [
'name.required' => '名称必须',
'name.max' => '名称不能超过100个字符',
'title.required' => '网页标题必须',
'title.max' => '网页标题不能超过200个字符',
'keywords.required' => '网页关键字必须',
'keywords.max' => '网页关键字不能超过200个字符',
'description.required' => '网页描述必须',
'description.max' => '网页描述不能超过250个字符',
'url.required' => '链接必须',
'url.max' => '链接不能超过200个字符',
'status.required' => '状态选择错误',
'status.in' => '状态必须是显示/隐藏'
],
'attr' => [
]
];
/**
* 列表数据
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/8 16:37
*/
public function index(){
// 每页数量
$limit = intval($this->param['limit']??20);
$lists = BCustom::_all($this->user['project_id'],$limit)->toArray();
return $this->success($lists);
}
/**
* 创建数据
* @author:dc
* @time 2023/5/8 16:39
*/
public function create(){
return $this->save();
}
/**
* 修改
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/8 17:06
*/
public function update(){
$this->verify['role']['id'] = ['required','integer','gt:0'];
$this->verify['message']['id.gt'] = $this->verify['message']['id.integer'] = $this->verify['message']['id.required'] = '编辑导航数据不存在';
return $this->save();
}
/**
* 新增修改
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/8 17:06
*/
private function save(){
$data = $this->validate(request() ,$this->verify['role'],$this->verify['message']);
// 保存
$id = BCustom::_save($this->user['project_id'],$data,$data['id']??0);
if($id===-1){
return $this->response('数据不存在','B_CUSTOM_NOTFOUND');
}
return $this->success(BCustom::_find($this->user['project_id'],$id,true));
}
/**
* 删除数据
* @return \Illuminate\Http\JsonResponse
* @author:dc
* @time 2023/5/9 9:20
*/
public function delete(){
$id = $this->param['id']??0;
$data = BCustom::_find($this->user['project_id'],$id);
if(empty($data)){
return $this->response('数据不存在','B_CUSTOM_NOTFOUND');
}
if($data->delete()){
return $this->response('删除成功',Code::SUCCESS);
}
}
}
... ...
... ... @@ -169,6 +169,33 @@ class NavController extends BaseController
}
/**
* @author:dc
* @time 2023/5/9 16:14
*/
public function urls(){
// todo::需要配合 c端来
return $this->success([
[
'url' => '/',
'name' => '首页'
],
[
'url' => '/list',
'name' => '列表'
],
[
'url' => '/page',
'name' => '单页'
],
[
'url' => 'goods',
'name' => '商品'
],
]);
}
... ...
... ... @@ -2,18 +2,15 @@
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Models\Template\AHeadFoot;
use App\Models\Template\BCustom;
use App\Models\Template\BHeadFoot;
use App\Models\Template\BTemplate;
use Illuminate\Support\Facades\DB;
use App\Models\Template\ATemplate;
use App\Models\Template\BSetting;
/**
* 自定义 页面
* 模板
* @author:dc
* @time 2023/5/4 15:59
* @time 2023/5/9 14:00
* Class TemplateController
* @package App\Http\Controllers\Bside
*/
... ... @@ -22,141 +19,57 @@ class TemplateController extends BaseController
/**
* 头部底部的 html
* 模板列表
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/4 16:15
* @time 2023/5/9 14:20
*/
public function index(){
$data = BTemplate::_get($this->user['project_id']);
// todo::这里要进行html的替换
return $this->success($data);
}
/**
* 读取编辑的html
* @author:dc
* @time 2023/5/4 16:19
*/
public function edit_html(){
$data = BHeadFoot::_get($this->user['project_id']);
if(!$data){
$data = AHeadFoot::_bDefault();
}
return $this->success([
'header' => $data[BHeadFoot::TYPE_HEADER]??'',
'footer' => $data[BHeadFoot::TYPE_FOOTER]??'',
]);
}
/**
* 保存
* @author:dc
* @time 2023/5/4 17:42
*/
public function edit_save(){
$limit = intval($this->param['limit']??20);
$header = $this->param['header']??'';
$footer = $this->param['footer']??'';
// 读取列表
$data = ATemplate::_bAll($limit)->toArray();
if(!$header && !$footer){
throw new BsideGlobalException('B01024','不能为空');
}
DB::beginTransaction();
try {
if($header){
BHeadFoot::_save($this->user['project_id'],BHeadFoot::TYPE_HEADER,$header);
}
if($footer){
BHeadFoot::_save($this->user['project_id'],BHeadFoot::TYPE_FOOTER,$footer);
}
}catch (\Throwable $e){
DB::rollBack();
throw new BsideGlobalException('B01024','保存失败');
}
DB::commit();
$this->success([]);
return $this->success($data);
}
/**
* 获取系统的模板
* 当前使用的模板
* @author:dc
* @time 2023/5/4 16:21
* @time 2023/5/9 15:19
*/
public function system_all_html(){
$data = AHeadFoot::_ball();
$lists = [];
// 以名字为单位区分
foreach ($data as $datum){
if(empty($lists[$datum['name']])) $lists[$datum['name']] = [];
$lists[$datum['name']]['name'] = $datum['name'];
$lists[$datum['name']]['default'] = $datum['is_default'];
$lists[$datum['name']][$datum['type']==AHeadFoot::TYPE_HEADER?'header':'footer'] = $datum['html'];
public function info(){
// 保存更新
if($this->isPost()){
$template_id = intval($this->param['template_id']??0);
// 是否存在模板
if($template_id && ATemplate::_bFind($template_id)){
BSetting::_save($this->user['project_id'],$template_id);
}else{
return $this->response('无法使用不存在的模板','B_TEMPLATE_NOTFOUND');
}
}
// 读取我的模板
$conf = BSetting::_get($this->user['project_id']);
// 读取模板信息
$data = ATemplate::_bFind($conf['template_id']);
return $this->success(array_values($lists));
}
/**
* 自定义 列表
* @author:dc
* @time 2023/5/4 17:13
*/
public function custom(){
$data = BCustom::_all($this->user['project_id']);
return $this->success($data->toArray());
}
public function custom_create(){
}
public function custom_edit($id){
}
public function custom_delete($id){
return $this->success([
'template_id' => $data['id']??0,
'name' => $data['name']??'',
'thumb' => $data['thumb']??'',
'time' => $conf['time']
]);
}
}
... ...
... ... @@ -30,10 +30,10 @@ class LoginAuthMiddleware
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
}
// 设置数据信息
// $project = ProjectServer::useProject($info['project_id']);
// if($project){
// return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);
// }
$project = ProjectServer::useProject($info['project_id']);
if($project){
return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);
}
//操作权限设置
$projectRoleModel = new ProjectRoleModel();
$role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
... ...
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* b端控制, c端显示的自定义页面
* @author:dc
* @time 2023/5/8 16:14
* Class BCustom
* @package App\Models
*/
class BCustom extends Base
{
protected $table = 'gl_web_custom';
use SoftDeletes;
public $hidden = ['deleted_at','project_id'];
/**
* 显示
*/
const STATUS_ACTIVE = 1;
/**
* 隐藏
*/
const STATUS_DISABLED = 0;
/**
* 创建或者新增导航栏
* @param int $project_id
* @param array $data
* @param int $id
* @return int
* @author:dc
* @time 2023/5/8 16:24
*/
public static function _save(int $project_id, array $data, int $id = 0):int {
if($id){
$model = static::where('id',$id)->where('project_id', $project_id)->first();
if(!$model){
return -1;
}
}else{
$model = new static();
$model->project_id = $project_id;
}
$model->name = $data['name'];
$model->title = $data['title'];
$model->keywords = $data['keywords'];
$model->description = $data['description'];
$model->url = $data['url'];
$model->status = $data['status'];
$model->html = $data['html'];
$model->save();
// 创建路由标识
try {
RouteMap::setRoute($model->url,RouteMap::SOURCE_CUSTOM,$model->id,$project_id);
}catch (\Throwable $e){
}
return $model->id;
}
/**
* 删除
* @param int $project_id
* @param int $id
* @return mixed
* @author:dc
* @time 2023/5/8 16:27
*/
public static function _del(int $project_id, int $id){
return static::where(['project_id'=>$project_id,'id'=>$id])->delete();
}
/**
* 查询当前项目下的所有信息
* @param int $project_id
* @return mixed
* @author:dc
* @time 2023/5/8 16:29
*/
public static function _all(int $project_id, int $limit = 20)
{
return static::where(function ($query) use ($project_id){
// 那个公司
$query->where('project_id',$project_id);
})
->select(['id','name','title','status','url','keywords','description','created_at','updated_at'])
->paginate($limit);
}
/**
* 查询一条数据
* @param int $project_id
* @param int $id
* @return mixed
* @author:dc
* @time 2023/5/8 17:04
*/
public static function _find(int $project_id, int $id, $array = false)
{
$data = static::where(['id'=>$id,'project_id'=>$project_id])->first();
if($data){
return $array ? $data->toArray() : $data;
}
return [];
}
}
... ...
... ... @@ -14,7 +14,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class BNav extends Base
{
protected $table = 'gl_bside_nav';
protected $table = 'gl_web_nav';
use SoftDeletes;
... ...
... ... @@ -24,7 +24,7 @@ class ManageLog extends Base
$log = new self();
$log->title = $menu ? $menu['title'] : '';
$log->manage_id = LoginLogic::manage('id');
$log->manage_id = LoginLogic::manage('id') ? : 0;
$log->route_name = request()->route()->getName();
$log->action = request()->path();
$log->method = request()->method();
... ...
... ... @@ -12,7 +12,7 @@ class Project extends Base
//设置关联表名
protected $table = 'gl_project';
const DATABASE_NAME_FIX = 'globalso_project_';
const DATABASE_NAME_FIX = 'gl_data_';
/**
* 星级客户
... ...
... ... @@ -26,6 +26,8 @@ class RouteMap extends Model
//路由类型
const SOURCE_BLOG = 'blog';
const SOURCE_NEWS = 'news';
// 自定义界面
const SOURCE_CUSTOM = 'custom';
/**
* 生成路由标识
* @param $title
... ...
<?php
namespace App\Models\Template;
/**
* 头部底部
* @author:dc
* @time 2023/5/4 15:52
* Class AHeadFoot
* @package App\Models\Template
*/
class AHeadFoot extends \App\Models\Base{
protected $table = 'gl_aside_template_header_footer';
// 分开存 头底 为了方便后期可能会 改版为 随意搭配 头底部
const TYPE_HEADER = 'H';
const TYPE_FOOTER = 'F';
const STATUS_ACTIVE = 1;
const STATUS_DISABLED = 0;
const IS_DEFAULT = 1;
/**
* b 端 查询
* @return mixed
* @author:dc
* @time 2023/5/4 16:24
*/
public static function _ball(){
return static::where('status',static::STATUS_ACTIVE)->orderBy('sort')->get(['id','name','type','html','is_default']);
}
/**
* b 端 读取默认的一个头部底部
* @return mixed
* @author:dc
* @time 2023/5/4 16:51
*/
public static function _bDefault(){
return static::where(['status'=>static::STATUS_ACTIVE,'is_default'=>static::IS_DEFAULT])
->get(['type','html'])
->pluck('html','type')
->toArray();
}
}
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 由 A端增删改
* 模板
* @author:dc
* @time 2023/5/9 13:56
* Class ATemplate
* @package App\Models\Template
*/
class ATemplate extends \App\Models\Base{
protected $table = 'gl_aside_template';
protected $hidden = ['deleted_at'];
use SoftDeletes;
/**
* 显示
*/
const STATUS_ACTIVE = 1;
/**
* 隐藏
*/
const STATUS_DISABLED = 0;
/**
* b 端调用
* @param int $limit
* @return mixed
* @author:dc
* @time 2023/5/9 14:14
*/
public static function _bAll(int $limit = 20)
{
return static::where(function ($query){
$query->where('status',static::STATUS_ACTIVE);
})
->select(['id','name','url','thumb','created_at','updated_at'])
->orderBy('sort')
->paginate($limit);
}
/**
* @param $id
* @return array
* @author:dc
* @time 2023/5/9 15:16
*/
public static function _bFind($id)
{
$data = static::where('id',$id)->first();
if(!$data || $data->status === static::STATUS_DISABLED){
return [];
}
return $data;
}
/**
* 获取默认模板
* @return mixed
* @author:dc
* @time 2023/5/9 15:09
*/
public static function _default()
{
return static::where(['status'=>static::STATUS_ACTIVE,'is_default'=>1])->first();
}
}
... ...
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 由 A端增删改
* 模板
* @author:dc
* @time 2023/5/9 13:56
* Class ATemplate
* @package App\Models\Template
*/
class ATemplateHtml extends \App\Models\Base{
protected $table = 'gl_aside_template_html';
protected $hidden = ['deleted_at'];
use SoftDeletes;
}
... ...
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 自定义 页面
* @author:dc
* @time 2023/5/4 17:18
* Class BCustom
* @package App\Models\Template
*/
class BCustom extends \App\Models\Base{
protected $table = 'gl_bside_template_custom';
use SoftDeletes;
const STATUS_ACTIVE = 1;
const STATUS_DISABLED = 0;
/**
* 读取列表
* @param $project_id
* @return mixed
* @author:dc
* @time 2023/5/4 17:22
*/
public static function _all($project_id){
return static::where([
'project_id' => $project_id
])->paginate(20);
}
}
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 当前用户的模板
* @author:dc
* @time 2023/5/9 15:03
* Class BSetting
* @package App\Models\Template
*/
class BSetting extends \App\Models\Base{
protected $table = 'gl_web_setting_template';
/**
* b 端调用
* @param int $limit
* @return mixed
* @author:dc
* @time 2023/5/9 14:14
*/
public static function _get(int $project_id)
{
$data = static::where('project_id',$project_id)->first();
if($data){
return [
'template_id' => $data['template_id'],
'time' => $data['updated_at']
];
}
// 米有数据
// 读取默认的模板
$temp = ATemplate::_default();
// 保存
self::_save($project_id,$temp['id']);
return [
'template_id' => $temp['id'],
'time' => date('Y-m-d H:i:s')
];
}
/**
* 模板保存
* @param int $project_id
* @param int $template_id
* @return mixed
* @author:dc
* @time 2023/5/9 15:13
*/
public static function _save(int $project_id, int $template_id)
{
$data = static::where('project_id',$project_id)->first();
if(!$data){
$data = new static();
$data->project_id = $project_id;
}
$data->template_id = $template_id;
$data->save();
return $data->id;
}
}
... ...
... ... @@ -11,7 +11,7 @@ namespace App\Models\Template;
*/
class BTemplate extends \App\Models\Base{
protected $table = 'gl_bside_template_html';
protected $table = 'gl_web_template_html';
... ...
... ... @@ -24,7 +24,7 @@ class ProjectServer extends BaseService
*/
public static function useProject($project_id)
{
$project = Project::getProjectById($project_id);
$project = Project::where(['id' => $project_id])->first();
if (empty($project))
return false;
... ...
... ... @@ -68,7 +68,7 @@ return [
'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'),
'database' => env('DB_DATABASE_TMP', 'gl_data_0_tmp'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
... ...
... ... @@ -221,21 +221,30 @@ Route::middleware(['bloginauth'])->group(function () {
// 自定义页面
// 模板
Route::prefix('template')->group(function () {
Route::get('/', [\App\Http\Controllers\Bside\TemplateController::class, 'index'])->name('template_header_footer');
Route::get('/edit', [\App\Http\Controllers\Bside\TemplateController::class, 'edit_html'])->name('template_header_footer_edit');
Route::get('/', [\App\Http\Controllers\Bside\TemplateController::class, 'index'])->name('bside_template');
Route::any('/use-template', [\App\Http\Controllers\Bside\TemplateController::class, 'info'])->name('bside_template_use');
Route::post('/edit', [\App\Http\Controllers\Bside\TemplateController::class, 'edit_save'])->name('template_header_footer_edit_save');
Route::get('/system', [\App\Http\Controllers\Bside\TemplateController::class, 'system_all_html'])->name('template_header_footer_system');
Route::get('/custom', [\App\Http\Controllers\Bside\TemplateController::class, 'custom'])->name('template_custom');
});
// 自定义页面,专题页
Route::prefix('custom')->group(function () {
Route::get('/', [\App\Http\Controllers\Bside\CustomController::class, 'index'])->name('bside_custom');
Route::post('/create', [\App\Http\Controllers\Bside\CustomController::class, 'create'])->name('bside_custom_create');
Route::post('/update', [\App\Http\Controllers\Bside\CustomController::class, 'update'])->name('bside_custom_update');
Route::delete('/delete', [\App\Http\Controllers\Bside\CustomController::class, 'delete'])->name('bside_custom_delete');
});
// 导航栏编辑
Route::prefix('nav')->group(function () {
Route::get('/', [\App\Http\Controllers\Bside\NavController::class, 'index'])->name('bside_nav');
Route::post('/create', [\App\Http\Controllers\Bside\NavController::class, 'create'])->name('bside_nav_create');
Route::post('/update', [\App\Http\Controllers\Bside\NavController::class, 'update'])->name('bside_nav_update');
Route::delete('/delete', [\App\Http\Controllers\Bside\NavController::class, 'delete'])->name('bside_nav_delete');
Route::get('/default-urls', [\App\Http\Controllers\Bside\NavController::class, 'urls'])->name('bside_nav_default_urls');
});
... ...