作者 刘锟

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

... ... @@ -41,17 +41,15 @@ class UpdateProgress extends Command
public function handle()
{
$project_id = Redis::rpop('updateProgress');
while ($project_id){
echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
try {
ProjectServer::useProject($project_id);
$this->getUpdateProgress($project_id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
try {
ProjectServer::useProject($project_id);
$this->getUpdateProgress($project_id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
}
/**
... ...
... ... @@ -143,7 +143,7 @@ class UpdateSeoTdk extends Command
$this->seo_tdk($project_id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
}
... ... @@ -255,7 +255,7 @@ class UpdateSeoTdk extends Command
}
if($json_field){
$old_data = json_decode($v[$field_arr[0]], true);
foreach ($old_data as $kk=>$vv){
foreach ($old_data ?: [] as $kk=>$vv){
empty($data[$json_field][$kk]) && $data[$json_field][$kk] = $vv;
}
$data[$json_field] = json_encode($data[$json_field]);
... ... @@ -366,6 +366,7 @@ class UpdateSeoTdk extends Command
public function ai_send($prompt)
{
$text = Gpt::instance()->openai_chat_qqs($prompt);
echo 'GPT result:' . $text . PHP_EOL;
$text = Common::deal_keywords($text);
return Common::deal_str($text);
}
... ...
... ... @@ -74,7 +74,7 @@ class Common
if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) {
$lang = Translate::$tls_list[$result['texts']['sl']]['text'];
} else {
$lang = 'Chinese';
$lang = 'English';
}
}
$str = 'Please answer in '.$lang;
... ...
... ... @@ -14,9 +14,20 @@ use Illuminate\Support\Facades\Log;
*/
class Gpt
{
public $api = 'http://openai.waimaoq.com/';
/**
* 头
* @var string[]
*/
public $header = [
'apikey' => 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6',
'X-CmerApi-Host' => 'bizopenai.p.cmer.com',
];
public $header = [];
/**
* 请求域名
* @var string
*/
public $api = 'https://api.cmer.com';
private static $instance;
... ... @@ -35,7 +46,7 @@ class Gpt
*/
public function openai_chat_qqs($content, $system_content = '')
{
$url = $this->api . 'v2/openai_chat_qqs';
$url = $this->api . '/v1/openai_chat';
$data = [
'messages' => [],
... ... @@ -57,9 +68,10 @@ class Gpt
->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json')
->post($url);
$json = $result->json();
if (!isset($json['text'])) {
if (!isset($json['text']) || $json['code'] !==200) {
Log::error('openai_chat_qqs data:', $data);
Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json);
$json = [];
}
} catch (\Throwable $e) {
Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage());
... ...
... ... @@ -555,3 +555,8 @@ if(!function_exists('curlGet')){
return json_decode($access_txt, true);
}
}
function ends_with($string, $suffix)
{
return substr($string, -strlen($suffix)) === $suffix;
}
... ...
... ... @@ -182,7 +182,7 @@ class CustomTemplateLogic extends BaseLogic
];
$this->setRouteDeleteSave($data);
//"字符串以\"-product\"结尾"
if (!endsWith($route, "-tag")) {
if (!ends_with($route, "-tag")) {
$route = $route."-tag";
}
}
... ...
... ... @@ -108,6 +108,7 @@ class KeywordLogic extends BaseLogic
try {
$idArr = [];
foreach ($this->param['title'] as $v){
$this->model = new Keyword();
$info = $this->model->read(['title'=>$v]);
if($info === false){
$param['project_id'] = $this->user['project_id'];
... ... @@ -120,6 +121,7 @@ class KeywordLogic extends BaseLogic
}
//批量生成路由
foreach ($idArr as $v){
$this->model = new Keyword();
$route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$v['id']]);
}
... ...
... ... @@ -216,7 +216,7 @@ class ProductLogic extends BaseLogic
];
$this->setRouteDeleteSave($data);
//"字符串以\"-product\"结尾"
if (!endsWith($route, "-product")) {
if (!ends_with($route, "-product")) {
$route = $route."-product";
}
}
... ...