Order.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. */
  13. class Order extends Model
  14. {
  15. protected $table = 'order';
  16. protected $primaryKey = 'oid';
  17. protected $appends = ['status_label'];
  18. function scopeUid($query)
  19. {
  20. return $query->where('user_id', Auth::user()->id);
  21. }
  22. function user()
  23. {
  24. return $this->hasOne(User::class, 'id', 'user_id');
  25. }
  26. function goods()
  27. {
  28. return $this->hasOne(Goods::class, 'id', 'goods_id')->withTrashed();
  29. }
  30. function coupon()
  31. {
  32. return $this->hasOne(Coupon::class, 'id', 'coupon_id')->withTrashed();
  33. }
  34. function payment()
  35. {
  36. return $this->hasOne(Payment::class, 'oid', 'oid');
  37. }
  38. function getOriginAmountAttribute($value)
  39. {
  40. return $value/100;
  41. }
  42. function setOriginAmountAttribute($value)
  43. {
  44. return $this->attributes['origin_amount'] = $value*100;
  45. }
  46. function getAmountAttribute($value)
  47. {
  48. return $value/100;
  49. }
  50. function setAmountAttribute($value)
  51. {
  52. return $this->attributes['amount'] = $value*100;
  53. }
  54. function getStatusLabelAttribute()
  55. {
  56. switch($this->attributes['status']){
  57. case -1:
  58. $status_label = '已关闭';
  59. break;
  60. case 1:
  61. $status_label = '已支付待确认';
  62. break;
  63. case 2:
  64. $status_label = '已完成';
  65. break;
  66. case 0:
  67. default:
  68. $status_label = '待支付';
  69. }
  70. return $status_label;
  71. }
  72. }