GeoController.php
4.9 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
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/10/23
* Time: 10:23
*/
namespace App\Http\Controllers\Aside\Geo;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\Geo\GeoConf;
use App\Models\Geo\GeoConfirm;
use App\Models\Manage\ManageHr;
use App\Models\Project\KeywordPrefix;
use App\Models\Project\Project;
use App\Models\ProjectAssociation\ProjectAssociation;
use Illuminate\Http\Request;
/**
* Class GeoController
* @package App\Http\Controllers\Aside\Geo
*/
class GeoController extends BaseController
{
/**
* 获取GEO相关配置
* @param Request $request
*/
public function getConfig()
{
$this->request->validate([
'project_id' => 'required',
], [
'project_id.required' => '项目ID不能为空',
]);
$projectModel = new Project();
$project_geo_conf = $projectModel->read(['project_id' => $this->param['project_id']],['title', 'version', 'geo_status', 'geo_qualify_num']);
$geoConfModel = new GeoConf();
$geo_conf = $geoConfModel->read(['project_id' => $this->param['project_id']]);
$geo_manage_list = $geoConfModel->geoManage();
// geo配置管理员,已经移除管理员列表,补充管理员信息
if ($geo_conf && $geo_conf['manager_id'] && empty($geo_manage_list[$geo_conf['manager_id']])) {
$manage = ManageHr::where(['id' => $geo_conf['manager_id']])->pluck('name', 'id')->toArray();
$geo_manage_list = array_merge($geo_manage_list, $manage);
}
$result = [
'project_geo_conf' => $project_geo_conf,
'geo_conf' => $geo_conf,
'geo_manage_list' => $geo_manage_list,
'geo_keyword' => [
'prefix' => KeywordPrefix::getKeyword($this->param['project_id'], KeywordPrefix::TYPE_GEO_PREFIX),
'suffix' => KeywordPrefix::getKeyword($this->param['project_id'], KeywordPrefix::TYPE_GEO_SUFFIX),
],
];
$this->response('success', Code::SUCCESS, $result);
}
/**
* 保存GEO配置
* TODO 单独保存GEO开启状态, 达标数量
* @param Request $request
* @throws \App\Exceptions\AsideGlobalException
*/
public function saveConfig()
{
$this->request->validate([
'project_id' => 'required',
'manager_id' => 'nullable|integer',
'company' => 'nullable|max:200',
'brand' => 'nullable|max:200',
'description' => 'nullable|max:500',
], [
'project_id.required' => '项目ID不能为空',
'manager_id.integer' => '管理员参数非法',
'company.max' => '公司名称不能超过200个字符',
'brand.max' => '品牌名不能超过200个字符',
'description.max' => '描述不能超过500个字符',
]);
try {
$data = GeoConf::saveConf($this->param['project_id'], $this->param['manager_id'], $this->param['company'], $this->param['brand'], $this->param['description'], $this->param['prefix'], $this->param['suffix']);
# FIXME 保存GEO状态 达标数量
$this->response('success', Code::SUCCESS, $data);
} catch (\Exception $e) {
$this->fail('配置保存失败, error:' . $e->getMessage());
}
}
/**
* 保存确认数据, 并推送微信群
* @param Request $request
* @throws \App\Exceptions\AsideGlobalException
*/
public function saveConfirmContent()
{
$this->request->validate([
'project_id' => 'required',
'type' => 'required|integer',
'content' => 'required',
'max_num' => 'required',
], [
'project_id.required' => '项目ID不能为空',
'type.required' => '确定数据类型不能为空',
'type.integer' => '确定数据类型不正确',
'content.required' => '确定数据不能为空',
'max_num.required' => '最大确认数量不能为空',
]);
try {
$data = GeoConfirm::saveContent($this->param['project_id'], $this->param['type'], $this->param['content'], $this->param['max_num']);
$friend = ProjectAssociation::where(['project_id' => $this->param['project_id']])->first();
if (empty($friend)){
$this->fail('项目未绑定微信群, 推送消息失败!');
}
$data = GeoConfirm::sendConfirmMessage($data->id, $friend->friend_id);
$this->response('success', Code::SUCCESS, $data);
} catch (\Exception $e) {
$this->fail('操作失败, error:' . $e->getMessage());
}
}
/**
* OA后台管理员,保存确认数据
* 客户可以进行确认, OA后台也可以进行确认,以及修改
* @param Request $request
*/
public function saveConfirmData(Request $request)
{}
}