作者 zhl

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

... ... @@ -6,10 +6,16 @@ use App\Helper\Arr;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateVisit;
use App\Models\Devops\ServerConfig;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Process\Process;
class Temp extends Command
{
... ... @@ -30,17 +36,106 @@ class Temp extends Command
public function handle()
{
$project = ProjectServer::useProject(626);
if ($project) {
CollectTask::select(['id', 'language'])->where('status', 0)->chunk(1000, function ($query) {
$domain_model = new DomainInfo();
$server_model = new ServerConfig();
$project_model = new Project();
foreach ($query as $item) {
$item->domain = 'lecusostreetlight.quanqiusou.cn/' . $item->language;
$item->save();
$domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
foreach ($domain_list as $info) {
$this->output('domain:' . $info['domain'] . ',开始');
$project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
if ($project_info === false) {
$this->output('获取项目数据失败');
continue;
}
$server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
if ($server_info === false) {
$this->output('获取服务器数据失败');
continue;
}
$domain_array = parse_url($info['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$amp_domain = implode('.', $host_array);
if (!$this->check_cname($amp_domain, $server_info)) {
$this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
continue;
}
$api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
$api_param = [
'domain' => $info['domain'],
'private_key' => '',
'cert' => ''
];
try {
$rs = HttpUtils::get($api_url, $api_param);
$rs = json_decode($rs, true);
if (isset($rs['status']) && $rs['status'] == 200) {
$this->output('创建AMP站点成功');
} else {
$this->output($rs['message'] ?? '');
continue;
}
});
} catch (\Exception | GuzzleException $e) {
errorLog('创建AMP站点', $api_param, $e);
$this->output('创建AMP站点失败');
continue;
}
$data = [
'amp_status' => 1,
'amp_type' => 1,
];
$domain_model->edit($data, ['id' => $info['id']]);
}
DB::disconnect('custom_mysql');
echo '成功' . PHP_EOL;
}
public function check_cname($domain, $server_info)
{
$checkA = false;
$checkCname = false;
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['host']) !== false;
if ($checkA) {
return $domain;
}
}
}
//是否cname
$process = new Process(['nslookup', '-qt=cname', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['init_domain']) !== false);
if ($checkCname) {
return $domain;
}
}
}
return false;
}
public function output($msg)
{
echo $msg . PHP_EOL;
}
}
... ...
... ... @@ -55,7 +55,7 @@ class UpdateRoute extends Command
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>645]);
$list = $projectModel->list(['id'=>1091]);
$data = [];
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
... ...
... ... @@ -92,13 +92,19 @@ class KeywordVideoController extends BaseController
'project_id.required' => '项目唯一标识不为空',
'number.required' => 'number不为空',
]);
//查看当前项目是否已添加
$keywordModel = new KeywordVideoTask();
$keywordInfo = $keywordModel->read(['project_id'=>$this->param['project_id']]);
if($keywordInfo !== false){
$this->response('当前项目已添加');
}
//查看当前项目是否有正式域名
$domainModel = new DomainInfo();
$info = $domainModel->read(['project_id'=>$this->param['project_id']]);
if($info === false){
$this->response('请先设置域名',Code::SYSTEM_ERROR);
}
$keywordModel = new KeywordVideoTask();
$rs = $keywordModel->add($this->param);
if($rs === false){
$this->response('添加失败',Code::SYSTEM_ERROR);
... ...
... ... @@ -540,7 +540,6 @@ class ProductController extends BaseController
'keyword.required' => 'keyword不能为空',
]);
$data = curl_c('http://title.globalso.com/ajax_data_for_web.php?keyword='.$this->param['keyword'],false);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($data, true) . PHP_EOL, FILE_APPEND);
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -359,6 +359,9 @@ class ImageController extends Controller
if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
$this->map['project_id'] = $this->cache['project_id'];
}
if(isset($this->map['name']) && !empty($this->map['name'])){
$this->map['name'] = ['like','%'.$this->map['name'].'%'];
}
$imageModel = new ImageModel();
$lists = $imageModel->lists($this->map,$this->page,$this->row);
if(!empty($lists) && !empty($lists['list'])){
... ...
... ... @@ -9,6 +9,7 @@ use App\Http\Logic\Logic;
use App\Models\Com\UpdateNotify;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteDelete;
use App\Models\Service\Service;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
... ... @@ -173,7 +174,7 @@ class BaseLogic extends Logic
$data['project_id'] = $this->user['project_id'];
$str = http_build_query($data);
$url = $this->user['domain'].'api/delHtml/?'.$str;
if($this->user['project_id'] == 672){//TODO::当前项目通知不过 ,跳过自动更新
if(isset($this->project['serve_id']) && ($this->project['serve_id'] == 3)){//TODO::当前项目通知不过 ,跳过自动更新
exec('curl -k "'.$url.'" > /dev/null 2>&1 &');
}else{
shell_exec('curl -k "'.$url.'"');
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\HomeCount;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\RouteMap\RouteMap;
use App\Models\Visit\Visit;
use App\Models\Visit\VisitItem;
use App\Models\HomeCount\Count;
... ... @@ -116,7 +117,7 @@ class CountLogic extends BaseLogic
public function with_data_count(){
$product_count = (new Product())->where(['project_id' => $this->user['project_id']])->count();
$news_count = (new News())->where(['project_id' => $this->user['project_id']])->count();
$page_count = (new BTemplate())->where(['project_id' => $this->user['project_id']])->count();
$page_count = (new RouteMap())->where(['project_id' => $this->user['project_id']])->count();
$data = [
'product_count' => $product_count,
'news_count' => $news_count,
... ...
... ... @@ -45,13 +45,18 @@ class ProductLogic extends BaseLogic
$category_ids = $this->handleCategory();
//处理其他字段
$this->param = $this->handleSaveParam($this->param);
// try {
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$seo_mate = (array)$this->model->read(['id'=>$this->param['id']],['seo_mate'])['seo_mate'];
$is_upgrade = $this->param['is_upgrade'] ?? 0;//1:5.0数据 0:6.0
$six_read = $this->param['six_read'] ?? 0;//是否按6.0显示
if($is_upgrade == 0 || $six_read == 1){
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
}
if(!empty($seo_mate)){
$seo_mate['title'] = $this->param['title'] ?? '';
$this->param['seo_mate'] = json_encode($seo_mate,true);
}
$route = $this->param['route'];
$this->model->edit($this->param,['id'=>$this->param['id']]);
$id = $this->param['id'];
... ... @@ -66,10 +71,10 @@ class ProductLogic extends BaseLogic
CategoryRelated::saveRelated($id, $category_ids);
//保存扩展字段
$this->saveExtendInfo($id,$extend);
// }catch (\Exception $e){
// Log::info('错误信息---'.$e->getMessage());
// $this->fail('系统错误请联系管理员');
// }
}catch (\Exception $e){
Log::info('错误信息---'.$e->getMessage());
$this->fail('系统错误请联系管理员');
}
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route);
$this->curlDelRoute(['new_route'=>$route]);
return $this->success();
... ...
... ... @@ -77,7 +77,7 @@ class UserLogic extends BaseLogic
}
$this->param['type'] = 1;
$this->param['operator_id'] = $this->user['id'];
if(isset($this->param['password']) && empty($this->param['password'])){
if(isset($this->param['password']) && !empty($this->param['password'])){
$this->param['password'] = base64_encode(md5($this->param['password']));
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
... ...
<?php
namespace App\Models\Com;
use App\Models\Base;
class Notify extends Base
{
protected $table = 'gl_notify';
}
... ...
... ... @@ -42,7 +42,7 @@ class HttpUtils
public static function get($url, $data, $headers = [])
{
LogUtils::info("HttpUtils-GET请求URL:" . $url);
$response = Http::timeout(20)->withHeaders($headers)->get($url, $data);
$response = Http::timeout(60)->withHeaders($headers)->get($url, $data);
self::checkSuccess($response);
return $response->getBody()->getContents();
}
... ... @@ -50,7 +50,7 @@ class HttpUtils
public static function post($url, $data, $headers = [])
{
LogUtils::info("HttpUtils-POST请求URL:" . $url);
$response = Http::timeout(20)->withHeaders($headers)->post($url, $data);
$response = Http::timeout(60)->withHeaders($headers)->post($url, $data);
self::checkSuccess($response);
return $response->getBody()->getContents();
}
... ...