Order.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. * @property-read \App\Http\Models\Coupon $coupon
  10. * @property mixed $amount
  11. * @property mixed $origin_amount
  12. * @property-read mixed $status_label
  13. * @property-read \App\Http\Models\Goods $goods
  14. * @property-read \App\Http\Models\Payment $payment
  15. * @property-read \App\Http\Models\User $user
  16. * @mixin \Eloquent
  17. */
  18. class Order extends Model
  19. {
  20. protected $table = 'order';
  21. protected $primaryKey = 'oid';
  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');
  29. }
  30. function coupon()
  31. {
  32. return $this->hasOne(Coupon::class, 'id', 'coupon_id');
  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. public 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. }