HolidaySet.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * HolidaySet.php UTF-8
  4. * 节假日配置
  5. *
  6. * @date : 2019/12/4 16:07
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK 8.5
  11. */
  12. namespace huoIdentify\controller;
  13. use huo\controller\common\Base;
  14. use huoIdentify\model\IdentifyHolidaySetModel;
  15. class HolidaySet extends Base {
  16. /**
  17. * 判断今日是否为节假日
  18. *
  19. * @return bool true 是 false 否
  20. */
  21. public function isHoliday() {
  22. $_year = date('Y');
  23. $_holiday_set = (new IdentifyHolidaySetModel())->getInfoByYear($_year);
  24. if (empty($_holiday_set)) {
  25. if (date('N') == 6 || date('N') == 7) {
  26. /* 当天为周六日,判断是否为调班 */
  27. return true;
  28. }
  29. return false;
  30. }
  31. $_date = date('Y-m-d');
  32. if (date('N') == 6 || date('N') == 7) {
  33. /* 当天为周六日,判断是否为调班 */
  34. if (in_array($_date, $_holiday_set['workday'])) {
  35. return false;
  36. }
  37. return true;
  38. } else {
  39. /* 非周六日,判断是否为节假日 */
  40. if (in_array($_date, $_holiday_set['holiday'])) {
  41. return true;
  42. }
  43. return false;
  44. }
  45. }
  46. /**
  47. * 判断今日是否允许登陆
  48. */
  49. public function isAllowLogin() {
  50. if (date('N') == 5 || date('N') == 6 || date('N') == 7) {
  51. /* 当天为周五六日,允许登陆 */
  52. return true;
  53. }
  54. $_year = date('Y');
  55. $_holiday_set = (new IdentifyHolidaySetModel())->getInfoByYear($_year);
  56. if (empty($_holiday_set)) {
  57. /* 未配置节假日则认为无节假日开放,不允许登陆 */
  58. return false;
  59. }
  60. $_date = date('Y-m-d');
  61. /* 如果今天是节假日则允许登陆 */
  62. if (in_array($_date, $_holiday_set['holiday'])) {
  63. return true;
  64. }
  65. return false;
  66. }
  67. }