ReferralApply.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Models;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * 返利申请.
  8. */
  9. class ReferralApply extends Model
  10. {
  11. protected $table = 'referral_apply';
  12. protected $casts = ['link_logs' => 'array'];
  13. public function scopeUid($query)
  14. {
  15. return $query->whereUserId(Auth::id());
  16. }
  17. public function user(): BelongsTo
  18. {
  19. return $this->belongsTo(User::class);
  20. }
  21. public function referral_logs()
  22. {
  23. return ReferralLog::whereIn('id', $this->link_logs);
  24. }
  25. public function getBeforeAttribute($value)
  26. {
  27. return $value / 100;
  28. }
  29. public function setBeforeAttribute($value): void
  30. {
  31. $this->attributes['before'] = $value * 100;
  32. }
  33. public function getAfterAttribute($value)
  34. {
  35. return $value / 100;
  36. }
  37. public function setAfterAttribute($value): void
  38. {
  39. $this->attributes['after'] = $value * 100;
  40. }
  41. public function getAmountAttribute($value)
  42. {
  43. return $value / 100;
  44. }
  45. public function setAmountAttribute($value): void
  46. {
  47. $this->attributes['amount'] = $value * 100;
  48. }
  49. }