|
@@ -8,8 +8,12 @@ use App\Helper\Arr; |
|
@@ -8,8 +8,12 @@ use App\Helper\Arr; |
|
8
|
use App\Http\Controllers\Bside\BaseController;
|
8
|
use App\Http\Controllers\Bside\BaseController;
|
|
9
|
use App\Http\Logic\Bside\Product\ProductLogic;
|
9
|
use App\Http\Logic\Bside\Product\ProductLogic;
|
|
10
|
use App\Http\Requests\Bside\Product\ProductRequest;
|
10
|
use App\Http\Requests\Bside\Product\ProductRequest;
|
|
|
|
11
|
+use App\Models\Product\Category;
|
|
11
|
use App\Models\Product\CategoryRelated;
|
12
|
use App\Models\Product\CategoryRelated;
|
|
|
|
13
|
+use App\Models\Product\Keyword;
|
|
12
|
use App\Models\Product\KeywordRelated;
|
14
|
use App\Models\Product\KeywordRelated;
|
|
|
|
15
|
+use App\Models\Product\Product;
|
|
|
|
16
|
+use App\Models\User\User;
|
|
13
|
use App\Rules\Ids;
|
17
|
use App\Rules\Ids;
|
|
14
|
use Illuminate\Http\Request;
|
18
|
use Illuminate\Http\Request;
|
|
15
|
use Illuminate\Support\Facades\DB;
|
19
|
use Illuminate\Support\Facades\DB;
|
|
@@ -23,43 +27,65 @@ use Illuminate\Support\Facades\DB; |
|
@@ -23,43 +27,65 @@ use Illuminate\Support\Facades\DB; |
|
23
|
class ProductController extends BaseController
|
27
|
class ProductController extends BaseController
|
|
24
|
{
|
28
|
{
|
|
25
|
|
29
|
|
|
26
|
- public function index(ProductLogic $logic)
|
30
|
+ public function index(Product $product)
|
|
27
|
{
|
31
|
{
|
|
28
|
- $map = [];
|
|
|
|
29
|
- if(!empty($this->param['search'])){
|
|
|
|
30
|
- $map[] = ['title', 'like', "%{$this->param['search']}%"];
|
|
|
|
31
|
- }
|
|
|
|
32
|
- if(!empty($this->param['created_at'][0])){
|
|
|
|
33
|
- $this->param['created_at'][0] .= ' 00:00:00';
|
|
|
|
34
|
- }
|
|
|
|
35
|
- if(!empty($this->param['created_at'][1])){
|
|
|
|
36
|
- $this->param['created_at'][1] .= ' 23:59:59';
|
|
|
|
37
|
- }
|
|
|
|
38
|
- if(empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
|
|
|
|
39
|
- $map[] = ['created_at', '>=', $this->param['created_at'][0]];
|
|
|
|
40
|
- }
|
|
|
|
41
|
- if(!empty($this->param['created_at'][0]) && empty($this->param['created_at'][1])){
|
|
|
|
42
|
- $map[] = ['created_at', '<=', $this->param['created_at']];
|
|
|
|
43
|
- }
|
|
|
|
44
|
- if(!empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
|
|
|
|
45
|
- $map[] = ['created_at', 'between', [$this->param['created_at']]];
|
|
|
|
46
|
- }
|
|
|
|
47
|
- if(!empty($this->param['category_id'])){
|
|
|
|
48
|
- $ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray();
|
|
|
|
49
|
- $map[] = ['id', 'in', $ids];
|
|
|
|
50
|
- }
|
|
|
|
51
|
- if(!empty($this->param['keyword_id'])){
|
|
|
|
52
|
- $ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray();
|
|
|
|
53
|
- $map[] = ['id', 'in', $ids];
|
|
|
|
54
|
- }
|
|
|
|
55
|
- if(isset($this->param['status'])){
|
|
|
|
56
|
- $map[] = ['status', $this->param['status']];
|
|
|
|
57
|
- }
|
|
|
|
58
|
- $sort = ['id' => 'desc'];
|
|
|
|
59
|
- $data = $logic->getList($map, $sort, ['id', 'project_id', 'title', 'thumb', 'product_type' , 'route' ,'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'],$this->row);
|
|
|
|
60
|
- return $this->response('success',Code::SUCCESS,$data);
|
32
|
+// $map = [];
|
|
|
|
33
|
+// if(!empty($this->param['search'])){
|
|
|
|
34
|
+// $map[] = ['title', 'like', "%{$this->param['search']}%"];
|
|
|
|
35
|
+// }
|
|
|
|
36
|
+// if(!empty($this->param['created_at'][0])){
|
|
|
|
37
|
+// $this->param['created_at'][0] .= ' 00:00:00';
|
|
|
|
38
|
+// }
|
|
|
|
39
|
+// if(!empty($this->param['created_at'][1])){
|
|
|
|
40
|
+// $this->param['created_at'][1] .= ' 23:59:59';
|
|
|
|
41
|
+// }
|
|
|
|
42
|
+// if(empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
|
|
|
|
43
|
+// $map[] = ['created_at', '>=', $this->param['created_at'][0]];
|
|
|
|
44
|
+// }
|
|
|
|
45
|
+// if(!empty($this->param['created_at'][0]) && empty($this->param['created_at'][1])){
|
|
|
|
46
|
+// $map[] = ['created_at', '<=', $this->param['created_at']];
|
|
|
|
47
|
+// }
|
|
|
|
48
|
+// if(!empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
|
|
|
|
49
|
+// $map[] = ['created_at', 'between', [$this->param['created_at']]];
|
|
|
|
50
|
+// }
|
|
|
|
51
|
+// if(!empty($this->param['category_id'])){
|
|
|
|
52
|
+// $ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray();
|
|
|
|
53
|
+// $map[] = ['id', 'in', $ids];
|
|
|
|
54
|
+// }
|
|
|
|
55
|
+// if(!empty($this->param['keyword_id'])){
|
|
|
|
56
|
+// $ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray();
|
|
|
|
57
|
+// $map[] = ['id', 'in', $ids];
|
|
|
|
58
|
+// }
|
|
|
|
59
|
+// if(isset($this->param['status'])){
|
|
|
|
60
|
+// $map[] = ['status', $this->param['status']];
|
|
|
|
61
|
+// }
|
|
|
|
62
|
+// $sort = ['id' => 'desc'];
|
|
|
|
63
|
+ $filed = ['id', 'project_id', 'title', 'thumb', 'product_type' , 'route' ,'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'];
|
|
|
|
64
|
+ $lists = $product->lists($this->map,$this->page,$this->row,$this->order,$filed);
|
|
|
|
65
|
+ if(!empty($lists['list'])){
|
|
|
|
66
|
+ foreach ($lists['list'] as &$v){
|
|
|
|
67
|
+ $v['thumb']['image_link'] = getImageUrl($v['thumb']['url']);//图片统一
|
|
|
|
68
|
+ $v['category_id_text'] = '';
|
|
|
|
69
|
+ $v['keyword_id_text'] = '';
|
|
|
|
70
|
+ if(!empty($v['category_id'])){
|
|
|
|
71
|
+ $category_arr = explode(',',$v['category_id']);
|
|
|
|
72
|
+ $categoryModel = new Category();
|
|
|
|
73
|
+ $category_data = $categoryModel->list(['id'=>['in',$category_arr]]);
|
|
|
|
74
|
+ }
|
|
|
|
75
|
+ if(!empty($v['keyword_id'])){
|
|
|
|
76
|
+ $keyword_arr = explode(',',$v['keyword_id']);
|
|
|
|
77
|
+ $keywordModel = new Keyword();
|
|
|
|
78
|
+ $keyword_data = $keywordModel->list(['id'=>['in',$keyword_arr]]);
|
|
|
|
79
|
+ }
|
|
|
|
80
|
+ $v['status_text'] = Product::statusMap()[$info['status']] ?? '';
|
|
|
|
81
|
+ $v['created_uid_text'] = (new User())->read(['id'=>$v['created_uid']])['name'] ?? '';
|
|
|
|
82
|
+ }
|
|
|
|
83
|
+ }
|
|
|
|
84
|
+ return $this->response('success',Code::SUCCESS,$lists);
|
|
61
|
}
|
85
|
}
|
|
62
|
|
86
|
|
|
|
|
87
|
+
|
|
|
|
88
|
+
|
|
63
|
public function info(Request $request, ProductLogic $logic){
|
89
|
public function info(Request $request, ProductLogic $logic){
|
|
64
|
$request->validate([
|
90
|
$request->validate([
|
|
65
|
'id'=>'required'
|
91
|
'id'=>'required'
|