Payment.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Models;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 支付单
  7. * Class Payment
  8. *
  9. * @package App\Http\Models
  10. * @mixin \Eloquent
  11. */
  12. class Payment extends Model
  13. {
  14. protected $table = 'payment';
  15. protected $primaryKey = 'id';
  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->belongsTo(User::class, 'user_id', 'id');
  24. }
  25. function order()
  26. {
  27. return $this->belongsTo(Order::class, 'oid', 'oid');
  28. }
  29. function getAmountAttribute($value)
  30. {
  31. return $value / 100;
  32. }
  33. function setAmountAttribute($value)
  34. {
  35. return $this->attributes['amount'] = $value * 100;
  36. }
  37. // 订单状态
  38. function getStatusLabelAttribute()
  39. {
  40. switch ($this->attributes['status']) {
  41. case -1:
  42. $status_label = '支付失败';
  43. break;
  44. case 1:
  45. $status_label = '支付成功';
  46. break;
  47. case 0:
  48. default:
  49. $status_label = '等待支付';
  50. }
  51. return $status_label;
  52. }
  53. // 支付方式
  54. function getPayWayLabelAttribute()
  55. {
  56. switch ($this->attributes['pay_way']) {
  57. case 1:
  58. $pay_way_label = '微信';
  59. break;
  60. case 2:
  61. default:
  62. $pay_way_label = '支付宝';
  63. }
  64. return $pay_way_label;
  65. }
  66. }