|
...
|
...
|
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Bside\News; |
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Controllers\Bside\BaseController;
|
|
|
|
use App\Http\Logic\Bside\News\NewsCategoryLogic;
|
|
|
|
use App\Http\Logic\Bside\News\NewsLogic;
|
|
|
|
use App\Http\Requests\Bside\News\NewsCategoryRequest;
|
|
|
|
use App\Models\News\News as NewsModel;
|
|
|
|
use App\Models\News\NewsCategory as NewsCategoryModel;
|
|
...
|
...
|
@@ -20,7 +22,7 @@ class NewsCategoryController extends BaseController |
|
|
|
*/
|
|
|
|
public function lists(NewsCategoryModel $newsCategory){
|
|
|
|
//搜索条件
|
|
|
|
$lists = $newsCategory->lists($this->map,$this->page,$this->row,$this->order);
|
|
|
|
$lists = $newsCategory->lists($this->map,$this->page,$this->row,'sort');
|
|
|
|
$this->response('success',Code::SUCCESS,$lists);
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -48,37 +50,12 @@ class NewsCategoryController extends BaseController |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function add(NewsCategoryRequest $request,NewsCategoryModel $newsCategoryModel,NewsModel $newsModel){
|
|
|
|
public function add(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
|
|
|
|
$request->validated();
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$this->param['operator_id'] = $this->uid;
|
|
|
|
$this->param['create_id'] = $this->uid;
|
|
|
|
DB::beginTransaction();
|
|
|
|
$rs = $newsCategoryModel->add($this->param);
|
|
|
|
if($rs === false){
|
|
|
|
DB::rollBack();
|
|
|
|
$this->response('error',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
//判断当前分内是否为一级分类
|
|
|
|
if(isset($this->param['pid']) && !empty($this->param['pid'])){
|
|
|
|
//查看当前上级分类下是否有其他分类
|
|
|
|
$cate_info = $newsCategoryModel->read(['pid'=>$this->param['pid'],'id'=>['!=',$newsCategoryModel->id]]);
|
|
|
|
if($cate_info === false){
|
|
|
|
//查看当前上一级分类下是否有商品
|
|
|
|
$news_info = $newsModel->read(['category_id'=>$this->param['pid'],'pid'=>0]);
|
|
|
|
if($news_info !== false){
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
$rs = $newsModel->edit(['category_id'=>$newsCategoryModel->id],['category_id'=>$this->param['pid']]);
|
|
|
|
if($rs === false){
|
|
|
|
DB::rollBack();
|
|
|
|
$this->response('error',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
//添加商品时,验证分类上级分类是否有商品,有则更新到当前分类中,没有时直接添加
|
|
|
|
$newsCategoryLogic->add_news_category();
|
|
|
|
//TODO::写入日志
|
|
|
|
$this->response('success',Code::SUCCESS);
|
|
|
|
$this->response('success',Code::SUCCESS,[]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|