作者 zhl

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

@@ -6,10 +6,16 @@ use App\Helper\Arr; @@ -6,10 +6,16 @@ use App\Helper\Arr;
6 use App\Models\Collect\CollectTask; 6 use App\Models\Collect\CollectTask;
7 use App\Models\Com\UpdateLog; 7 use App\Models\Com\UpdateLog;
8 use App\Models\Com\UpdateVisit; 8 use App\Models\Com\UpdateVisit;
  9 +use App\Models\Devops\ServerConfig;
  10 +use App\Models\Domain\DomainInfo;
9 use App\Models\Product\Product; 11 use App\Models\Product\Product;
  12 +use App\Models\Project\Project;
10 use App\Services\ProjectServer; 13 use App\Services\ProjectServer;
  14 +use App\Utils\HttpUtils;
  15 +use GuzzleHttp\Exception\GuzzleException;
11 use Illuminate\Console\Command; 16 use Illuminate\Console\Command;
12 use Illuminate\Support\Facades\DB; 17 use Illuminate\Support\Facades\DB;
  18 +use Symfony\Component\Process\Process;
13 19
14 class Temp extends Command 20 class Temp extends Command
15 { 21 {
@@ -30,17 +36,106 @@ class Temp extends Command @@ -30,17 +36,106 @@ class Temp extends Command
30 36
31 public function handle() 37 public function handle()
32 { 38 {
33 - $project = ProjectServer::useProject(626);  
34 - if ($project) {  
35 - CollectTask::select(['id', 'language'])->where('status', 0)->chunk(1000, function ($query) { 39 + $domain_model = new DomainInfo();
  40 + $server_model = new ServerConfig();
  41 + $project_model = new Project();
36 42
37 - foreach ($query as $item) {  
38 - $item->domain = 'lecusostreetlight.quanqiusou.cn/' . $item->language;  
39 - $item->save(); 43 + $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
  44 + foreach ($domain_list as $info) {
  45 + $this->output('domain:' . $info['domain'] . ',开始');
  46 +
  47 + $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
  48 + if ($project_info === false) {
  49 + $this->output('获取项目数据失败');
  50 + continue;
  51 + }
  52 +
  53 + $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
  54 + if ($server_info === false) {
  55 + $this->output('获取服务器数据失败');
  56 + continue;
  57 + }
  58 +
  59 + $domain_array = parse_url($info['domain']);
  60 + $host = $domain_array['host'] ?? $domain_array['path'];
  61 + $host_array = explode('.', $host);
  62 + if (count($host_array) <= 2) {
  63 + array_unshift($host_array, 'm');
  64 + } else {
  65 + $host_array[0] = 'm';
  66 + }
  67 + $amp_domain = implode('.', $host_array);
  68 + if (!$this->check_cname($amp_domain, $server_info)) {
  69 + $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
  70 + continue;
  71 + }
  72 +
  73 + $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
  74 + $api_param = [
  75 + 'domain' => $info['domain'],
  76 + 'private_key' => '',
  77 + 'cert' => ''
  78 + ];
  79 +
  80 + try {
  81 + $rs = HttpUtils::get($api_url, $api_param);
  82 + $rs = json_decode($rs, true);
  83 + if (isset($rs['status']) && $rs['status'] == 200) {
  84 + $this->output('创建AMP站点成功');
  85 + } else {
  86 + $this->output($rs['message'] ?? '');
  87 + continue;
40 } 88 }
41 - }); 89 + } catch (\Exception | GuzzleException $e) {
  90 + errorLog('创建AMP站点', $api_param, $e);
  91 + $this->output('创建AMP站点失败');
  92 + continue;
  93 + }
  94 +
  95 + $data = [
  96 + 'amp_status' => 1,
  97 + 'amp_type' => 1,
  98 + ];
  99 + $domain_model->edit($data, ['id' => $info['id']]);
42 } 100 }
43 - DB::disconnect('custom_mysql'); 101 +
44 echo '成功' . PHP_EOL; 102 echo '成功' . PHP_EOL;
45 } 103 }
  104 +
  105 + public function check_cname($domain, $server_info)
  106 + {
  107 + $checkA = false;
  108 + $checkCname = false;
  109 +
  110 + $process = new Process(['nslookup', '-qt=a', $domain]);
  111 + $process->run();
  112 + $output = explode(PHP_EOL, $process->getOutput());
  113 + foreach ($output as $line) {
  114 + if ($line) {
  115 + $checkA = strpos($line, $server_info['host']) !== false;
  116 + if ($checkA) {
  117 + return $domain;
  118 + }
  119 + }
  120 + }
  121 +
  122 + //是否cname
  123 + $process = new Process(['nslookup', '-qt=cname', $domain]);
  124 + $process->run();
  125 + $output = explode(PHP_EOL, $process->getOutput());
  126 + foreach ($output as $line) {
  127 + if ($line) {
  128 + $checkCname = (strpos($line, $server_info['init_domain']) !== false);
  129 + if ($checkCname) {
  130 + return $domain;
  131 + }
  132 + }
  133 + }
  134 + return false;
  135 + }
  136 +
  137 + public function output($msg)
  138 + {
  139 + echo $msg . PHP_EOL;
  140 + }
46 } 141 }
@@ -55,7 +55,7 @@ class UpdateRoute extends Command @@ -55,7 +55,7 @@ class UpdateRoute extends Command
55 */ 55 */
56 public function handle(){ 56 public function handle(){
57 $projectModel = new Project(); 57 $projectModel = new Project();
58 - $list = $projectModel->list(['id'=>645]); 58 + $list = $projectModel->list(['id'=>1091]);
59 $data = []; 59 $data = [];
60 foreach ($list as $v){ 60 foreach ($list as $v){
61 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; 61 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
@@ -92,13 +92,19 @@ class KeywordVideoController extends BaseController @@ -92,13 +92,19 @@ class KeywordVideoController extends BaseController
92 'project_id.required' => '项目唯一标识不为空', 92 'project_id.required' => '项目唯一标识不为空',
93 'number.required' => 'number不为空', 93 'number.required' => 'number不为空',
94 ]); 94 ]);
  95 + //查看当前项目是否已添加
  96 + $keywordModel = new KeywordVideoTask();
  97 + $keywordInfo = $keywordModel->read(['project_id'=>$this->param['project_id']]);
  98 + if($keywordInfo !== false){
  99 + $this->response('当前项目已添加');
  100 + }
95 //查看当前项目是否有正式域名 101 //查看当前项目是否有正式域名
96 $domainModel = new DomainInfo(); 102 $domainModel = new DomainInfo();
97 $info = $domainModel->read(['project_id'=>$this->param['project_id']]); 103 $info = $domainModel->read(['project_id'=>$this->param['project_id']]);
98 if($info === false){ 104 if($info === false){
99 $this->response('请先设置域名',Code::SYSTEM_ERROR); 105 $this->response('请先设置域名',Code::SYSTEM_ERROR);
100 } 106 }
101 - $keywordModel = new KeywordVideoTask(); 107 +
102 $rs = $keywordModel->add($this->param); 108 $rs = $keywordModel->add($this->param);
103 if($rs === false){ 109 if($rs === false){
104 $this->response('添加失败',Code::SYSTEM_ERROR); 110 $this->response('添加失败',Code::SYSTEM_ERROR);
@@ -540,7 +540,6 @@ class ProductController extends BaseController @@ -540,7 +540,6 @@ class ProductController extends BaseController
540 'keyword.required' => 'keyword不能为空', 540 'keyword.required' => 'keyword不能为空',
541 ]); 541 ]);
542 $data = curl_c('http://title.globalso.com/ajax_data_for_web.php?keyword='.$this->param['keyword'],false); 542 $data = curl_c('http://title.globalso.com/ajax_data_for_web.php?keyword='.$this->param['keyword'],false);
543 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($data, true) . PHP_EOL, FILE_APPEND);  
544 $this->response('success',Code::SUCCESS,$data); 543 $this->response('success',Code::SUCCESS,$data);
545 } 544 }
546 } 545 }
@@ -359,6 +359,9 @@ class ImageController extends Controller @@ -359,6 +359,9 @@ class ImageController extends Controller
359 if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){ 359 if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
360 $this->map['project_id'] = $this->cache['project_id']; 360 $this->map['project_id'] = $this->cache['project_id'];
361 } 361 }
  362 + if(isset($this->map['name']) && !empty($this->map['name'])){
  363 + $this->map['name'] = ['like','%'.$this->map['name'].'%'];
  364 + }
362 $imageModel = new ImageModel(); 365 $imageModel = new ImageModel();
363 $lists = $imageModel->lists($this->map,$this->page,$this->row); 366 $lists = $imageModel->lists($this->map,$this->page,$this->row);
364 if(!empty($lists) && !empty($lists['list'])){ 367 if(!empty($lists) && !empty($lists['list'])){
@@ -9,6 +9,7 @@ use App\Http\Logic\Logic; @@ -9,6 +9,7 @@ use App\Http\Logic\Logic;
9 use App\Models\Com\UpdateNotify; 9 use App\Models\Com\UpdateNotify;
10 use App\Models\Project\Project; 10 use App\Models\Project\Project;
11 use App\Models\RouteMap\RouteDelete; 11 use App\Models\RouteMap\RouteDelete;
  12 +use App\Models\Service\Service;
12 use Illuminate\Support\Facades\Cache; 13 use Illuminate\Support\Facades\Cache;
13 use Illuminate\Support\Str; 14 use Illuminate\Support\Str;
14 15
@@ -173,7 +174,7 @@ class BaseLogic extends Logic @@ -173,7 +174,7 @@ class BaseLogic extends Logic
173 $data['project_id'] = $this->user['project_id']; 174 $data['project_id'] = $this->user['project_id'];
174 $str = http_build_query($data); 175 $str = http_build_query($data);
175 $url = $this->user['domain'].'api/delHtml/?'.$str; 176 $url = $this->user['domain'].'api/delHtml/?'.$str;
176 - if($this->user['project_id'] == 672){//TODO::当前项目通知不过 ,跳过自动更新 177 + if(isset($this->project['serve_id']) && ($this->project['serve_id'] == 3)){//TODO::当前项目通知不过 ,跳过自动更新
177 exec('curl -k "'.$url.'" > /dev/null 2>&1 &'); 178 exec('curl -k "'.$url.'" > /dev/null 2>&1 &');
178 }else{ 179 }else{
179 shell_exec('curl -k "'.$url.'"'); 180 shell_exec('curl -k "'.$url.'"');
@@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\HomeCount; @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\HomeCount;
4 4
5 5
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\RouteMap\RouteMap;
7 use App\Models\Visit\Visit; 8 use App\Models\Visit\Visit;
8 use App\Models\Visit\VisitItem; 9 use App\Models\Visit\VisitItem;
9 use App\Models\HomeCount\Count; 10 use App\Models\HomeCount\Count;
@@ -116,7 +117,7 @@ class CountLogic extends BaseLogic @@ -116,7 +117,7 @@ class CountLogic extends BaseLogic
116 public function with_data_count(){ 117 public function with_data_count(){
117 $product_count = (new Product())->where(['project_id' => $this->user['project_id']])->count(); 118 $product_count = (new Product())->where(['project_id' => $this->user['project_id']])->count();
118 $news_count = (new News())->where(['project_id' => $this->user['project_id']])->count(); 119 $news_count = (new News())->where(['project_id' => $this->user['project_id']])->count();
119 - $page_count = (new BTemplate())->where(['project_id' => $this->user['project_id']])->count(); 120 + $page_count = (new RouteMap())->where(['project_id' => $this->user['project_id']])->count();
120 $data = [ 121 $data = [
121 'product_count' => $product_count, 122 'product_count' => $product_count,
122 'news_count' => $news_count, 123 'news_count' => $news_count,
@@ -45,13 +45,18 @@ class ProductLogic extends BaseLogic @@ -45,13 +45,18 @@ class ProductLogic extends BaseLogic
45 $category_ids = $this->handleCategory(); 45 $category_ids = $this->handleCategory();
46 //处理其他字段 46 //处理其他字段
47 $this->param = $this->handleSaveParam($this->param); 47 $this->param = $this->handleSaveParam($this->param);
48 -// try { 48 + try {
49 if(isset($this->param['id']) && !empty($this->param['id'])){ 49 if(isset($this->param['id']) && !empty($this->param['id'])){
  50 + $seo_mate = (array)$this->model->read(['id'=>$this->param['id']],['seo_mate'])['seo_mate'];
50 $is_upgrade = $this->param['is_upgrade'] ?? 0;//1:5.0数据 0:6.0 51 $is_upgrade = $this->param['is_upgrade'] ?? 0;//1:5.0数据 0:6.0
51 $six_read = $this->param['six_read'] ?? 0;//是否按6.0显示 52 $six_read = $this->param['six_read'] ?? 0;//是否按6.0显示
52 if($is_upgrade == 0 || $six_read == 1){ 53 if($is_upgrade == 0 || $six_read == 1){
53 $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']); 54 $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
54 } 55 }
  56 + if(!empty($seo_mate)){
  57 + $seo_mate['title'] = $this->param['title'] ?? '';
  58 + $this->param['seo_mate'] = json_encode($seo_mate,true);
  59 + }
55 $route = $this->param['route']; 60 $route = $this->param['route'];
56 $this->model->edit($this->param,['id'=>$this->param['id']]); 61 $this->model->edit($this->param,['id'=>$this->param['id']]);
57 $id = $this->param['id']; 62 $id = $this->param['id'];
@@ -66,10 +71,10 @@ class ProductLogic extends BaseLogic @@ -66,10 +71,10 @@ class ProductLogic extends BaseLogic
66 CategoryRelated::saveRelated($id, $category_ids); 71 CategoryRelated::saveRelated($id, $category_ids);
67 //保存扩展字段 72 //保存扩展字段
68 $this->saveExtendInfo($id,$extend); 73 $this->saveExtendInfo($id,$extend);
69 -// }catch (\Exception $e){  
70 -// Log::info('错误信息---'.$e->getMessage());  
71 -// $this->fail('系统错误请联系管理员');  
72 -// } 74 + }catch (\Exception $e){
  75 + Log::info('错误信息---'.$e->getMessage());
  76 + $this->fail('系统错误请联系管理员');
  77 + }
73 $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route); 78 $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route);
74 $this->curlDelRoute(['new_route'=>$route]); 79 $this->curlDelRoute(['new_route'=>$route]);
75 return $this->success(); 80 return $this->success();
@@ -77,7 +77,7 @@ class UserLogic extends BaseLogic @@ -77,7 +77,7 @@ class UserLogic extends BaseLogic
77 } 77 }
78 $this->param['type'] = 1; 78 $this->param['type'] = 1;
79 $this->param['operator_id'] = $this->user['id']; 79 $this->param['operator_id'] = $this->user['id'];
80 - if(isset($this->param['password']) && empty($this->param['password'])){ 80 + if(isset($this->param['password']) && !empty($this->param['password'])){
81 $this->param['password'] = base64_encode(md5($this->param['password'])); 81 $this->param['password'] = base64_encode(md5($this->param['password']));
82 } 82 }
83 $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); 83 $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  1 +<?php
  2 +
  3 +namespace App\Models\Com;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class Notify extends Base
  8 +{
  9 + protected $table = 'gl_notify';
  10 +}
@@ -42,7 +42,7 @@ class HttpUtils @@ -42,7 +42,7 @@ class HttpUtils
42 public static function get($url, $data, $headers = []) 42 public static function get($url, $data, $headers = [])
43 { 43 {
44 LogUtils::info("HttpUtils-GET请求URL:" . $url); 44 LogUtils::info("HttpUtils-GET请求URL:" . $url);
45 - $response = Http::timeout(20)->withHeaders($headers)->get($url, $data); 45 + $response = Http::timeout(60)->withHeaders($headers)->get($url, $data);
46 self::checkSuccess($response); 46 self::checkSuccess($response);
47 return $response->getBody()->getContents(); 47 return $response->getBody()->getContents();
48 } 48 }
@@ -50,7 +50,7 @@ class HttpUtils @@ -50,7 +50,7 @@ class HttpUtils
50 public static function post($url, $data, $headers = []) 50 public static function post($url, $data, $headers = [])
51 { 51 {
52 LogUtils::info("HttpUtils-POST请求URL:" . $url); 52 LogUtils::info("HttpUtils-POST请求URL:" . $url);
53 - $response = Http::timeout(20)->withHeaders($headers)->post($url, $data); 53 + $response = Http::timeout(60)->withHeaders($headers)->post($url, $data);
54 self::checkSuccess($response); 54 self::checkSuccess($response);
55 return $response->getBody()->getContents(); 55 return $response->getBody()->getContents();
56 } 56 }