|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
+ * Created by PhpStorm.
|
|
|
|
4
|
+ * User: zhl
|
|
|
|
5
|
+ * Date: 2024/5/28
|
|
|
|
6
|
+ * Time: 14:25
|
|
|
|
7
|
+ */
|
|
|
|
8
|
+namespace App\Http\Controllers\Aside\Task;
|
|
|
|
9
|
+
|
|
|
|
10
|
+use App\Enums\Common\Code;
|
|
|
|
11
|
+use App\Http\Controllers\Aside\BaseController;
|
|
|
|
12
|
+use App\Models\Com\Notify;
|
|
|
|
13
|
+use App\Models\Project\Project;
|
|
|
|
14
|
+use App\Models\WebSetting\WebLanguage;
|
|
|
|
15
|
+use Illuminate\Http\Request;
|
|
|
|
16
|
+
|
|
|
|
17
|
+/**
|
|
|
|
18
|
+ * 自动任务信息
|
|
|
|
19
|
+ * Class AutoTaskController
|
|
|
|
20
|
+ * @package App\Http\Controllers\Aside\Task
|
|
|
|
21
|
+ */
|
|
|
|
22
|
+class AutoTaskController extends BaseController
|
|
|
|
23
|
+{
|
|
|
|
24
|
+ /**
|
|
|
|
25
|
+ * 页面生成任务
|
|
|
|
26
|
+ * @param Request $request
|
|
|
|
27
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
|
28
|
+ */
|
|
|
|
29
|
+ public function createHtmlTask(Request $request)
|
|
|
|
30
|
+ {
|
|
|
|
31
|
+ // 接收信息
|
|
|
|
32
|
+ $project_id = intval($request->input('project_id'));
|
|
|
|
33
|
+ $status = intval($request->input('status'));
|
|
|
|
34
|
+ $route = intval($request->input('route'));
|
|
|
|
35
|
+ $type = intval($request->input('type'));
|
|
|
|
36
|
+ $row = intval($request->input('row', 20));
|
|
|
|
37
|
+ // 所有参数都有初始化数据, 无数据验证
|
|
|
|
38
|
+ // 查询初始数据
|
|
|
|
39
|
+ $where = compact('project_id', 'route', 'type');
|
|
|
|
40
|
+ $where = array_filter($where);
|
|
|
|
41
|
+ if ($status)
|
|
|
|
42
|
+ $where['status'] = $status - 1;
|
|
|
|
43
|
+ $result = Notify::select(['id','project_id', 'type', 'data', 'status', 'route', 'num', 'updated_at', 'created_at'])
|
|
|
|
44
|
+ ->where('id', '>', 84000) // 查询有效数据
|
|
|
|
45
|
+ ->where('server_id', '<>', 9) // 过滤测试环境数据
|
|
|
|
46
|
+ ->where('server_id', '>', 0) // 过滤测试环境数据
|
|
|
|
47
|
+ ->where($where)
|
|
|
|
48
|
+ ->orderBy('id', 'desc')
|
|
|
|
49
|
+ ->paginate($row);
|
|
|
|
50
|
+
|
|
|
|
51
|
+ // 数据中需要处理项目信息
|
|
|
|
52
|
+ $project_ids = $result->pluck('project_id')->toArray();
|
|
|
|
53
|
+ $projects = Project::whereIN('id', $project_ids)->pluck('title', 'id')->toArray();
|
|
|
|
54
|
+ // 数据中需要处理的语种信息
|
|
|
|
55
|
+ $language = WebLanguage::pluck('chinese', 'id')->toArray();
|
|
|
|
56
|
+ // 数据中需要映射的参数信息
|
|
|
|
57
|
+ $type = Notify::typeMap();
|
|
|
|
58
|
+ $route = Notify::routeMap();
|
|
|
|
59
|
+ $status = Notify::statusMap();
|
|
|
|
60
|
+ // 转数组操作, 如果是对象, 添加字段会报错
|
|
|
|
61
|
+ $result = $result->toArray();
|
|
|
|
62
|
+ foreach ($result['list'] as &$val) {
|
|
|
|
63
|
+ // 解析data信息, 以后数据库尽量不要存需要处理的JSON信息, 拆分成指定字段
|
|
|
|
64
|
+ $data = json_decode($val['data'], true);
|
|
|
|
65
|
+ $val['language'] = [];
|
|
|
|
66
|
+ // 小语种 并且 有语种信息, 将语种转换成中文
|
|
|
|
67
|
+ if ($val['type'] == Notify::TYPE_MINOR && FALSE == empty($data['language'])) {
|
|
|
|
68
|
+ foreach ($data['language'] as $v) {
|
|
|
|
69
|
+ $val['language'][] = $language[$v];
|
|
|
|
70
|
+ }
|
|
|
|
71
|
+ }
|
|
|
|
72
|
+ // 映射信息 以及解析信息
|
|
|
|
73
|
+ $val['type'] = $type[$val['type']];
|
|
|
|
74
|
+ $val['route'] = $route[$val['route']];
|
|
|
|
75
|
+ $val['status'] = $status[$val['status']];
|
|
|
|
76
|
+ $val['project_title'] = $projects[$val['project_id']] ?? '';
|
|
|
|
77
|
+ $val['domain'] = $data['domain'] ?? '';
|
|
|
|
78
|
+ $val['url'] = FALSE == empty($data['url']) ? json_decode($data['url'], true) : [];
|
|
|
|
79
|
+
|
|
|
|
80
|
+ }
|
|
|
|
81
|
+ return $this->response('success', Code::SUCCESS, $result);
|
|
|
|
82
|
+ }
|
|
|
|
83
|
+
|
|
|
|
84
|
+ /**
|
|
|
|
85
|
+ * 页面生成任务参数
|
|
|
|
86
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
|
87
|
+ */
|
|
|
|
88
|
+ public function createHtmlTaskParam()
|
|
|
|
89
|
+ {
|
|
|
|
90
|
+ $status = Notify::statusMap();
|
|
|
|
91
|
+ $status_new = [];
|
|
|
|
92
|
+ foreach ($status as $key=>$val) {
|
|
|
|
93
|
+ $status_new[$key+1] = $val;
|
|
|
|
94
|
+ }
|
|
|
|
95
|
+ $result = [
|
|
|
|
96
|
+ 'status' => $status_new,
|
|
|
|
97
|
+ 'type' => Notify::typeMap(),
|
|
|
|
98
|
+ 'route' => Notify::routeMap()
|
|
|
|
99
|
+ ];
|
|
|
|
100
|
+ return $this->response('success', Code::SUCCESS, $result);
|
|
|
|
101
|
+ }
|
|
|
|
102
|
+} |