|
...
|
...
|
@@ -23,7 +23,7 @@ class CategoryLogic extends BaseLogic |
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->param = $this->requestAll;
|
|
|
|
$this->model = new Category();
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -41,6 +41,13 @@ class CategoryLogic extends BaseLogic |
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取详情
|
|
|
|
* @name :getInfo
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/8/21 17:14
|
|
|
|
*/
|
|
|
|
public function getInfo($id)
|
|
|
|
{
|
|
|
|
$info = $this->model->read(['id'=>$id]);
|
|
...
|
...
|
@@ -49,26 +56,29 @@ class CategoryLogic extends BaseLogic |
|
|
|
return $this->success($info);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save($param){
|
|
|
|
$param['pid'] = $param['pid'] ?? 0;
|
|
|
|
if(!empty($param['pid'])){
|
|
|
|
if(!empty($param['id']) && $param['pid'] == $param['id']){
|
|
|
|
$this->fail('上级分类不能是本分类');
|
|
|
|
}
|
|
|
|
$p_cate = $this->getCacheInfo($param['pid']);
|
|
|
|
if(!$p_cate){
|
|
|
|
$this->fail('上级分类不存在');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @remark :保存分类
|
|
|
|
* @name :categorySave
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/8/21 17:14
|
|
|
|
*/
|
|
|
|
public function categorySave(){
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$res = parent::save($param);
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
$this->handleEditParam($this->param);
|
|
|
|
$id = $this->param['id'];
|
|
|
|
$this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$id = $this->model->addReturnId();
|
|
|
|
}
|
|
|
|
//路由映射
|
|
|
|
$route = RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_CATE, $res['id'], $this->user['project_id']);
|
|
|
|
$route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
|
|
|
|
DB::commit();
|
|
|
|
} catch (\Exception $e){
|
|
|
|
DB::rollBack();
|
|
|
|
errorLog('产品分类保存失败', $param, $e);
|
|
|
|
$this->fail('保存失败');
|
|
|
|
}
|
|
|
|
//通知更新
|
|
...
|
...
|
@@ -76,6 +86,25 @@ class CategoryLogic extends BaseLogic |
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleEditParam(&$param){
|
|
|
|
if($param['pid'] == $param['id']){
|
|
|
|
$this->fail('上级分类不能是本分类');
|
|
|
|
}
|
|
|
|
$info = $this->model->read(['id'=>$param['id']]);
|
|
|
|
$sub_info = $this->model->read(['pid'=>$param['id']]);
|
|
|
|
if(($info['pid'] != $param['pid']) && ($sub_info != false)){
|
|
|
|
$this->fail('当前分类拥有字分类,不允许修改上级分类');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :删除
|
|
|
|
* @name :delete
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/8/21 17:23
|
|
|
|
*/
|
|
|
|
public function delete($ids, $map = []){
|
|
|
|
$ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
|
|
|
|
|
...
|
...
|
|