作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate

@@ -73,7 +73,7 @@ class Count extends Command @@ -73,7 +73,7 @@ class Count extends Command
73 $arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']); 73 $arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']);
74 DB::disconnect('custom_mysql'); 74 DB::disconnect('custom_mysql');
75 //服务达标天数 75 //服务达标天数
76 - $arr['compliance_day'] = $this->compliance_day($v['id']); 76 + $arr['compliance_day'] = $v['finish_remain_day'];
77 //剩余服务时常 77 //剩余服务时常
78 $arr['service_day'] = $v['remain_day']; 78 $arr['service_day'] = $v['remain_day'];
79 //项目id 79 //项目id
@@ -193,6 +193,7 @@ class Count extends Command @@ -193,6 +193,7 @@ class Count extends Command
193 'gl_project.type AS type', 193 'gl_project.type AS type',
194 'gl_project.extend_type AS extend_type', 194 'gl_project.extend_type AS extend_type',
195 'gl_project.remain_day AS remain_day', 195 'gl_project.remain_day AS remain_day',
  196 + 'gl_project.finish_remain_day AS finish_remain_day',
196 'gl_project_deploy_build.test_domain AS test_domain', 197 'gl_project_deploy_build.test_domain AS test_domain',
197 'gl_project_deploy_optimize.domain AS domain', 198 'gl_project_deploy_optimize.domain AS domain',
198 'gl_project_deploy_build.project_id AS project_id', 199 'gl_project_deploy_build.project_id AS project_id',
@@ -49,13 +49,19 @@ class DomainInfo extends Command @@ -49,13 +49,19 @@ class DomainInfo extends Command
49 } 49 }
50 $ssl = $this->updateDomainSsl($v['domain']); 50 $ssl = $this->updateDomainSsl($v['domain']);
51 $time = $this->updateDomain($v['domain']); 51 $time = $this->updateDomain($v['domain']);
52 - $data = [  
53 - 'certificate_start_time'=>$ssl['from'],  
54 - 'certificate_end_time'=>$ssl['to'],  
55 - 'domain_start_time'=>$time['start'],  
56 - 'domain_end_time'=>$time['end']  
57 - ];  
58 - 52 + if(!empty($time['start']) && !!empty($time['end'])){
  53 + $data = [
  54 + 'certificate_start_time'=>$ssl['from'],
  55 + 'certificate_end_time'=>$ssl['to'],
  56 + 'domain_start_time'=>$time['start'],
  57 + 'domain_end_time'=>$time['end']
  58 + ];
  59 + }else{
  60 + $data = [
  61 + 'domain_start_time'=>$time['start'],
  62 + 'domain_end_time'=>$time['end']
  63 + ];
  64 + }
59 $domainModel->edit($data,['id'=>$v['id']]); 65 $domainModel->edit($data,['id'=>$v['id']]);
60 } 66 }
61 return 1; 67 return 1;
@@ -169,8 +175,8 @@ class DomainInfo extends Command @@ -169,8 +175,8 @@ class DomainInfo extends Command
169 $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']); 175 $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
170 fclose($stream); 176 fclose($stream);
171 }catch (\Exception $e){ 177 }catch (\Exception $e){
172 - $valid_from = date('Y-m-d H:i:s');  
173 - $valid_to = date('Y-m-d H:i:s'); 178 + $valid_from = '';
  179 + $valid_to = '';
174 } 180 }
175 return ['from'=>$valid_from,'to'=>$valid_to]; 181 return ['from'=>$valid_from,'to'=>$valid_to];
176 } 182 }
@@ -259,6 +259,7 @@ class ProjectUpdate extends Command @@ -259,6 +259,7 @@ class ProjectUpdate extends Command
259 } 259 }
260 //分类 260 //分类
261 $category_id = ''; 261 $category_id = '';
  262 + $category_arr = [];
262 if ($item['category'] ?? []) { 263 if ($item['category'] ?? []) {
263 $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); 264 $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
264 $category_id = $logic->getLastCategory(array_column($category_arr, 'id')); 265 $category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
@@ -291,7 +292,6 @@ class ProjectUpdate extends Command @@ -291,7 +292,6 @@ class ProjectUpdate extends Command
291 'route' => $route 292 'route' => $route
292 ]); 293 ]);
293 $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); 294 $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
294 - CategoryRelated::saveRelated($id, array_column($category_arr, 'id'));  
295 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); 295 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
296 } else { 296 } else {
297 $id = $product['id']; 297 $id = $product['id'];
@@ -309,6 +309,10 @@ class ProjectUpdate extends Command @@ -309,6 +309,10 @@ class ProjectUpdate extends Command
309 ]), 309 ]),
310 'sort' => $item['sort'] ?? 0, 310 'sort' => $item['sort'] ?? 0,
311 ], ['id' => $id]); 311 ], ['id' => $id]);
  312 + }
  313 +
  314 + //关联分类
  315 + if($category_arr){
312 CategoryRelated::saveRelated($id, array_column($category_arr, 'id')); 316 CategoryRelated::saveRelated($id, array_column($category_arr, 'id'));
313 } 317 }
314 318
@@ -53,7 +53,7 @@ class ProjectAssociationController extends BaseController @@ -53,7 +53,7 @@ class ProjectAssociationController extends BaseController
53 53
54 /** 54 /**
55 * 获取aicc用户列表 并返回绑定的数据 55 * 获取aicc用户列表 并返回绑定的数据
56 - * @return array|void 56 + * @return void
57 */ 57 */
58 public function check() 58 public function check()
59 { 59 {
@@ -65,55 +65,23 @@ class ProjectAssociationController extends BaseController @@ -65,55 +65,23 @@ class ProjectAssociationController extends BaseController
65 $status = (int)$status ? ProjectAssociation::STATUS_NORMAL : ProjectAssociation::STATUS_DISABLED; 65 $status = (int)$status ? ProjectAssociation::STATUS_NORMAL : ProjectAssociation::STATUS_DISABLED;
66 } 66 }
67 $isRes = $this->ProjectAssociationLogic->normal($project_id); 67 $isRes = $this->ProjectAssociationLogic->normal($project_id);
68 - DB::beginTransaction();  
69 - try {  
70 - // 当数据不存在时并开启状态,自动添加一条数据  
71 - if (is_null($isRes) && (!is_null($status) && $status)) {  
72 - $isRes = $this->ProjectAssociationLogic->disabled($project_id);  
73 - if (is_null($isRes)) {  
74 - $isRes = new ProjectAssociation();  
75 - }  
76 - $isRes->project_id = $project_id;  
77 - $isRes->user_id = (int)env('AICC_WECHAT_USER_ID');  
78 - $isRes->status = $status;  
79 - $isRes->save();  
80 - DB::commit();  
81 - } // 关闭状态  
82 - elseif (!is_null($isRes) && (!is_null($status) && empty($status))) {  
83 - $isRes->status = $status;  
84 - $isRes->save();  
85 - DB::commit();  
86 - return [  
87 - 'code' => Code::SUCCESS,  
88 - 'data' => [],  
89 - 'message' => '关闭AICC绑定成功!',  
90 - ]; 68 + // 当数据不存在时并开启状态,自动添加一条数据
  69 + if (is_null($isRes) && (!is_null($status) && $status)) {
  70 + $bool = $this->ProjectAssociationLogic->saveProject($project_id, $status);
  71 + if (empty($bool)) {
  72 + // 保存数据失败
  73 + $this->response('error', Code::SERVER_ERROR);
91 } 74 }
92 - } catch (\Exception $exception) {  
93 - DB::rollBack();  
94 - // 数据错误,请重试  
95 - $this->response('error', Code::SERVER_ERROR);  
96 - }  
97 - if (is_null($isRes)) { 75 + } // 关闭状态
  76 + elseif (!is_null($isRes) && (!is_null($status) && empty($status))) {
  77 + $res = $this->ProjectAssociationLogic->closedState($isRes, $status);
  78 + $this->response($res['message'], $res['code']);
  79 + } elseif (is_null($isRes)) {
98 // 请开启AICC绑定 80 // 请开启AICC绑定
99 - $this->response('success', Code::SERVER_ERROR);  
100 - }  
101 - $redis_key = 'aicc_friend_lists_' . (int)env('AICC_WECHAT_USER_ID');  
102 - $result = isset($cache) ? false : redis_get($redis_key);  
103 - if (empty($result)) {  
104 - $url = env('AICC_URL') . env('AICC_WECHAT_FRIEND_API_URL');  
105 - $result = curlGet($url);  
106 - redis_set($redis_key, json_encode($result), 60);  
107 - } else {  
108 - $result = json_decode($result, true); 81 + $this->response('error', Code::SERVER_ERROR);
109 } 82 }
110 -  
111 - $result['info'] = [  
112 - 'friend_id' => $isRes->friend_id ?? 0,  
113 - 'nickname' => $isRes->nickname ?? '',  
114 - 'user_name' => $isRes->user_name ?? '',  
115 - 'image' => $isRes->image ?? '',  
116 - ]; 83 + $cache = isset($cache);
  84 + $result = $this->ProjectAssociationLogic->getAiccWechatLists($isRes, $cache);
117 $this->response('success', Code::SUCCESS, $result); 85 $this->response('success', Code::SUCCESS, $result);
118 } 86 }
119 } 87 }
@@ -47,4 +47,84 @@ class ProjectAssociationLogic extends Logic @@ -47,4 +47,84 @@ class ProjectAssociationLogic extends Logic
47 { 47 {
48 return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_DISABLED)->first(); 48 return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_DISABLED)->first();
49 } 49 }
  50 +
  51 + /**
  52 + * 初始化数据/修改数据
  53 + * @param int $project_id
  54 + * @param int $status
  55 + * @return bool
  56 + */
  57 + public function saveProject($project_id, $status)
  58 + {
  59 + $bool = false;
  60 + DB::beginTransaction();
  61 + $isRes = $this->disabled($project_id);
  62 + if (is_null($isRes)) {
  63 + $isRes = new ProjectAssociation();
  64 + }
  65 + $isRes->project_id = $project_id;
  66 + $isRes->user_id = (int)env('AICC_WECHAT_USER_ID');
  67 + $isRes->status = $status;
  68 + try {
  69 + $bool = $isRes->save();
  70 + DB::commit();
  71 + } catch (\Exception $exception) {
  72 + DB::rollBack();
  73 + }
  74 + return $bool;
  75 + }
  76 +
  77 + /**
  78 + * 获取AICC微信列表数据
  79 + * @param ProjectAssociation $res
  80 + * @param bool $cache
  81 + * @return mixed
  82 + */
  83 + public function getAiccWechatLists($res, $cache = false)
  84 + {
  85 + $redis_key = 'aicc_friend_lists_' . (int)env('AICC_WECHAT_USER_ID');
  86 + $result = $cache ? false : redis_get($redis_key);
  87 + if (empty($result)) {
  88 + $url = env('AICC_URL') . env('AICC_WECHAT_FRIEND_API_URL');
  89 + $result = curlGet($url);
  90 + redis_set($redis_key, json_encode($result), 60);
  91 + } else {
  92 + $result = json_decode($result, true);
  93 + }
  94 + $result['info'] = [
  95 + 'friend_id' => $res->friend_id ?? 0,
  96 + 'nickname' => $res->nickname ?? '',
  97 + 'user_name' => $res->user_name ?? '',
  98 + 'image' => $res->image ?? '',
  99 + ];
  100 + return $result;
  101 + }
  102 +
  103 + /**
  104 + * 关闭状态
  105 + * @param ProjectAssociation $res
  106 + * @param int $status 1 - 正常, 0 - 禁用
  107 + * @return array
  108 + */
  109 + public function closedState($res, $status)
  110 + {
  111 + DB::beginTransaction();
  112 + try {
  113 + $res->status = $status;
  114 + $res->save();
  115 + DB::commit();
  116 + $code = Code::SUCCESS;
  117 + $message = '关闭AICC绑定成功!';
  118 + } catch (\Exception $exception) {
  119 + DB::rollBack();
  120 + // 数据错误,请重试
  121 + $code = Code::SERVER_ERROR;
  122 + $message = 'error';
  123 + }
  124 + return [
  125 + 'code' => $code,
  126 + 'data' => [],
  127 + 'message' => $message,
  128 + ];
  129 + }
50 } 130 }
@@ -41,6 +41,11 @@ class CountLogic extends BaseLogic @@ -41,6 +41,11 @@ class CountLogic extends BaseLogic
41 $info = $this->model->read(['project_id' => $this->user['project_id']], 41 $info = $this->model->read(['project_id' => $this->user['project_id']],
42 ['pv_num','ip_num','inquiry_num','date','compliance_day','service_day','country']); 42 ['pv_num','ip_num','inquiry_num','date','compliance_day','service_day','country']);
43 } 43 }
  44 + //获取项目的剩余时长
  45 + $projectModel = new Project();
  46 + $projectInfo = $projectModel->read(['id'=>$this->user['project_id']],['remain_day','finish_remain_day']);
  47 + $info['service_day'] = $projectInfo['remain_day'];
  48 + $info['compliance_day'] = $projectInfo['finish_remain_day'];
44 return $this->success($info); 49 return $this->success($info);
45 } 50 }
46 51