作者 lyh

gx

... ... @@ -103,7 +103,7 @@ class BlogCategoryController extends BaseController
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$blogCategoryLogic->del_blog_category();
$blogCategoryLogic->delBlogCategory();
//TODO::写入操作日志
$this->response('success');
}
... ...
... ... @@ -126,7 +126,7 @@ class BlogController extends BaseController
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$blogLogic->blog_status();
$blogLogic->blogStatus();
//TODO::写入日志
$this->response('success');
}
... ... @@ -143,7 +143,7 @@ class BlogController extends BaseController
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$blogLogic->blog_del();
$blogLogic->blogDel();
$this->response('success');
}
... ...
... ... @@ -82,28 +82,14 @@ class NavController extends BaseController
*/
public function urls(){
// todo::需要配合 c端来
return $this->success([
[
'url' => 'index',
'name' => '首页'
],
[
'url' => 'news',
'name' => '新闻'
],
[
'url' => 'products',
'name' => '产品'
],
[
'url' => 'search',
'name' => '搜索页'
],
[
'url' => 'blog',
'name' => '博客'
]
$data = $this->success([
['url'=>'index', 'name'=>'首页'],
['url'=>'news', 'name'=>'新闻'],
['url'=>'products', 'name'=>'产品'],
['url'=>'search', 'name'=>'搜索页'],
['url'=>'blog', 'name'=>'博客']
]);
$this->response('success',Code::SUCCESS,$data);
}
/**
... ...
... ... @@ -61,30 +61,17 @@ class NewsCategoryController extends BaseController
$info['url'] = $this->user['domain'] . $info['alias'];
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加分类
* @author :liyuhang
* @method
*/
public function add(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
$request->validated();
//添加时,验证分类上级分类是否有,有则更新到当前分类中,没有时直接添加
$newsCategoryLogic->add_news_category();
$this->response('success');
}
/**
* @name :编辑分类
* @author :liyuhang
* @method
* @remark :保存数据
* @name :save
* @author :lyh
* @method :post
* @time :2023/9/7 14:51
*/
public function edit(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$newsCategoryLogic->edit_news_category();
public function save(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
$request->validated();
$newsCategoryLogic->newsCategorySave();
$this->response('success');
}
... ...
... ... @@ -153,25 +153,35 @@ class BlogCategoryLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function del_blog_category(){
$ids = $this->param['id'];
foreach ($ids as $v){
//查询是否有子分类
$rs = $this->model->read(['pid'=>$v],['id']);
if($rs !== false){
$this->response('当前分类拥有子分类不允许删除');
}
//查看当前分内下是否有博客
$blogModel = new BlogModel();
$rs = $blogModel->read(['category_id'=>$v],['id']);
if($rs !== false){
$this->response('当前分类拥有博客,不允许删除');
}
public function delBlogCategory(){
foreach ($this->param['id'] as $id){
$this->verifyIsDelete($id);
//删除路由
$this->delRoute($v);
$this->delRoute($id);
$this->model->del(['id'=>$id]);
}
return $this->success();
}
/**
* @remark :验证是否可删除
* @name :VerifyIsDelete
* @author :lyh
* @method :post
* @time :2023/9/7 14:40
*/
public function verifyIsDelete($id){
//查询是否有子分类
$rs = $this->model->read(['pid'=>$id],['id']);
if($rs !== false){
$this->response('当前分类拥有子分类不允许删除');
}
//查看当前分内下是否有博客
$blogModel = new BlogModel();
$rs = $blogModel->read(['category_id'=>$id],['id']);
if($rs !== false){
$this->response('当前分类拥有博客,不允许删除');
}
$this->param['id'] = ['in',$this->param['id']];
$this->model->del($this->param);
return $this->success();
}
... ...
... ... @@ -150,7 +150,7 @@ class BlogLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function blog_status(){
public function blogStatus(){
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>['in',$this->param['id']]]);
if($rs === false){
... ... @@ -165,14 +165,12 @@ class BlogLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function blog_del(){
$ids = $this->param['id'];
public function blogDel(){
DB::beginTransaction();
try {
$this->param['id'] = ['in',$this->param['id']];
$this->del($this->param,$ids);
foreach ($ids as $id){
foreach ($this->param['id'] as $id){
$this->delRoute($id);
$this->model->del(['id'=>$id]);
}
DB::commit();
}catch (Exception $e){
... ...
... ... @@ -5,6 +5,8 @@ namespace App\Http\Logic\Bside\Nav;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Nav\BNav;
use App\Models\RouteMap\RouteMap;
use Illuminate\Support\Facades\DB;
/**
... ... @@ -32,23 +34,41 @@ class NavLogic extends BaseLogic
*/
public function navSave()
{
if(isset($this->param['id']) && !empty($this->param['id'])){
$info = $this->model->read(['id'=>$this->param['id']]);
if($this->param['pid'] == $info['id']){
$this->fail('不允许成为自己的上级');
DB::beginTransaction();
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->handleEditParam();//验证是否可编辑分类
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$this->model->add($this->param);
}
$pid_info = $this->model->read(['pid'=>$this->param['id']]);
if(($pid_info !== false) && $this->param['pid'] != $info['pid']){
$this->fail('当前菜单拥有子集不允许修改上级');
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
}
if($rs === false){
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
//编辑菜单后,通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NAV, 'route'=>'all']);
return $this->success();
}
/**
* @remark :验证是否可编辑
* @name :handleEditParam
* @author :lyh
* @method :post
* @time :2023/9/7 14:36
*/
public function handleEditParam(){
$info = $this->model->read(['id'=>$this->param['id']]);
if($this->param['pid'] == $info['id']){
$this->fail('不允许成为自己的上级');
}
$pid_info = $this->model->read(['pid'=>$this->param['id']]);
if(($pid_info !== false) && $this->param['pid'] != $info['pid']){
$this->fail('当前菜单拥有子集不允许修改上级');
}
return $this->success();
}
... ... @@ -70,6 +90,8 @@ class NavLogic extends BaseLogic
if($rs === false){
$this->fail('error');
}
//编辑菜单后,通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NAV, 'route'=>'all']);
return $this->success();
}
... ...
... ... @@ -44,59 +44,46 @@ class NewsCategoryLogic extends BaseLogic
* @method
*/
public function info_news_category(){
$info = $this->info($this->param);
$info = $this->model->read($this->param);
return $this->success($info);
}
/**
* @name :添加时验证上级分类是否有商品,有则替换带当前分类下
* @return void
* @author :liyuhang
* @method
* @remark :保存数据
* @name :newsCategorySave
* @author :lyh
* @method :post
* @time :2023/9/7 14:53
*/
public function add_news_category(){
public function newsCategorySave(){
//验证名称是否存在
$this->verifyParamName($this->param['name']);
//参数处理
$this->param = $this->addParamProcessing($this->param);
DB::beginTransaction();
try {
$cate_id = $this->model->insertGetId($this->param);
//当父级分类拥有产品时,处理子集
$this->addProcessingSon($cate_id);
$route = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'],
RouteMap::SOURCE_NEWS_CATE, $cate_id, $this->user['project_id']);
$this->model->edit(['alias'=>$route],['id'=>$cate_id]);
if(isset($this->param['id']) && !empty($this->param['id'])){
//验证是否可编辑
$this->verifyEditParam($this->param['id'],$this->param['pid']);
$this->param['operator_id'] = $this->user['id'];
//查看路由是否更新
$id = $this->editCategoryRoute($this->param['id'],$this->param['alias']);
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
$id = $this->model->addReturnId($this->param);
//当父级分类拥有产品时,处理子集
$this->addProcessingSon($id);
}
$route = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
$this->model->edit(['alias'=>$route],['id'=>$id]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
//通知更新
//更新通知记录表
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$this->param['alias']]);
return $this->success();
}
/**
* @name :编辑分类
* @return void
* @author :liyuhang
* @method
*/
public function edit_news_category(){
//验证名称是否存在
$this->verifyParamName($this->param['name'],$this->param['id']);
//验证是否可编辑
$this->verifyEditParam($this->param['id'],$this->param['pid']);
$this->param['operator_id'] = $this->user['id'];
$this->param['alias'] = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'],
RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']);
//查看路由是否更新
$this->editCategoryRoute($this->param['id'],$this->param['alias']);
$this->edit($this->param,['id'=>$this->param['id']]);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$this->param['alias']]);
return $this->success();
}
/**
* @remark :编辑路由时生成路由记录
... ... @@ -115,7 +102,7 @@ class NewsCategoryLogic extends BaseLogic
];
$this->setRouteDeleteSave($data);
}
return $this->success();
return $id;
}
/**
... ... @@ -165,23 +152,21 @@ class NewsCategoryLogic extends BaseLogic
* @method
*/
public function del_news_category(){
$ids = $this->param['id'];
foreach ($this->param['id'] as $v){
foreach ($this->param['id'] as $id){
//查询是否有子分类
$rs = $this->model->read(['pid'=>$v],['id']);
$rs = $this->model->read(['pid'=>$id],['id']);
if($rs !== false){
$this->fail('当前分类拥有子分类不允许删除');
}
//查看当前分内下是否有商品
$newsModel = new NewsModel();
$rs = $newsModel->read(['category_id'=>$v],['id']);
$rs = $newsModel->read(['category_id'=>$id],['id']);
if($rs !== false){
$this->fail('当前分类拥有商品');
}
$this->delRoute($v);
$this->delRoute($id);
$this->model->del(['id'=>$id]);
}
$this->param['id'] = ['in',$this->param['id']];
$this->del($this->param,$ids);
return $this->success();
}
... ... @@ -207,16 +192,11 @@ class NewsCategoryLogic extends BaseLogic
* @method :post
* @time :2023/6/13 11:41
*/
public function verifyParamName($name,$id = ''){
if(isset($id) && !empty($id)){
$condition = [
'id'=>['!=',$id],
'name'=>$name,
];
public function verifyParamName($name){
if(isset($this->param['id']) && !empty($this->param['id'])){
$condition = ['id'=>['!=',$this->param['id']], 'name'=>$name];
}else{
$condition = [
'name'=>$name
];
$condition = ['name'=>$name];
}
$info = $this->model->read($condition);
if($info !== false){
... ... @@ -235,8 +215,6 @@ class NewsCategoryLogic extends BaseLogic
$param['project_id'] = $this->user['project_id'];
$param['operator_id'] = $this->user['id'];
$param['create_id'] = $this->user['id'];
$param['created_at'] = date('Y-m-d H:i:s');
$param['updated_at'] = date('Y-m-d H:i:s');
return $this->success($param);
}
... ...
... ... @@ -124,8 +124,8 @@ class ProductLogic extends BaseLogic
* @time :2023/8/21 17:11
*/
public function productDelete(){
DB::beginTransaction();
try {
// DB::beginTransaction();
// try {
foreach ($this->param['ids'] as $k => $id) {
$info = $this->model->read(['id'=>$id]);
if($info['status'] == Product::STATUS_RECYCLE){
... ... @@ -138,11 +138,11 @@ class ProductLogic extends BaseLogic
$this->model->edit(['status'=>Product::STATUS_RECYCLE],['id'=>$id]);
}
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('删除失败');
}
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// $this->fail('删除失败');
// }
return $this->success();
}
... ...
... ... @@ -33,6 +33,8 @@ class RouteMap extends Base
const PATH_NEWS_CATE = 'news_catalog';
const PATH_BLOG_CATE = 'blog_catalog';
const SOURCE_NAV = 'nav';
/**
* 生成路由标识
* @param $title
... ...
... ... @@ -50,9 +50,9 @@ Route::middleware(['bloginauth'])->group(function () {
Route::prefix('news')->group(function () {
//分类
Route::any('/category/', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'lists'])->name('news_category_lists');
Route::any('/category/add', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'add'])->name('news_category_add');
Route::any('/category/add', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'save'])->name('news_category_add');
Route::any('/category/info', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'info'])->name('news_category_info');
Route::any('/category/edit', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'edit'])->name('news_category_edit');
Route::any('/category/edit', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'save'])->name('news_category_edit');
Route::any('/category/del', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'del'])->name('news_category_del');
Route::any('/category/status', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'status'])->name('news_category_status');
Route::any('/category/categoryTopList', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'categoryTopList'])->name('news_category_categoryTopList');
... ...