ReferralApply.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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(): ReferralLog|\Illuminate\Database\Query\Builder
  27. {
  28. return ReferralLog::whereIn('id', $this->link_logs);
  29. }
  30. protected function amountTag(): Attribute
  31. {
  32. return Attribute::make(
  33. get: fn () => Helpers::getPriceTag($this->amount),
  34. );
  35. }
  36. protected function statusLabel(): Attribute
  37. {
  38. return Attribute::make(
  39. get: fn () => match ($this->status) {
  40. 1 => '<span class="badge badge-sm badge-info">'.trans('common.status.pending').'</span>',
  41. 2 => trans('common.status.withdrawn'),
  42. default => '<span class="badge badge-sm badge-warning">'.trans('common.status.applying').'</span>',
  43. },
  44. );
  45. }
  46. }