moshaorui 1 өдөр өмнө
parent
commit
cd42944aeb

+ 8 - 2
app/Console/Commands/TimerSsmPost.php

@@ -58,6 +58,12 @@ class TimerSsmPost extends Command
                     Log::info('twitter可发送时间未到,暂时无法发送,ID'.$log->post_id);
                     continue;
                 }
+                //发送社媒帖子中
+                $log->status = 1;//发送中
+                $log->updated_at = Carbon::now();
+                $log->save();
+                //发送社媒帖子中 end
+
                 $logIds[] = $log->id;
                 //获取帖子内容
                 $post = SmmPost::getPostById($log->post_id);
@@ -86,14 +92,14 @@ class TimerSsmPost extends Command
                 $responseIds = isset($response['data']['responseIds'])? $response['data']['responseIds'] : [];
                 //更新post_logs表
                 if ($response['status'] == true) {
-                    $log->status = 1;
+                    $log->status = 2;//发送成功
                     $log->response_ids = json_encode($responseIds);
                     $log->updated_at = Carbon::now();
                     $log->send_time = Carbon::now();
                     $log->request_count = $log->request_count + 1;
                     $log->save();
                 } else {
-                    $log->status = 2;
+                    $log->status = 3;//发送失败
                     $log->remark = $response['data'];
                     $log->updated_at = Carbon::now();
                     $log->send_time = Carbon::now();

+ 3 - 2
app/Distributor/Controllers/SmmPostLogController.php

@@ -39,8 +39,9 @@ class SmmPostLogController extends AdminController
             $grid->column('created_at');
             $grid->column('status')->using(admin_trans_array(config('dictionary.post_log_status')))->label([
                 0 => 'gray',
-                1 => 'success',
-                2 => 'orange1',
+                1 => 'info',
+                2 => 'success',
+                3 => 'orange1',
             ]);
             //$grid->column('remark')->width('15%');
             $grid->column('send_time', admin_trans_label('etd'))->sortable();

+ 14 - 1
app/Distributor/Repositories/SmmPostLog.php

@@ -43,7 +43,20 @@ class SmmPostLog extends EloquentRepository
     public static function getSendLog($limit = 5)
     {
         $log = new Model();
-        $logs = $log->wherein('status', [0,2])->where('request_count', '<=', 2)->where('send_time', '<', Carbon::now())->limit($limit)->get();
+        $logs = $log->where('status', 1)->first();//查找状态为1的日志,发送中的日志
+        if ($logs) {
+            //updated_at与当前时间差距30分钟以上,则更新日志状态为3
+            $nowTime = Carbon::now();
+            $diffTime = $nowTime->diffInMinutes($logs->updated_at);
+            if ($diffTime >= 30) {
+                $logs->status = 3;
+                $log->request_count = $log->request_count + 1;
+                $logs->save();
+            }
+            return [];
+        }
+        //找出待发送与发送失败的日志
+        $logs = $log->wherein('status', [0,3])->where('request_count', '<=', 2)->where('send_time', '<', Carbon::now())->limit($limit)->get();
         return $logs;
     }
 

+ 3 - 2
config/dictionary.php

@@ -117,8 +117,9 @@ return [
 
     'post_log_status' => [
         0 => 'pending_to_send',
-        1 => 'success',
-        2 => 'failure',
+        1 => 'Sending',
+        2 => 'success',
+        3 => 'failure',
     ],
 
 ];

+ 1 - 0
lang/zh_CN/global.php

@@ -246,6 +246,7 @@ return [
         'success'              => '成功',
         'failed'               => '失败',
         'send_post'              => '发送帖子',
+        'Sending'              => '发送中',
     ],
     'options' => [
         //