DetailController.php
4.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* @remark :
* @name :DetailController.php
* @author :lyh
* @method :post
* @time :2024/11/12 14:55
*/
namespace App\Http\Controllers\Bside\Product;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\DetailLogic;
use App\Models\Product\Column;
use App\Models\Product\Detail;
use Illuminate\Support\Facades\DB;
class DetailController extends BaseController
{
/**
* @remark :获取当前产品的描述详情
* @name :getDetail
* @author :lyh
* @method :post
* @time :2024/11/13 9:53
*/
public function getDetail(Detail $detail,Column $column){
$this->request->validate([
'product_id'=>'required',
],[
'product_id.required' => '产品id不能为空',
]);
$data = $detail->list($this->map,'sort',['*'],'asc');
$data_column = $column->list([],'id',['*'],'asc');
if(!empty($data_column) && !empty($data)){
foreach ($data_column as $k => $v){
$column_data = [];
foreach ($data as $v1){
if($v['id'] == $v1['column_id']){
$column_data[] = $v1;
}
}
$v['data'] = $column_data;
$data_column[$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$data_column);
}
/**
* @remark :获取产品描述页所有详情
* @name :getType
* @author :lyh
* @method :post
* @time :2024/11/12 14:57
*/
public function getType(Detail $detail){
$data = [
'text_type' => $detail->text_type(),
'line_two_type' => $detail->line_two_type(),
'image_two_type' => $detail->image_two_type(),
'three_type' => $detail->three_type(),
'image_three_type' => $detail->image_three_type(),
];
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取产品描述栏目
* @name :getColumn
* @author :lyh
* @method :post
* @time :2024/11/12 15:07
*/
public function getColumn(Column $column){
$data = $column->list($this->map,'id',['*'],'asc');
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :保存切换栏
* @name :saveColumn
* @author :lyh
* @method :post
* @time :2024/11/12 15:13
*/
public function saveColumn(DetailLogic $logic){
$this->request->validate([
'column_name'=>'required'
],[
'column_name.required' => '栏目名称不能为空'
]);
$data = $logic->saveColumn();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :保存数据
* @name :saveDetail
* @author :lyh
* @method :post
* @time :2024/11/12 16:24
*/
public function saveDetail(DetailLogic $logic){
$this->request->validate([
'product_id'=>'required',
'data'=>'required',
],[
'product_id.required' => '产品id不能为空',
'data.required' => 'data不能为空',
]);
$data = $logic->saveDetail();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :删除切换栏
* @name :delColumn
* @author :lyh
* @method :post
* @time :2024/11/13 10:40
*/
public function delColumn(Column $column,Detail $detail){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'id不能为空',
]);
$info = $column->read($this->map);
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
if($info['id'] == 1){
$this->fail('当前默认模块不允许删除');
}
DB::beginTransaction();
try {
$column->del(['id'=>$this->param['id']]);
$detail->del(['column_id'=>$info['id']]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('删除失败,请联系管理员');
}
$this->response('success');
}
/***
* @remark :删除模块
* @name :delDetail
* @author :lyh
* @method :post
* @time :2024/11/13 10:24
*/
public function delDetail(Detail $detail){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'id不能为空',
]);
$detail->del($this->map);
$this->response('success');
}
}