UserCreditLog.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. /**
  6. * 账号余额操作日志.
  7. *
  8. * @property int $id
  9. * @property int $user_id 用户ID
  10. * @property int|null $order_id 订单ID
  11. * @property int $before 发生前余额,单位分
  12. * @property int $after 发生后金额,单位分
  13. * @property int $amount 发生金额,单位分
  14. * @property string|null $description 操作描述
  15. * @property \Illuminate\Support\Carbon $created_at 创建时间
  16. * @property-read \App\Models\Order|null $order
  17. * @property-read \App\Models\User $user
  18. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog newModelQuery()
  19. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog newQuery()
  20. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog query()
  21. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog whereAfter($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog whereAmount($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog whereBefore($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog whereCreatedAt($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog whereDescription($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog whereId($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog whereOrderId($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|UserCreditLog whereUserId($value)
  29. * @mixin \Eloquent
  30. */
  31. class UserCreditLog extends Model
  32. {
  33. public const UPDATED_AT = null;
  34. protected $table = 'user_credit_log';
  35. public function user(): BelongsTo
  36. {
  37. return $this->belongsTo(User::class);
  38. }
  39. public function order(): BelongsTo
  40. {
  41. return $this->belongsTo(Order::class);
  42. }
  43. public function getBeforeAttribute($value)
  44. {
  45. return $value / 100;
  46. }
  47. public function setBeforeAttribute($value)
  48. {
  49. return $this->attributes['before'] = $value * 100;
  50. }
  51. public function getAfterAttribute($value)
  52. {
  53. return $value / 100;
  54. }
  55. public function setAfterAttribute($value)
  56. {
  57. return $this->attributes['after'] = $value * 100;
  58. }
  59. public function getAmountAttribute($value)
  60. {
  61. return $value / 100;
  62. }
  63. public function setAmountAttribute($value)
  64. {
  65. return $this->attributes['amount'] = $value * 100;
  66. }
  67. }