ProductController.php
3.6 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace App\Http\Controllers\Bside\Product;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\CategoryRelated;
use App\Models\Product\KeywordRelated;
use App\Rules\Ids;
use Illuminate\Http\Request;
/**
* Class ProductController
* @package App\Http\Controllers\Bside
* @author zbj
* @date 2023/4/17
*/
class ProductController extends BaseController
{
public function index(ProductLogic $logic)
{
$map = [];
if(!empty($this->param['search'])){
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
if(!empty($this->param['created_at'][0])){
$this->param['created_at'][0] .= ' 00:00:00';
}
if(!empty($this->param['created_at'][1])){
$this->param['created_at'][1] .= ' 23:59:59';
}
if(empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
$map[] = ['created_at', '>=', $this->param['created_at'][0]];
}
if(!empty($this->param['created_at'][0]) && empty($this->param['created_at'][1])){
$map[] = ['created_at', '<=', $this->param['created_at']];
}
if(!empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
$map[] = ['created_at', 'between', [$this->param['created_at']]];
}
if(!empty($this->param['category_id'])){
$ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray();
$map[] = ['id', 'in', $ids];
}
if(!empty($this->param['keyword_id'])){
$ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray();
$map[] = ['id', 'in', $ids];
}
if(isset($this->param['status'])){
$map[] = ['status', $this->param['status']];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'project_id', 'title', 'thumb', 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']);
return $this->success($data);
}
public function info(Request $request, ProductLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'project_id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content',
'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text', 'route', 'url']));
}
public function save(ProductRequest $request, ProductLogic $logic)
{
$data = $logic->save($this->param);
//通知更新界面
$this->projectUrlNotify('product');
return $this->success($data);
}
public function delete(Request $request, ProductLogic $logic)
{
$request->validate([
'ids'=>['required', new Ids()]
],[
'ids.required' => 'ID不能为空'
]);
$data = $logic->delete($this->param['ids']);
return $this->success($data);
}
public function getStatusNumber(ProductLogic $logic){
$data = $logic->getStatusNumber();
$this->response('success',Code::SUCCESS,$data);
}
}