作者 刘锟

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

... ... @@ -15,6 +15,7 @@ use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* 初始化项目
... ... @@ -149,7 +150,7 @@ class UpdateSeoTdk extends Command
echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
ProjectUpdateTdk::retry($task->id, $e->getMessage());
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
}
}
... ... @@ -162,18 +163,25 @@ class UpdateSeoTdk extends Command
$ai_commands = Arr::setValueToKey($ai_commands, 'key');
foreach ($this->maps as $table => $map) {
$update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0];
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL . json_encode($update[$table]);
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
$list = DB::connection('custom_mysql')->table($table)->get();
if (!empty($list)) {
$list = $list->toArray();
foreach ($list as $v) {
echo '打印数据:'.date('Y-m-d H:i:s') . $update[$table]['total_page'].PHP_EOL;
$update[$table]['total_page']++;
$v = (array)$v;
echo date('Y-m-d H:i:s') . '更新--' . $table . ':id' . $v['id'] . PHP_EOL;
//缓存 在处理的项目数据 id
$cache_key = "seo_tdk_{$project_id}_{$table}_{$v['id']}";
if(!Redis::setnx($cache_key, 1)){
continue;
}
Redis::expire($cache_key, 120);
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
$data = [];
$json_field = '';
echo date('Y-m-d H:i:s') . json_encode($map) . PHP_EOL;
foreach ($map as $ai_key => $field) {
$field_arr = explode('.', $field);
if (count($field_arr) > 1) {
... ... @@ -188,14 +196,6 @@ class UpdateSeoTdk extends Command
continue;
}
//缓存 在处理的 项目 数据 id
$cache_key = "seo_tdk_{$project_id}_{$table}_{$v['id']}";
if(Cache::get($cache_key)){
echo '其他进程在处理' . PHP_EOL;
continue;
}
Cache::put($cache_key, 1, 120);
//AI生成
if (!empty($ai_commands[$ai_key]['ai'])) {
$prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v);
... ... @@ -307,8 +307,6 @@ class UpdateSeoTdk extends Command
}
$prompt .= '.Please answer in ' . ($lang ?: 'English');
echo $prompt . PHP_EOL;
return $prompt;
}
... ... @@ -375,7 +373,6 @@ 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);
}
... ...
... ... @@ -67,6 +67,13 @@ class ProjectLogic extends BaseLogic
if($info['extend_type'] != 0){
$info['type'] = $info['extend_type'];
}
//升级项目初始上传配置
if(empty($info['upload_config'])){
$info['upload_config'] =["upload_max_num"=>100, "allow_file_type"=>"doc,docx,xls,xlsx,pdf,txt,csv,png,jpg,jpeg", "upload_max_size"=>5];
}
if(empty($info['channel'])){
$info['channel'] = ["user_id"=>"", "zone_id"=>"", "channel_id"=>""];
}
return $this->success($info);
}
... ... @@ -525,9 +532,12 @@ class ProjectLogic extends BaseLogic
* @time :2023/11/8 14:23
*/
public function copyProject(){
DB::beginTransaction();
try {
//复制初始项目
$data = $this->model::where('id', $this->param['project_id'])->first();
$data = $data->getAttributes();
$type = $data['type'];
$data['type'] = 0;
$data['title'] = $data['title'].'-copy';
unset($data['id']);
... ... @@ -562,6 +572,15 @@ class ProjectLogic extends BaseLogic
$paymentData['project_id'] = $project_id;
$paymentModel->insert($paymentData);
}
//复制售后表
$afterModel = new After();
$afterData = $afterModel::where('project_id', $this->param['project_id'])->first();
if(!empty($afterData)){
$afterData = $afterData->getAttributes();
unset($afterData['id']);
$afterData['project_id'] = $project_id;
$afterModel->insert($afterData);
}
//复制用户
$userModel = new UserModel();
$userData = $userModel::where('project_id', $this->param['project_id'])->where('role_id',0)->first();
... ... @@ -580,7 +599,14 @@ class ProjectLogic extends BaseLogic
$settingData['project_id'] = $project_id;
$settingTemplateModel->insert($settingData);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
if($type != 0){
$this->copyMysql($this->param['project_id'],$project_id);
}
return $this->success($data);
}
... ...
... ... @@ -13,6 +13,7 @@ use App\Helper\Arr;
use App\Models\Base;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class ProjectUpdateTdk extends Base
{
... ... @@ -30,6 +31,7 @@ class ProjectUpdateTdk extends Base
* @date 2023/11/9
*/
public static function add_task($project_id){
Redis::lpush('updateSeoTdk', $project_id);
$model = new self();
$model->project_id = $project_id;
$model->save();
... ... @@ -42,6 +44,15 @@ class ProjectUpdateTdk extends Base
* @date 2023/11/9
*/
public static function getPendingTask(){
//有其他任务 就取其他任务 没有其他任务运行未结束的任务
$project_id = Redis::rpop('updateSeoTdk');
$data = [];
if($project_id){
$data = self::find($project_id);
}
if($data){
return $data;
}
return self::where('status', self::STATUS_PENDING)->orderBy('id', 'asc')->first();
}
... ...