作者 刘锟

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

... ... @@ -2,10 +2,14 @@
namespace App\Console\Commands\AyrShare;
use App\Helper\AyrShare as AyrShareHelper;
use App\Models\Ai\AiVideo;
use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
use App\Models\Project\AiVideoTask;
use App\Services\ProjectServer;
use Carbon\Carbon;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ShareUser extends Command
{
... ... @@ -32,6 +36,7 @@ class ShareUser extends Command
public function handle()
{
echo $this->user_operator_record();
return true;
}
/**
... ... @@ -46,6 +51,7 @@ class ShareUser extends Command
$ayr_release = new AyrReleaseModel();
$ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=','']]);
foreach ($ayr_share_list as $v){
echo date('Y-m-d H:i:s').'执行数据的邮箱--'.$v['title'].PHP_EOL;
$time = Carbon::now()->modify('-1 days')->toDateString();
//创建时间小于7天前的当前时间
if($v['created_at'] > $time){
... ... @@ -60,15 +66,24 @@ class ShareUser extends Command
continue;
}
//查询7天是否发送博文
$release_info = $this->release_seven_info($ayr_release);
$release_info = $this->release_seven_info($ayr_release,$v);
//有发送博文,则跳出循环
if($release_info !== false){
echo '7天内有推文跳过。'.date('Y-m-d H:i:s').PHP_EOL;
continue;
}
$aiVideoInfo = $this->aiVideoInfo($v['project_id'] ?? 0);
if($aiVideoInfo !== false){
echo '7天内有ai视频推送跳过。'.date('Y-m-d H:i:s').PHP_EOL;
continue;
}
//删除用户第三方配置
if(!empty($v['profile_key'])){
$this->del_profiles($v);
$res = $this->del_profiles($v);
if($res === false){
//删除失败-跳过
continue;
}
}
//更新数据库
$this->save_ayr_share($ayr_share_model,$v);
... ... @@ -90,8 +105,8 @@ class ShareUser extends Command
];
$res = $ayr_share_helper->deleted_profiles($data_profiles);
if($res['status'] == 'fail'){
echo '第三方删除失败';
return true;
echo '第三方删除失败'.json_encode($data_profiles,true);
return false;
}
return true;
}
... ... @@ -138,11 +153,30 @@ class ShareUser extends Command
* @method :post
* @time :2023/6/14 16:28
*/
public function release_seven_info(&$ayr_release){
public function release_seven_info(&$ayr_release,$v){
//查看用户是否在一周内有发送博客
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]]]);
$release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]],'share_id'=>$v['id']]);
return $release_info;
}
/**
* @remark :7天内是否推送了ai视频
* @name :aiVidoe
* @author :lyh
* @method :post
* @time :2025/9/22 17:13
*/
public function aiVideoInfo($project_id)
{
if($project_id == 0){
return false;
}
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$aiVideoModel = new AiVideoTask();
$videoInfo = $aiVideoModel->read(['project_id'=>$project_id,'next_auto_date'=>null,'created_at'=>['between',[$start_at,$end_at]]]);
return $videoInfo;
}
}
... ...
... ... @@ -17,6 +17,7 @@ use App\Models\Project\AggregateKeywordAffix;
use App\Models\Project\AiBlogTask;
use App\Models\Project\DeployBuild;
use App\Models\Project\KeywordPrefix;
use App\Models\Project\Payment;
use App\Models\Project\Project;
use App\Models\Project\ProjectAiSetting;
use App\Models\Project\ProjectWhiteHatAffix;
... ... @@ -50,7 +51,17 @@ class lyhDemo extends Command
protected $description = '更新路由';
public function handle(){
return $this->_actionRoute();
$projectModel = new Payment();
$lists = $projectModel->list(['renewal_record'=>['not like','"expire_at": null']]);
foreach ($lists as $item){
foreach ($item['renewal_record'] as $key => $val){
if(!isset($val['end_time']) && !empty($val['expire_at'])){
$val['end_time'] = $val['expire_at'];
}
$item['renewal_record'][$key] = $val;
}
$projectModel->edit(['renewal_record'=>json_encode($item['renewal_record'],true)],['id'=>$item['id']]);
}
return true;
}
... ...
... ... @@ -1588,4 +1588,27 @@ if (!function_exists('httpGetSsl')) {
$result = json_decode($res, true);
return is_array($result) ? $result : $res;
}
/**
* @remark :截取自付出啊
* @name :truncate_words
* @author :lyh
* @method :post
* @time :2025/9/22 14:46
*/
function truncate_text($text, $limit = 300) {
// 长度小于限制直接返回
if (mb_strlen($text, 'UTF-8') <= $limit) {
return $text;
}
// 先取前 $limit 个字符
$truncated = mb_substr($text, 0, $limit, 'UTF-8');
// 如果这一段包含空格(说明有英文单词),尽量在最后一个空格处截断
$lastSpace = mb_strrpos($truncated, ' ', 0, 'UTF-8');
if ($lastSpace !== false) {
// 在最后一个空格处截断,避免英文单词被截断
$truncated = mb_substr($truncated, 0, $lastSpace, 'UTF-8');
}
return $truncated;
}
}
... ...
... ... @@ -229,13 +229,11 @@ class AiBlogController extends BaseController
'image'=>['required'],
'author_id'=>['required'],
'text'=>['required'],
'description'=>['required'],
],[
'new_title.required' => '标题不能为空',
'image.required' => '缩略图不能为空',
'author_id.required' => '作者id不能为空',
'text.required' => '作者id不能为空',
'description.required' => '短描述不能为空',
'text.required' => '内容不能为空',
]);
$data = $aiBlogLogic->customSaveBlog($this->param);
$this->response('success',Code::SUCCESS,$data);
... ...
... ... @@ -182,6 +182,7 @@ class ProjectLogic extends BaseLogic
$this->setAiBlog($this->param['id'],$this->param['main_lang_id'],$this->param['is_ai_blog'] ?? 0,
$this->param['company']??"", $this->param['deploy_optimize']['company_en_name'] ?? '',
$this->param['deploy_optimize']['company_en_description'] ?? '',$this->param['is_ai_video'] ?? 0,$this->param['is_related_video'] ?? 0);
$this->param = $this->getPaymentRamainDay($this->param);
//保存项目信息
$this->saveProject($this->param);
//保存建站部署信息
... ... @@ -412,6 +413,53 @@ class ProjectLogic extends BaseLogic
}
/**
* @remark :推广续费网站设置剩余服务时常
* @name :getPaymentRamainDay
* @author :lyh
* @method :post
* @time :2025/9/22 11:13
*/
public function getPaymentRamainDay($param)
{
// 推广续费网站单独处理
if (in_array($param['type'] ,[2,3,4])) {
// 先找到 expire_at 不为 null 的记录
$validRecords = array_filter(
$param['payment']['renewal_record'] ?? [],
fn($item) => !is_null($item['expire_at'] ?? null)
);
$maxExpireAt = null;
if ($validRecords) {
// 取出最大日期
$maxExpireAt = max(array_column($validRecords, 'expire_at'));
}
if (!$maxExpireAt) {
return $this->success($param);
}
// 遍历原始 renewal_record(用引用,方便写回)
foreach ($param['payment']['renewal_record'] as &$record) {
if (!is_null($record['expire_at'] ?? null) && $record['expire_at'] === $maxExpireAt) {
// 如果 end_time 不存在或与 expire_at 不一致,则更新
if (!isset($record['end_time']) || $record['end_time'] != $record['expire_at']) {
$record['end_time'] = $record['expire_at']; // ✅ 写回原数据
// 重新计算剩余天数
$diff = (strtotime($record['expire_at']) - strtotime(date('Y-m-d'))) / (60 * 60 * 24);
if ($param['project_type'] == Project::PROJECT_TYPE_SEO) {
$param['deploy_build']['seo_service_duration'] = $diff + $param['deploy_build']['seo_service_duration'];
} else {
$param['deploy_build']['service_duration'] = $diff + $param['deploy_build']['service_duration'];
}
}
break; // 找到后跳出循环
}
}
unset($record); // 释放引用
}
return $this->success($param);
}
/**
* @remark :保存项目
* @name :setExtendType
* @author :lyh
... ... @@ -751,24 +799,6 @@ class ProjectLogic extends BaseLogic
//改为异步
NoticeLog::createLog(NoticeLog::TYPE_INIT_PROJECT, ['project_id' => $param['id']]);
}
//推广续费网站单独处理
if($param['type'] == Project::TYPE_FOUR){
// 提取非 null 的 expire_at 字段
$validDates = array_filter(
array_column($param['payment']['renewal_record'] ?? [], 'expire_at'),
fn($date) => !is_null($date)
);
// 获取最大日期(如果有)
$maxExpireAt = $validDates ? max($validDates) : null;
if(!empty($maxExpireAt)){
$diff = (strtotime($maxExpireAt) - strtotime($param['uptime'] ?? date('Y-m-d'))) / (60 * 60 * 24);
if($param['project_type'] == Project::PROJECT_TYPE_SEO){
$param['deploy_build']['seo_service_duration'] = $diff;
}else{
$param['deploy_build']['service_duration'] = $diff;
}
}
}
return $this->success($param);
}
... ...
... ... @@ -179,6 +179,9 @@ class AiBlogLogic extends BaseLogic
'title'=>$param['new_title'], 'thumb'=>$param['image'], 'foreword'=>$param['description'] ?? '',
'author_id'=>$this->param['author_id'], 'url'=>$param['route'],
];
if(!isset($param['description']) || empty($param['description'])){
$param['description'] = truncate_text($param['text']);
}
if(isset($param['id']) && !empty($param['id'])){
$id = $param['id'];
$data['task_id'] = $param['task_id'];
... ... @@ -196,13 +199,6 @@ class AiBlogLogic extends BaseLogic
$text1 = Common::deal_str($text1);
$param['seo_keyword'] = $text1;
}
if(!isset($param['description']) || empty($param['description'])){
$ai = "According to the keyword {$param['title']}, write a seo meta description show to purchaser within 100 characters";
$text2 = Gpt::instance()->openai_chat_qqs($ai);
$text2 = Common::deal_keywords($text2);
$text2 = Common::deal_str($text2);
$param['description'] = $text2;
}
$param['route'] = RouteMap::setRoute($param['route'], RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']);
$this->model->edit($param,['id'=>$param['id']]);
}else{
... ...