ReferralApply.php 1.7 KB

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