UserCreditLog.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. /**
  6. * 账号余额操作日志.
  7. */
  8. class UserCreditLog extends Model
  9. {
  10. public const UPDATED_AT = null;
  11. protected $table = 'user_credit_log';
  12. protected $guarded = [];
  13. public function user(): BelongsTo
  14. {
  15. return $this->belongsTo(User::class);
  16. }
  17. public function order(): BelongsTo
  18. {
  19. return $this->belongsTo(Order::class);
  20. }
  21. public function getBeforeAttribute($value)
  22. {
  23. return $value / 100;
  24. }
  25. public function setBeforeAttribute($value)
  26. {
  27. return $this->attributes['before'] = $value * 100;
  28. }
  29. public function getAfterAttribute($value)
  30. {
  31. return $value / 100;
  32. }
  33. public function setAfterAttribute($value)
  34. {
  35. return $this->attributes['after'] = $value * 100;
  36. }
  37. public function getAmountAttribute($value)
  38. {
  39. return $value / 100;
  40. }
  41. public function setAmountAttribute($value)
  42. {
  43. return $this->attributes['amount'] = $value * 100;
  44. }
  45. }