PrivateController.php
13.3 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/1/6
* Time: 17:41
*/
namespace App\Http\Controllers\Api;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\User\UserLoginLogic;
use App\Models\Blog\Blog;
use App\Models\Domain\DomainInfo;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\User\User;
use App\Models\WebSetting\WebLanguage;
use App\Services\ProjectServer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
/**
* Class PrivateController
* @package App\Http\Controllers\Api
*/
class PrivateController extends BaseController
{
/**
* 优化中项目列表
* @param Request $request
* @return false|string
*/
public function optimizeProjectList(Request $request)
{
$page_size = $request->input('page_size', 20);
$field = ['gl_project.id', 'gl_project.company', 'gl_project.is_upgrade', 'b.start_date', 'd.domain'];
$result = Project::select($field)->leftJoin('gl_project_deploy_optimize as b', 'gl_project.id', '=', 'b.project_id')
->leftJoin('gl_project_online_check as c', 'gl_project.id', '=', 'c.project_id')
->leftJoin('gl_domain_info as d', 'gl_project.id', '=', 'd.project_id')
->where('gl_project.type', Project::TYPE_TWO)
->where('gl_project.extend_type', 0) // 是否续费是由extend_type字段控制
->where('gl_project.delete_status', Project::IS_DEL_FALSE)
->where(function ($subQuery) {
$subQuery->orwhere('c.qa_status', OnlineCheck::STATUS_ONLINE_TRUE)->orwhere('gl_project.is_upgrade', Project::IS_UPGRADE_TRUE);
})
->paginate($page_size)
->toArray();
return $this->success($result);
}
/**
* 获取项目链接
* FIXME 当前直接获取的产品和产品分类, 后期需要封装到内部, 需要添加完整的链接规则
* @param Request $request
* @return false|string
*/
public function getProjectRoute(Request $request)
{
$project_id = intval($request->input('project_id'));
// $type = $request->input('type');
$type = [RouteMap::SOURCE_PRODUCT, RouteMap::SOURCE_PRODUCT_CATE];
$project = Project::where(['id' => $project_id])->first();
if (empty($project))
return $this->error('未发现需要查找的项目!');
$project = ProjectServer::useProject($project_id);
$domain = DomainInfo::where(['project_id' => $project_id])->first();
$host = FALSE == empty($domain) ? 'https://' . $domain->domain . '/' : $project->deploy_build->test_domain;
// 需要标题, 不能直接查询map表
// $list = RouteMap::where(['project_id' => $project_id])
// ->when($type, function ($query) use ($type) {
// return $query->whereIn('source', $type);
// })
// ->get();
//
// $result = [];
// foreach ($list as $val) {
// // 排除首页
// if ($val->source == RouteMap::SOURCE_PAGE && in_array($val->route, ['index', '']))
// continue;
// $result[$val->source][] = $host . $val->route;
// }
$result = [];
$product = Product::where(['status' => Product::STATUS_ON])->get(['title', 'route'])->toArray();
foreach ($product as $val) {
$val['route'] = $host . $val['route'];
// FALSE == preg_match('/(\.html|\.htm)$/', $val['route'])
if (FALSE === strpos($val['route'], '.htm')) {
$val['route'] .= '/';
}
$result[RouteMap::SOURCE_PRODUCT][] = $val;
}
$product_category= Category::get(['title', 'route'])->toArray();
foreach ($product_category as $val) {
$val['route'] = $host . $val['route'];
if (FALSE === strpos($val['route'], '.htm')) {
$val['route'] .= '/';
}
$result[RouteMap::SOURCE_PRODUCT_CATE][] = $val;
}
return $this->success($result);
}
/**
* 验证当前用户是否存在
* TODO 查询手机号码是否是项目用户, 如果升级项目未上线项目return false;
* @param Request $request
* @return false|string
*/
public function hasUser(Request $request)
{
// 获取数据,初始化信息
$mobile = trim($request->input('mobile'));
$result = ['mobile' => $mobile, 'v6_user' => false];
// 获取用户,验证用户
$project_ids = User::where(['mobile' => $mobile])->pluck('project_id')->toArray();
if (empty($project_ids))
return $this->success($result);
$projects = Project::whereIn('id', $project_ids)->where('delete_status', 0)->get();
foreach ($projects as $project) {
// 如果是升级项目 并且未上线状态,不算做有效用户
if ($project->is_upgrade == Project::IS_UPGRADE_TRUE && $project->type <= Project::TYPE_ONE)
continue;
$result['v6_user'] = true;
}
return $this->success($result);
}
/**
* v6 有效用户
* @param Request $request
* @return false|string
*/
public function validUser(Request $request)
{
// 排除演示项目数据
$valid_user = User::select(['gl_project_user.mobile'])->leftJoin('gl_project', 'gl_project.id', '=', 'gl_project_user.project_id')->where(['delete_status' => 0, 'is_upgrade' => Project::IS_UPGRADE_FALSE])->where('gl_project.id', '>', 1)->pluck('mobile')->toArray();
$upgrade_user = User::select(['gl_project_user.mobile'])->leftJoin('gl_project', 'gl_project.id', '=', 'gl_project_user.project_id')->where(['delete_status' => 0, 'is_upgrade' => Project::IS_UPGRADE_TRUE])->where('gl_project.type', '>', Project::TYPE_ONE)->pluck('mobile')->toArray();
$user = array_unique(array_merge($valid_user, $upgrade_user));
return $this->success($user);
}
/**
* 模拟登录返回token
*/
public function getAutoToken(){
$this->request->validate([
'project_id' => 'required',
], [
'project_id.required' => '项目id不能为空',
]);
//获取当前用户的管理员
$userModel = new User();
$userInfo = $userModel->read(['project_id'=>$this->param['project_id'],'role_id'=>0]);
$userLoginLogicModel = new UserLoginLogic();
$info = $userLoginLogicModel->autoAssembleParam($userInfo);
//生成新token
$token = md5(uniqid().'auto'.$info['id']);
//存储缓存
$info['token'] = $token;
Cache::add($token,$info,3600);
$languageModel = new WebLanguage();
$languageInfo = $languageModel->read(['id'=>$info['main_lang_id']],['short','english','chinese']);
$data = ['token'=>$token,'main_lang_id'=>$info['main_lang_id'],'language_info'=>$languageInfo];
$this->response('success',Code::SUCCESS,$data);
}
/**
* 项目 有效产品路由列表
* @param Request $request
* @return false|string
*/
public function getProductRoute(Request $request)
{
$domain = trim($request->input('domain'));
if (empty($domain)) {
return $this->error('非法参数!');
}
$project = Project::getProjectByDomain($domain);
if (empty($project)) {
return $this->error('未找到当前域名对应的项目!');
}
ProjectServer::useProject($project->id);
$feature_category = Category::whereIn('title', ['Featured','featured', 'Featured Products'])->pluck('id');
$feature_product = CategoryRelated::whereIn('cate_id',$feature_category)->pluck('product_id')->unique()->toArray();
$product_route = Product::where(['status' => Product::STATUS_ON])->whereNotIn('id', $feature_product)->pluck('route')->toArray();
return $this->success($product_route);
}
/**
* 获取项目信息---站群服务
* @param Request $request
* @return false|string
*/
public function getProjectByDomain(Request $request)
{
$domain = trim($request->input('domain'));
if (empty($domain)) {
return $this->error('非法参数!');
}
$project = Project::getProjectByDomain($domain);
if (empty($project)) {
return $this->error('未找到当前域名对应的项目!');
}
$optimize = $project->deploy_optimize;
$keyword = $project->project_keyword;
$keywords = explode("\r\n", $keyword ? $keyword->main_keyword : []);
$result = [
'company' => $project->company,
'company_en_name' => $optimize ? $optimize->company_en_name : '',
'company_en_description' => $optimize ? $optimize->company_en_description : '',
'keywords' => $keywords
];
return $this->success($result);
}
/**
* 获取产品信息---站群服务
* @param Request $request
* @return false|string
*/
public function getProjectProduct(Request $request)
{
$domain = trim($request->input('domain'));
$page_size = intval($request->input('page_size', 20));
if (empty($domain)) {
return $this->error('非法参数!');
}
$project = Project::getProjectByDomain($domain);
if (empty($project)) {
return $this->error('未找到当前域名对应的项目!');
}
ProjectServer::useProject($project->id);
$products = Product::select(['id', 'title', 'thumb', 'gallery', 'intro', 'content', 'keyword_id', 'route'])->with('category')->where(['status' => Product::STATUS_ON])->paginate($page_size);
// $products_ids = $products->pluck('id')->toArray();
// $category_ids = CategoryRelated::whereIn('product_id', $products_ids)->pluck('cate_id')->toArray();
// $category = Category::whereIn('id', $category_ids)->pluck('title', 'id')->toArray();
$keyword_id = $products->pluck('keyword_id')->toArray();
$keyword_ids = array_reduce($keyword_id, 'array_merge', array());
$keyword = Keyword::whereIn('id', $keyword_ids)->pluck('title', 'id')->toArray();
foreach ($products as $product) {
$product_keyword = [];
foreach ($product->keyword_id as $k_id) {
array_push($product_keyword, $keyword[$k_id]);
}
$product_category = $product->category->pluck('title')->toArray();
unset($product->category);
unset($product->keyword_id);
$product->category = $product_category;
$product->keyword = $product_keyword;
}
return $this->success($products);
}
/**
* 获取上线项目 --- 监控服务
* @param Request $request
* @return false|string
*/
public function getProjectOnline(Request $request)
{
$page_size = intval($request->input('page_size', 20));
$projects = Project::select(['id', 'title', 'company', 'type', 'finish_remain_day', 'remain_day'])->whereIn('type', [2, 3, 4, 6])->where('delete_status', 0)->paginate($page_size);
foreach ($projects as $project) {
$project->domain = $project->domainInfo ? $project->domainInfo->domain : '';
}
return $this->success($projects);
}
/**
* 获取有效时间内 新增有效URL
* 用于自动提交Google收录
* @param Request $request
* @return false|string
*/
public function projectNewUrl(Request $request)
{
$domain = trim($request->input('domain'));
$domain_parse = parse_url($domain);
$domain = $domain_parse['host'] ?? $domain;
$date = trim($request->input('date'));
if (empty($domain) || empty($date)) {
return $this->error('非法参数!');
}
$project = Project::getProjectByDomain($domain);
if (empty($project)) {
return $this->error('未找到当前域名对应的项目!');
}
ProjectServer::useProject($project->id);
$result = [];
// 查询有效时间后 有效的产品、新闻、博客、聚合页 链接
$product = Product::where(['status' => Product::STATUS_ON])->where('created_at', '>=', $date)->pluck('route');
$news = News::where(['status' => News::STATUS_ONE])->where('release_at', '>', $date)->pluck('url');
$blog = Blog::where(['status' => Blog::STATUS_ONE])->where('release_at', '>', $date)->pluck('url');
// $keyword = Keyword::where('created_at', '>', $date)->pluck('route');
// 组装链接
foreach ($product as $item) {
$url = 'https://' . $domain . '/' . $item;
array_push($result, $url);
}
// foreach ($keyword as $item) {
// $url = 'https://' . $domain . '/' . $item;
// array_push($result, $url);
// }
foreach ($news as $item) {
$url = 'https://' . $domain . '/news/' . $item;
array_push($result, $url);
}
foreach ($blog as $item) {
$url = 'https://' . $domain . '/blogs/' . $item;
array_push($result, $url);
}
return $this->success($result);
}
}