|
...
|
...
|
@@ -2,9 +2,16 @@ |
|
|
|
|
|
|
|
namespace App\Http\Logic\Bside\Product;
|
|
|
|
|
|
|
|
use App\Helper\Arrays;
|
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CategoryLogic
|
|
|
|
* @package App\Http\Logic\Bside\Product
|
|
|
|
* @author zbj
|
|
|
|
* @date 2023/4/14
|
|
|
|
*/
|
|
|
|
class CategoryLogic extends BaseLogic
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
...
|
...
|
@@ -13,4 +20,34 @@ class CategoryLogic extends BaseLogic |
|
|
|
|
|
|
|
$this->model = new Category();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save($param){
|
|
|
|
if(!empty($param['pid'])){
|
|
|
|
if(!empty($param['id']) && $param['pid'] == $param['id']){
|
|
|
|
$this->fail('上级分类不能是本分类');
|
|
|
|
}
|
|
|
|
$p_cate = Category::find($param['pid']);
|
|
|
|
if(!$p_cate){
|
|
|
|
$this->fail('上级分类不存在');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parent::save($param);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($ids){
|
|
|
|
$ids= array_filter(Arrays::splitFilterToArray($ids), 'intval');
|
|
|
|
foreach ($ids as $id){
|
|
|
|
$info = $this->getInfo($id);
|
|
|
|
if(!$info){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//是否有子分类
|
|
|
|
if(Category::where('pid', $id)->count()){
|
|
|
|
$this->fail("分类{$info['title']}存在子分类,不能删除");
|
|
|
|
}
|
|
|
|
//todo 是否有对应商品
|
|
|
|
|
|
|
|
return parent::delete($ids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|