moshaorui 18 hodín pred
rodič
commit
e2a7049f6f

+ 33 - 0
app/Console/Commands/TimerSsmPost.php

@@ -8,6 +8,7 @@ use App\Distributor\Repositories\SmmUserAccount;
 use App\Libraries\CommonHelper;
 use App\Services\SmmService;
 use Carbon\Carbon;
+use Dcat\Admin\Traits\HasUploadedFile;
 use Illuminate\Console\Command;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
@@ -35,6 +36,8 @@ class TimerSsmPost extends Command
     protected $description = '发送社媒帖子';
 
 
+    use HasUploadedFile;
+
     public function handle()
     {
         try {
@@ -42,6 +45,10 @@ class TimerSsmPost extends Command
             Log::info('开始生成发送帖子日志');
             $this->createLog();
 
+            //上传图片到oss
+            Log::info('开始上传图片到oss');
+            $this->ossUpload();
+
             //刷新access_token
             Log::info('开始刷新access_token');
             $this->refreshAccessToken();
@@ -49,6 +56,9 @@ class TimerSsmPost extends Command
             //发送社媒帖子开始
             Log::info('开始发送社媒帖子');
             $sendLog = SmmPostLog::getSendLog(5);
+
+
+
             $logIds = [];
             foreach ($sendLog as $log) {
                 Log::info('开始发送社媒帖子,id:'. $log->id);
@@ -195,4 +205,27 @@ class TimerSsmPost extends Command
         }
     }
 
+
+    public function ossUpload()
+    {
+        // 发送社媒帖子
+        $disk = $this->disk('oss');
+        $ossUploadPost = SmmPost::getOssUploadPost();
+        foreach ($ossUploadPost as $post) {
+            //上传图片到oss
+            $imageVideoUrl = explode(',', $post->image_video_url);
+            foreach ($imageVideoUrl as $key => $url) {
+                $localPath = toStoragePath($url);
+                $filename = basename($url);
+                $dir = dirname($url);
+                $disk->putFileAs($dir, $localPath, $filename);
+            }
+            $post->oss_upload = 1;
+            $post->save();
+        }
+    }
+
+
+
+
 }

+ 13 - 5
app/Distributor/Controllers/SmmPostController.php

@@ -72,6 +72,7 @@ class SmmPostController extends AdminDistController
                                 ->accept(config('admin.upload.oss_video.accept'))
                                 ->maxSize(120400)
                                 ->removable();
+                                //->chunked()
                         })
                         ->options([ 0=>admin_trans_label('images'), 1=>admin_trans_label('videos')])->default(0);
                     $this->stepLeaving($step,0);
@@ -153,18 +154,25 @@ class SmmPostController extends AdminDistController
      */
     public function upload() {
         try {
+            //保存到本地
+            $disk = $this->disk('local');
+            // 判断是否是删除文件请求
+            if ($this->isDeleteRequest()) {
+                // 删除文件并响应
+                return $this->deleteFileAndResponse($disk);
+            }
+
             // 获取上传的文件
             $file = $this->file();
             $dir = 'ssm/'.getDistributorId();
             $newName = md5(uniqid() . mt_rand()) .'.'.$file->getClientOriginalExtension();
 
-            //oss 保存
-            $disk = $this->disk('oss');
+            //保存在本地
             $result = $disk->putFileAs($dir, $file, $newName);
 
-            //保存到本地
-            $disk = $this->disk('local');
-            $result = $disk->putFileAs($dir, $file, $newName);
+            //oss 保存
+//            $disk = $this->disk('oss');
+//            $result = $disk->putFileAs($dir, $file, $newName);
 
             return $result
                 ? $this->responseUploaded($result, $disk->url($result))

+ 7 - 0
app/Distributor/Repositories/SmmPost.php

@@ -46,6 +46,13 @@ class SmmPost extends EloquentRepository
         return $model;
     }
 
+    public static function getOssUploadPost()
+    {
+        $model = new Model();
+        $model = $model->where('oss_upload',0)->get();
+        return $model;
+    }
+
     public static function getPostById($id)
     {
         $model = new Model();

+ 10 - 0
app/Distributor/Repositories/SmmPostLog.php

@@ -5,6 +5,7 @@ namespace App\Distributor\Repositories;
 use App\Models\SmmPostLog as Model;
 use Carbon\Carbon;
 use Dcat\Admin\Repositories\EloquentRepository;
+use Illuminate\Support\Facades\Log;
 
 class SmmPostLog extends EloquentRepository
 {
@@ -49,12 +50,21 @@ class SmmPostLog extends EloquentRepository
             $nowTime = Carbon::now();
             $diffTime = $nowTime->diffInMinutes($result->updated_at);
             if ($diffTime >= 30) {
+                Log::info('发送中的帖子超过30分钟,更新状态为3,发送失败');
                 $result->status = 3;
                 $result->request_count = $result->request_count + 1;
                 $result->save();
             }
+            Log::info('有正在发送中的帖子,返回[]');
             return [];
         }
+        //找出是否有帖子正在上传到Oss如果有,则不发送
+        $ossUploadPost = SmmPost::getOssUploadPost();
+        if ($ossUploadPost)  {
+            Log::info('有帖子正在上传到Oss如,不发送帖子');
+            return [];
+        }
+
         //找出待发送与发送失败的日志
         $result = $log->wherein('status', [0,3])->where('request_count', '<=', 2)->where('send_time', '<', Carbon::now())->limit($limit)->get();
         return $result;