From 8ae79f5d7ec099abc5d3a385cf5e96e4b3301556 Mon Sep 17 00:00:00 2001 From: chengxl Date: Fri, 23 May 2025 10:33:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=85=AC=E4=BC=97=E5=8F=B7?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Cronwechat.php | 64 +++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/application/api/controller/Cronwechat.php b/application/api/controller/Cronwechat.php index 81b57d3..e0ee6be 100644 --- a/application/api/controller/Cronwechat.php +++ b/application/api/controller/Cronwechat.php @@ -113,7 +113,7 @@ class Cronwechat extends Controller //日志记录 $aLog = []; foreach ($aWechatArticle as $value) { - $aLogInfo = ['article_id' => $value,'type' => 3,'msg' =>'','status' => 1,'create_time' => time()]; + $aLogInfo = ['article_id' => $value['article_id'],'type' => 3,'msg' =>'','status' => 1,'create_time' => time()]; if(empty($value['media_id'])){ $sMsg = '需要发布的文章:'.$value['article_id']."未查询到media_id\n\n"; $aLogInfo['status'] = 2; @@ -127,14 +127,13 @@ class Cronwechat extends Controller $aResult = json_decode($oAiarticle->publishDraft($aUploadParm),true); $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; $sMsg = empty($aResult['msg']) ? '操作异常'."\n" : $aResult['msg']."\n"; + $aLogInfo['msg'] = $sMsg; if($iStatus != 1){ - $aLogInfo['msg'] = $sMsg; $aLogInfo['status'] = 2; $aLog[] = $aLogInfo; $this->showMessage('文章ID:'.$value.'====='.$sMsg."\n",2); continue; } - $aLogInfo['msg'] = $sMsg; $aLog[] = $aLogInfo; } //插入操作日志 @@ -146,6 +145,65 @@ class Cronwechat extends Controller } $this->showMessage('AI生成的文章发布草稿箱完成:'.$sDate."\n",1); } + + /** + * 查询微信公众号草稿箱的AI文章已发布的文章状态 + * + * @return void + */ + public function queryWechatArticleStatus(){ + + $aParam = $this->request->post(); + //获取前一天日期 + $sDate = empty($aParam['date']) ? date('Y-m-d', strtotime('-1 day')) : $aParam['date']; + //获取AI生成的文章 + $sStartDate = strtotime($sDate.' 00:00:00'); + //结束时间 + $sEndDate = strtotime($sDate.'23:59:59'); + //查询条件 + $aWhere = ['is_publish' => 1,'publish_id' => ['<>',''],'publish_status' => 1,'is_delete' => 2,'update_time' => ['between',[$sStartDate,$sEndDate]]]; + + //查询已发布文章信息 + $aWechatArticle = Db::name('ai_wechat_article')->where($aWhere)->field('id,article_id,template_id,wechat_id,publish_id')->select(); + if(empty($aWechatArticle)){ + $this->showMessage('未查询到需要发布的文章:'.$sDate."\n\n",2); + exit; + } + + //数据处理 + $aLog = []; + $oAiarticle = new Aiarticle; + foreach ($aWechatArticle as $key => $value) { + $aLogInfo = ['article_id' => $value['article_id'],'type' => 4,'msg' =>'','status' => 1,'create_time' => time()]; + if(empty($value['wechat_id']) || empty($value['publish_id'])){ + $sMsg = '需要查询的文章:'.$value['article_id']."wechat_id或publish_id\n\n"; + $aLogInfo['status'] = 2; + $aLogInfo['msg'] = $sMsg; + $aLog[] = $aLogInfo; + $this->showMessage($sMsg,2); + continue; + } + $aResult = json_decode($oAiarticle->queryStatus($value),true); + $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; + $sMsg = empty($aResult['msg']) ? '操作异常'."\n" : $aResult['msg']."\n"; + $aLogInfo['msg'] = $sMsg; + if($iStatus != 1){ + $aLogInfo['msg'] = $sMsg; + $aLogInfo['status'] = 2; + $this->showMessage('文章ID:'.$value.'====='.$sMsg."\n",2); + continue; + } + $aLog[] = $aLogInfo; + } + //插入操作日志 + if(!empty($aLog)){ + $result = Db::name('wechat_crontab_log')->insertAll($aLog); + if($result === false){ + $this->showMessage('插入日志记录失败:'.json_encode($aLog)."\n",2); + } + } + $this->showMessage('AI生成的文章发布状态查询完成:'.$sDate."\n",1); + } /** * * 格式化信息输出