ReferralApply.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Models;
  3. use App\Casts\money;
  4. use App\Utils\Helpers;
  5. use Auth;
  6. use Illuminate\Database\Eloquent\Builder;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  9. /**
  10. * 返利申请.
  11. */
  12. class ReferralApply extends Model
  13. {
  14. protected $table = 'referral_apply';
  15. protected $casts = ['before' => money::class, 'after' => money::class, 'amount' => money::class, 'link_logs' => 'array'];
  16. protected $guarded = [];
  17. public function scopeUid(Builder $query): Builder
  18. {
  19. return $query->whereUserId(Auth::id());
  20. }
  21. public function user(): BelongsTo
  22. {
  23. return $this->belongsTo(User::class);
  24. }
  25. public function referral_logs(): ReferralLog|\Illuminate\Database\Query\Builder
  26. {
  27. return ReferralLog::whereIn('id', $this->link_logs);
  28. }
  29. public function getAmountTagAttribute(): string
  30. {
  31. return Helpers::getPriceTag($this->amount);
  32. }
  33. public function getStatusLabelAttribute(): string
  34. {
  35. return match ($this->attributes['status']) {
  36. 1 => '<span class="badge badge-sm badge-info">'.trans('common.status.pending').'</span>',
  37. 2 => trans('common.status.withdrawn'),
  38. default => '<span class="badge badge-sm badge-warning">'.trans('common.status.applying').'</span>',
  39. };
  40. }
  41. }