UserHourlyDataFlow.php 845 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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(
  28. 'created_at',
  29. '>=',
  30. date('Y-m-d H:55')
  31. );
  32. }
  33. }