作者 lyh

gx

... ... @@ -64,7 +64,7 @@ class SyncProject extends Command
while (true){
$list = NoticeLog::where('type', NoticeLog::TYPE_PROJECT)->where('status', NoticeLog::STATUS_PENDING)->get();
foreach ($list as $item){
echo 'start:' . $item['id'] . PHP_EOL;
echo date('Y-m-d') . ' start:' . $item['id'] . PHP_EOL;
try {
$is_update = $item['data']['is_update']??0;//是否是4.0或5.0更新到6.0
$order_id = $item['data']['order_id'];
... ... @@ -97,7 +97,7 @@ class SyncProject extends Command
$item->save();
echo 'success:' . $item['id'] . PHP_EOL;
}catch (\Exception $e){
echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL;
echo 'error:' . $item['id'] . $e->getMessage() .' line ' . $e->getLine() . PHP_EOL;
errorLog('项目同步失败', $item, $e);
$this->retry($item, $e->getMessage());
}
... ... @@ -217,7 +217,7 @@ class SyncProject extends Command
DB::beginTransaction();
try {
$id = $this->saveProject($data['project']);
$this->setPostId($data['deploy_build']['plan'],$id);;
$this->setPostId($data['deploy_build']['plan'],$id);
$this->savePayment($data['payment'],$id);
$this->saveDeployBuild($data['deploy_build'],$id);
$this->saveDeployOptimize($data['deploy_optimize'],$id);
... ... @@ -230,8 +230,16 @@ class SyncProject extends Command
//初始账号
$this->createUser($data['project']['mobile'],$id,$data['project']['lead_name']);
//新增数据抓取任务
$task_list = [];
foreach ($param['api_type'] as $v_type){
UpdateLog::createLog($id,$v_type,$param['get_data_url']);
if($v_type == 'category'){
UpdateLog::createLog($id,$v_type,$param['get_data_url']);
}else{
$task_list[] = $v_type;
}
}
foreach ($task_list as $task){
UpdateLog::createLog($id,$task,$param['get_data_url']);
}
}
DB::commit();
... ...
... ... @@ -8,10 +8,12 @@ use App\Http\Logic\Bside\Product\KeywordLogic;
use App\Models\Blog\Blog;
use App\Models\Com\UpdateLog;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Models\WebSetting\WebSettingReceiving;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
... ... @@ -52,7 +54,7 @@ class ProjectUpdate extends Command
{
$task_id = $this->get_task();
if (!$task_id) {
sleep(2);
sleep(60);
return true;
}
... ... @@ -77,28 +79,140 @@ class ProjectUpdate extends Command
//设置数据库
$project = ProjectServer::useProject($task->project_id);
if ($project) {
if ($api_type == 'website_info') {
if ($api_type == 'category') {
//分类
$url = $api_url . '?' . http_build_query(['w' => 'category']);
$data = http_get($url, ['charset' => 'UTF-8']);
if (isset($data['code']) && $data['code'] == 200) {
$items = $data['data'] ?? [];
$this->category_insert($project_id, $items, 0);
// $model = new Category();
// foreach ($items as $item) {
// $parent = $model->read(['pid' => 0, 'title' => $item['name']], 'id');
// if (!$parent) {
// try {
// $parent_id = $model->addReturnId([
// 'project_id' => $project_id,
// 'title' => $item['name'],
// 'pid' => 0,
// 'keywords' => $item['keywords'],
// 'describe' => $item['description']
// ]);
// $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
// $model->edit(['route' => $route], ['id' => $parent_id]);
// } catch (\Exception $e) {
// echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
// continue;
// }
// } else {
// $parent_id = $parent['id'];
// }
//
// foreach ($item['children'] as $child) {
// $child_info = $model->read(['pid' => $parent_id, 'title' => $child['name']]);
// if (!$child_info) {
// try {
// $child_id = $model->addReturnId([
// 'project_id' => $project_id,
// 'title' => $child['name'],
// 'pid' => $parent_id,
// 'keywords' => $child['keywords'],
// 'describe' => $child['description']
// ]);
// $route = RouteMap::setRoute($child['url'] ? $this->get_url_route($child['url']) : $child['name'], RouteMap::SOURCE_PRODUCT_CATE, $child_id, $project_id);
// $model->edit(['route' => $route], ['id' => $child_id]);
// } catch (\Exception $e) {
// echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
// continue;
// }
// }
// }
// }
} else {
return true;
}
} elseif ($api_type == 'tag') {
//关键词
$url = $api_url . '?' . http_build_query(['w' => 'website_info']);
$url = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => 1, 'pagesize' => 0]);
$data = http_get($url, ['charset' => 'UTF-8']);
if (isset($data['code']) && $data['code'] == 200) {
$items = $data['data']['tags'] ?? [];
$count = $data['data']['count'] ?? 0;
$total_page = ceil($count / $page_size);
for ($page = 1; $page <= $total_page; $page++) {
$url_page = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => $page, 'pagesize' => $page_size]);
$data_page = http_get($url_page, ['charset' => 'UTF-8']);
if (isset($data_page['code']) && $data_page['code'] == 200) {
$items = $data_page['data']['data'] ?? [];
$model = new Keyword();
foreach ($items as $item) {
if (strlen($item) > 50) {
continue;
$model = new Keyword();
foreach ($items as $item) {
if ($item['name'] ?? '') {
$keyword = $model->read(['title' => $item['name']], 'id');
if (!$keyword) {
try {
$id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['name'],
'seo_title' => $item['seo_title'] ?? '',
'seo_keywords' => $item['seo_keywords'] ?? '',
'seo_description' => $item['seo_description'] ?? '',
]);
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
$model->edit(['route' => $route], ['id' => $id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
}
}
}
}
}
$keyword = $model->read(['title' => $item], 'id');
if (!$keyword) {
$id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item
]);
$route = RouteMap::setRoute($item, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
$model->edit(['route' => $route], ['id' => $id]);
}
} else {
return true;
}
} elseif ($api_type == 'website_info') {
//网站信息
$url = $api_url . '?' . http_build_query(['w' => 'website_info']);
$data = http_get($url, ['charset' => 'UTF-8']);
if (isset($data['code']) && $data['code'] == 200) {
$phones = $data['data']['phones'] ?? '';
$emails = $data['data']['emails'] ?? '';
$model = new WebSettingReceiving();
if ($phones) {
$phone_arr = explode(',', $phones);
foreach ($phone_arr as $v_phone) {
if ($v_phone) {
$receiving_phones = $model->read(['type' => 2, 'values' => $v_phone]);
if (!$receiving_phones) {
$model->add([
'type' => 1,
'values' => $v_phone,
'project_id' => $project_id
]);
}
}
}
}
if ($emails) {
$email_arr = explode(',', $emails);
foreach ($email_arr as $v_email) {
if ($v_email) {
$receiving_emails = $model->read(['type' => 1, 'values' => $v_email]);
if (!$receiving_emails) {
$model->add([
'type' => 2,
'values' => $v_email,
'project_id' => $project_id
]);
}
}
}
}
} else {
return true;
}
} elseif ($api_type == 'post') {
//产品
... ... @@ -117,58 +231,61 @@ class ProjectUpdate extends Command
$model = new Product();
foreach ($items as $item) {
$product = $model->read(['title' => $item['ttile']], 'id');
if (!$product) {
//图片
$gallery = [];
foreach ($item['images'] as $k_img => $img) {
$gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
}
//关键词
$keyword_id = '';
if ($item['keywords']) {
$keywordLogic = new KeywordLogic();
$keyword_id = $keywordLogic->importProductKeyword($project_id, $item['keywords']);
}
//分类
$category_id = '';
if ($item['category']) {
$category_arr = [];
foreach ($item['category'] as $cate) {
if ($cate['parent'] == 0) {
array_unshift($category_arr, $cate['name']);
} else {
array_push($category_arr, $cate['name']);
if ($item['ttile'] ?? '') {
$product = $model->read(['title' => $item['ttile']], 'id');
if (!$product) {
//图片
$gallery = [];
if ($item['images'] ?? []) {
foreach ($item['images'] as $k_img => $img) {
$gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
}
}
//分类
$category_id = '';
if ($item['category'] ?? []) {
$category_arr = [];
foreach ($item['category'] as $cate) {
if ($cate['parent'] == 0) {
array_unshift($category_arr, $cate['name']);
} else {
array_push($category_arr, $cate['name']);
}
}
if ($category_arr) {
$categoryLogic = new CategoryLogic();
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
}
}
if ($category_arr) {
$categoryLogic = new CategoryLogic();
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
try {
$id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['ttile'],
'intro' => $item['description'] ?? '',
'content' => $item['content'] ?? '',
'category_id' => $category_id,
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
'gallery' => Arr::a2s($gallery),
'seo_mate' => Arr::a2s([
'title' => $item['ttile'],
'keyword' => $item['keywords'] ?? '',
'description' => $item['description'] ?? ''
]),
'status' => Product::STATUS_ON
]);
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);
$model->edit(['route' => $route], ['id' => $id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
}
}
$id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['ttile'],
'intro' => $item['description'],
'content' => $item['content'],
'keyword_id' => $keyword_id,
'category_id' => $category_id,
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
'gallery' => Arr::a2s($gallery),
'seo_mate' => Arr::a2s([
'title' => $item['ttile'],
'keyword' => $item['keywords'],
'description' => $item['description']
]),
'status' => Product::STATUS_ON
]);
$route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);
$model->edit(['route' => $route], ['id' => $id]);
}
}
}
}
} else {
return true;
}
} elseif ($api_type == 'news' || $api_type == 'blog') {
//新闻或博客
... ... @@ -192,22 +309,33 @@ class ProjectUpdate extends Command
foreach ($items as $item) {
$news = $model->read(['name' => $item['ttile']], 'id');
if (!$news) {
$id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['ttile'],
'seo_title' => $item['ttile'],
'text' => $item['content'],
'image' => $item['images'][0] ?? '',
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE
]);
$route = RouteMap::setRoute($item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
$model->edit(['url' => $route], ['id' => $id]);
if ($item['ttile'] ?? '') {
$news = $model->read(['name' => $item['ttile']], 'id');
if (!$news) {
try {
$id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['ttile'],
'seo_title' => $item['ttile'],
'seo_keywords' => $item['keywords'] ?? '',
'seo_description' => $item['description'] ?? '',
'text' => $item['content'] ?? '',
'image' => $item['images'][0] ?? '',
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE
]);
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
$model->edit(['url' => $route], ['id' => $id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
}
}
}
}
}
}
} else {
return true;
}
} else {
//单页
... ... @@ -226,20 +354,32 @@ class ProjectUpdate extends Command
$model = new BCustomTemplate();
foreach ($items as $item) {
$custom = $model->read(['name' => $item['ttile']], 'id');
if (!$custom) {
$id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['ttile'],
'html' => $item['content']
]);
$route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
$model->edit(['url' => $route], ['id' => $id]);
if ($item['ttile'] ?? '') {
$custom = $model->read(['name' => $item['ttile']], 'id');
if (!$custom) {
try {
$id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['ttile'],
'title' => $item['ttile'],
'keywords' => $item['keywords'] ?? '',
'description' => $item['description'] ?? '',
'html' => $item['content'] ?? '',
'status' => 1
]);
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
$model->edit(['url' => $route], ['id' => $id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
}
}
}
}
}
}
} else {
return true;
}
}
}
... ... @@ -263,7 +403,7 @@ class ProjectUpdate extends Command
return $task_id;
}
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->limit(20)->get();
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
if ($task_list->count() == 0) {
return false;
}
... ... @@ -276,4 +416,37 @@ class ProjectUpdate extends Command
return $task_id;
}
//获取地址路由
protected function get_url_route($url)
{
$arr = explode('/', $url);
return $arr[count($arr) - 2];
}
protected function category_insert($project_id, $items, $pid = 0)
{
$model = new Category();
foreach ($items as $item) {
if ($item['name'] ?? '') {
$parent = $model->read(['pid' => $pid, 'title' => $item['name']], 'id');
if (!$parent) {
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['name'],
'pid' => $pid,
'keywords' => $item['keywords'] ?? '',
'describe' => $item['description'] ?? ''
]);
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
$model->edit(['route' => $route], ['id' => $parent_id]);
} else {
$parent_id = $parent['id'];
}
if (!empty($item['children'])) {
$this->category_insert($project_id, $item['children'], $parent_id);
}
}
}
}
}
... ...
... ... @@ -44,12 +44,17 @@ class UpdateProgress extends Command
//获取所有项目
$projectModel = new Project();
$list = $projectModel->list(['type'=>['in',[1,2,3,4]]]);
foreach ($list as $v){
echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->getUpdateProgress($v['id']);
DB::disconnect('custom_mysql');
try {
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->getUpdateProgress($v['id']);
DB::disconnect('custom_mysql');
}
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: ' . PHP_EOL;
}
/**
... ...
... ... @@ -9,9 +9,11 @@ use App\Helper\Translate;
use App\Models\Ai\AiCommand;
use App\Models\Mail\Mail;
use App\Models\Project\DeployOptimize;
use App\Models\Project\ProjectUpdateTdk;
use App\Models\User\User;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
... ... @@ -132,47 +134,54 @@ class UpdateSeoTdk extends Command
public function handle()
{
while (true) {
$project_id = Redis::rpop('updateSeoTdk');
if (!$project_id) {
sleep(2);
$task = ProjectUpdateTdk::getPendingTask();
if (!$task) {
sleep(10);
continue;
}
$project_id = $task->project_id;
echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
try {
ProjectServer::useProject($project_id);
$this->seo_tdk($project_id);
$this->seo_tdk($project_id, $task->id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
ProjectUpdateTdk::retry($task->id, $e->getMessage());
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
}
}
public function seo_tdk($project_id)
public function seo_tdk($project_id, $task_id)
{
$data = [];
$update = [
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s'),
'project_id'=>$project_id,
];//更新统计
//更新统计
$update = [];
$ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray();
$ai_commands = Arr::setValueToKey($ai_commands, 'key');
foreach ($this->maps as $table => $map) {
$update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0];
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL . json_encode($update[$table]);
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
$list = DB::connection('custom_mysql')->table($table)->get();
if (!empty($list)) {
$list = $list->toArray();
foreach ($list as $v) {
echo '打印数据:'.date('Y-m-d H:i:s') . $update[$table]['total_page'].PHP_EOL;
$update[$table]['total_page']++;
$v = (array)$v;
echo date('Y-m-d H:i:s') . '更新--' . $table . ':id' . $v['id'] . PHP_EOL;
//缓存 在处理的项目数据 id
$cache_key = "seo_tdk_{$project_id}_{$table}_{$v['id']}";
if(!Redis::setnx($cache_key, 1)){
continue;
}
Redis::expire($cache_key, 120);
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
$data = [];
$json_field = '';
echo date('Y-m-d H:i:s') . json_encode($map) . PHP_EOL;
foreach ($map as $ai_key => $field) {
$field_arr = explode('.', $field);
if (count($field_arr) > 1) {
... ... @@ -186,6 +195,7 @@ class UpdateSeoTdk extends Command
echo $field.'已有值 跳过' . PHP_EOL;
continue;
}
//AI生成
if (!empty($ai_commands[$ai_key]['ai'])) {
$prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v);
... ... @@ -255,17 +265,16 @@ class UpdateSeoTdk extends Command
}
if($json_field){
$old_data = json_decode($v[$field_arr[0]], true);
foreach ($old_data as $kk=>$vv){
foreach ($old_data ?: [] as $kk=>$vv){
empty($data[$json_field][$kk]) && $data[$json_field][$kk] = $vv;
}
$data[$json_field] = json_encode($data[$json_field]);
}
DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data);
}
$update[$table] = json_encode($update[$table]);
}
}
DB::table('gl_project_update_tdk')->insert($update);
ProjectUpdateTdk::finish($task_id, $update);
}
public function getPrompt($project_id, $prompt, $table, $data){
... ... @@ -298,8 +307,6 @@ class UpdateSeoTdk extends Command
}
$prompt .= '.Please answer in ' . ($lang ?: 'English');
echo $prompt . PHP_EOL;
return $prompt;
}
... ...
... ... @@ -151,6 +151,9 @@ class Arr extends \Illuminate\Support\Arr
*/
public static function s2a($str)
{
if(!$str){
return [];
}
if (is_array($str)) {
return $str;
}
... ...
... ... @@ -74,7 +74,7 @@ class Common
if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) {
$lang = Translate::$tls_list[$result['texts']['sl']]['text'];
} else {
$lang = 'Chinese';
$lang = 'English';
}
}
$str = 'Please answer in '.$lang;
... ...
... ... @@ -14,9 +14,20 @@ use Illuminate\Support\Facades\Log;
*/
class Gpt
{
public $api = 'http://openai.waimaoq.com/';
/**
* 头
* @var string[]
*/
public $header = [
'apikey' => 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6',
'X-CmerApi-Host' => 'bizopenai.p.cmer.com',
];
public $header = [];
/**
* 请求域名
* @var string
*/
public $api = 'https://api.cmer.com';
private static $instance;
... ... @@ -35,7 +46,7 @@ class Gpt
*/
public function openai_chat_qqs($content, $system_content = '')
{
$url = $this->api . 'v2/openai_chat_qqs';
$url = $this->api . '/v1/openai_chat';
$data = [
'messages' => [],
... ... @@ -57,9 +68,10 @@ class Gpt
->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json')
->post($url);
$json = $result->json();
if (!isset($json['text'])) {
if (!isset($json['text']) || $json['code'] !==200) {
Log::error('openai_chat_qqs data:', $data);
Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json);
$json = [];
}
} catch (\Throwable $e) {
Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage());
... ...
<?php
use App\Models\File\Image;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use App\Utils\EncryptUtils;
use App\Utils\LogUtils;
... ... @@ -560,3 +561,24 @@ function ends_with($string, $suffix)
{
return substr($string, -strlen($suffix)) === $suffix;
}
/**
* @remark :获取二级路由
* @name :getRouteMap
* @author :lyh
* @method :post
* @time :2023/11/10 14:29
*/
function getRouteMap($source,$source_id){
$route = '';
$routeMapModel = new RouteMap();
$info = $routeMapModel->read(['source'=>$source,'source_id'=>$source_id]);
if($info !== false){
if(!empty($info['path'])){
$route = $info['path'].'/'.$info['route'];
}else{
$route = $info['route'];
}
}
return $route;
}
... ...
... ... @@ -11,6 +11,7 @@ namespace App\Http\Controllers\Aside\Com;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Project\ProjectUpdateTdk;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
... ... @@ -37,7 +38,7 @@ class UpdateController extends BaseController
],[
'project_id.required' => 'project_id不能为空',
]);
Redis::lpush('updateSeoTdk', $this->param['project_id']);
ProjectUpdateTdk::add_task($this->param['project_id']);
$this->response('任务添加成功');
}
}
... ...
... ... @@ -311,7 +311,7 @@ class ProjectController extends BaseController
$domainModel = new DomainInfo();
$item['domain'] = !empty($item['domain']) ? $domainModel->getDomain($item['domain']) : '';
$item['product_num'] = $data['product'] ?? 0;
$item['keyword_num'] = $item['key'] ?? 0;
$item['keyword_num'] = $data['key'] ?? 0;
$item['autologin_code'] = getAutoLoginCode($item['id']);
$item['article_num'] = ($data['blog'] ?? 0) + ($data['news'] ?? 0);
$item['task_finish_num'] = Task::getNumByProjectId($item['id'], Task::STATUS_DOWN);
... ... @@ -777,6 +777,9 @@ class ProjectController extends BaseController
* @time :2023/11/8 14:17
*/
public function copyProject(ProjectLogic $logic){
if($this->manage['mobile'] != '15680871314' || $this->manage['mobile'] != '18008059100'){
$this->response('当前账号不支持复制项目');
}
$this->request->validate([
'project_id'=>'required',
],[
... ... @@ -786,4 +789,21 @@ class ProjectController extends BaseController
$this->response('success',Code::SUCCESS,$data);
}
/**
* AICC采集数据接口token
* @author zbj
* @date 2023/11/10
*/
public function site_token(Request $request, ProjectLogic $logic){
$this->request->validate([
'project_id'=>'required',
],[
'project_id.required' => 'project_id不能为空',
]);
$token = $logic->getAiccToken($this->map);
$this->response('success',Code::SUCCESS,['site_token' => $token]);
}
}
... ...
... ... @@ -27,7 +27,7 @@ class BlogCategoryController extends BaseController
$blogModel = new BlogModel();
foreach ($lists as $k => $v){
$v['num'] = $blogModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$v['url'] = $this->user['domain'] . $v['alias'].'/';
$v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_BLOG_CATE,$v['id']);
$lists[$k] = $v;
}
if(!isset($this->map['name'])){
... ... @@ -81,7 +81,6 @@ class BlogCategoryController extends BaseController
'id.required' => 'ID不能为空'
]);
$info = $blogCategoryLogic->info_blog_category();
$info['url'] = $this->user['domain'] . $info['alias'];
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -10,6 +10,7 @@ use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\Product\Category;
use App\Models\RouteMap\RouteMap;
use App\Models\User\User;
class BlogController extends BaseController
... ... @@ -35,7 +36,7 @@ class BlogController extends BaseController
$user = new User();
foreach ($lists['list'] as $k => $v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['url'] = $this->user['domain'] .$v['url'].'/';
$v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_BLOG,$v['id']);
$v['image_link'] = getImageUrl($v['image']);
$v['operator_name'] = $user->getName($v['operator_id']);
$lists['list'][$k] = $v;
... ...
... ... @@ -27,7 +27,7 @@ class NewsCategoryController extends BaseController
$newsModel = new NewsModel();
foreach ($lists as $k => $v){
$v['num'] = $newsModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$v['url'] = $this->user['domain'] . $v['alias'].'/';
$v['url'] = $this->user['domain'].getRouteMap(RouteMap::SOURCE_NEWS_CATE,$v['id']);
$lists[$k] = $v;
}
if(!isset($this->map['name'])){
... ...
... ... @@ -8,6 +8,7 @@ use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Requests\Bside\News\NewsRequest;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory;
use App\Models\RouteMap\RouteMap;
use App\Models\User\User;
... ... @@ -35,7 +36,7 @@ class NewsController extends BaseController
$user = new User();
foreach ($lists['list'] as $k => $v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['url'] = $this->user['domain'] .$v['url'].'/';
$v['url'] = $this->user['domain'].getRouteMap(RouteMap::SOURCE_NEWS,$v['id']);
$v['image_link'] = getImageUrl($v['image']);
$v['operator_name'] = $user->getName($v['operator_id']);
$lists['list'][$k] = $v;
... ... @@ -44,6 +45,8 @@ class NewsController extends BaseController
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :处理列表返回参数
* @name :handleReturnParam
... ...
... ... @@ -35,6 +35,7 @@ use App\Models\User\User as UserModel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
/**
* Class ProjectLogic
... ... @@ -535,34 +536,82 @@ class ProjectLogic extends BaseLogic
* @time :2023/11/8 14:23
*/
public function copyProject(){
//复制初始项目
$data = $this->model::where('id', $this->param['project_id'])->first();
$data = $data->getAttributes();
$data['type'] = 0;
$data['title'] = $data['title'].'-copy';
unset($data['id']);
$project_id = $this->model->insertGetId($data);
//复制部署表
$buildModel = new DeployBuild();
$buildData = $buildModel::where('project_id', $this->param['project_id'])->first();
if(!empty($buildData)){
$buildData = $buildData->getAttributes();
$buildData['project_id'] = $project_id;
$hashids = new Hashids('test_domain', 5, 'abcdefghjkmnpqrstuvwxyz1234567890');
$code = $hashids->encode($project_id);
$buildData['test_domain'] = 'https://v6-' . $code . '.globalso.site/';
unset($buildData['id']);
$buildModel->insert($buildData);
}
//复制优化表
$optimizeModel = new DeployOptimize();
$optimizeData = $optimizeModel::where('project_id', $this->param['project_id'])->first();
if(!empty($optimizeData)){
$optimizeData = $optimizeData->getAttributes();
unset($optimizeData['id'],$optimizeData['domain']);
$optimizeData['project_id'] = $project_id;
$optimizeModel->insert($optimizeData);
DB::beginTransaction();
try {
//复制初始项目
$data = $this->model::where('id', $this->param['project_id'])->first();
$data = $data->getAttributes();
$type = $data['type'];
$data['type'] = 0;
$data['title'] = $data['title'].'-copy';
unset($data['id']);
$project_id = $this->model->insertGetId($data);
//复制部署表
$buildModel = new DeployBuild();
$buildData = $buildModel::where('project_id', $this->param['project_id'])->first();
if(!empty($buildData)){
$buildData = $buildData->getAttributes();
$buildData['project_id'] = $project_id;
$hashids = new Hashids('test_domain', 5, 'abcdefghjkmnpqrstuvwxyz1234567890');
$code = $hashids->encode($project_id);
$buildData['test_domain'] = 'https://v6-' . $code . '.globalso.site/';
unset($buildData['id']);
$buildModel->insert($buildData);
}
//复制优化表
$optimizeModel = new DeployOptimize();
$optimizeData = $optimizeModel::where('project_id', $this->param['project_id'])->first();
if(!empty($optimizeData)){
$optimizeData = $optimizeData->getAttributes();
unset($optimizeData['id'],$optimizeData['domain']);
$optimizeData['project_id'] = $project_id;
$optimizeModel->insert($optimizeData);
}
//复制付费表
$paymentModel = new Payment();
$paymentData = $paymentModel::where('project_id', $this->param['project_id'])->first();
if(!empty($paymentData)){
$paymentData = $paymentData->getAttributes();
unset($paymentData['id']);
$paymentData['project_id'] = $project_id;
$paymentModel->insert($paymentData);
}
//复制售后表
$afterModel = new After();
$afterData = $afterModel::where('project_id', $this->param['project_id'])->first();
if(!empty($afterData)){
$afterData = $afterData->getAttributes();
unset($afterData['id']);
$afterData['project_id'] = $project_id;
$afterModel->insert($afterData);
}
//复制用户
$userModel = new UserModel();
$userData = $userModel::where('project_id', $this->param['project_id'])->where('role_id',0)->first();
if(!empty($userData)){
$userData = $userData->getAttributes();
unset($userData['id']);
$userData['project_id'] = $project_id;
$userModel->insert($userData);
}
//复制设置的模版
$settingTemplateModel = new Setting();
$settingData = $settingTemplateModel::where('project_id', $this->param['project_id'])->first();
if(!empty($settingData)){
$settingData = $settingData->getAttributes();
unset($settingData['id']);
$settingData['project_id'] = $project_id;
$settingTemplateModel->insert($settingData);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
if($type != 0){
$this->copyMysql($this->param['project_id'],$project_id);
}
<<<<<<< HEAD
//复制付费表
$paymentModel = new Payment();
$paymentData = $paymentModel::where('project_id', $this->param['project_id'])->first();
... ... @@ -600,6 +649,8 @@ class ProjectLogic extends BaseLogic
$settingTemplateModel->insert($settingData);
}
$this->copyMysql($this->param['project_id'],$project_id);
=======
>>>>>>> e1fa24b098cb6fa80fc919409b2426954c9a660b
return $this->success($data);
}
... ... @@ -647,4 +698,21 @@ class ProjectLogic extends BaseLogic
return true;
}
/**
* 获取AICC采集数据接口token
* @param $data
* @return string
* @author zbj
* @date 2023/11/10
*/
public function getAiccToken($data){
$project = $this->getCacheInfo($data['project_id']);
if(empty($project['site_token']) || !empty($data['refresh'])){
$token = strtolower(Str::random() . base64_encode("globalso_v6"));
$project->site_token = $token;
$project->save();
}
return $project->site_token;
}
}
... ...
... ... @@ -29,15 +29,11 @@ class UserLogic extends BaseLogic
*/
public function user_info()
{
$info = Common::get_user_cache($this->model, $this->param['id'], 'A');
if (empty($info)) {
$info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'operator_id']);
if ($info === false) {
$this->fail('当前数据不存在');
}
$info['project_name'] = (new Project())->read(['id' => $info['project_id']], ['title'])['title'];
Common::set_user_cache($info, $this->model, $this->param['id'], 'A');
$info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'operator_id']);
if ($info === false) {
$this->fail('当前数据不存在');
}
$info['project_name'] = (new Project())->read(['id' => $info['project_id']], ['title'])['title'];
return $this->success($info);
}
... ...
... ... @@ -181,10 +181,6 @@ class CustomTemplateLogic extends BaseLogic
'route'=>$info['url'],
];
$this->setRouteDeleteSave($data);
//"字符串以\"-product\"结尾"
if (!ends_with($route, "-tag")) {
$route = $route."-tag";
}
}
return $route;
}
... ...
... ... @@ -59,6 +59,7 @@ class KeywordLogic extends BaseLogic
}else{
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s');
$this->param['title'] = $this->param['title'].'-tag';
$this->param['updated_at'] = $this->param['created_at'];
$id = $this->model->insertGetId($this->param);
//路由映射
... ...
... ... @@ -36,8 +36,10 @@ class APublicModel extends Base
->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
$newsNumber = DB::connection('custom_mysql')->table('gl_news')
->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
$keyNumber = DB::connection('custom_mysql')->table('gl_product_keyword')
->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
DB::disconnect('custom_mysql');
return ['product'=>$productNumber,'blog'=>$blogNumber,'news'=>$newsNumber];
return ['product'=>$productNumber,'blog'=>$blogNumber,'news'=>$newsNumber,'key'=>$keyNumber];
}
}
... ...
... ... @@ -9,10 +9,115 @@
namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class ProjectUpdateTdk extends Base
{
//设置关联表名
protected $table = 'gl_project_update_tdk';
const STATUS_PENDING = 0;
const STATUS_SUCCESS = 1;
const STATUS_FAIL = 2;
/**
* 新建任务
* @param $project_id
* @author zbj
* @date 2023/11/9
*/
public static function add_task($project_id){
Redis::lpush('updateSeoTdk', $project_id);
$model = new self();
$model->project_id = $project_id;
$model->save();
}
/**
* 获取待处理任务
* @return mixed
* @author zbj
* @date 2023/11/9
*/
public static function getPendingTask(){
//有其他任务 就取其他任务 没有其他任务运行未结束的任务
$project_id = Redis::rpop('updateSeoTdk');
$data = [];
if($project_id){
$data = self::find($project_id);
}
if($data){
return $data;
}
return self::where('status', self::STATUS_PENDING)->orderBy('id', 'asc')->first();
}
/**
* 重试任务
* @param $id
* @param $remark
* @author zbj
* @date 2023/11/9
*/
public static function retry($id, $remark)
{
DB::beginTransaction();
try {
//行锁 避免脏读写
$data = self::where('id', $id)->lockForUpdate()->first();
$data->retry = $data->retry + 1;
if ($data->retry > 3) {
$data->status = self::STATUS_FAIL;
}else{
$data->status = self::STATUS_PENDING;
}
$data->remark = mb_substr($remark, 0, 250);
$data->save();
DB::commit();
} catch (\Exception $e) {
DB::rollback();
Log::error('project_update_tdk retry error:' . $e->getMessage());
}
}
/**
* 完成
* @param $id
* @param $update_data
* @author zbj
* @date 2023/11/9
*/
public static function finish($id, $update_data){
DB::beginTransaction();
try {
//行锁 避免脏读写
$data = self::where('id', $id)->lockForUpdate()->first();
$data->status = self::STATUS_SUCCESS;
foreach($update_data as $field => $item){
$old_date = Arr::s2a($data->$field);
$new_data = [];
foreach($item as $k=>$v){
if($k == 'total_page'){
$new_data[$k] = $v;
}else{
$new_data[$k] = $v + ($old_date[$k] ?? 0);
}
}
$data->$field = $new_data;
}
$data->save();
DB::commit();
} catch (\Exception $e) {
DB::rollback();
Log::error('project_update_tdk finish error:' . $e->getMessage());
}
}
}
... ...
... ... @@ -170,6 +170,7 @@ Route::middleware(['aloginauth'])->group(function () {
Route::any('/getRenewLog', [Aside\Project\ProjectController::class, 'getRenewLog'])->name('admin.project_getRenewLog');
Route::any('/tdkList', [Aside\Project\ProjectController::class, 'tdkList'])->name('admin.project_tdkList');
Route::any('/copyProject', [Aside\Project\ProjectController::class, 'copyProject'])->name('admin.project_copyProject');
Route::any('/site_token', [Aside\Project\ProjectController::class, 'site_token'])->name('admin.project_site_token');
//获取关键词前缀和后缀
Route::prefix('keyword')->group(function () {
Route::any('/getKeywordPrefix', [Aside\Project\KeywordPrefixController::class, 'getKeywordPrefix'])->name('admin.keyword_getKeywordPrefix');
... ...