PayMealsModel.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 getPayMoneyAttribute()
  44. {
  45. if ($this->discount > 0) {
  46. return round($this->money * $this->discount / 100, 2);
  47. }
  48. return $this->money;
  49. }
  50. }