Order.php 1.7 KB

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