DisasterService.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Module\Farm\Services;
  3. use App\Module\Farm\Enums\DISASTER_TYPE;
  4. class DisasterService
  5. {
  6. /**
  7. * 获取所有灾害 减产比例
  8. *
  9. * @return float[]
  10. */
  11. public static function getAllDisasters()
  12. {
  13. $disasterTypes = [
  14. DISASTER_TYPE::DROUGHT->valueInt() => 0.05, // 干旱
  15. DISASTER_TYPE::PEST->valueInt() => 0.05, // 虫害
  16. DISASTER_TYPE::WEED->valueInt() => 0.05, // 杂草
  17. ];
  18. return $disasterTypes;
  19. }
  20. /**
  21. * 获取灾害 产生比例
  22. *
  23. * @return float[]
  24. */
  25. public static function getRate()
  26. {
  27. $disasterTypes = [
  28. DISASTER_TYPE::DROUGHT->valueInt() => 0.9, // 干旱
  29. DISASTER_TYPE::PEST->valueInt() => 0.9, // 虫害
  30. DISASTER_TYPE::WEED->valueInt() => 0.9, // 杂草
  31. ];
  32. return $disasterTypes;
  33. }
  34. /**
  35. * 获取灾害类型对应的键名
  36. *
  37. * @param int $disasterType
  38. * @return string
  39. */
  40. public static function getDisasterKey(int $disasterType): string
  41. {
  42. $keys = [
  43. DISASTER_TYPE::DROUGHT->valueInt() => 'drought',
  44. DISASTER_TYPE::PEST->valueInt() => 'pest',
  45. DISASTER_TYPE::WEED->valueInt() => 'weed',
  46. ];
  47. return $keys[$disasterType] ?? '';
  48. }
  49. /**
  50. * 灾害检查间隔时间(分钟)
  51. *
  52. * @return int
  53. */
  54. public static function getCheckInterval(): int
  55. {
  56. return 5; // 每5分钟检查一次
  57. }
  58. }