|
...
|
...
|
@@ -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);
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|