Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev
正在显示
6 个修改的文件
包含
114 行增加
和
52 行删除
| @@ -88,12 +88,12 @@ class BaseController extends Controller | @@ -88,12 +88,12 @@ class BaseController extends Controller | ||
| 88 | case "name": | 88 | case "name": |
| 89 | $this->map['name'] = ['like','%'.$v.'%']; | 89 | $this->map['name'] = ['like','%'.$v.'%']; |
| 90 | break; | 90 | break; |
| 91 | - case "created_at": | 91 | + case "start_at": |
| 92 | $this->_btw[0] = $v; | 92 | $this->_btw[0] = $v; |
| 93 | $this->_btw[1] = date('Y-m-d H:i:s',time()); | 93 | $this->_btw[1] = date('Y-m-d H:i:s',time()); |
| 94 | $this->map['created_at'] = ['between', $this->_btw]; | 94 | $this->map['created_at'] = ['between', $this->_btw]; |
| 95 | break; | 95 | break; |
| 96 | - case "updated_at": | 96 | + case "end_at": |
| 97 | $this->_btw[1] = $v; | 97 | $this->_btw[1] = $v; |
| 98 | $this->map['updated_at'] = ['between', $this->_btw]; | 98 | $this->map['updated_at'] = ['between', $this->_btw]; |
| 99 | break; | 99 | break; |
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | namespace App\Http\Controllers\Bside\Blog; | 3 | namespace App\Http\Controllers\Bside\Blog; |
| 4 | 4 | ||
| 5 | use App\Http\Controllers\Bside\BaseController; | 5 | use App\Http\Controllers\Bside\BaseController; |
| 6 | +use App\Http\Logic\Bside\Blog\BlogCategoryLogic; | ||
| 6 | use App\Http\Requests\Bside\Blog\BlogCategoryRequest; | 7 | use App\Http\Requests\Bside\Blog\BlogCategoryRequest; |
| 7 | use App\Models\Blog\Blog as BlogModel; | 8 | use App\Models\Blog\Blog as BlogModel; |
| 8 | use App\Models\Blog\BlogCategory as BlogCategoryModel; | 9 | use App\Models\Blog\BlogCategory as BlogCategoryModel; |
| @@ -46,36 +47,10 @@ class BlogCategoryController extends BaseController | @@ -46,36 +47,10 @@ class BlogCategoryController extends BaseController | ||
| 46 | * @author :liyuhang | 47 | * @author :liyuhang |
| 47 | * @method | 48 | * @method |
| 48 | */ | 49 | */ |
| 49 | - public function add(BlogCategoryRequest $request,BlogCategoryModel $blogCategoryModel,BlogModel $blogModel){ | 50 | + public function add(BlogCategoryRequest $request,BlogCategoryLogic $blogCategoryLogic){ |
| 50 | $request->validated(); | 51 | $request->validated(); |
| 51 | - $this->param['project_id'] = $this->user['project_id']; | ||
| 52 | - $this->param['operator_id'] = $this->uid; | ||
| 53 | - $this->param['create_id'] = $this->uid; | ||
| 54 | - DB::beginTransaction(); | ||
| 55 | - $rs = $blogCategoryModel->add($this->param); | ||
| 56 | - if($rs === false){ | ||
| 57 | - DB::rollBack(); | ||
| 58 | - $this->response('error',Code::USER_ERROR); | ||
| 59 | - } | ||
| 60 | - //TODO::判断当前分内是否为一级分类 | ||
| 61 | - if(isset($this->param['pid']) && !empty($this->param['pid'])){ | ||
| 62 | - //查看当前上级分类下是否有其他分类 | ||
| 63 | - $cate_info = $blogCategoryModel->read(['pid'=>$this->param['pid'],'id'=>['!=',$blogCategoryModel->id]]); | ||
| 64 | - if($cate_info === false){ | ||
| 65 | - //查看当前上一级分类下是否有商品 | ||
| 66 | - $news_info = $blogModel->read(['category_id'=>$this->param['pid'],'pid'=>0]); | ||
| 67 | - if($news_info !== false){ | ||
| 68 | - //更新所有商品到当前分类 | ||
| 69 | - $rs = $blogModel->edit(['category_id'=>$blogCategoryModel->id],['category_id'=>$this->param['pid']]); | ||
| 70 | - if($rs === false){ | ||
| 71 | - DB::rollBack(); | ||
| 72 | - $this->response('error',Code::USER_ERROR); | ||
| 73 | - } | ||
| 74 | - } | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | - //TODO::写入日志 | ||
| 78 | - DB::commit(); | 52 | + //添加时,验证分类上级分类是否有,有则更新到当前分类中,没有时直接添加 |
| 53 | + $blogCategoryLogic->add_blog_category(); | ||
| 79 | $this->response('success'); | 54 | $this->response('success'); |
| 80 | } | 55 | } |
| 81 | 56 |
| @@ -52,7 +52,7 @@ class NewsCategoryController extends BaseController | @@ -52,7 +52,7 @@ class NewsCategoryController extends BaseController | ||
| 52 | */ | 52 | */ |
| 53 | public function add(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){ | 53 | public function add(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){ |
| 54 | $request->validated(); | 54 | $request->validated(); |
| 55 | - //添加商品时,验证分类上级分类是否有商品,有则更新到当前分类中,没有时直接添加 | 55 | + //添加时,验证分类上级分类是否有,有则更新到当前分类中,没有时直接添加 |
| 56 | $newsCategoryLogic->add_news_category(); | 56 | $newsCategoryLogic->add_news_category(); |
| 57 | //TODO::写入日志 | 57 | //TODO::写入日志 |
| 58 | $this->response('success',Code::SUCCESS,[]); | 58 | $this->response('success',Code::SUCCESS,[]); |
| @@ -76,7 +76,7 @@ class NewsCategoryController extends BaseController | @@ -76,7 +76,7 @@ class NewsCategoryController extends BaseController | ||
| 76 | $this->response('error',Code::USER_ERROR); | 76 | $this->response('error',Code::USER_ERROR); |
| 77 | } | 77 | } |
| 78 | //TODO::写入日志 | 78 | //TODO::写入日志 |
| 79 | - $this->response('success',Code::SUCCESS); | 79 | + $this->response('success'); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | /** | 82 | /** |
| @@ -105,29 +105,13 @@ class NewsCategoryController extends BaseController | @@ -105,29 +105,13 @@ class NewsCategoryController extends BaseController | ||
| 105 | * @author :liyuhang | 105 | * @author :liyuhang |
| 106 | * @method | 106 | * @method |
| 107 | */ | 107 | */ |
| 108 | - public function del(Request $request,NewsCategoryModel $newsCategory,NewsModel $news){ | 108 | + public function del(Request $request,NewsCategoryLogic $newsCategoryLogic){ |
| 109 | $request->validate([ | 109 | $request->validate([ |
| 110 | 'id'=>['required'], | 110 | 'id'=>['required'], |
| 111 | ],[ | 111 | ],[ |
| 112 | 'id.required' => 'ID不能为空', | 112 | 'id.required' => 'ID不能为空', |
| 113 | ]); | 113 | ]); |
| 114 | - foreach ($this->param['id'] as $v){ | ||
| 115 | - //查询是否有子分类 | ||
| 116 | - $rs = $newsCategory->read(['pid'=>$v],['id']); | ||
| 117 | - if($rs !== false){ | ||
| 118 | - $this->response('当前分类拥有子分类不允许删除',Code::USER_ERROR); | ||
| 119 | - } | ||
| 120 | - //查看当前分内下是否有商品 | ||
| 121 | - $rs = $news->read(['category_id'=>$v],['id']); | ||
| 122 | - if($rs !== false){ | ||
| 123 | - $this->response('当前分类拥有商品',Code::USER_ERROR); | ||
| 124 | - } | ||
| 125 | - } | ||
| 126 | - $this->param['id'] = ['in',$this->param['id']]; | ||
| 127 | - $rs = $newsCategory->del($this->param); | ||
| 128 | - if($rs === false){ | ||
| 129 | - $this->response('error',Code::USER_ERROR); | ||
| 130 | - } | 114 | + $newsCategoryLogic->del_news_category(); |
| 131 | $this->response('success'); | 115 | $this->response('success'); |
| 132 | } | 116 | } |
| 133 | } | 117 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside\Blog; | ||
| 4 | + | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Http\Logic\Bside\BaseLogic; | ||
| 7 | +use App\Models\Blog\BlogCategory as BlogCategoryModel; | ||
| 8 | +use App\Models\Blog\Blog as BlogModel; | ||
| 9 | +use Illuminate\Support\Facades\DB; | ||
| 10 | + | ||
| 11 | +class BlogCategoryLogic extends BaseLogic | ||
| 12 | +{ | ||
| 13 | + public function __construct() | ||
| 14 | + { | ||
| 15 | + parent::__construct(); | ||
| 16 | + | ||
| 17 | + $this->model = new BlogCategoryModel(); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * @name :添加时验证上级分类是否有商品,有则替换带当前分类下 | ||
| 22 | + * @return void | ||
| 23 | + * @author :liyuhang | ||
| 24 | + * @method | ||
| 25 | + */ | ||
| 26 | + public function add_blog_category(){ | ||
| 27 | + DB::beginTransaction(); | ||
| 28 | + $this->param = $this->requestAll; | ||
| 29 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 30 | + $this->param['operator_id'] = $this->user['id']; | ||
| 31 | + $this->param['create_id'] = $this->user['id']; | ||
| 32 | + $this->param['created_at'] = date('Y-m-d H:i:s'); | ||
| 33 | + $this->param['updated_at'] = date('Y-m-d H:i:s'); | ||
| 34 | + $cate_id = $this->model->insertGetId($this->param); | ||
| 35 | + if($cate_id === false){ | ||
| 36 | + DB::rollBack(); | ||
| 37 | + $this->fail('error',Code::USER_ERROR); | ||
| 38 | + } | ||
| 39 | + //判断为子分类时 | ||
| 40 | + if(isset($this->param['pid']) && !empty($this->param['pid'])) { | ||
| 41 | + //查看当前上级分类下是否有其他分类 | ||
| 42 | + $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]); | ||
| 43 | + if ($cate_info === false) { | ||
| 44 | + //查看当前上一级分类下是否有新闻 | ||
| 45 | + $blogModel = new BlogModel(); | ||
| 46 | + $news_info = $blogModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]); | ||
| 47 | + if ($news_info !== false) { | ||
| 48 | + $replacement = ',' . $cate_id . ','; | ||
| 49 | + $old = ',' . $this->param['pid'] . ','; | ||
| 50 | + //更新所有商品到当前分类 | ||
| 51 | + $rs = DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%') | ||
| 52 | + ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]); | ||
| 53 | + if ($rs === false) { | ||
| 54 | + DB::rollBack(); | ||
| 55 | + $this->fail('error', Code::USER_ERROR); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + DB::commit(); | ||
| 61 | + return $this->success(); | ||
| 62 | + } | ||
| 63 | +} |
app/Http/Logic/Bside/Blog/BlogLogic.php
0 → 100644
| @@ -57,6 +57,36 @@ class NewsCategoryLogic extends BaseLogic | @@ -57,6 +57,36 @@ class NewsCategoryLogic extends BaseLogic | ||
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| 59 | DB::commit(); | 59 | DB::commit(); |
| 60 | - $this->success(); | 60 | + return $this->success(); |
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * @name :删除新闻分类 | ||
| 65 | + * @return array | ||
| 66 | + * @throws \App\Exceptions\BsideGlobalException | ||
| 67 | + * @author :liyuhang | ||
| 68 | + * @method | ||
| 69 | + */ | ||
| 70 | + public function del_news_category(){ | ||
| 71 | + $this->param = $this->requestAll; | ||
| 72 | + foreach ($this->param['id'] as $v){ | ||
| 73 | + //查询是否有子分类 | ||
| 74 | + $rs = $this->model->read(['pid'=>$v],['id']); | ||
| 75 | + if($rs !== false){ | ||
| 76 | + $this->fail('当前分类拥有子分类不允许删除',Code::USER_ERROR); | ||
| 77 | + } | ||
| 78 | + //查看当前分内下是否有商品 | ||
| 79 | + $newsModel = new NewsModel(); | ||
| 80 | + $rs = $newsModel->read(['category_id'=>$v],['id']); | ||
| 81 | + if($rs !== false){ | ||
| 82 | + $this->fail('当前分类拥有商品',Code::USER_ERROR); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + $this->param['id'] = ['in',$this->param['id']]; | ||
| 86 | + $rs = $this->model->del($this->param); | ||
| 87 | + if($rs === false){ | ||
| 88 | + $this->fail('error',Code::USER_ERROR); | ||
| 89 | + } | ||
| 90 | + return $this->success(); | ||
| 61 | } | 91 | } |
| 62 | } | 92 | } |
-
请 注册 或 登录 后发表评论