作者 张关杰

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

... ... @@ -84,6 +84,10 @@ class ProjectImport extends Command
'http' => [
'method' => 'GET',
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
];
$file_handle = fopen($task->file_url, 'r', null, stream_context_create($opts));
... ...
... ... @@ -7,7 +7,9 @@ use App\Exceptions\InquiryFilterException;
use App\Services\SyncSubmitTaskService;
use Illuminate\Console\Command;
use App\Models\SyncSubmitTask\SyncSubmitTask as SyncSubmitTaskModel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
/**
... ... @@ -25,9 +27,17 @@ class SyncSubmitTask extends Command
public function handle()
{
$backup = false;
while (true) {
$task_id = $this->getTaskId();
if ($task_id > 2000000) {
$backup = true;
}
if (empty($task_id)) {
if ($backup) {
$this->backup();
$backup = false;
}
sleep(5);
continue;
}
... ... @@ -43,7 +53,7 @@ class SyncSubmitTask extends Command
$task_info->save();
$this->output('任务完成');
} catch (InquiryFilterException $e){
} catch (InquiryFilterException $e) {
$task_info->status = 1;
$task_info->is_filtered = 1;
$task_info->remark = $e->getMessage();
... ... @@ -65,11 +75,12 @@ class SyncSubmitTask extends Command
}
}
public function getTaskId(){
public function getTaskId()
{
$task_id = Redis::rpop('sync_submit_task');
if (empty($task_id)) {
$ids = SyncSubmitTaskModel::where('status', 0)->pluck('id');
foreach($ids as $id){
$ids = SyncSubmitTaskModel::where('status', 0)->limit(100)->pluck('id');
foreach ($ids as $id) {
Redis::lpush('sync_submit_task', $id);
}
$task_id = Redis::rpop('sync_submit_task');
... ... @@ -86,4 +97,30 @@ class SyncSubmitTask extends Command
return true;
}
/**
* 备份数据
* @author zbj
* @date 2024/1/23
*/
public function backup()
{
DB::beginTransaction();
try {
$table = (new SyncSubmitTaskModel())->getTable();
$new_table = $table . '_backup_' . date('Ymd');
//重命名当前表
Schema::rename($table, $new_table);
//克隆表数据
DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table);
DB::commit();
$this->output('数据备份成功');
} catch (\Exception $e) {
$this->output('数据备份失败' . $e->getMessage());
DB::rollBack();
}
return true;
}
}
... ...
... ... @@ -55,7 +55,7 @@ class UpdateRoute extends Command
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>433]);
$list = $projectModel->list(['id'=>627]);
$data = [];
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
... ... @@ -116,6 +116,7 @@ class UpdateRoute extends Command
if(!empty($v['route'])){
$tag = "-tag";
if (!(substr($v['route'], -strlen($tag)) === $tag)) {
echo date('Y-m-d H:i:s') . '拼接 :'.$v['id'] . PHP_EOL;
// $route = Translate::tran($v['route'], 'en').$tag;
// 如果不是以 '-tag' 结尾,则拼接上 '-tag'
$route = $v['route'].$tag;
... ...
... ... @@ -33,7 +33,11 @@ class CustomModuleController extends BaseController
* @time :2023/12/4 15:43
*/
public function lists(){
ProjectServer::useProject($this->param['project_id']);
$result = ProjectServer::useProject($this->param['project_id']);
if($result === false){
$this->response('success');
}
$customModule = new CustomModule();
$this->map['status'] = 0;
$lists = $customModule->lists($this->map,$this->page,$this->row,$this->order = ['topping_time','sort','id']);
... ...
... ... @@ -184,7 +184,7 @@ class OptimizeController extends BaseController
if(isset($this->map['online_updated_at']) && !empty($this->map['online_updated_at'])){
$query = $query->whereBetween('gl_project_deploy_optimize.updated_at', $this->map['online_updated_at']);
}
if(isset($this->map['special']) && !empty($this->map['special'])){
if(isset($this->map['special'])){
$query = $query->where('gl_project_deploy_optimize.special','like','%'.$this->map['special'].'%');
}
if(isset($this->map['manager_mid']) && !empty($this->map['manager_mid'])){
... ... @@ -193,7 +193,7 @@ class OptimizeController extends BaseController
if(isset($this->map['optimize_manager_mid']) && !empty($this->map['optimize_manager_mid'])){
$query = $query->where('gl_project_deploy_optimize.manager_mid','like','%'.$this->map['optimize_manager_mid'].'%');
}
if(isset($this->map['is_upgrade']) && !empty($this->map['is_upgrade'])){
if(isset($this->map['is_upgrade'])){
$query = $query->where('gl_project.is_upgrade',$this->map['is_upgrade']);
}
if(isset($this->map['optimize_tech_mid']) && !empty($this->map['optimize_tech_mid'])){
... ...
... ... @@ -70,4 +70,21 @@ class ExtendController extends BaseController
$extendLogic->extendDel();
$this->response('success');
}
/**
* 可搜索的字段列表
* @author zbj
* @date 2024/1/22
*/
public function search_filed(){
$map = [
'title' => '产品标题',
'intro' => '短描述',
];
//文本框类型扩展字段
$extends = Extend::where('type', 1)->pluck('title', 'key')->toArray();
$data = array_merge($map, $extends);
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -243,10 +243,8 @@ class ProductController extends BaseController
}else{
$v['status_text'] = '';
}
//获取当前用户选择的模版
$v['video'] = json_decode($v['video'] ?? '');
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id'] ?? 0);
$v['url'] = $this->user['domain'].$v['route'];
//获取当前数据扩展字段及值
$v['extend'] = $this->getExtendInfo($v['id']);
... ...
... ... @@ -329,7 +329,8 @@ class ProjectLogic extends BaseLogic
$config['filter_emails'] = Arr::a2s(!empty($config['filter_emails']) ? $config['filter_emails'] : []);
$config['filter_mobiles'] = Arr::a2s(!empty($config['filter_mobiles']) ? $config['filter_mobiles'] : []);
$config['filter_names'] = Arr::a2s(!empty($config['filter_names']) ? $config['filter_names'] : []);
$config['black_ips'] = $config['black_ips'] ?? '';
$model = InquiryFilterConfig::where('project_id', $config['project_id'])->first();
if(!$model){
$model = new InquiryFilterConfig();
... ...
... ... @@ -264,38 +264,42 @@ class ProductLogic extends BaseLogic
*/
public function handleSaveParam(&$param){
//产品图
if(isset($param['gallery']) && !empty($param['gallery'])){
if(isset($param['gallery'])){
foreach ($param['gallery'] as $k => $v){
$v['url'] = str_replace_url($v['url']);
$param['gallery'][$k] = $v;
}
$param['thumb'] = Arr::a2s($param['gallery'][0] ?? []);
$param['gallery'] = Arr::a2s($param['gallery'] ?? []);
}else{
$param['gallery'] = Arr::a2s([]);
$param['thumb'] = Arr::a2s([]);
}
if(isset($param['video']) && !empty($param['video'])){
if(isset($param['files'])){
foreach ($param['files'] as $k => $v){
$v['url'] = str_replace_url($v['url']);
$param['files'][$k] = $v;
}
$param['files'] = Arr::a2s($param['files'] ?? []);
}
if(isset($param['video'])){
foreach ($param['video'] as $k => $v){
$v['url'] = str_replace_url($v['url']);
$param['video'][$k] = $v;
}
$param['video'] = Arr::a2s($param['video'] ?? []);
}else{
$param['video'] = Arr::a2s([]);
}
$param['attrs'] = Arr::a2s($param['attrs'] ?? []);
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
if(isset($param['keyword_id'])){
$param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
}
$param['attrs'] = Arr::a2s($param['attrs'] ?? []);
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
$param['describe'] = Arr::a2s($param['describe'] ?? []);
$param['describe_id'] = Arr::arrToSet($param['describe_id'] ?? '');
$param['seo_mate'] = Arr::a2s($param['seo_mate'] ?? '');
$param['related_product_id'] = Arr::arrToSet($param['related_product_id'] ?? '');
if(isset($param['icon']) && !empty($param['icon'])){
if(isset($param['icon'])){
foreach ($param['icon'] as $k1 => $v1){
$param['icon'][$k1] = str_replace_url($v1);
}
$param['icon'] = Arr::a2s($param['icon'] ?? []);
}else{
$param['icon'] = Arr::a2s([]);
}
$param['created_uid'] = $this->user['id'];
return $param;
... ...
... ... @@ -37,6 +37,13 @@ class WebSettingReceivingLogic extends BaseLogic
try {
$this->model->del(['project_id'=>$this->user['project_id']]);
foreach ($this->param['data'] as $k => $v){
if($v['type'] == 2){
// 使用正则表达式匹配中国大陆手机号
$pattern = '/^1[3456789]\d{9}$/';
if (!preg_match($pattern, $v['values'])) {
continue;
}
}
$v['project_id'] = $this->user['project_id'];
$v['created_at'] = date('Y-m-d H:i:s');
$v['updated_at'] = date('Y-m-d H:i:s');
... ...
... ... @@ -166,6 +166,46 @@ class Product extends Base
}
/**
* @remark :下载文件
* @name :getFilesAttribute
* @author :lyh
* @method :post
* @time :2024/1/23 14:29
*/
public function getFilesAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
foreach ($value as $k => $v){
if(!empty($v['url'])){
$v['url'] = getImageUrl($v['url']);
}
$value[$k] = $v;
}
}
return $value;
}
/**
* @remark :视频
* @name :getVideoAttribute
* @author :lyh
* @method :post
* @time :2024/1/23 14:31
*/
public function getVideoAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
foreach ($value as $k => $v){
if(!empty($v['url'])){
$v['url'] = getImageUrl($v['url']);
}
$value[$k] = $v;
}
}
return $value;
}
/**
* @remark :图标获取器
* @name :getGalleryAttribute
* @author :lyh
... ...
<?php
/**
* @remark :上传文件与图片到亚马逊
* @name :AmazonS3Service.php
* @author :lyh
* @method :post
* @time :2024/1/23 9:17
*/
namespace App\Services;
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
class AmazonS3Service
{
// 替换为你自己的 AWS 访问密钥、区域和存储桶名称
protected $s3;
protected $accessKeyId = '';//key
protected $secretAccessKey = '';//密匙
protected $region = '';//地址
protected $bucket = '';//桶子
public function __construct()
{
// 创建 S3 客户端
$this->s3 = new S3Client([
'version' => 'latest',
'region' => $this->region,
'credentials' => [
'key' => $this->accessKeyId,
'secret' => $this->secretAccessKey,
],
]);
}
/**
* @remark :上传图片与文件
* @name :uploadImage
* @author :lyh
* @method :post
* @time :2024/1/23 9:20
*/
public function uploadFiles($localFilePath, $s3Key)
{
try {
$result = $this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => $s3Key,
'SourceFile' => $localFilePath,
'ACL' => 'public-read', // 设置图片为公共可读,可根据需求修改
]);
return $result['ObjectURL'];
} catch (S3Exception $e) {
return false;
}
}
}
... ...
... ... @@ -47,7 +47,9 @@ class SyncSubmitTaskService
return false;
}
ProjectServer::useProject($project['id']);
if(!ProjectServer::useProject($project['id'])){
return false;
}
$action = $task['type'];
$handler = new self();
... ... @@ -133,7 +135,6 @@ class SyncSubmitTaskService
* @date 2023/11/30
*/
public static function checkIpCountry($domain, $ip, $type){
$domain = 'https://demo.globalso.site/';
$project = Project::getProjectByDomain($domain);
if(empty($project)){
throw new InquiryFilterException('项目不存在');
... ... @@ -210,11 +211,11 @@ class SyncSubmitTaskService
if($config['filter_referers']){
//只比较path路径
$paths = array_map(function ($v){
return parse_url(Url::to($v), PHP_URL_PATH);
return trim(parse_url(Url::to($v), PHP_URL_PATH), '/');
},$config['filter_referers']);
//后端获取的referer
if(in_array(parse_url($data['referer'], PHP_URL_PATH), $paths)){
if(in_array(trim(parse_url($data['referer'], PHP_URL_PATH), '/'), $paths)){
throw new InquiryFilterException( '过滤来源链接:' . $data['referer']);
}
//前端获取的referer
... ...
... ... @@ -251,6 +251,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('extend', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'lists'])->name('product_extend');
Route::any('extend/save', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'save'])->name('product_extend_save');
Route::any('extend/del', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'del'])->name('product_extend_del');
Route::any('extend/search_filed', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'search_filed'])->name('product_extend_search_filed');
});
... ...