ReferralApply.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Models;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * 返利申请.
  8. */
  9. class ReferralApply extends Model
  10. {
  11. protected $table = 'referral_apply';
  12. protected $casts = ['link_logs' => 'array'];
  13. public function scopeUid($query)
  14. {
  15. return $query->whereUserId(Auth::id());
  16. }
  17. public function user(): BelongsTo
  18. {
  19. return $this->belongsTo(User::class);
  20. }
  21. public function referral_logs()
  22. {
  23. return ReferralLog::whereIn('id', $this->link_logs);
  24. }
  25. public function getBeforeAttribute($value)
  26. {
  27. return $value / 100;
  28. }
  29. public function setBeforeAttribute($value): void
  30. {
  31. $this->attributes['before'] = $value * 100;
  32. }
  33. public function getAfterAttribute($value)
  34. {
  35. return $value / 100;
  36. }
  37. public function setAfterAttribute($value): void
  38. {
  39. $this->attributes['after'] = $value * 100;
  40. }
  41. public function getAmountAttribute($value)
  42. {
  43. return $value / 100;
  44. }
  45. public function setAmountAttribute($value): void
  46. {
  47. $this->attributes['amount'] = $value * 100;
  48. }
  49. public function getStatusLabelAttribute(): string
  50. {
  51. switch ($this->attributes['status']) {
  52. case 1:
  53. $status_label = '<span class="badge badge-sm badge-info">'.trans('user.status.pending').'</span>';
  54. break;
  55. case 2:
  56. $status_label = trans('user.status.withdrawn');
  57. break;
  58. case 0:
  59. default:
  60. $status_label = '<span class="badge badge-sm badge-warning">'.trans('user.status.applying').'</span>';
  61. }
  62. return $status_label;
  63. }
  64. }