PayMealsModel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Models;
  3. /**
  4. * 缴费充值套餐模型
  5. */
  6. class PayMealsModel extends BaseModel
  7. {
  8. protected $table = 'pay_meals';
  9. protected $fillable = [
  10. 'product_id',
  11. 'money',
  12. 'discount',
  13. 'remark',
  14. 'gas_type',
  15. 'type',
  16. 'electric_type',
  17. 'phone_type',
  18. 'phone_service',
  19. 'sort',
  20. 'create_time',
  21. 'update_time',
  22. 'status',
  23. 'mark'
  24. ];
  25. /**
  26. * 获取类型文本
  27. */
  28. public function getTypeTextAttribute()
  29. {
  30. $typeMap = [
  31. 1 => '话费充值',
  32. 2 => '电费充值',
  33. 3 => '燃气充值'
  34. ];
  35. return $typeMap[$this->type] ?? '未知';
  36. }
  37. /**
  38. * 获取状态文本
  39. */
  40. public function getStatusTextAttribute()
  41. {
  42. return $this->status == 1 ? '有效' : '无效';
  43. }
  44. /**
  45. * 获取折扣
  46. */
  47. public function getDiscountAttribute($value)
  48. {
  49. return floatval($value);
  50. }
  51. /**
  52. * 获取实付金额
  53. */
  54. public function getPayMoneyAttribute()
  55. {
  56. if ($this->discount > 0) {
  57. return round($this->money * $this->discount / 100, 2);
  58. }
  59. return $this->money;
  60. }
  61. }