Order.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 订单
  6. * Class Order
  7. *
  8. * @package App\Http\Models
  9. */
  10. class Order extends Model
  11. {
  12. protected $table = 'order';
  13. protected $primaryKey = 'oid';
  14. function user()
  15. {
  16. return $this->hasOne(User::class, 'id', 'user_id');
  17. }
  18. function goods()
  19. {
  20. return $this->hasOne(Goods::class, 'id', 'goods_id');
  21. }
  22. function coupon()
  23. {
  24. return $this->hasOne(Coupon::class, 'id', 'coupon_id');
  25. }
  26. function payment()
  27. {
  28. return $this->hasOne(Payment::class, 'oid', 'oid');
  29. }
  30. function getOriginAmountAttribute($value)
  31. {
  32. return $value / 100;
  33. }
  34. function setOriginAmountAttribute($value)
  35. {
  36. return $this->attributes['origin_amount'] = $value * 100;
  37. }
  38. function getAmountAttribute($value)
  39. {
  40. return $value / 100;
  41. }
  42. function setAmountAttribute($value)
  43. {
  44. return $this->attributes['amount'] = $value * 100;
  45. }
  46. }