Payment.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. }
  49. return $status_label;
  50. }
  51. // 支付方式
  52. public function getPayWayLabelAttribute()
  53. {
  54. switch ($this->attributes['pay_way']) {
  55. case 1:
  56. $pay_way_label = '微信';
  57. break;
  58. case 2:
  59. default:
  60. $pay_way_label = '支付宝';
  61. }
  62. return $pay_way_label;
  63. }
  64. }