作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -41,17 +41,15 @@ class UpdateProgress extends Command @@ -41,17 +41,15 @@ class UpdateProgress extends Command
41 public function handle() 41 public function handle()
42 { 42 {
43 $project_id = Redis::rpop('updateProgress'); 43 $project_id = Redis::rpop('updateProgress');
44 - while ($project_id){  
45 - echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;  
46 - try {  
47 - ProjectServer::useProject($project_id);  
48 - $this->getUpdateProgress($project_id);  
49 - DB::disconnect('custom_mysql');  
50 - }catch (\Exception $e){  
51 - echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;  
52 - }  
53 - echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL; 44 + echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
  45 + try {
  46 + ProjectServer::useProject($project_id);
  47 + $this->getUpdateProgress($project_id);
  48 + DB::disconnect('custom_mysql');
  49 + }catch (\Exception $e){
  50 + echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
54 } 51 }
  52 + echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
55 } 53 }
56 54
57 /** 55 /**
@@ -143,7 +143,7 @@ class UpdateSeoTdk extends Command @@ -143,7 +143,7 @@ class UpdateSeoTdk extends Command
143 $this->seo_tdk($project_id); 143 $this->seo_tdk($project_id);
144 DB::disconnect('custom_mysql'); 144 DB::disconnect('custom_mysql');
145 }catch (\Exception $e){ 145 }catch (\Exception $e){
146 - echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; 146 + echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
147 } 147 }
148 echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL; 148 echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
149 } 149 }
@@ -255,7 +255,7 @@ class UpdateSeoTdk extends Command @@ -255,7 +255,7 @@ class UpdateSeoTdk extends Command
255 } 255 }
256 if($json_field){ 256 if($json_field){
257 $old_data = json_decode($v[$field_arr[0]], true); 257 $old_data = json_decode($v[$field_arr[0]], true);
258 - foreach ($old_data as $kk=>$vv){ 258 + foreach ($old_data ?: [] as $kk=>$vv){
259 empty($data[$json_field][$kk]) && $data[$json_field][$kk] = $vv; 259 empty($data[$json_field][$kk]) && $data[$json_field][$kk] = $vv;
260 } 260 }
261 $data[$json_field] = json_encode($data[$json_field]); 261 $data[$json_field] = json_encode($data[$json_field]);
@@ -366,6 +366,7 @@ class UpdateSeoTdk extends Command @@ -366,6 +366,7 @@ class UpdateSeoTdk extends Command
366 public function ai_send($prompt) 366 public function ai_send($prompt)
367 { 367 {
368 $text = Gpt::instance()->openai_chat_qqs($prompt); 368 $text = Gpt::instance()->openai_chat_qqs($prompt);
  369 + echo 'GPT result:' . $text . PHP_EOL;
369 $text = Common::deal_keywords($text); 370 $text = Common::deal_keywords($text);
370 return Common::deal_str($text); 371 return Common::deal_str($text);
371 } 372 }
@@ -74,7 +74,7 @@ class Common @@ -74,7 +74,7 @@ class Common
74 if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) { 74 if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) {
75 $lang = Translate::$tls_list[$result['texts']['sl']]['text']; 75 $lang = Translate::$tls_list[$result['texts']['sl']]['text'];
76 } else { 76 } else {
77 - $lang = 'Chinese'; 77 + $lang = 'English';
78 } 78 }
79 } 79 }
80 $str = 'Please answer in '.$lang; 80 $str = 'Please answer in '.$lang;
@@ -14,9 +14,20 @@ use Illuminate\Support\Facades\Log; @@ -14,9 +14,20 @@ use Illuminate\Support\Facades\Log;
14 */ 14 */
15 class Gpt 15 class Gpt
16 { 16 {
17 - public $api = 'http://openai.waimaoq.com/'; 17 + /**
  18 + * 头
  19 + * @var string[]
  20 + */
  21 + public $header = [
  22 + 'apikey' => 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6',
  23 + 'X-CmerApi-Host' => 'bizopenai.p.cmer.com',
  24 + ];
18 25
19 - public $header = []; 26 + /**
  27 + * 请求域名
  28 + * @var string
  29 + */
  30 + public $api = 'https://api.cmer.com';
20 31
21 private static $instance; 32 private static $instance;
22 33
@@ -35,7 +46,7 @@ class Gpt @@ -35,7 +46,7 @@ class Gpt
35 */ 46 */
36 public function openai_chat_qqs($content, $system_content = '') 47 public function openai_chat_qqs($content, $system_content = '')
37 { 48 {
38 - $url = $this->api . 'v2/openai_chat_qqs'; 49 + $url = $this->api . '/v1/openai_chat';
39 50
40 $data = [ 51 $data = [
41 'messages' => [], 52 'messages' => [],
@@ -57,9 +68,10 @@ class Gpt @@ -57,9 +68,10 @@ class Gpt
57 ->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json') 68 ->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json')
58 ->post($url); 69 ->post($url);
59 $json = $result->json(); 70 $json = $result->json();
60 - if (!isset($json['text'])) { 71 + if (!isset($json['text']) || $json['code'] !==200) {
61 Log::error('openai_chat_qqs data:', $data); 72 Log::error('openai_chat_qqs data:', $data);
62 Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json); 73 Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json);
  74 + $json = [];
63 } 75 }
64 } catch (\Throwable $e) { 76 } catch (\Throwable $e) {
65 Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage()); 77 Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage());
@@ -555,3 +555,8 @@ if(!function_exists('curlGet')){ @@ -555,3 +555,8 @@ if(!function_exists('curlGet')){
555 return json_decode($access_txt, true); 555 return json_decode($access_txt, true);
556 } 556 }
557 } 557 }
  558 +
  559 +function ends_with($string, $suffix)
  560 +{
  561 + return substr($string, -strlen($suffix)) === $suffix;
  562 +}
@@ -182,7 +182,7 @@ class CustomTemplateLogic extends BaseLogic @@ -182,7 +182,7 @@ class CustomTemplateLogic extends BaseLogic
182 ]; 182 ];
183 $this->setRouteDeleteSave($data); 183 $this->setRouteDeleteSave($data);
184 //"字符串以\"-product\"结尾" 184 //"字符串以\"-product\"结尾"
185 - if (!endsWith($route, "-tag")) { 185 + if (!ends_with($route, "-tag")) {
186 $route = $route."-tag"; 186 $route = $route."-tag";
187 } 187 }
188 } 188 }
@@ -108,6 +108,7 @@ class KeywordLogic extends BaseLogic @@ -108,6 +108,7 @@ class KeywordLogic extends BaseLogic
108 try { 108 try {
109 $idArr = []; 109 $idArr = [];
110 foreach ($this->param['title'] as $v){ 110 foreach ($this->param['title'] as $v){
  111 + $this->model = new Keyword();
111 $info = $this->model->read(['title'=>$v]); 112 $info = $this->model->read(['title'=>$v]);
112 if($info === false){ 113 if($info === false){
113 $param['project_id'] = $this->user['project_id']; 114 $param['project_id'] = $this->user['project_id'];
@@ -120,6 +121,7 @@ class KeywordLogic extends BaseLogic @@ -120,6 +121,7 @@ class KeywordLogic extends BaseLogic
120 } 121 }
121 //批量生成路由 122 //批量生成路由
122 foreach ($idArr as $v){ 123 foreach ($idArr as $v){
  124 + $this->model = new Keyword();
123 $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']); 125 $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']);
124 $this->model->edit(['route'=>$route],['id'=>$v['id']]); 126 $this->model->edit(['route'=>$route],['id'=>$v['id']]);
125 } 127 }
@@ -216,7 +216,7 @@ class ProductLogic extends BaseLogic @@ -216,7 +216,7 @@ class ProductLogic extends BaseLogic
216 ]; 216 ];
217 $this->setRouteDeleteSave($data); 217 $this->setRouteDeleteSave($data);
218 //"字符串以\"-product\"结尾" 218 //"字符串以\"-product\"结尾"
219 - if (!endsWith($route, "-product")) { 219 + if (!ends_with($route, "-product")) {
220 $route = $route."-product"; 220 $route = $route."-product";
221 } 221 }
222 } 222 }