ReferralLog.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 ReferralLog extends Model
  13. {
  14. protected $table = 'referral_log';
  15. protected $casts = ['amount' => money::class, 'commission' => money::class];
  16. protected $guarded = [];
  17. public function scopeUid(Builder $query): Builder
  18. {
  19. return $query->whereInviterId(Auth::id());
  20. }
  21. public function invitee(): BelongsTo
  22. {
  23. return $this->belongsTo(User::class);
  24. }
  25. public function inviter(): BelongsTo
  26. {
  27. return $this->belongsTo(User::class);
  28. }
  29. public function order(): BelongsTo
  30. {
  31. return $this->belongsTo(Order::class);
  32. }
  33. public function getAmountTagAttribute(): string
  34. {
  35. return Helpers::getPriceTag($this->amount);
  36. }
  37. public function getCommissionTagAttribute(): string
  38. {
  39. return Helpers::getPriceTag($this->commission);
  40. }
  41. public function getStatusLabelAttribute(): string
  42. {
  43. return match ($this->attributes['status']) {
  44. 1 => '<span class="badge badge-sm badge-info">'.trans('common.status.applying').'</span>',
  45. 2 => '<span class="badge badge-sm badge-default">'.trans('common.status.withdrawn').'</span>',
  46. default => '<span class="badge badge-sm badge-success">'.trans('common.status.unwithdrawn').'</span>',
  47. };
  48. }
  49. }