Order.php 1.1 KB

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