PayOrdersModel.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Models;
  3. /**
  4. * 充值缴费订单模型
  5. */
  6. class PayOrdersModel extends BaseModel
  7. {
  8. protected $table = 'pay_orders';
  9. protected $fillable = [
  10. 'order_no',
  11. 'user_id',
  12. 'total',
  13. 'type',
  14. 'discount',
  15. 'pay_total',
  16. 'charge_amount',
  17. 'pay_at',
  18. 'account',
  19. 'transaction_id',
  20. 'meal_id',
  21. 'product_id',
  22. 'out_trade_no',
  23. 'charge_kami',
  24. 'remark',
  25. 'failed_remark',
  26. 'create_time',
  27. 'update_time',
  28. 'refund_status',
  29. 'refund_money',
  30. 'status',
  31. 'mark'
  32. ];
  33. /**
  34. * 关联用户
  35. */
  36. public function user()
  37. {
  38. return $this->belongsTo(MemberModel::class, 'user_id', 'id');
  39. }
  40. /**
  41. * 关联套餐
  42. */
  43. public function meal()
  44. {
  45. return $this->belongsTo(PayMealsModel::class, 'meal_id', 'id');
  46. }
  47. /**
  48. * 获取类型文本
  49. */
  50. public function getTypeTextAttribute()
  51. {
  52. $typeMap = [
  53. 1 => '话费',
  54. 2 => '电费',
  55. 3 => '燃气'
  56. ];
  57. return $typeMap[$this->type] ?? '未知';
  58. }
  59. /**
  60. * 获取状态文本
  61. */
  62. public function getStatusTextAttribute()
  63. {
  64. $statusMap = [
  65. 1 => '待付款',
  66. 2 => '已付款',
  67. 3 => '充值中',
  68. 4 => '充值成功',
  69. 5 => '充值失败',
  70. 6 => '部分成功'
  71. ];
  72. return $statusMap[$this->status] ?? '未知';
  73. }
  74. /**
  75. * 获取退款状态文本
  76. */
  77. public function getRefundStatusTextAttribute()
  78. {
  79. $refundStatusMap = [
  80. 0 => '无',
  81. 1 => '已成功',
  82. 2 => '待退款',
  83. 3 => '退款失败'
  84. ];
  85. return $refundStatusMap[$this->refund_status] ?? '未知';
  86. }
  87. }