作者 zhl

Merge remote-tracking branch 'origin/master' into zhl

... ... @@ -73,7 +73,7 @@ class Count extends Command
$arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']);
DB::disconnect('custom_mysql');
//服务达标天数
$arr['compliance_day'] = $this->compliance_day($v['id']);
$arr['compliance_day'] = $v['finish_remain_day'];
//剩余服务时常
$arr['service_day'] = $v['remain_day'];
//项目id
... ... @@ -193,6 +193,7 @@ class Count extends Command
'gl_project.type AS type',
'gl_project.extend_type AS extend_type',
'gl_project.remain_day AS remain_day',
'gl_project.finish_remain_day AS finish_remain_day',
'gl_project_deploy_build.test_domain AS test_domain',
'gl_project_deploy_optimize.domain AS domain',
'gl_project_deploy_build.project_id AS project_id',
... ...
... ... @@ -49,13 +49,19 @@ class DomainInfo extends Command
}
$ssl = $this->updateDomainSsl($v['domain']);
$time = $this->updateDomain($v['domain']);
if(!empty($time['start']) && !!empty($time['end'])){
$data = [
'certificate_start_time'=>$ssl['from'],
'certificate_end_time'=>$ssl['to'],
'domain_start_time'=>$time['start'],
'domain_end_time'=>$time['end']
];
}else{
$data = [
'domain_start_time'=>$time['start'],
'domain_end_time'=>$time['end']
];
}
$domainModel->edit($data,['id'=>$v['id']]);
}
return 1;
... ... @@ -169,8 +175,8 @@ class DomainInfo extends Command
$valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
fclose($stream);
}catch (\Exception $e){
$valid_from = date('Y-m-d H:i:s');
$valid_to = date('Y-m-d H:i:s');
$valid_from = '';
$valid_to = '';
}
return ['from'=>$valid_from,'to'=>$valid_to];
}
... ...
... ... @@ -83,10 +83,12 @@ class HtmlCollect extends Command
//采集html页面,下载资源到本地并替换
try {
$html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
if ($html == '0') {
if ($html == '0' || strpos($html,'404 Not Found') !== false) {
$collect_info->status = CollectTask::STATUS_FAIL;
$collect_info->save();
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL;
$error = $html == '0' ? 'no html' : '404 not found';
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $error . PHP_EOL;
sleep(2);
return true;
}
... ...
... ... @@ -85,10 +85,12 @@ class HtmlLanguageCollect extends Command
//采集html页面,下载资源到本地并替换
try {
$html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
if ($html == '0') {
if ($html == '0' || strpos($html,'404 Not Found') !== false) {
$collect_info->status = CollectTask::STATUS_FAIL;
$collect_info->save();
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL;
$error = $html == '0' ? 'no html' : '404 not found';
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $error . PHP_EOL;
sleep(2);
return true;
}
... ...
... ... @@ -85,10 +85,12 @@ class HtmlLanguageSpecialCollect extends Command
//采集html页面,下载资源到本地并替换
try {
$html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
if ($html == '0') {
if ($html == '0' || strpos($html,'404 Not Found') !== false) {
$collect_info->status = CollectTask::STATUS_FAIL;
$collect_info->save();
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL;
$error = $html == '0' ? 'no html' : '404 not found';
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $error . PHP_EOL;
sleep(2);
return true;
}
... ...
... ... @@ -13,6 +13,7 @@ use App\Models\Com\UpdateOldInfo;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Extend;
use App\Models\Product\ExtendInfo;
use App\Models\Product\Keyword;
... ... @@ -258,6 +259,7 @@ class ProjectUpdate extends Command
}
//分类
$category_id = '';
$category_arr = [];
if ($item['category'] ?? []) {
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
... ... @@ -290,7 +292,6 @@ class ProjectUpdate extends Command
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
} else {
$id = $product['id'];
... ... @@ -310,6 +311,11 @@ class ProjectUpdate extends Command
], ['id' => $id]);
}
//关联分类
if($category_arr){
CategoryRelated::saveRelated($id, array_column($category_arr, 'id'));
}
//扩展字段
if ($item['extend'] ?? []) {
foreach (array_reverse($item['extend']) as $ke => $ve) {
... ...
... ... @@ -289,11 +289,12 @@ class OptimizeController extends BaseController
$this->request->validate([
'project_id'=>'required',
'status'=>'required',
'type'=>'required',
'type'=>'required|in:is_translate,is_translate_tag',
],[
'project_id.required' => 'project_id不能为空',
'status.required' => 'status不能为空',
'type.required' => 'type不能为空',
'type.in' => 'type类型错误',
]);
$projectModel = new Project();
$projectModel->edit([$this->param['type']=>$this->param['status']],['id'=>$this->param['project_id']]);
... ...
... ... @@ -63,7 +63,8 @@ class ProjectController extends BaseController
->where('gl_project.delete_status',Project::TYPE_ZERO)
->where('gl_project.extend_type',Project::TYPE_ZERO);
$query = $this->searchParam($query);
$lists = $query->orderBy('gl_project.id', 'desc')->paginate($this->row, $this->selectParam(), 'page', $this->page)->toArray();
$query = $this->orderByList($query);
$lists = $query->paginate($this->row, $this->selectParam(), 'page', $this->page)->toArray();
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v = $this->handleParam($v);
... ... @@ -74,6 +75,18 @@ class ProjectController extends BaseController
}
/**
* @remark :排序
* @name :orderByList
* @author :lyh
* @method :post
* @time :2023/12/29 17:14
*/
public function orderByList($query){
$query = $query->orderBy('gl_project.uptime', 'desc')->orderBy('gl_project.id', 'desc');
return $query;
}
/**
* @remark :搜索参数处理
* @name :searchParam
* @author :lyh
... ...
... ... @@ -48,9 +48,13 @@ class ProjectAssociationController extends BaseController
$image = request()->post('image', '');
$data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
$this->ProjectAssociationLogic->saveWeChatData($data);
$this->response('success');
$this->response('绑定成功');
}
/**
* 获取aicc用户列表 并返回绑定的数据
* @return void
*/
public function check()
{
$project_id = (int)request()->input('project_id', 0);
... ... @@ -61,53 +65,30 @@ class ProjectAssociationController extends BaseController
$status = (int)$status ? ProjectAssociation::STATUS_NORMAL : ProjectAssociation::STATUS_DISABLED;
}
$isRes = $this->ProjectAssociationLogic->normal($project_id);
DB::beginTransaction();
try {
// 当数据不存在时并开启状态,自动添加一条数据
if (is_null($isRes) && (!is_null($status) && $status)) {
$isRes = $this->ProjectAssociationLogic->disabled($project_id);
$isRes = $this->ProjectAssociationLogic->saveProject($project_id, $status);
if (is_null($isRes)) {
$isRes = new ProjectAssociation();
// 保存数据失败
$this->response('绑定AICC数据失败!', Code::SERVER_ERROR);
}
$isRes->project_id = $project_id;
$isRes->user_id = (int)env('AICC_WECHAT_USER_ID');
$isRes->status = $status;
$isRes->save();
DB::commit();
} // 关闭状态
elseif (!is_null($isRes) && (!is_null($status) && empty($status))) {
$isRes->status = $status;
$isRes->save();
DB::commit();
return [
'code' => Code::SUCCESS,
'data' => [],
'message' => '关闭AICC绑定成功!',
];
$bool = $this->ProjectAssociationLogic->closedState($isRes, $status);
if ($bool) {
// 关闭aicc绑定成功
$this->response('关闭aicc绑定 - 成功!');
}else{
// 关闭aicc绑定失败
$this->response('关闭aicc绑定 - 失败!');
}
} catch (\Exception $exception) {
DB::rollBack();
$this->response('数据错误,请重试!', Code::SERVER_ERROR);
}
if (is_null($isRes)) {
$this->response('请开启AICC绑定!', Code::USER_ERROR, []);
// 请开启AICC绑定
$this->response('success', Code::SERVER_ERROR);
}
$redis_key = 'aicc_friend_lists_' . (int)env('AICC_WECHAT_USER_ID');
$result = isset($cache) ? false : redis_get($redis_key);
if (empty($result)) {
$url = env('AICC_URL') . env('AICC_WECHAT_FRIEND_API_URL');
$result = curlGet($url);
redis_set($redis_key, json_encode($result));
} else {
$result = json_decode($result, true);
}
$result['info'] = [
'friend_id' => $isRes->friend_id ?? 0,
'nickname' => $isRes->nickname ?? '',
'user_name' => $isRes->user_name ?? '',
'image' => $isRes->image ?? '',
];
$cache = isset($cache);
$result = $this->ProjectAssociationLogic->getAiccWechatLists($isRes, $cache);
$this->response('success', Code::SUCCESS, $result);
}
}
... ...
... ... @@ -39,7 +39,7 @@ class DomainInfoLogic extends BaseLogic
$this->param['domain'] = trim($domain['host']);
}
//验证域名
$this->verifyDomain($this->param['domain'],isset($this->param['id']) ?? '');
$this->verifyDomain($this->param['domain'],$this->param['id'] ?? '');
if(isset($this->param['id']) && !empty($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
... ...
... ... @@ -47,4 +47,76 @@ class ProjectAssociationLogic extends Logic
{
return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_DISABLED)->first();
}
/**
* 初始化数据/修改数据
* @param int $project_id
* @param int $status
* @return Builder|Model|object|ProjectAssociation|null
*/
public function saveProject($project_id, $status)
{
$bool = false;
DB::beginTransaction();
$isRes = $this->disabled($project_id);
if (is_null($isRes)) {
$isRes = new ProjectAssociation();
}
$isRes->project_id = $project_id;
$isRes->user_id = (int)env('AICC_WECHAT_USER_ID');
$isRes->status = $status;
try {
$isRes->save();
DB::commit();
} catch (\Exception $exception) {
DB::rollBack();
}
return $isRes;
}
/**
* 获取AICC微信列表数据
* @param ProjectAssociation $res
* @param bool $cache
* @return mixed
*/
public function getAiccWechatLists($res, $cache = false)
{
$redis_key = 'aicc_friend_lists_' . (int)env('AICC_WECHAT_USER_ID');
$result = $cache ? false : redis_get($redis_key);
if (empty($result)) {
$url = env('AICC_URL') . env('AICC_WECHAT_FRIEND_API_URL');
$result = curlGet($url);
redis_set($redis_key, json_encode($result), 60);
} else {
$result = json_decode($result, true);
}
$result['info'] = [
'friend_id' => $res->friend_id ?? 0,
'nickname' => $res->nickname ?? '',
'user_name' => $res->user_name ?? '',
'image' => $res->image ?? '',
];
return $result;
}
/**
* 关闭状态
* @param ProjectAssociation $res
* @param int $status 1 - 正常, 0 - 禁用
* @return bool
*/
public function closedState($res, $status)
{
DB::beginTransaction();
$bool = false;
try {
$res->status = $status;
$bool = $res->save();
DB::commit();
} catch (\Exception $exception) {
DB::rollBack();
}
return $bool;
}
}
... ...
... ... @@ -41,6 +41,11 @@ class CountLogic extends BaseLogic
$info = $this->model->read(['project_id' => $this->user['project_id']],
['pv_num','ip_num','inquiry_num','date','compliance_day','service_day','country']);
}
//获取项目的剩余时长
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$this->user['project_id']],['remain_day','finish_remain_day']);
$info['service_day'] = $projectInfo['remain_day'];
$info['compliance_day'] = $projectInfo['finish_remain_day'];
return $this->success($info);
}
... ...