Payment.php 1.2 KB

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