作者 赵彬吉

update

... ... @@ -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';
}
/**
... ...
... ... @@ -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;
}
}
... ...