Order.php 1.5 KB

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