TicketUploadDataController.php
8.7 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
/**
* @remark :
* @name :TicketUploadDataController.php
* @author :lyh
* @method :post
* @time :2025/9/25 09:40
*/
namespace App\Http\Controllers\Api\WorkOrder;
use App\Enums\Common\Code;
use App\Http\Controllers\Api\BaseController;
use App\Models\Blog\BlogCategory;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
use App\Models\Product\Keyword;
use App\Models\Ticket\TicketUploadData;
use App\Services\ProjectServer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* @remark :上传产品/博客/新闻模块
* @name :TicketUploadDataController
* @author :lyh
* @method :post
* @time :2025/9/25 09:40
*/
class TicketUploadDataController extends BaseController
{
public function __construct(Request $request)
{
parent::__construct($request);
$this->model = new TicketUploadData();
}
/**
* @remark :已提交列表
* @name :lists
* @author :lyh
* @method :post
* @time :2025/9/25 10:28
*/
public function lists()
{
$this->request->validate([
'project_id' => 'required',
], [
'project_id.required' => 'project_id不能为空',
]);
$data = $this->model->lists($this->map, $this->page, $this->row, $this->order);
ProjectServer::useProject($this->map['project_id']);
if(!empty($data) && !empty($data['list'])){
foreach ($data['list'] as &$item) {
$item = $this->getHandleFileImage($item);
$item['text']['cate_name'] = $this->cateText($item['type'],$item['text']['category_id'] ?? []);
}
}
DB::disconnect('custom_mysql');
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :处理数据
* @name :getHandleFileImage
* @author :lyh
* @method :post
* @time :2025/9/25 16:53
*/
public function getHandleFileImage($v){
if($v['type'] == 1){
if(!empty($v['text']['image'])){
foreach ($v['text']['image'] as $gallery_k => $gallery_v){
$gallery_v['url'] = getImageUrl($gallery_v['url']);
$v['text']['image'][$gallery_k] = $gallery_v;
}
}
}else{
$v['text']['image'] = getImageUrl($v['text']['image']);
}
return $v;
}
/**
* @remark :获取分类名称
* @name :cateText
* @author :lyh
* @method :post
* @time :2025/9/29 17:18
*/
public function cateText($type,$category_id,$keyword_id = [],$is_array = false)
{
if(empty($category_id)){
return '';
}else{
$filed = 'name';
if($type == 1){
$cateModel = new Category();
$filed = 'title';
}elseif ($type == 2){
$cateModel = new BlogCategory();
}else{
$cateModel = new NewsCategory();
}
if($is_array){
$cate_arr = $cateModel->whereIn('id', (array)$category_id)
->pluck($filed, 'id')
->toArray();
if($type == 1){
$keywodModel = new KeyWord();
$keywod_arr = $keywodModel->whereIn('id', (array)$keyword_id)
->pluck($filed, 'id')
->toArray();
return ['keywod_arr' => $keywod_arr, 'cate_arr' => $cate_arr];
}
return ['cate_arr' => $cate_arr];
}else{
$cateArr = $cateModel->selectField(['id'=>['in',$category_id]],$filed);
return implode(',',$cateArr);
}
}
}
/**
* @remark :获取数据详情
* @name :info
* @author :lyh
* @method :post
* @time :2025/9/25 10:35
*/
public function info()
{
$this->request->validate([
'id' => 'required',
], [
'id.required' => 'id不能为空',
]);
$info = $this->model->read($this->param);
if($info === false){
$this->response('当前数据不存在或已被删除',Code::SYSTEM_ERROR);
}
ProjectServer::useProject($info['project_id']);
$info['text']['cate_name'] = $this->cateText($info['type'],$info['text']['category_id'] ?? [],$info['text']['keyword_id'] ?? [],true);
$info = $this->getHandleFileImage($info);
DB::disconnect('custom_mysql');
$this->response('success', Code::SUCCESS, $info);
}
/**
* @remark :提交数据
* @name :save
* @author :lyh
* @method :post
* @time :2025/9/25 09:48
*/
public function save()
{
$this->request->validate([
'project_id' => 'required',
'type' => 'required',
'text' => 'required'
], [
'project_id.required' => 'project_id不能为空',
'type.required' => '上传类型不能为空',
'text' => '数据详情不为空'
]);
//验证当前数据是否已提交
$this->param['text'] = json_encode($this->param['text'], true);
if(isset($this->param['id']) && !empty($this->param['id'])){
//执行编辑
$info = $this->model->read(['id'=>$this->param['id']]);
if($info['status'] == 0){
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->response('当前状态不允许编辑', Code::SYSTEM_ERROR);
}
$this->response('success');
}else{
$info = $this->model->read(['project_id' => $this->param['project_id'], 'type' => $this->param['type'], 'text' => $this->param['text'], 'status' => 0]);
if ($info === false) {
$id = $this->model->addReturnId($this->param);
} else {
$id = $info['id'];
}
$data = ['id' => $id];
$this->response('success', Code::SUCCESS, $data);
}
}
/**
* @remark :根据项目获取分类
* @name :getProductCate
* @author :lyh
* @method :post
* @time :2025/9/25 15:41
*/
public function getProductCate()
{
$this->request->validate([
'project_id' => 'required',
'type' => 'required',
'search' => 'required'
], [
'project_id.required' => 'project_id不能为空',
'type.required' => 'type不能为空',
'search.required' => '搜索参数不能为空',
]);
ProjectServer::useProject($this->param['project_id']);
if ($this->param['type'] == 1) {
//todo::搜索获取分类
$productCateModel = new Category();
$data = $productCateModel->lists(['title' => ['like','%' . $this->param['search'] . '%']], 1, 20,'id',['id','title as name']);
} else {
$keywordModel = new Keyword();
$data = $keywordModel->lists(['title' => ['like','%' . $this->param['search'] . '%']], 1, 20,'id',['id','title as name']);
}
DB::disconnect('custom_mysql');
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :获取博客分类
* @name :getBlogCate
* @author :lyh
* @method :post
* @time :2025/9/25 15:42
*/
public function getBlogCate()
{
$this->request->validate([
'project_id' => 'required',
'search' => 'required'
], [
'project_id.required' => 'project_id不能为空',
'search.required' => '搜索参数不能为空',
]);
ProjectServer::useProject($this->param['project_id']);
$blogCateModel = new BlogCategory();
$data = $blogCateModel->lists(['name' => ['like' ,'%' . $this->param['search'] . '%']], 1, 20,'id',['id','name']);
DB::disconnect('custom_mysql');
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :获取新闻分类
* @name :getNewsCate
* @author :lyh
* @method :post
* @time :2025/9/25 15:43
*/
public function getNewsCate()
{
$this->request->validate([
'project_id' => 'required',
'search' => 'required'
], [
'project_id.required' => 'project_id不能为空',
'search.required' => '搜索参数不能为空',
]);
ProjectServer::useProject($this->param['project_id']);
$newsCateModel = new NewsCategory();
$data = $newsCateModel->lists(['name' => ['like' , '%' . $this->param['search'] . '%']], 1, 20,'id',['id','name']);
DB::disconnect('custom_mysql');
$this->response('success', Code::SUCCESS, $data);
}
}