ProductLogic.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace App\Http\Logic\Bside\Product;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Product;
/**
* Class ProductLogic
* @package App\Http\Logic\Bside\Product
* @author zbj
* @date 2023/4/14
*/
class ProductLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Product();
}
public function save($param){
if(!empty($param['pid'])){
if(!empty($param['id']) && $param['pid'] == $param['id']){
$this->fail('上级分类不能是本分类');
}
$p_cate = Product::find($param['pid']);
if(!$p_cate){
$this->fail('上级分类不存在');
}
}
return parent::save($param);
}
public function delete($ids){
$ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
foreach ($ids as $id){
$info = $this->getCacheInfo($id);
if(!$info){
continue;
}
//是否有子分类
if(Product::where('pid', $id)->count()){
$this->fail("分类{$info['title']}存在子分类,不能删除");
}
//todo 是否有对应商品
}
return parent::delete($ids);
}
}