GeoController.php
7.2 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
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/10/23
* Time: 17:29
*/
namespace App\Http\Controllers\Api;
use App\Enums\Common\Code;
use App\Models\Geo\GeoConf;
use App\Models\Geo\GeoConfirm;
use App\Models\Geo\GeoWritings;
use App\Models\Manage\ManageHr;
use App\Models\Project\Project;
use App\Services\DingService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
/**
* GEO相关
* Class GeoController
* @package App\Http\Controllers\Api
*/
class GeoController extends BaseController
{
/**
* 获取确认文章列表
* @param Request $request
* @return false|string
*/
public function getWritingsList()
{
try {
$token = trim($this->param['token']);
$param = Crypt::decrypt($token);
}catch (\Exception $e){
$this->response('非法请求',Code::SYSTEM_ERROR);
}
if ($param['send_at'] + 86400 < time()) {
$this->response('非法请求,已过期',Code::SYSTEM_ERROR);
}
$project_id = $param['project_id'];
$projectModel = new Project();
$projectInfo = $projectModel->read(['id' => $project_id],['title','version']);
$geoWritingsModel = new GeoWritings();
$lists = $geoWritingsModel->list(['project_id' => $project_id, 'status' => ['in',[GeoWritings::STATUS_RUNNING,GeoWritings::STATUS_FINISH]] ,'is_del' => GeoWritings::IS_DEL_FALSE],'id',['title', 'status', 'uniqid', 'confirm_at']);
$result = [
'project' => $projectInfo,
'list' => $lists
];
$this->response('success',Code::SUCCESS,$result);
}
/**
* 获取详情
* @param Request $request
* @return false|string
*/
public function getWritingsDetail()
{
$geoWritingsModel = new GeoWritings();
$token = trim($this->param['token']);
$detail = $geoWritingsModel->read(['uniqid' => $token],['title', 'content', 'status']);
$this->response('success',Code::SUCCESS,$detail);
}
/**
* 确认核心文章数据
* @param Request $request
* @return false|string
*/
public function confirmWritings()
{
$this->request->validate([
'token' => 'required',
'title' => 'required|max:120',
'content' => 'required'
], [
'token.required' => '非法请求',
'title.required' => '标题不能为空',
'title.max' => '最大长度不能超过120字符',
'content.required' => '内容不能为空',
]);
$token = trim($this->param['token']);
$geoWritingsModel = new GeoWritings();
$info = $geoWritingsModel->read(['uniqid' => $token]);
if ($info === false){
return $this->response('非法请求',Code::SYSTEM_ERROR);
}
if ($info['status'] == GeoWritings::STATUS_FINISH){
return $this->response('当前文章已确认,不可再次确认',Code::SYSTEM_ERROR);
}
try {
$this->param['confirm_ip'] = $this->request->ip();
$this->param['confirm_at'] = date('Y-m-d H:i:s');
$this->param['content_length'] = strlen($this->param['content']);
$this->param['status'] = GeoWritings::STATUS_FINISH;
$geoWritingsModel->edit($this->param,['uniqid' => $token]);
$geoConfModel = new GeoConf();
$confInfo = $geoConfModel->read(['project_id'=>$info['project_id']]);
$hrModel = new ManageHr();
$manage_name = $hrModel->getName($confInfo['manager_id'] ??'');
$dingService = new DingService();
$dingService->handle([
'keyword' => '项目数据确认',
'msg' =>
'cm:文章确认完成' . PHP_EOL .
'项目名称:'.$confInfo['company'] ?? '' . PHP_EOL .
'负责人:'.$manage_name . PHP_EOL,
'isAtAll' => false, // 是否@所有人
], 'https://oapi.dingtalk.com/robot/send?access_token=4effe85882009a8a1617dbeadc38c350f832deef7431ce10f5fda751b4c82fb9');
}catch (\Exception $e){
$this->response('非法请求',Code::SYSTEM_ERROR);
}
$this->response('success',Code::SUCCESS);
}
/**
* 获取确认数据
* @param Request $request
* @return false|string
*/
public function getConfirm()
{
$token = trim($this->param['token']);
$data = GeoConfirm::where(['uniqid' => $token])->first();
if (empty($data)){
return $this->response('确认链接已重置,请查看最新推送链接!',Code::SYSTEM_ERROR);
}
$content = explode("\n", $data->content);
$confirm = explode("\n", $data->confirm);
$max_num = $data->max_num;
$type = $data->type;
$status = $data->status;
$projectModel = new Project();
$projectInfo = $projectModel->read(['id' => $data->project_id],['title','version']);
$project_title = $projectInfo['title'] ?? '';
$result = compact('content', 'confirm', 'type', 'status', 'project_title','max_num');
$this->response('success',Code::SUCCESS,$result);
}
/**
* 保存确认数据
* 验证当前确认数据状态, 不可重复确认
* @param Request $request
*/
public function saveConfirm()
{
$this->request->validate([
'uniqid' => 'required',
'confirm' => 'required',
'confirm_num' => 'required',
], [
'uniqid.required' => '非法请求',
'confirm.required' => '客户确认内容不能为空',
'confirm_num.max' => '客户确认数量不能为空',
]);
$geoConfirmModel = new GeoConfirm();
$info = $geoConfirmModel->read(['uniqid'=>$this->param['uniqid']]);
if ($info === false){
$this->response('当前数据不存在已被删除',Code::SYSTEM_ERROR);
}
try {
$this->param['status'] = $geoConfirmModel::STATUS_FINISH;
$this->param['confirm_ip'] = $this->request->ip();
$this->param['confirm_at'] = date('Y-m-d H:i:s');
$result = $geoConfirmModel->edit($this->param,['id'=>$info['$info']]);
$geoConfModel = new GeoConf();
$confInfo = $geoConfModel->read(['project_id'=>$info['project_id']]);
$hrModel = new ManageHr();
$manage_name = $hrModel->getName($confInfo['manager_id'] ??'');
$dingService = new DingService();
$dingService->handle([
'keyword' => '项目数据确认',
'msg' =>
'cm:'.(($info['type'] == 1) ? '标题确认' : '关键词确认'). PHP_EOL .
'项目名称:'.$confInfo['company'] ?? '' . PHP_EOL .
'负责人:'.$manage_name . PHP_EOL,
'isAtAll' => false, // 是否@所有人
], 'https://oapi.dingtalk.com/robot/send?access_token=4effe85882009a8a1617dbeadc38c350f832deef7431ce10f5fda751b4c82fb9');
}catch (\Exception $e){
$this->response('非法请求',Code::SYSTEM_ERROR);
}
$this->response('success',Code::SUCCESS,$result);
}
}