ReferralApply.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. protected $guarded = [];
  14. public function scopeUid($query)
  15. {
  16. return $query->whereUserId(Auth::id());
  17. }
  18. public function user(): BelongsTo
  19. {
  20. return $this->belongsTo(User::class);
  21. }
  22. public function referral_logs()
  23. {
  24. return ReferralLog::whereIn('id', $this->link_logs);
  25. }
  26. public function getBeforeAttribute($value)
  27. {
  28. return $value / 100;
  29. }
  30. public function setBeforeAttribute($value): void
  31. {
  32. $this->attributes['before'] = $value * 100;
  33. }
  34. public function getAfterAttribute($value)
  35. {
  36. return $value / 100;
  37. }
  38. public function setAfterAttribute($value): void
  39. {
  40. $this->attributes['after'] = $value * 100;
  41. }
  42. public function getAmountAttribute($value)
  43. {
  44. return $value / 100;
  45. }
  46. public function setAmountAttribute($value): void
  47. {
  48. $this->attributes['amount'] = $value * 100;
  49. }
  50. public function getStatusLabelAttribute(): string
  51. {
  52. switch ($this->attributes['status']) {
  53. case 1:
  54. $status_label = '<span class="badge badge-sm badge-info">'.trans('user.status.pending').'</span>';
  55. break;
  56. case 2:
  57. $status_label = trans('user.status.withdrawn');
  58. break;
  59. case 0:
  60. default:
  61. $status_label = '<span class="badge badge-sm badge-warning">'.trans('user.status.applying').'</span>';
  62. }
  63. return $status_label;
  64. }
  65. }