Order.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. function getStatusLabelAttribute()
  56. {
  57. switch($this->attributes['status']){
  58. case -1:
  59. $status_label = '已关闭';
  60. break;
  61. case 1:
  62. $status_label = '已支付待确认';
  63. break;
  64. case 2:
  65. $status_label = '已完成';
  66. break;
  67. case 0:
  68. default:
  69. $status_label = '待支付';
  70. }
  71. return $status_label;
  72. }
  73. }