PayOrdersModel.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. 'area',
  25. 'ytype',
  26. 'id_card_no',
  27. 'city',
  28. 'remark',
  29. 'result',
  30. 'failed_remark',
  31. 'create_time',
  32. 'update_time',
  33. 'refund_status',
  34. 'refund_money',
  35. 'refund_remark',
  36. 'status',
  37. 'mark'
  38. ];
  39. /**
  40. * 关联用户
  41. */
  42. public function user()
  43. {
  44. return $this->belongsTo(MemberModel::class, 'user_id', 'id');
  45. }
  46. /**
  47. * 推荐收益用户
  48. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  49. */
  50. public function recUser()
  51. {
  52. return $this->hasOne(MemberModel::class, 'id', 'rec_bonus_id')
  53. ->select(['id', 'mobile', 'nickname', 'realname', 'status']);
  54. }
  55. /**
  56. * 关联套餐
  57. */
  58. public function meal()
  59. {
  60. return $this->belongsTo(PayMealsModel::class, 'meal_id', 'id');
  61. }
  62. /**
  63. * 获取类型文本
  64. */
  65. public function getTypeTextAttribute()
  66. {
  67. $typeMap = [
  68. 1 => '话费',
  69. 2 => '电费',
  70. 3 => '燃气'
  71. ];
  72. return $typeMap[$this->type] ?? '未知';
  73. }
  74. /**
  75. * 获取状态文本
  76. */
  77. public function getStatusTextAttribute()
  78. {
  79. $statusMap = [
  80. 1 => '待付款',
  81. 2 => '已付款',
  82. 3 => '充值中',
  83. 4 => '充值成功',
  84. 5 => '充值失败',
  85. 6 => '部分成功'
  86. ];
  87. return $statusMap[$this->status] ?? '未知';
  88. }
  89. /**
  90. * 获取退款状态文本
  91. */
  92. public function getRefundStatusTextAttribute()
  93. {
  94. $refundStatusMap = [
  95. 0 => '无',
  96. 1 => '已成功',
  97. 2 => '待退款',
  98. 3 => '退款失败'
  99. ];
  100. return $refundStatusMap[$this->refund_status] ?? '未知';
  101. }
  102. }