UserHourlyDataFlow.php 796 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. /**
  6. * 用户流量每小时统计
  7. */
  8. class UserHourlyDataFlow extends Model
  9. {
  10. public const UPDATED_AT = null;
  11. protected $table = 'user_hourly_data_flow';
  12. public function user(): BelongsTo
  13. {
  14. return $this->belongsTo(User::class);
  15. }
  16. public function node(): BelongsTo
  17. {
  18. return $this->belongsTo(Node::class);
  19. }
  20. // 用户每时使用总流量
  21. public function scopeUserHourly($query, $uid)
  22. {
  23. return $query->whereUserId($uid)->whereNodeId(0);
  24. }
  25. public function scopeUserRecentUsed($query, $uid)
  26. {
  27. return $query->userHourly($uid)->where('created_at', '>=', date('Y-m-d H:55'));
  28. }
  29. }