Payment.php 1.4 KB

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