Payment.php 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. protected $table = 'payment';
  11. protected $fillable = ['qr_code', 'url', 'status'];
  12. public function scopeUid($query) {
  13. return $query->whereUserId(Auth::id());
  14. }
  15. public function user(): BelongsTo {
  16. return $this->belongsTo(User::class);
  17. }
  18. public function order(): BelongsTo {
  19. return $this->belongsTo(Order::class);
  20. }
  21. public function getAmountAttribute($value) {
  22. return $value / 100;
  23. }
  24. public function setAmountAttribute($value) {
  25. return $this->attributes['amount'] = $value * 100;
  26. }
  27. // 订单状态
  28. public function getStatusLabelAttribute(): string {
  29. switch($this->attributes['status']){
  30. case -1:
  31. $status_label = '支付失败';
  32. break;
  33. case 1:
  34. $status_label = '支付成功';
  35. break;
  36. case 0:
  37. default:
  38. $status_label = '等待支付';
  39. }
  40. return $status_label;
  41. }
  42. }