SmmPost.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Distributor\Repositories;
  3. use App\Models\SmmPost as Model;
  4. use Carbon\Carbon;
  5. use Dcat\Admin\Repositories\EloquentRepository;
  6. class SmmPost extends EloquentRepository
  7. {
  8. /**
  9. * Model.
  10. *
  11. * @var string
  12. */
  13. protected $eloquentClass = Model::class;
  14. /*
  15. * 插入数据
  16. */
  17. public static function create($post,$sendTime,$imageVideoUrl,$distId)
  18. {
  19. $model = new Model();
  20. // $model->send_type = $post['send_type'];
  21. $model->send_time = $sendTime;
  22. $model->message = $post['message'];
  23. $model->post_type = $post['post_type'];
  24. $model->account_ids = implode(',',$post['account_ids']);
  25. $model->image_video_url = $imageVideoUrl;
  26. $model->status = 0;
  27. $model->dist_id = $distId;
  28. $model->backup_field1 = json_encode([
  29. 'youtube_category' => $post['youtube_category'],
  30. 'yutube_title' => $post['yutube_title'],
  31. ]);
  32. $model->save();
  33. return $model->id;
  34. }
  35. /*
  36. * 找出状态 0 的数据
  37. */
  38. public static function getWaitPost()
  39. {
  40. $model = new Model();
  41. $model = $model->where('status',0)->get();
  42. return $model;
  43. }
  44. public static function getOssUploadPost()
  45. {
  46. $model = new Model();
  47. $model = $model->where('oss_upload',0)->get();
  48. return $model;
  49. }
  50. public static function hasOssUploadingPost()
  51. {
  52. $model = new Model();
  53. $result = $model->where('oss_upload',1)->first();
  54. if($result){
  55. //updated_at到现在时间大于10分钟,则认为已经上传失败
  56. $now = Carbon::now();
  57. $diff = $now->diffInMinutes($result->updated_at);
  58. if($diff > 10){
  59. $result->oss_upload = 0;//改为0,重新发送
  60. $result->updated_at = $now;
  61. $result->save();
  62. return true;
  63. }
  64. return true;
  65. } else {
  66. return false;
  67. }
  68. }
  69. public static function getPostById($id)
  70. {
  71. $model = new Model();
  72. $model = $model->where('id',$id)->first();
  73. return $model;
  74. }
  75. }