作者 lyh
@@ -268,30 +268,9 @@ class ProjectUpdate extends Command @@ -268,30 +268,9 @@ class ProjectUpdate extends Command
268 } 268 }
269 //分类 269 //分类
270 $category_id = ''; 270 $category_id = '';
271 - //产品类型,2Featured Products,3Hot Products  
272 - $product_type = '';  
273 -  
274 if ($item['category'] ?? []) { 271 if ($item['category'] ?? []) {
275 - $type_arr = [];  
276 - $new_category = [];  
277 - foreach ($item['category'] as $cate) {  
278 - if ($cate['parent'] == 0 && $cate['name'] == 'Featured Products') {  
279 - $type_arr[] = 2;  
280 - } elseif ($cate['parent'] == 0 && $cate['name'] == 'Hot Products') {  
281 - $type_arr[] = 3;  
282 - } else {  
283 - $new_category[] = $cate['id'];  
284 - }  
285 - }  
286 -  
287 - if ($type_arr) {  
288 - $product_type = ',' . implode(',', $type_arr);  
289 - }  
290 -  
291 - if ($new_category) {  
292 - $category_arr = $category_model->list(['original_id' => ['in', $new_category]]);  
293 - $category_id = $logic->getLastCategory(array_column($category_arr, 'id'));  
294 - } 272 + $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
  273 + $category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
295 } 274 }
296 try { 275 try {
297 $item['ttile'] = $this->special2str($item['ttile'] ?? ''); 276 $item['ttile'] = $this->special2str($item['ttile'] ?? '');
@@ -303,7 +282,6 @@ class ProjectUpdate extends Command @@ -303,7 +282,6 @@ class ProjectUpdate extends Command
303 'category_id' => $category_id, 282 'category_id' => $category_id,
304 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', 283 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
305 'gallery' => Arr::a2s($gallery), 284 'gallery' => Arr::a2s($gallery),
306 - 'product_type' => $product_type,  
307 'seo_mate' => Arr::a2s([ 285 'seo_mate' => Arr::a2s([
308 'title' => $item['ttile'], 286 'title' => $item['ttile'],
309 'keyword' => $item['keywords'] ?? '', 287 'keyword' => $item['keywords'] ?? '',
@@ -467,7 +445,7 @@ class ProjectUpdate extends Command @@ -467,7 +445,7 @@ class ProjectUpdate extends Command
467 DB::disconnect('custom_mysql'); 445 DB::disconnect('custom_mysql');
468 446
469 $task->status = UpdateLog::STATUS_COM;//同步完成 447 $task->status = UpdateLog::STATUS_COM;//同步完成
470 - if($is_flush){ 448 + if ($is_flush) {
471 $task->collect_status = UpdateLog::COLLECT_STATUS_UN; 449 $task->collect_status = UpdateLog::COLLECT_STATUS_UN;
472 } 450 }
473 $task->save(); 451 $task->save();
@@ -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 /**
@@ -8,6 +8,7 @@ use App\Helper\Translate; @@ -8,6 +8,7 @@ use App\Helper\Translate;
8 use App\Http\Logic\Bside\BaseLogic; 8 use App\Http\Logic\Bside\BaseLogic;
9 use App\Models\Ai\AiCommand; 9 use App\Models\Ai\AiCommand;
10 use App\Models\Project\DeployOptimize; 10 use App\Models\Project\DeployOptimize;
  11 +use App\Models\WebSetting\WebLanguage;
11 use Illuminate\Support\Facades\Cache; 12 use Illuminate\Support\Facades\Cache;
12 13
13 class AiCommandLogic extends BaseLogic 14 class AiCommandLogic extends BaseLogic
@@ -58,8 +59,8 @@ class AiCommandLogic extends BaseLogic @@ -58,8 +59,8 @@ class AiCommandLogic extends BaseLogic
58 if(trim($ai_command->ai) == '{core keywords 8}'){ 59 if(trim($ai_command->ai) == '{core keywords 8}'){
59 $ai_send = false; 60 $ai_send = false;
60 }else{ 61 }else{
61 - $lang = $this->getLang($this->param['keywords']);  
62 - $prompt .= '.Please answer in ' . ($lang ?: 'English'); 62 + $lang = WebLanguage::getLangById($this->project['main_lang_id']??1)['english'] ?? 'English';
  63 + $prompt .= '.Please answer in ' . $lang;
63 $ai_send = true; 64 $ai_send = true;
64 } 65 }
65 66
@@ -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 }