Payment.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Models;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * 支付单.
  8. */
  9. class Payment extends Model
  10. {
  11. protected $table = 'payment';
  12. protected $guarded = [];
  13. public function scopeUid($query)
  14. {
  15. return $query->whereUserId(Auth::id());
  16. }
  17. public function user(): BelongsTo
  18. {
  19. return $this->belongsTo(User::class);
  20. }
  21. public function order(): BelongsTo
  22. {
  23. return $this->belongsTo(Order::class);
  24. }
  25. public function getAmountAttribute($value)
  26. {
  27. return $value / 100;
  28. }
  29. public function setAmountAttribute($value)
  30. {
  31. return $this->attributes['amount'] = $value * 100;
  32. }
  33. // 订单状态
  34. public function getStatusLabelAttribute(): string
  35. {
  36. switch ($this->attributes['status']) {
  37. case -1:
  38. $status_label = '支付失败';
  39. break;
  40. case 1:
  41. $status_label = '支付成功';
  42. break;
  43. case 0:
  44. default:
  45. $status_label = '等待支付';
  46. }
  47. return $status_label;
  48. }
  49. }