|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
++-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
4
|
+ * 管理端控制层: Category 控制类
|
|
|
|
5
|
++-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
6
|
+ *
|
|
|
|
7
|
+ * PHP version 7
|
|
|
|
8
|
+ *
|
|
|
|
9
|
+ * @category App\Admin\Controllers
|
|
|
|
10
|
+ * @package App\Admin\Controllers
|
|
|
|
11
|
+ * @author Richer <yangzi1028@163.com>
|
|
|
|
12
|
+ * @date 2023年4月20日14:26:14
|
|
|
|
13
|
+ * @copyright 2020-2022 Richer (http://www.Richer.com/)
|
|
|
|
14
|
+ * @license http://www.Richer.com/ License
|
|
|
|
15
|
+ * @link http://www.Richer.com/
|
|
|
|
16
|
+ */
|
|
|
|
17
|
+namespace App\Admin\Controllers;
|
|
|
|
18
|
+
|
|
|
|
19
|
+use App\Admin\Forms\FirstCategoryForm;
|
|
|
|
20
|
+use App\Admin\Grids\FirstCategoryGrid;
|
|
|
|
21
|
+use App\Jobs\Category\CategoryLabelCreatedJob;
|
|
|
|
22
|
+use App\Models\Category\Category;
|
|
|
|
23
|
+use App\Models\Category\CategoryExample;
|
|
|
|
24
|
+use App\Models\Category\CategoryLabel;
|
|
|
|
25
|
+use App\Models\Category\CategoryLabelItem;
|
|
|
|
26
|
+use App\Models\Label;
|
|
|
|
27
|
+use App\Models\LabelItem;
|
|
|
|
28
|
+use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
|
|
29
|
+use Illuminate\Http\JsonResponse;
|
|
|
|
30
|
+
|
|
|
|
31
|
+/**
|
|
|
|
32
|
+ * Class FirstCategoriesController.
|
|
|
|
33
|
+ *
|
|
|
|
34
|
+ * @package App\Admin\Controllers
|
|
|
|
35
|
+ */
|
|
|
|
36
|
+class FirstCategoriesController extends BaseController
|
|
|
|
37
|
+{
|
|
|
|
38
|
+ use FirstCategoryGrid, FirstCategoryForm;
|
|
|
|
39
|
+
|
|
|
|
40
|
+ /**
|
|
|
|
41
|
+ * FirstCategoriesController constructor.
|
|
|
|
42
|
+ *
|
|
|
|
43
|
+ * @param Category $model 注入model
|
|
|
|
44
|
+ */
|
|
|
|
45
|
+ public function __construct(Category $model)
|
|
|
|
46
|
+ {
|
|
|
|
47
|
+ // 资源显示的中名称
|
|
|
|
48
|
+ $this->title = $model::OBJ_NAME_ZH;
|
|
|
|
49
|
+ // 是否可查看
|
|
|
|
50
|
+ $this->can_view = false;
|
|
|
|
51
|
+ // 是否可新增
|
|
|
|
52
|
+ $this->can_create = true;
|
|
|
|
53
|
+ // 是否可编辑
|
|
|
|
54
|
+ $this->can_edit = true;
|
|
|
|
55
|
+ // 是否可删除
|
|
|
|
56
|
+ $this->can_delete = true;
|
|
|
|
57
|
+ // 是否开启下拉菜单
|
|
|
|
58
|
+ $this->dropdownActions = false;
|
|
|
|
59
|
+
|
|
|
|
60
|
+ // 执行父类构造方法
|
|
|
|
61
|
+ parent::__construct($model);
|
|
|
|
62
|
+ }
|
|
|
|
63
|
+
|
|
|
|
64
|
+ /**
|
|
|
|
65
|
+ * 获取 实例
|
|
|
|
66
|
+ *
|
|
|
|
67
|
+ * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse
|
|
|
|
68
|
+ */
|
|
|
|
69
|
+ public function examples($id)
|
|
|
|
70
|
+ {
|
|
|
|
71
|
+ $list = null;
|
|
|
|
72
|
+ try {
|
|
|
|
73
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
74
|
+ $model = $this->model->findOrFail($id);
|
|
|
|
75
|
+
|
|
|
|
76
|
+ $list = $model->examples()->get();
|
|
|
|
77
|
+ return view('admin::category.examples', compact('id', 'list')) ;
|
|
|
|
78
|
+
|
|
|
|
79
|
+ } catch (ModelNotFoundException $e) {
|
|
|
|
80
|
+ return view('admin::category.examples', compact('id', 'list')) ;
|
|
|
|
81
|
+ }
|
|
|
|
82
|
+ }
|
|
|
|
83
|
+
|
|
|
|
84
|
+ /**
|
|
|
|
85
|
+ * 添加实例界面
|
|
|
|
86
|
+ *
|
|
|
|
87
|
+ * @param $id
|
|
|
|
88
|
+ */
|
|
|
|
89
|
+ public function examplePage($id)
|
|
|
|
90
|
+ {
|
|
|
|
91
|
+ $example_id = request('example_id', 0);
|
|
|
|
92
|
+ $example = null;
|
|
|
|
93
|
+ if ($example_id) {
|
|
|
|
94
|
+ $example = CategoryExample::find($example_id);
|
|
|
|
95
|
+ }
|
|
|
|
96
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
97
|
+ return view('admin::category.example', compact('id', 'example_id','example')) ;
|
|
|
|
98
|
+ }
|
|
|
|
99
|
+
|
|
|
|
100
|
+ /**
|
|
|
|
101
|
+ * 添加站点
|
|
|
|
102
|
+ *
|
|
|
|
103
|
+ * @param integer $id 主键id
|
|
|
|
104
|
+ *
|
|
|
|
105
|
+ * @return JsonResponse
|
|
|
|
106
|
+ */
|
|
|
|
107
|
+ public function addExample($id)
|
|
|
|
108
|
+ {
|
|
|
|
109
|
+ try {
|
|
|
|
110
|
+
|
|
|
|
111
|
+ $example_id = request('example_id', 0);
|
|
|
|
112
|
+ if ($example_id > 0) {
|
|
|
|
113
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
114
|
+ $model = CategoryExample::findOrFail($example_id);
|
|
|
|
115
|
+ $model->question = request('question');
|
|
|
|
116
|
+ $model->answer = request('answer');
|
|
|
|
117
|
+ $model->save();
|
|
|
|
118
|
+ } else {
|
|
|
|
119
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
120
|
+ $model = $this->model->findOrFail($id);
|
|
|
|
121
|
+ $model->examples()->create([
|
|
|
|
122
|
+ 'question' => request('question'),
|
|
|
|
123
|
+ 'answer' => request('answer'),
|
|
|
|
124
|
+ ]);
|
|
|
|
125
|
+ }
|
|
|
|
126
|
+
|
|
|
|
127
|
+ return response()->json(
|
|
|
|
128
|
+ [
|
|
|
|
129
|
+ 'code' => 0,
|
|
|
|
130
|
+ 'status' => 1,
|
|
|
|
131
|
+ 'message' => __('operate_succeeded'),
|
|
|
|
132
|
+ ]
|
|
|
|
133
|
+ );
|
|
|
|
134
|
+ } catch (\Exception $e) {
|
|
|
|
135
|
+ return response()->json(
|
|
|
|
136
|
+ [
|
|
|
|
137
|
+ 'code' => 1,
|
|
|
|
138
|
+ 'status' => 0,
|
|
|
|
139
|
+ 'message' => $e->getMessage(),
|
|
|
|
140
|
+ ]
|
|
|
|
141
|
+ );
|
|
|
|
142
|
+ }
|
|
|
|
143
|
+ }
|
|
|
|
144
|
+
|
|
|
|
145
|
+ /**
|
|
|
|
146
|
+ * 线路更新站点的顺序
|
|
|
|
147
|
+ *
|
|
|
|
148
|
+ * @param integer $id 主键id
|
|
|
|
149
|
+ *
|
|
|
|
150
|
+ * @return JsonResponse
|
|
|
|
151
|
+ */
|
|
|
|
152
|
+ public function deleteExample($id)
|
|
|
|
153
|
+ {
|
|
|
|
154
|
+ try {
|
|
|
|
155
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
156
|
+
|
|
|
|
157
|
+ $model = $this->model->findOrFail($id);
|
|
|
|
158
|
+
|
|
|
|
159
|
+ $result = $model->examples()->where('id', request('id'))->delete();
|
|
|
|
160
|
+
|
|
|
|
161
|
+ if ($result) {
|
|
|
|
162
|
+ return response()->json(
|
|
|
|
163
|
+ [
|
|
|
|
164
|
+ 'code' => 0,
|
|
|
|
165
|
+ 'status' => 1,
|
|
|
|
166
|
+ 'message' =>__('operate_succeeded'),
|
|
|
|
167
|
+ ]
|
|
|
|
168
|
+ );
|
|
|
|
169
|
+ }
|
|
|
|
170
|
+
|
|
|
|
171
|
+ return response()->json(
|
|
|
|
172
|
+ [
|
|
|
|
173
|
+ 'code' => 1,
|
|
|
|
174
|
+ 'status' => 1,
|
|
|
|
175
|
+ 'message' =>__('操作失败。'),
|
|
|
|
176
|
+ ]
|
|
|
|
177
|
+ );
|
|
|
|
178
|
+
|
|
|
|
179
|
+
|
|
|
|
180
|
+ } catch (\Exception $e) {
|
|
|
|
181
|
+ return response()->json(
|
|
|
|
182
|
+ [
|
|
|
|
183
|
+ 'code' => 1,
|
|
|
|
184
|
+ 'status' => 0,
|
|
|
|
185
|
+ 'message' => $e->getMessage(),
|
|
|
|
186
|
+ ]
|
|
|
|
187
|
+ );
|
|
|
|
188
|
+ }
|
|
|
|
189
|
+ }
|
|
|
|
190
|
+
|
|
|
|
191
|
+ /**
|
|
|
|
192
|
+ * 获取 实例
|
|
|
|
193
|
+ *
|
|
|
|
194
|
+ * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse
|
|
|
|
195
|
+ */
|
|
|
|
196
|
+ public function labels($id)
|
|
|
|
197
|
+ {
|
|
|
|
198
|
+ $list = null;
|
|
|
|
199
|
+ try {
|
|
|
|
200
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
201
|
+ $model = $this->model->findOrFail($id);
|
|
|
|
202
|
+
|
|
|
|
203
|
+ $list = $model->labels()->get();
|
|
|
|
204
|
+ return view('admin::category.labels', compact('id', 'list')) ;
|
|
|
|
205
|
+
|
|
|
|
206
|
+ } catch (ModelNotFoundException $e) {
|
|
|
|
207
|
+ return view('admin::category.labels', compact('id', 'list')) ;
|
|
|
|
208
|
+ }
|
|
|
|
209
|
+ }
|
|
|
|
210
|
+
|
|
|
|
211
|
+ /**
|
|
|
|
212
|
+ * 添加 标签 界面
|
|
|
|
213
|
+ *
|
|
|
|
214
|
+ * @param $id
|
|
|
|
215
|
+ */
|
|
|
|
216
|
+ public function labelPage($id)
|
|
|
|
217
|
+ {
|
|
|
|
218
|
+ $label_id = request('label_id', 0);
|
|
|
|
219
|
+ $label = null;
|
|
|
|
220
|
+ if ($label_id) {
|
|
|
|
221
|
+ $label = CategoryLabel::find($label_id);
|
|
|
|
222
|
+ }
|
|
|
|
223
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
224
|
+ return view('admin::category.label', compact('id', 'label_id','label')) ;
|
|
|
|
225
|
+ }
|
|
|
|
226
|
+
|
|
|
|
227
|
+ /**
|
|
|
|
228
|
+ * 添加 标签
|
|
|
|
229
|
+ *
|
|
|
|
230
|
+ * @param integer $id 主键id
|
|
|
|
231
|
+ *
|
|
|
|
232
|
+ * @return JsonResponse
|
|
|
|
233
|
+ */
|
|
|
|
234
|
+ public function addLabel($id)
|
|
|
|
235
|
+ {
|
|
|
|
236
|
+ try {
|
|
|
|
237
|
+ $label_id = request('label_id', 0);
|
|
|
|
238
|
+ if ($label_id > 0) {
|
|
|
|
239
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
240
|
+ $model = CategoryLabel::findOrFail($label_id);
|
|
|
|
241
|
+ $model->name = request('name');
|
|
|
|
242
|
+ $model->can_multiple = request('can_multiple', 0);
|
|
|
|
243
|
+ $model->semantics = request('semantics');
|
|
|
|
244
|
+ $model->description = request('description');
|
|
|
|
245
|
+ $model->save();
|
|
|
|
246
|
+
|
|
|
|
247
|
+ } else {
|
|
|
|
248
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
249
|
+ $model = $this->model->findOrFail($id);
|
|
|
|
250
|
+ $result = $model->labels()->create([
|
|
|
|
251
|
+ 'name' => request('name'),
|
|
|
|
252
|
+ 'semantics' => request('semantics'),
|
|
|
|
253
|
+ 'description' => request('description'),
|
|
|
|
254
|
+ 'can_multiple' => request('can_multiple', 0),
|
|
|
|
255
|
+ ]);
|
|
|
|
256
|
+
|
|
|
|
257
|
+ // 同步到远程服务器
|
|
|
|
258
|
+// CategoryLabelCreatedJob::dispatch($result);
|
|
|
|
259
|
+
|
|
|
|
260
|
+ }
|
|
|
|
261
|
+
|
|
|
|
262
|
+ return response()->json(
|
|
|
|
263
|
+ [
|
|
|
|
264
|
+ 'code' => 0,
|
|
|
|
265
|
+ 'status' => 1,
|
|
|
|
266
|
+ 'message' => __('operate_succeeded'),
|
|
|
|
267
|
+ ]
|
|
|
|
268
|
+ );
|
|
|
|
269
|
+ } catch (\Exception $e) {
|
|
|
|
270
|
+ return response()->json(
|
|
|
|
271
|
+ [
|
|
|
|
272
|
+ 'code' => 1,
|
|
|
|
273
|
+ 'status' => 0,
|
|
|
|
274
|
+ 'message' => $e->getMessage(),
|
|
|
|
275
|
+ ]
|
|
|
|
276
|
+ );
|
|
|
|
277
|
+ }
|
|
|
|
278
|
+ }
|
|
|
|
279
|
+
|
|
|
|
280
|
+ /**
|
|
|
|
281
|
+ * 删除 标签
|
|
|
|
282
|
+ *
|
|
|
|
283
|
+ * @param integer $id 主键id
|
|
|
|
284
|
+ *
|
|
|
|
285
|
+ * @return JsonResponse
|
|
|
|
286
|
+ */
|
|
|
|
287
|
+ public function deleteLabel($id)
|
|
|
|
288
|
+ {
|
|
|
|
289
|
+ try {
|
|
|
|
290
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
291
|
+
|
|
|
|
292
|
+ $model = $this->model->findOrFail($id);
|
|
|
|
293
|
+
|
|
|
|
294
|
+ $result = $model->labels()->where('id', request('id'))->delete();
|
|
|
|
295
|
+
|
|
|
|
296
|
+ if ($result) {
|
|
|
|
297
|
+ return response()->json(
|
|
|
|
298
|
+ [
|
|
|
|
299
|
+ 'code' => 0,
|
|
|
|
300
|
+ 'status' => 1,
|
|
|
|
301
|
+ 'message' =>__('operate_succeeded'),
|
|
|
|
302
|
+ ]
|
|
|
|
303
|
+ );
|
|
|
|
304
|
+ }
|
|
|
|
305
|
+
|
|
|
|
306
|
+ return response()->json(
|
|
|
|
307
|
+ [
|
|
|
|
308
|
+ 'code' => 1,
|
|
|
|
309
|
+ 'status' => 1,
|
|
|
|
310
|
+ 'message' =>__('操作失败。'),
|
|
|
|
311
|
+ ]
|
|
|
|
312
|
+ );
|
|
|
|
313
|
+
|
|
|
|
314
|
+
|
|
|
|
315
|
+ } catch (\Exception $e) {
|
|
|
|
316
|
+ return response()->json(
|
|
|
|
317
|
+ [
|
|
|
|
318
|
+ 'code' => 1,
|
|
|
|
319
|
+ 'status' => 0,
|
|
|
|
320
|
+ 'message' => $e->getMessage(),
|
|
|
|
321
|
+ ]
|
|
|
|
322
|
+ );
|
|
|
|
323
|
+ }
|
|
|
|
324
|
+ }
|
|
|
|
325
|
+
|
|
|
|
326
|
+ /**
|
|
|
|
327
|
+ * 添加 标签明细 界面
|
|
|
|
328
|
+ *
|
|
|
|
329
|
+ * @param $id
|
|
|
|
330
|
+ */
|
|
|
|
331
|
+ public function labelItemPage($id)
|
|
|
|
332
|
+ {
|
|
|
|
333
|
+ $label_item_id = request('label_item_id', 0);
|
|
|
|
334
|
+ $label_item = null;
|
|
|
|
335
|
+ if ($label_item_id) {
|
|
|
|
336
|
+ $label_item = CategoryExample::find($label_item_id);
|
|
|
|
337
|
+ }
|
|
|
|
338
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
339
|
+ return view('admin::category.label-item', compact('id', 'label_item_id','label_item')) ;
|
|
|
|
340
|
+ }
|
|
|
|
341
|
+
|
|
|
|
342
|
+ /**
|
|
|
|
343
|
+ * 添加 标签明细
|
|
|
|
344
|
+ *
|
|
|
|
345
|
+ * @param integer $id 主键id
|
|
|
|
346
|
+ *
|
|
|
|
347
|
+ * @return JsonResponse
|
|
|
|
348
|
+ */
|
|
|
|
349
|
+ public function addLabelItem($id)
|
|
|
|
350
|
+ {
|
|
|
|
351
|
+ try {
|
|
|
|
352
|
+ $label_id = request('label_item_id', 0);
|
|
|
|
353
|
+ if ($label_id > 0) {
|
|
|
|
354
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
355
|
+ $model = CategoryLabelItem::findOrFail($label_id);
|
|
|
|
356
|
+ $model->name = request('name');
|
|
|
|
357
|
+ $model->description = request('description');
|
|
|
|
358
|
+ $model->save();
|
|
|
|
359
|
+ } else {
|
|
|
|
360
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
361
|
+ $model = CategoryLabel::findOrFail($id);
|
|
|
|
362
|
+ $model->items()->create([
|
|
|
|
363
|
+ 'name' => request('name'),
|
|
|
|
364
|
+ 'description' => request('description'),
|
|
|
|
365
|
+ ]);
|
|
|
|
366
|
+ }
|
|
|
|
367
|
+
|
|
|
|
368
|
+ return response()->json(
|
|
|
|
369
|
+ [
|
|
|
|
370
|
+ 'code' => 0,
|
|
|
|
371
|
+ 'status' => 1,
|
|
|
|
372
|
+ 'message' => __('operate_succeeded'),
|
|
|
|
373
|
+ ]
|
|
|
|
374
|
+ );
|
|
|
|
375
|
+ } catch (\Exception $e) {
|
|
|
|
376
|
+ return response()->json(
|
|
|
|
377
|
+ [
|
|
|
|
378
|
+ 'code' => 1,
|
|
|
|
379
|
+ 'status' => 0,
|
|
|
|
380
|
+ 'message' => $e->getMessage(),
|
|
|
|
381
|
+ ]
|
|
|
|
382
|
+ );
|
|
|
|
383
|
+ }
|
|
|
|
384
|
+ }
|
|
|
|
385
|
+
|
|
|
|
386
|
+ /**
|
|
|
|
387
|
+ * 删除 标签明细
|
|
|
|
388
|
+ *
|
|
|
|
389
|
+ * @param integer $id 主键id
|
|
|
|
390
|
+ *
|
|
|
|
391
|
+ * @return JsonResponse
|
|
|
|
392
|
+ */
|
|
|
|
393
|
+ public function deleteLabelItem($id)
|
|
|
|
394
|
+ {
|
|
|
|
395
|
+ try {
|
|
|
|
396
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
397
|
+ $result = CategoryLabelItem::where('id', request('id'))->delete();
|
|
|
|
398
|
+
|
|
|
|
399
|
+ if ($result) {
|
|
|
|
400
|
+ return response()->json(
|
|
|
|
401
|
+ [
|
|
|
|
402
|
+ 'code' => 0,
|
|
|
|
403
|
+ 'status' => 1,
|
|
|
|
404
|
+ 'message' =>__('operate_succeeded'),
|
|
|
|
405
|
+ ]
|
|
|
|
406
|
+ );
|
|
|
|
407
|
+ }
|
|
|
|
408
|
+
|
|
|
|
409
|
+ return response()->json(
|
|
|
|
410
|
+ [
|
|
|
|
411
|
+ 'code' => 1,
|
|
|
|
412
|
+ 'status' => 1,
|
|
|
|
413
|
+ 'message' =>__('操作失败。'),
|
|
|
|
414
|
+ ]
|
|
|
|
415
|
+ );
|
|
|
|
416
|
+
|
|
|
|
417
|
+
|
|
|
|
418
|
+ } catch (\Exception $e) {
|
|
|
|
419
|
+ return response()->json(
|
|
|
|
420
|
+ [
|
|
|
|
421
|
+ 'code' => 1,
|
|
|
|
422
|
+ 'status' => 0,
|
|
|
|
423
|
+ 'message' => $e->getMessage(),
|
|
|
|
424
|
+ ]
|
|
|
|
425
|
+ );
|
|
|
|
426
|
+ }
|
|
|
|
427
|
+ }
|
|
|
|
428
|
+
|
|
|
|
429
|
+// /**
|
|
|
|
430
|
+// * 获取 实例
|
|
|
|
431
|
+// *
|
|
|
|
432
|
+// * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse
|
|
|
|
433
|
+// */
|
|
|
|
434
|
+// public function labels($id)
|
|
|
|
435
|
+// {
|
|
|
|
436
|
+// $list = null;
|
|
|
|
437
|
+// try {
|
|
|
|
438
|
+// // 获取数据,如果没有获取到抛出异常
|
|
|
|
439
|
+// $model = $this->model->findOrFail($id);
|
|
|
|
440
|
+//
|
|
|
|
441
|
+// $list = $model->labels()->get();
|
|
|
|
442
|
+// return view('admin::category.labels', compact('id', 'list')) ;
|
|
|
|
443
|
+//
|
|
|
|
444
|
+// } catch (ModelNotFoundException $e) {
|
|
|
|
445
|
+// return view('admin::category.labels', compact('id', 'list')) ;
|
|
|
|
446
|
+// }
|
|
|
|
447
|
+// }
|
|
|
|
448
|
+
|
|
|
|
449
|
+ /**
|
|
|
|
450
|
+ * 添加 标签 界面
|
|
|
|
451
|
+ *
|
|
|
|
452
|
+ * @param $id
|
|
|
|
453
|
+ */
|
|
|
|
454
|
+ public function childPage($id)
|
|
|
|
455
|
+ {
|
|
|
|
456
|
+ $label_id = request('id', 0);
|
|
|
|
457
|
+ $label = null;
|
|
|
|
458
|
+ if ($label_id) {
|
|
|
|
459
|
+ $label = CategoryLabel::find($label_id);
|
|
|
|
460
|
+ }
|
|
|
|
461
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
462
|
+ return view('admin::category.child', compact('id', 'label_id','label')) ;
|
|
|
|
463
|
+ }
|
|
|
|
464
|
+
|
|
|
|
465
|
+ /**
|
|
|
|
466
|
+ * 添加 标签
|
|
|
|
467
|
+ *
|
|
|
|
468
|
+ * @param integer $id 主键id
|
|
|
|
469
|
+ *
|
|
|
|
470
|
+ * @return JsonResponse
|
|
|
|
471
|
+ */
|
|
|
|
472
|
+ public function addChild($id)
|
|
|
|
473
|
+ {
|
|
|
|
474
|
+ try {
|
|
|
|
475
|
+ $label_id = request('label_id', 0);
|
|
|
|
476
|
+ if ($label_id > 0) {
|
|
|
|
477
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
478
|
+ $model = CategoryLabel::findOrFail($label_id);
|
|
|
|
479
|
+ $model->name = request('name');
|
|
|
|
480
|
+ $model->can_multiple = request('can_multiple', 0);
|
|
|
|
481
|
+ $model->semantics = request('semantics');
|
|
|
|
482
|
+ $model->description = request('description');
|
|
|
|
483
|
+ $model->save();
|
|
|
|
484
|
+
|
|
|
|
485
|
+ } else {
|
|
|
|
486
|
+ // 获取数据,如果没有获取到抛出异常
|
|
|
|
487
|
+ $model = $this->model->findOrFail($id);
|
|
|
|
488
|
+ $result = $model->labels()->create([
|
|
|
|
489
|
+ 'name' => request('name'),
|
|
|
|
490
|
+ 'semantics' => request('semantics'),
|
|
|
|
491
|
+ 'description' => request('description'),
|
|
|
|
492
|
+ 'can_multiple' => request('can_multiple', 0),
|
|
|
|
493
|
+ ]);
|
|
|
|
494
|
+
|
|
|
|
495
|
+ // 同步到远程服务器
|
|
|
|
496
|
+// CategoryLabelCreatedJob::dispatch($result);
|
|
|
|
497
|
+
|
|
|
|
498
|
+ }
|
|
|
|
499
|
+
|
|
|
|
500
|
+ return response()->json(
|
|
|
|
501
|
+ [
|
|
|
|
502
|
+ 'code' => 0,
|
|
|
|
503
|
+ 'status' => 1,
|
|
|
|
504
|
+ 'message' => __('operate_succeeded'),
|
|
|
|
505
|
+ ]
|
|
|
|
506
|
+ );
|
|
|
|
507
|
+ } catch (\Exception $e) {
|
|
|
|
508
|
+ return response()->json(
|
|
|
|
509
|
+ [
|
|
|
|
510
|
+ 'code' => 1,
|
|
|
|
511
|
+ 'status' => 0,
|
|
|
|
512
|
+ 'message' => $e->getMessage(),
|
|
|
|
513
|
+ ]
|
|
|
|
514
|
+ );
|
|
|
|
515
|
+ }
|
|
|
|
516
|
+ }
|
|
|
|
517
|
+
|
|
|
|
518
|
+} |