Invite.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Models;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. /**
  8. * 邀请码
  9. */
  10. class Invite extends Model
  11. {
  12. use SoftDeletes;
  13. protected $table = 'invite';
  14. protected $dates = ['dateline', 'deleted_at'];
  15. protected $guarded = [];
  16. public function scopeUid($query)
  17. {
  18. return $query->whereInviterId(Auth::id());
  19. }
  20. public function inviter(): BelongsTo
  21. {
  22. return $this->belongsTo(User::class);
  23. }
  24. public function invitee(): BelongsTo
  25. {
  26. return $this->belongsTo(User::class);
  27. }
  28. public function getStatusLabelAttribute(): string
  29. {
  30. switch ($this->attributes['status']) {
  31. case 0:
  32. $status_label = '<span class="badge badge-success">'.trans('user.status.unused').'</span>';
  33. break;
  34. case 1:
  35. $status_label = '<span class="badge badge-danger">'.trans('user.status.used').'</span>';
  36. break;
  37. case 2:
  38. $status_label = '<span class="badge badge-default">'.trans('user.status.expired').'</span>';
  39. break;
  40. default:
  41. $status_label = '<span class="badge badge-default"> 未知 </span>';
  42. }
  43. return $status_label;
  44. }
  45. }