作者 lyh

gx

... ... @@ -140,6 +140,11 @@ class Handler extends ExceptionHandler
'code' => $code,
'message' => $message
];
// 调试模式
if(env('app_debug')){
$response['trace'] = $exception->getTrace();
}
//加密返回
if (config('app.params_encrypt')) {
$k = config('app.params_encrypt_key');
... ...
<?php
namespace App\Http\Controllers\Aside;
use App\Models\Template\AHeadFoot;
/**
* 模板
* @author:dc
* @time 2023/5/4 17:10
* Class TemplateController
* @package App\Http\Controllers\Aside
*/
class TemplateController extends BaseController
{
/**
* 列表
* @author:dc
* @time 2023/5/4 17:10
*/
public function index(){
$data = AHeadFoot::all();
$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']]['sort'] = $datum['sort'];
$lists[$datum['name']]['status'] = $datum['status'];
$lists[$datum['name']]['created_at'] = $datum['created_at'];
// $lists[$datum['name']]['tags'] = $datum['tags'];
$lists[$datum['name']][$datum['type']==AHeadFoot::TYPE_HEADER?'header':'footer'] = $datum['html'];
}
return $this->success($lists);
}
/**
* 编辑
* @author:dc
* @time 2023/5/4 16:19
*/
public function edit(){
}
/**
* 新增
* @author:dc
* @time 2023/5/5 9:30
*/
public function insert(){
}
private function save($name = ''){
}
/**
* 删除
* @author:dc
* @time 2023/5/4 17:10
*/
public function delete(){
}
}
... ...
... ... @@ -35,10 +35,15 @@ class BaseController extends Controller
$info = Cache::get($this->token);
$this->user = $info;
$this->uid = $info['id'];
<<<<<<< HEAD
//参数处理
$this->get_param();
//日志记录
$this->set_user_log();
=======
}else{
throw new HttpResponseException(response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']));
>>>>>>> db84ec9e0ac005907f6868b371df2ccf8defd114
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\BNav;
/**
* 导航栏目 b端编辑 c端显示
* @author:dc
* @time 2023/5/8 16:31
* Class NavController
* @package App\Http\Controllers\Bside
*/
class NavController extends BaseController
{
/**
* 验证规则
* @var array[]
*/
private $verify = [
'role' => [
'pid' => ['required','integer','gte:0'],
'name' => ['required','max:100'],
'location' => ['required','in:header,footer'],
'url' => ['required','max:200'],
'status' => ['required','in:0,1'],
'target' => ['required','in:0,1'],
'sort' => ['required','integer','gte:0']
],
'message' => [
'pid.required' => '上级选择错误',
'pid.gte' => '上级选择错误',
'pid.integer' => '上级选择错误',
'name.required' => '名称必须',
'name.max' => '名称不能超过100个字符',
'location.required' => '位置选择错误',
'location.in' => '位置选择错误',
'url.required' => '链接必须',
'url.max' => '链接不能超过200个字符',
'status.required' => '状态选择错误',
'status.in' => '状态必须是显示/隐藏',
'target.required' => '打开方式必须',
'target.in' => '打开方式选择错误',
'sort.required' => '排序必须',
'sort.integer' => '排序必须是一个数字',
'sort.gte' => '排序必须大于等于0',
],
'attr' => [
]
];
/**
* 列表数据
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/8 16:37
*/
public function index(){
$isTree = $this->param['tree']??false;
// 显示位置
$location = $this->param['location']??'';
$lists = BNav::_all($this->user['project_id'],$location)->toArray();
if($isTree){
$lists = list_to_tree($lists);
}
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']);
if($data['pid']){
// 验证是否存在上级
$all = BNav::_all($this->user['project_id'],$data['location']);
if(!$all->where('id',$data['pid'])->count()){
return $this->response('上级栏目不存在','B_NAV_PID_NOTFOUND');
}
// 上级不允许是自己的下级
if(!empty($data['id'])){
$all = list_to_tree($all->toArray(),$data['id']);
$all = tree_to_list($all);
if(in_array($data['pid'],array_column($all,'id'))){
return $this->response('上级栏目不允许为本身的下级','B_NAV_PID_IS_CHILD');
}
}
}
// 保存
$id = BNav::_save($this->user['project_id'],$data,$data['id']??0);
if($id===-1){
return $this->response('导航菜单不存在','B_NAV_NOTFOUND');
}
return $this->success(BNav::_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 = BNav::_find($this->user['project_id'],$id);
if(empty($data)){
return $this->response('导航菜单不存在','B_NAV_NOTFOUND');
}
if(BNav::isChild($data['id'],$this->user['project_id'])){
return $this->response('存在下级无法删除','B_NAV_DELETE_CHILD');
}
if($data->delete()){
return $this->response('删除成功',Code::SUCCESS);
}
}
}
... ...
<?php
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;
/**
* 自定义 页面
* @author:dc
* @time 2023/5/4 15:59
* Class TemplateController
* @package App\Http\Controllers\Bside
*/
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
*/
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(){
$header = $this->param['header']??'';
$footer = $this->param['footer']??'';
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([]);
}
/**
* 获取系统的模板
* @author:dc
* @time 2023/5/4 16:21
*/
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'];
}
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){
}
}
... ...
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* b端控制, c端显示的导航
* @author:dc
* @time 2023/5/8 16:14
* Class BNav
* @package App\Models
*/
class BNav extends Base
{
protected $table = 'gl_bside_nav';
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->pid = $data['pid'];
$model->name = $data['name'];
$model->location = $data['location'];
$model->url = $data['url'];
$model->status = $data['status'];
$model->target = $data['target'];
$model->sort = $data['sort'];
$model->save();
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, string $location = null)
{
return static::where(function ($query) use ($project_id,$location){
// 那个公司
$query->where('project_id',$project_id);
// 显示位置
$location && $query->where('location',$location);
})
->orderBy('sort')
->get();
}
/**
* 查询一条数据
* @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 [];
}
/**
* 是否存在
* @param int $project_id
* @param int $id
* @return mixed
* @author:dc
* @time 2023/5/8 17:24
*/
public static function _check(int $project_id, int $id)
{
return static::where(['id'=>$id,'project_id'=>$project_id])->count();
}
/**
* 是否有下级
* @param int $id
* @param int $project_id
* @return mixed
* @author:dc
* @time 2023/5/9 9:23
*/
public static function isChild(int $id,int $project_id=0)
{
return static::where(['pid'=>$id,'project_id'=>$project_id])->limit(1)->count();
}
}
... ...
<?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;
/**
* 自定义 页面
* @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;
/**
* 自定义 界面
* @author:dc
* @time 2023/5/8 13:52
* Class BTemplate
* @package App\Models\Template
*/
class BTemplate extends \App\Models\Base{
protected $table = 'gl_bside_template_html';
/**
* @param $project_id
* @return mixed
* @author:dc
* @time 2023/5/4 16:13
*/
public static function _get($project_id){
return static::where(['project_id'=>$project_id])->get(['html','type'])->pluck('html','type')->toArray();
}
public static function _all($project_id){
return static::where(['project_id'=>$project_id])->get();
}
/**
* 保存
* @param $project_id
* @param $type
* @param $html
* @author:dc
* @time 2023/5/4 17:50
*/
public static function _save($project_id,$type,$html){
$data = static::where(['project_id'=>$project_id,'type'=>$type])->first();
if(!$data){
$data = new static();
$data->project_id = $project_id;
$data->type = $type;
}
$data->html = $html;
$data->save();
return $data->id;
}
}
... ...
... ... @@ -11,7 +11,11 @@ define('LARAVEL_START', microtime(true));
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
<<<<<<< HEAD
| loading of any of our classes manually. It's great to relax.
=======
| loading of any our classes "manually". Feels great to relax.
>>>>>>> db84ec9e0ac005907f6868b371df2ccf8defd114
|
*/
... ...
... ... @@ -124,6 +124,16 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w
});
});
// 自定义页面 模板,头部底部
Route::prefix('template')->group(function () {
Route::get('/', [\App\Http\Controllers\Aside\TemplateController::class, 'index'])->name('admin.template_header_footer');
Route::get('/edit', [\App\Http\Controllers\Aside\TemplateController::class, 'edit'])->name('admin.template_header_footer_edit');
Route::get('/insert', [\App\Http\Controllers\Aside\TemplateController::class, 'insert'])->name('admin.template_header_footer_insert');
Route::get('/delete', [\App\Http\Controllers\Aside\TemplateController::class, 'delete'])->name('admin.template_header_footer_system');
});
});
//无需登录验证的路由组
... ...
... ... @@ -216,6 +216,30 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/del', [\App\Http\Controllers\Bside\AyrShare\AyrShareController::class, 'del_account'])->name('ayr_del_account');
Route::any('/bind', [\App\Http\Controllers\Bside\AyrShare\AyrShareController::class, 'bind_account'])->name('ayr_bind_account');
});
// 自定义页面
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::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('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');
});
});
//无需登录验证的路由组
... ...