正在显示
8 个修改的文件
包含
87 行增加
和
34 行删除
| @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Bside\News; | @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Bside\News; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Bside\BaseController; | 6 | use App\Http\Controllers\Bside\BaseController; |
| 7 | +use App\Http\Logic\Bside\News\NewsCategoryLogic; | ||
| 8 | +use App\Http\Logic\Bside\News\NewsLogic; | ||
| 7 | use App\Http\Requests\Bside\News\NewsCategoryRequest; | 9 | use App\Http\Requests\Bside\News\NewsCategoryRequest; |
| 8 | use App\Models\News\News as NewsModel; | 10 | use App\Models\News\News as NewsModel; |
| 9 | use App\Models\News\NewsCategory as NewsCategoryModel; | 11 | use App\Models\News\NewsCategory as NewsCategoryModel; |
| @@ -20,7 +22,7 @@ class NewsCategoryController extends BaseController | @@ -20,7 +22,7 @@ class NewsCategoryController extends BaseController | ||
| 20 | */ | 22 | */ |
| 21 | public function lists(NewsCategoryModel $newsCategory){ | 23 | public function lists(NewsCategoryModel $newsCategory){ |
| 22 | //搜索条件 | 24 | //搜索条件 |
| 23 | - $lists = $newsCategory->lists($this->map,$this->page,$this->row,$this->order); | 25 | + $lists = $newsCategory->lists($this->map,$this->page,$this->row,'sort'); |
| 24 | $this->response('success',Code::SUCCESS,$lists); | 26 | $this->response('success',Code::SUCCESS,$lists); |
| 25 | } | 27 | } |
| 26 | 28 | ||
| @@ -48,37 +50,12 @@ class NewsCategoryController extends BaseController | @@ -48,37 +50,12 @@ class NewsCategoryController extends BaseController | ||
| 48 | * @author :liyuhang | 50 | * @author :liyuhang |
| 49 | * @method | 51 | * @method |
| 50 | */ | 52 | */ |
| 51 | - public function add(NewsCategoryRequest $request,NewsCategoryModel $newsCategoryModel,NewsModel $newsModel){ | 53 | + public function add(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){ |
| 52 | $request->validated(); | 54 | $request->validated(); |
| 53 | - $this->param['project_id'] = $this->user['project_id']; | ||
| 54 | - $this->param['operator_id'] = $this->uid; | ||
| 55 | - $this->param['create_id'] = $this->uid; | ||
| 56 | - DB::beginTransaction(); | ||
| 57 | - $rs = $newsCategoryModel->add($this->param); | ||
| 58 | - if($rs === false){ | ||
| 59 | - DB::rollBack(); | ||
| 60 | - $this->response('error',Code::USER_ERROR); | ||
| 61 | - } | ||
| 62 | - //判断当前分内是否为一级分类 | ||
| 63 | - if(isset($this->param['pid']) && !empty($this->param['pid'])){ | ||
| 64 | - //查看当前上级分类下是否有其他分类 | ||
| 65 | - $cate_info = $newsCategoryModel->read(['pid'=>$this->param['pid'],'id'=>['!=',$newsCategoryModel->id]]); | ||
| 66 | - if($cate_info === false){ | ||
| 67 | - //查看当前上一级分类下是否有商品 | ||
| 68 | - $news_info = $newsModel->read(['category_id'=>$this->param['pid'],'pid'=>0]); | ||
| 69 | - if($news_info !== false){ | ||
| 70 | - //更新所有商品到当前分类 | ||
| 71 | - $rs = $newsModel->edit(['category_id'=>$newsCategoryModel->id],['category_id'=>$this->param['pid']]); | ||
| 72 | - if($rs === false){ | ||
| 73 | - DB::rollBack(); | ||
| 74 | - $this->response('error',Code::USER_ERROR); | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | - } | ||
| 78 | - } | ||
| 79 | - DB::commit(); | 55 | + //添加商品时,验证分类上级分类是否有商品,有则更新到当前分类中,没有时直接添加 |
| 56 | + $newsCategoryLogic->add_news_category(); | ||
| 80 | //TODO::写入日志 | 57 | //TODO::写入日志 |
| 81 | - $this->response('success',Code::SUCCESS); | 58 | + $this->response('success',Code::SUCCESS,[]); |
| 82 | } | 59 | } |
| 83 | 60 | ||
| 84 | /** | 61 | /** |
| @@ -79,6 +79,8 @@ class NewsController extends BaseController | @@ -79,6 +79,8 @@ class NewsController extends BaseController | ||
| 79 | $this->param['create_id'] = $this->uid; | 79 | $this->param['create_id'] = $this->uid; |
| 80 | $this->param['operator_id'] = $this->uid; | 80 | $this->param['operator_id'] = $this->uid; |
| 81 | $this->param['project_id'] = $this->user['project_id']; | 81 | $this->param['project_id'] = $this->user['project_id']; |
| 82 | + //多个分类按逗号隔开 | ||
| 83 | + $this->param['category_id'] = ','.$this->param['category_id'].','; | ||
| 82 | //TODO::路由映射 | 84 | //TODO::路由映射 |
| 83 | $rs = $news->add($this->param); | 85 | $rs = $news->add($this->param); |
| 84 | if($rs === false){ | 86 | if($rs === false){ |
| @@ -101,6 +103,8 @@ class NewsController extends BaseController | @@ -101,6 +103,8 @@ class NewsController extends BaseController | ||
| 101 | 'id.required' => 'ID不能为空', | 103 | 'id.required' => 'ID不能为空', |
| 102 | ]); | 104 | ]); |
| 103 | $this->param['operator_id'] = $this->uid; | 105 | $this->param['operator_id'] = $this->uid; |
| 106 | + //多个分类按逗号隔开 | ||
| 107 | + $this->param['category_id'] = ','.$this->param['category_id'].','; | ||
| 104 | $rs = $news->edit($this->param,['id'=>$this->param['id']]); | 108 | $rs = $news->edit($this->param,['id'=>$this->param['id']]); |
| 105 | if($rs === false){ | 109 | if($rs === false){ |
| 106 | $this->response('error',Code::USER_ERROR); | 110 | $this->response('error',Code::USER_ERROR); |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside\News; | ||
| 4 | + | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Http\Logic\Bside\BaseLogic; | ||
| 7 | +use App\Models\News\News as NewsModel; | ||
| 8 | +use App\Models\News\NewsCategory as NewsCategoryModel; | ||
| 9 | +use Illuminate\Support\Facades\DB; | ||
| 10 | + | ||
| 11 | +class NewsCategoryLogic extends BaseLogic | ||
| 12 | +{ | ||
| 13 | + public function __construct() | ||
| 14 | + { | ||
| 15 | + parent::__construct(); | ||
| 16 | + | ||
| 17 | + $this->model = new NewsCategoryModel(); | ||
| 18 | + } | ||
| 19 | + /** | ||
| 20 | + * @name :添加时验证上级分类是否有商品,有则替换带当前分类下 | ||
| 21 | + * @return void | ||
| 22 | + * @author :liyuhang | ||
| 23 | + * @method | ||
| 24 | + */ | ||
| 25 | + public function add_news_category(){ | ||
| 26 | + DB::beginTransaction(); | ||
| 27 | + $this->param = $this->requestAll; | ||
| 28 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 29 | + $this->param['operator_id'] = $this->user['id']; | ||
| 30 | + $this->param['create_id'] = $this->user['id']; | ||
| 31 | + $this->param['created_at'] = date('Y-m-d H:i:s'); | ||
| 32 | + $this->param['updated_at'] = date('Y-m-d H:i:s'); | ||
| 33 | + $cate_id = $this->model->insertGetId($this->param); | ||
| 34 | + if($cate_id === false){ | ||
| 35 | + DB::rollBack(); | ||
| 36 | + $this->fail('error',Code::USER_ERROR); | ||
| 37 | + } | ||
| 38 | + //判断为子分类时 | ||
| 39 | + if(isset($this->param['pid']) && !empty($this->param['pid'])) { | ||
| 40 | + //查看当前上级分类下是否有其他分类 | ||
| 41 | + $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]); | ||
| 42 | + if ($cate_info === false) { | ||
| 43 | + //查看当前上一级分类下是否有新闻 | ||
| 44 | + $newsModel = new NewsModel(); | ||
| 45 | + $news_info = $newsModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]); | ||
| 46 | + if ($news_info !== false) { | ||
| 47 | + $replacement = ',' . $cate_id . ','; | ||
| 48 | + $old = ',' . $this->param['pid'] . ','; | ||
| 49 | + //更新所有商品到当前分类 | ||
| 50 | + $rs = DB::table('gl_news')->where('category_id', 'like', '%' . $old . '%') | ||
| 51 | + ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]); | ||
| 52 | + if ($rs === false) { | ||
| 53 | + DB::rollBack(); | ||
| 54 | + $this->fail('error', Code::USER_ERROR); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + DB::commit(); | ||
| 60 | + $this->success(); | ||
| 61 | + } | ||
| 62 | +} |
app/Http/Logic/Bside/News/NewsLogic.php
0 → 100644
| @@ -24,7 +24,7 @@ class NewsCategoryRequest extends FormRequest | @@ -24,7 +24,7 @@ class NewsCategoryRequest extends FormRequest | ||
| 24 | public function rules() | 24 | public function rules() |
| 25 | { | 25 | { |
| 26 | return [ | 26 | return [ |
| 27 | - 'name'=>'required|max:100', | 27 | + 'name'=>'required|max:100||unique:gl_news_category', |
| 28 | ]; | 28 | ]; |
| 29 | } | 29 | } |
| 30 | 30 |
| @@ -19,7 +19,7 @@ class ProjectGroupRequest extends FormRequest | @@ -19,7 +19,7 @@ class ProjectGroupRequest extends FormRequest | ||
| 19 | public function rules() | 19 | public function rules() |
| 20 | { | 20 | { |
| 21 | return [ | 21 | return [ |
| 22 | - 'name' => 'required|max:255', | 22 | + 'name' => 'required|max:255||unique:gl_project_group', |
| 23 | ]; | 23 | ]; |
| 24 | } | 24 | } |
| 25 | 25 |
| @@ -19,7 +19,7 @@ class ProjectRoleRequest extends FormRequest | @@ -19,7 +19,7 @@ class ProjectRoleRequest extends FormRequest | ||
| 19 | public function rules() | 19 | public function rules() |
| 20 | { | 20 | { |
| 21 | return [ | 21 | return [ |
| 22 | - 'name'=>'required|max:11', | 22 | + 'name'=>'required|max:11||unique:gl_project_role', |
| 23 | 'role_menu'=>'required|string', | 23 | 'role_menu'=>'required|string', |
| 24 | ]; | 24 | ]; |
| 25 | } | 25 | } |
| @@ -24,7 +24,7 @@ class UserRequest extends FormRequest | @@ -24,7 +24,7 @@ class UserRequest extends FormRequest | ||
| 24 | public function rules() | 24 | public function rules() |
| 25 | { | 25 | { |
| 26 | return [ | 26 | return [ |
| 27 | - 'mobile'=>'required|string|max:11', | 27 | + 'mobile'=>'required|string|max:11||unique:gl_project_user', |
| 28 | 'password'=>'required|string|min:5', | 28 | 'password'=>'required|string|min:5', |
| 29 | 'name'=>'required|max:20', | 29 | 'name'=>'required|max:20', |
| 30 | 'role_id'=>'required' | 30 | 'role_id'=>'required' |
-
请 注册 或 登录 后发表评论