UserType.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace addons\exam\enum;
  3. /**
  4. * 会员类型
  5. */
  6. class UserType extends BaseEnum
  7. {
  8. /** 普通用户 */
  9. const NORMAL = 'NORMAL';
  10. /** 月卡会员 */
  11. const VIP_MONTH = 'VIP_MONTH';
  12. /** 年卡会员 */
  13. const VIP_YEAR = 'VIP_YEAR';
  14. /** 终身会员 */
  15. const VIP_LIFE = 'VIP_LIFE';
  16. /**
  17. * 获取会员类型时限说明
  18. * @param $type
  19. * @return string
  20. */
  21. public static function getDurationDesc($type)
  22. {
  23. switch ($type) {
  24. case self::VIP_MONTH:
  25. return '1个月';
  26. case self::VIP_YEAR:
  27. return '12个月';
  28. case self::VIP_LIFE:
  29. return '终身会员';
  30. default:
  31. return '非会员';
  32. }
  33. }
  34. /**
  35. * 获取会员类型时限值
  36. * @param $type
  37. * @return int
  38. */
  39. public static function getDurationVal($type)
  40. {
  41. switch ($type) {
  42. case self::VIP_MONTH:
  43. return intval(date("t", strtotime(date('Y-m-d'))));
  44. case self::VIP_YEAR:
  45. $year = date('Y');
  46. $days = 0;
  47. for ($month = 1; $month <= 12; $month++) {
  48. $days = $days + date("t", strtotime("{$year}-{$month}"));
  49. }
  50. return $days;
  51. case self::VIP_LIFE:
  52. return 365 * 100;
  53. default:
  54. return 0;
  55. }
  56. }
  57. }