UserCreditLog.php 2.0 KB

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