作者 lyh
... ... @@ -268,30 +268,9 @@ class ProjectUpdate extends Command
}
//分类
$category_id = '';
//产品类型,2Featured Products,3Hot Products
$product_type = '';
if ($item['category'] ?? []) {
$type_arr = [];
$new_category = [];
foreach ($item['category'] as $cate) {
if ($cate['parent'] == 0 && $cate['name'] == 'Featured Products') {
$type_arr[] = 2;
} elseif ($cate['parent'] == 0 && $cate['name'] == 'Hot Products') {
$type_arr[] = 3;
} else {
$new_category[] = $cate['id'];
}
}
if ($type_arr) {
$product_type = ',' . implode(',', $type_arr);
}
if ($new_category) {
$category_arr = $category_model->list(['original_id' => ['in', $new_category]]);
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
}
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
}
try {
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
... ... @@ -303,7 +282,6 @@ class ProjectUpdate extends Command
'category_id' => $category_id,
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
'gallery' => Arr::a2s($gallery),
'product_type' => $product_type,
'seo_mate' => Arr::a2s([
'title' => $item['ttile'],
'keyword' => $item['keywords'] ?? '',
... ... @@ -467,7 +445,7 @@ class ProjectUpdate extends Command
DB::disconnect('custom_mysql');
$task->status = UpdateLog::STATUS_COM;//同步完成
if($is_flush){
if ($is_flush) {
$task->collect_status = UpdateLog::COLLECT_STATUS_UN;
}
$task->save();
... ...
... ... @@ -11,6 +11,7 @@ use App\Models\Mail\Mail;
use App\Models\Project\DeployOptimize;
use App\Models\Project\ProjectUpdateTdk;
use App\Models\User\User;
use App\Models\WebSetting\WebLanguage;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
... ... @@ -40,6 +41,8 @@ class UpdateSeoTdk extends Command
*/
protected $description = '一键生成tdk';
protected $project;
/**
* Create a new command instance.
*
... ... @@ -143,7 +146,7 @@ class UpdateSeoTdk extends Command
echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
try {
ProjectServer::useProject($project_id);
$this->project = ProjectServer::useProject($project_id);
$this->seo_tdk($project_id, $task->id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
... ... @@ -280,7 +283,6 @@ class UpdateSeoTdk extends Command
}
public function getPrompt($project_id, $prompt, $table, $data){
$lang = '';
if(strpos($prompt, '{topic}') !== false){
$topic = $data[$this->topic_fields[$table]] ?? '';
if(!$topic){
... ... @@ -288,7 +290,6 @@ class UpdateSeoTdk extends Command
return false;
}
$prompt = str_replace('{topic}', $topic, $prompt);
$lang = $this->getLang($topic);
}
if(strpos($prompt, '{keyword}') !== false) {
$keyword = $this->mainKeywords($project_id, 1);
... ... @@ -297,7 +298,6 @@ class UpdateSeoTdk extends Command
return false;
}
$prompt = str_replace('{keyword}', $keyword, $prompt);
!$lang && $lang = $this->getLang($keyword);
}
if(strpos($prompt, '{company name}') !== false) {
$company_name = $this->companyName($project_id);
... ... @@ -307,8 +307,7 @@ class UpdateSeoTdk extends Command
}
$prompt = str_replace('{company name}', $company_name, $prompt);
}
$prompt .= '.Please answer in ' . ($lang ?: 'English');
$prompt .= '.Please answer in ' . $this->getLang();
return $prompt;
}
... ... @@ -365,14 +364,9 @@ class UpdateSeoTdk extends Command
return $str;
}
public function getLang($content){
$result = Translate::translateSl($content);
if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) {
$lang = Translate::$tls_list[$result['texts']['sl']]['lang_en'];
} else {
$lang = 'English';
}
return $lang;
public function getLang(){
$lang = WebLanguage::getLangById($this->project['main_lang_id']??1);
return $lang['english'] ?? 'English';
}
/**
... ...
... ... @@ -8,6 +8,7 @@ use App\Helper\Translate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Ai\AiCommand;
use App\Models\Project\DeployOptimize;
use App\Models\WebSetting\WebLanguage;
use Illuminate\Support\Facades\Cache;
class AiCommandLogic extends BaseLogic
... ... @@ -58,8 +59,8 @@ class AiCommandLogic extends BaseLogic
if(trim($ai_command->ai) == '{core keywords 8}'){
$ai_send = false;
}else{
$lang = $this->getLang($this->param['keywords']);
$prompt .= '.Please answer in ' . ($lang ?: 'English');
$lang = WebLanguage::getLangById($this->project['main_lang_id']??1)['english'] ?? 'English';
$prompt .= '.Please answer in ' . $lang;
$ai_send = true;
}
... ...
... ... @@ -10,8 +10,26 @@
namespace App\Models\WebSetting;
use App\Models\Base;
use Illuminate\Support\Facades\Cache;
class WebLanguage extends Base
{
protected $table = 'gl_web_language';
/**
* @param $id
* @return mixed
* @author zbj
* @date 2023/12/11
*/
public static function getLangById($id){
$cache_key = 'lang_'.$id;
$lang = Cache::get($cache_key);
if(!$lang){
$lang = self::find($id);
Cache::put($cache_key, $lang, 7200);
}
return $lang;
}
}
... ...