PayMealsModel.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. 'type',
  15. 'sort',
  16. 'create_time',
  17. 'update_time',
  18. 'status',
  19. 'mark'
  20. ];
  21. /**
  22. * 获取类型文本
  23. */
  24. public function getTypeTextAttribute()
  25. {
  26. $typeMap = [
  27. 1 => '话费充值',
  28. 2 => '电费充值',
  29. 3 => '燃气充值'
  30. ];
  31. return $typeMap[$this->type] ?? '未知';
  32. }
  33. /**
  34. * 获取状态文本
  35. */
  36. public function getStatusTextAttribute()
  37. {
  38. return $this->status == 1 ? '有效' : '无效';
  39. }
  40. /**
  41. * 获取折扣
  42. */
  43. public function getDiscountAttribute($value)
  44. {
  45. return floatval($value);
  46. }
  47. /**
  48. * 获取实付金额
  49. */
  50. public function getPayMoneyAttribute()
  51. {
  52. if ($this->discount > 0) {
  53. return round($this->money * $this->discount / 100, 2);
  54. }
  55. return $this->money;
  56. }
  57. }