Order.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Http\Models;
  3. use Auth;
  4. use Eloquent;
  5. use Illuminate\Database\Eloquent\Builder;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Support\Carbon;
  8. /**
  9. * 订单
  10. * Class Order
  11. *
  12. * @package App\Http\Models
  13. * @mixin Eloquent
  14. * @property-read mixed $status_label
  15. * @property int $oid
  16. * @property string $order_sn 订单编号
  17. * @property int $user_id 操作人
  18. * @property int $goods_id 商品ID
  19. * @property int $coupon_id 优惠券ID
  20. * @property string|null $email 邮箱
  21. * @property int $origin_amount 订单原始总价,单位分
  22. * @property int $amount 订单总价,单位分
  23. * @property string|null $expire_at 过期时间
  24. * @property int $is_expire 是否已过期:0-未过期、1-已过期
  25. * @property int $pay_way 支付方式:1-余额支付、2-有赞云支付
  26. * @property int $status 订单状态:-1-已关闭、0-待支付、1-已支付待确认、2-已完成
  27. * @property Carbon|null $created_at 创建时间
  28. * @property Carbon|null $updated_at 最后一次更新时间
  29. * @property-read Coupon $coupon
  30. * @property-read Goods $goods
  31. * @property-read Payment $payment
  32. * @property-read User $user
  33. * @method static Builder|Order newModelQuery()
  34. * @method static Builder|Order newQuery()
  35. * @method static Builder|Order query()
  36. * @method static Builder|Order uid()
  37. * @method static Builder|Order whereAmount($value)
  38. * @method static Builder|Order whereCouponId($value)
  39. * @method static Builder|Order whereCreatedAt($value)
  40. * @method static Builder|Order whereEmail($value)
  41. * @method static Builder|Order whereExpireAt($value)
  42. * @method static Builder|Order whereGoodsId($value)
  43. * @method static Builder|Order whereIsExpire($value)
  44. * @method static Builder|Order whereOid($value)
  45. * @method static Builder|Order whereOrderSn($value)
  46. * @method static Builder|Order whereOriginAmount($value)
  47. * @method static Builder|Order wherePayWay($value)
  48. * @method static Builder|Order whereStatus($value)
  49. * @method static Builder|Order whereUpdatedAt($value)
  50. * @method static Builder|Order whereUserId($value)
  51. */
  52. class Order extends Model
  53. {
  54. protected $table = 'order';
  55. protected $primaryKey = 'oid';
  56. protected $appends = ['status_label'];
  57. function scopeUid($query)
  58. {
  59. return $query->where('user_id', Auth::user()->id);
  60. }
  61. function user()
  62. {
  63. return $this->hasOne(User::class, 'id', 'user_id');
  64. }
  65. function goods()
  66. {
  67. return $this->hasOne(Goods::class, 'id', 'goods_id')->withTrashed();
  68. }
  69. function coupon()
  70. {
  71. return $this->hasOne(Coupon::class, 'id', 'coupon_id')->withTrashed();
  72. }
  73. function payment()
  74. {
  75. return $this->hasOne(Payment::class, 'oid', 'oid');
  76. }
  77. function getOriginAmountAttribute($value)
  78. {
  79. return $value/100;
  80. }
  81. function setOriginAmountAttribute($value)
  82. {
  83. return $this->attributes['origin_amount'] = $value*100;
  84. }
  85. function getAmountAttribute($value)
  86. {
  87. return $value/100;
  88. }
  89. function setAmountAttribute($value)
  90. {
  91. return $this->attributes['amount'] = $value*100;
  92. }
  93. }