作者 赵彬吉

update

@@ -11,6 +11,7 @@ use App\Models\Mail\Mail; @@ -11,6 +11,7 @@ use App\Models\Mail\Mail;
11 use App\Models\Project\DeployOptimize; 11 use App\Models\Project\DeployOptimize;
12 use App\Models\Project\ProjectUpdateTdk; 12 use App\Models\Project\ProjectUpdateTdk;
13 use App\Models\User\User; 13 use App\Models\User\User;
  14 +use App\Models\WebSetting\WebLanguage;
14 use App\Services\ProjectServer; 15 use App\Services\ProjectServer;
15 use Illuminate\Console\Command; 16 use Illuminate\Console\Command;
16 use Illuminate\Support\Facades\Cache; 17 use Illuminate\Support\Facades\Cache;
@@ -40,6 +41,8 @@ class UpdateSeoTdk extends Command @@ -40,6 +41,8 @@ class UpdateSeoTdk extends Command
40 */ 41 */
41 protected $description = '一键生成tdk'; 42 protected $description = '一键生成tdk';
42 43
  44 + protected $project;
  45 +
43 /** 46 /**
44 * Create a new command instance. 47 * Create a new command instance.
45 * 48 *
@@ -143,7 +146,7 @@ class UpdateSeoTdk extends Command @@ -143,7 +146,7 @@ class UpdateSeoTdk extends Command
143 146
144 echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL; 147 echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
145 try { 148 try {
146 - ProjectServer::useProject($project_id); 149 + $this->project = ProjectServer::useProject($project_id);
147 $this->seo_tdk($project_id, $task->id); 150 $this->seo_tdk($project_id, $task->id);
148 DB::disconnect('custom_mysql'); 151 DB::disconnect('custom_mysql');
149 }catch (\Exception $e){ 152 }catch (\Exception $e){
@@ -280,7 +283,6 @@ class UpdateSeoTdk extends Command @@ -280,7 +283,6 @@ class UpdateSeoTdk extends Command
280 } 283 }
281 284
282 public function getPrompt($project_id, $prompt, $table, $data){ 285 public function getPrompt($project_id, $prompt, $table, $data){
283 - $lang = '';  
284 if(strpos($prompt, '{topic}') !== false){ 286 if(strpos($prompt, '{topic}') !== false){
285 $topic = $data[$this->topic_fields[$table]] ?? ''; 287 $topic = $data[$this->topic_fields[$table]] ?? '';
286 if(!$topic){ 288 if(!$topic){
@@ -288,7 +290,6 @@ class UpdateSeoTdk extends Command @@ -288,7 +290,6 @@ class UpdateSeoTdk extends Command
288 return false; 290 return false;
289 } 291 }
290 $prompt = str_replace('{topic}', $topic, $prompt); 292 $prompt = str_replace('{topic}', $topic, $prompt);
291 - $lang = $this->getLang($topic);  
292 } 293 }
293 if(strpos($prompt, '{keyword}') !== false) { 294 if(strpos($prompt, '{keyword}') !== false) {
294 $keyword = $this->mainKeywords($project_id, 1); 295 $keyword = $this->mainKeywords($project_id, 1);
@@ -297,7 +298,6 @@ class UpdateSeoTdk extends Command @@ -297,7 +298,6 @@ class UpdateSeoTdk extends Command
297 return false; 298 return false;
298 } 299 }
299 $prompt = str_replace('{keyword}', $keyword, $prompt); 300 $prompt = str_replace('{keyword}', $keyword, $prompt);
300 - !$lang && $lang = $this->getLang($keyword);  
301 } 301 }
302 if(strpos($prompt, '{company name}') !== false) { 302 if(strpos($prompt, '{company name}') !== false) {
303 $company_name = $this->companyName($project_id); 303 $company_name = $this->companyName($project_id);
@@ -307,8 +307,7 @@ class UpdateSeoTdk extends Command @@ -307,8 +307,7 @@ class UpdateSeoTdk extends Command
307 } 307 }
308 $prompt = str_replace('{company name}', $company_name, $prompt); 308 $prompt = str_replace('{company name}', $company_name, $prompt);
309 } 309 }
310 - $prompt .= '.Please answer in ' . ($lang ?: 'English');  
311 - 310 + $prompt .= '.Please answer in ' . $this->getLang();
312 return $prompt; 311 return $prompt;
313 } 312 }
314 313
@@ -365,14 +364,9 @@ class UpdateSeoTdk extends Command @@ -365,14 +364,9 @@ class UpdateSeoTdk extends Command
365 return $str; 364 return $str;
366 } 365 }
367 366
368 - public function getLang($content){  
369 - $result = Translate::translateSl($content);  
370 - if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) {  
371 - $lang = Translate::$tls_list[$result['texts']['sl']]['lang_en'];  
372 - } else {  
373 - $lang = 'English';  
374 - }  
375 - return $lang; 367 + public function getLang(){
  368 + $lang = WebLanguage::getLangById($this->project['main_lang_id']??1);
  369 + return $lang['english'] ?? 'English';
376 } 370 }
377 371
378 /** 372 /**
@@ -10,8 +10,26 @@ @@ -10,8 +10,26 @@
10 namespace App\Models\WebSetting; 10 namespace App\Models\WebSetting;
11 11
12 use App\Models\Base; 12 use App\Models\Base;
  13 +use Illuminate\Support\Facades\Cache;
13 14
14 class WebLanguage extends Base 15 class WebLanguage extends Base
15 { 16 {
16 protected $table = 'gl_web_language'; 17 protected $table = 'gl_web_language';
  18 +
  19 +
  20 + /**
  21 + * @param $id
  22 + * @return mixed
  23 + * @author zbj
  24 + * @date 2023/12/11
  25 + */
  26 + public static function getLangById($id){
  27 + $cache_key = 'lang_'.$id;
  28 + $lang = Cache::get($cache_key);
  29 + if(!$lang){
  30 + $lang = self::find($id);
  31 + Cache::put($cache_key, $lang, 7200);
  32 + }
  33 + return $lang;
  34 + }
17 } 35 }