Payment.php 1.6 KB

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