Ticket5UploadDataController.php
7.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
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
<?php
/**
* @remark :
* @name :Ticket5UploadDataController.php
* @author :lyh
* @method :post
* @time :2025/11/8 09:35
*/
namespace App\Http\Controllers\Api\WorkOrder;
use App\Enums\Common\Code;
use App\Http\Controllers\Api\BaseController;
use App\Models\Ticket\Project5Cate;
use App\Models\Ticket\TicketUploadData;
use App\Models\WorkOrder\TicketProject;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class Ticket5UploadDataController extends BaseController
{
public function __construct(Request $request)
{
parent::__construct($request);
$this->model = new TicketUploadData();
}
/**
* @remark :获取对应项目的分类
* @name :getProject5Cate
* @author :lyh
* @method :post
* @time :2025/11/8 09:27
*/
public function getProject5Cate(){
$this->request->validate([
'post_id'=>'required',
'type'=>'required',
],[
'post_id.required' => 'post_id不能为空',
'type.required' => '类型不能为空',
]);
//查询是否有值
$project5CateModel = new Project5Cate();
$cateInfo = $project5CateModel->read(['project_id' => $this->param['post_id'],'type'=>$this->param['type'],'updated_at'=>['>', date('Y-m-d H:i:s', strtotime('-24 hours'))]]);
if($cateInfo !== false){
$resultData = $cateInfo['text'];
$this->response('success', Code::SUCCESS, $resultData);
}
//获取域名
$ticketProjectMdoel = new TicketProject();
$projectInfo = $ticketProjectMdoel->read(['post_id' => $this->param['post_id']]);
if($projectInfo === false){
$this->response('当前项目不存在或数据未同步',Code::SYSTEM_ERROR);
}
//todo::目前写死
$projectInfo['website'] = 'https://devmark.globalso.com/';
$action = $project5CateModel->getCateTypeAction($this->param['type']);
if(empty($action)){
$this->response('未知请求',Code::SYSTEM_ERROR);
}
$url = $projectInfo['website'].'wp-admin/admin-ajax.php?action='.$action;
$data = http_get($url);
if($data && $data['status'] == 200){
$resultData = $data['data'];
$saveData = [
'project_id' => $projectInfo['post_id'],
'domain' => $projectInfo['website'],
'text'=>json_encode($data['data']),
'type' => $this->param['type'],
];
$project5CateModel->addReturnId($saveData);
$this->response('success', Code::SUCCESS,$resultData);
}
$this->response('success',Code::SUCCESS,$url);
}
/**
* @remark :新增分类
* @name :addProject5Cate
* @author :lyh
* @method :post
* @time :2025/11/8 10:25
*/
public function addProject5Cate()
{
$this->request->validate([
'post_id'=>'required',
'type'=>'required',
'name'=>'required',
'parent'=>'required',
],[
'post_id.required' => 'post_id不能为空',
'type.required' => '类型不能为空',
'name.required' => '名称不能为空',
'parent.required' => '上级ID不能为空',
]);
//获取域名
$ticketProjectMdoel = new TicketProject();
$projectInfo = $ticketProjectMdoel->read(['post_id' => $this->param['post_id']]);
if($projectInfo === false){
$this->response('当前项目不存在或数据未同步',Code::SYSTEM_ERROR);
}
$project5CateModel = new Project5Cate();
//todo::目前写死,上线放开
$projectInfo['website'] = 'https://devmark.globalso.com/';
$action = $project5CateModel->saveCateTypeAction($this->param['type']);
$url = $projectInfo['website'].'wp-admin/admin-ajax.php?action='.$action;
if(empty($action)){
$this->response('未知请求',Code::SYSTEM_ERROR);
}
$response = Http::withHeaders([])->asForm()->post($url, [
'name' => $this->param['name'],
'parent' => $this->param['parent'] ?? 0,
]);
if ($response->successful()) {
$result = $response->json(); // 获取 JSON 响应体
if($result && $result['status'] == 200){
//todo::更新分类数据
$action1 = $project5CateModel->getCateTypeAction($this->param['type']);
$url1 = $projectInfo['website'].'wp-admin/admin-ajax.php?action='.$action1;
$data = http_get($url1);
if($data && $data['status'] == 200){
$resultData = $data['data'];
$saveData = [
'text'=>json_encode($data['data']),
];
$project5CateModel->edit($saveData,['project_id' => $projectInfo['post_id'],'type'=>$this->param['type']]);
$this->response('success', Code::SUCCESS,$resultData);
}
$this->response('success');
}
}
$this->response('请求失败',Code::SYSTEM_ERROR);
}
/**
* @remark :提交数据
* @name :save
* @author :lyh
* @method :post
* @time :2025/11/10 11:01
*/
public function save5Data()
{
$this->request->validate([
'post_id' => 'required',
'type' => 'required',
'text' => 'required'
], [
'post_id.required' => 'post_id不能为空',
'type.required' => '类型不能为空',
'text' => '数据详情不为空'
]);
if(empty($this->param['text']['image'])){
$this->response('参数错误',Code::SYSTEM_ERROR);
}
if(empty($this->param['text']['title'])){
$this->response('参数错误,标题不能为空',Code::SYSTEM_ERROR);
}
//验证当前数据是否已提交
$this->param['text'] = json_encode($this->param['text'], true);
// $this->pushTicketByBots($this->param['post_id'],$this->param['project_type']);
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['post_id'],'project_type'=>$this->model::TYPE_FIVE ,'type' => $this->param['type'], 'text' => $this->param['text'], 'status' => 0]);
if ($info === false) {
$this->param['project_type'] = $this->model::TYPE_FIVE ;
$this->param['project_id'] = $this->param['post_id'];
$id = $this->model->addReturnId($this->param);
} else {
$id = $info['id'];
}
$data = ['id' => $id];
$this->response('success', Code::SUCCESS, $data);
}
}
/**
* @remark :钉钉通知
* @name :pushTicketByBots
* @method :post
* @time :2025/11/10 11:10
* @author :lyh
*/
public function pushTicketByBots($post_id,$type = 1)
{
$project = TicketProject::where('post_id', $post_id)->where('project_cate',$type)->where('is_del', 0)->first();
if ($project){
return $project->pushWechatGroupMsg("您好,用户已上传数据,请审核!");
}
return true;
}
}