ReferralApply.php 1.4 KB

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