123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * 日志规则控制器
  4. *
  5. * @author qifan
  6. * @date 2020-12-03
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\logic\DailyRuleLogic;
  10. use think\Hook;
  11. use think\Request;
  12. class DailyRule extends ApiCommon
  13. {
  14. /**
  15. * 用于判断权限
  16. * @permission 无限制
  17. * @allow 登录用户可访问
  18. * @other 其他根据系统设置
  19. **/
  20. public function _initialize()
  21. {
  22. $action = [
  23. 'permission'=>[''],
  24. 'allow'=>['welcome', 'setwelcome', 'worklogrule', 'setworklogrule','scheduleList','addschedule','setschedule','delschedule']
  25. ];
  26. Hook::listen('check_auth',$action);
  27. $request = Request::instance();
  28. $a = strtolower($request->action());
  29. if (!in_array($a, $action['permission'])) {
  30. parent::_initialize();
  31. }
  32. }
  33. /**
  34. * 获取欢迎语
  35. *
  36. * @param DailyRuleLogic $dailyRuleLogic
  37. * @return \think\response\Json
  38. */
  39. public function welcome(DailyRuleLogic $dailyRuleLogic)
  40. {
  41. $data = $dailyRuleLogic->welcome();
  42. return resultArray(['data' => $data]);
  43. }
  44. /**
  45. * 添加欢迎语
  46. *
  47. * @param DailyRuleLogic $dailyRuleLogic
  48. * @return \think\response\Json
  49. * @throws \think\Exception
  50. * @throws \think\exception\PDOException
  51. */
  52. public function setWelcome(DailyRuleLogic $dailyRuleLogic)
  53. {
  54. $mark = $this->param['welcome'];
  55. if (empty($mark)) return resultArray(['error' => '缺少日志欢迎语!']);
  56. if (!$dailyRuleLogic->setWelcome($mark)) return resultArray(['error' => '添加失败!']);
  57. return resultArray(['data' => '添加成功!']);
  58. }
  59. /**
  60. * 获取日志规则
  61. *
  62. * @param DailyRuleLogic $dailyRuleLogic
  63. * @return \think\response\Json
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. * @throws \think\exception\DbException
  67. */
  68. public function workLogRule(DailyRuleLogic $dailyRuleLogic)
  69. {
  70. $data = $dailyRuleLogic->workLogRule();
  71. return resultArray(['data' => $data]);
  72. }
  73. /**
  74. * 设置日志规则
  75. *
  76. * @param DailyRuleLogic $dailyRuleLogic
  77. * @return \think\response\Json
  78. * @throws \think\Exception
  79. * @throws \think\exception\PDOException
  80. */
  81. public function setWorkLogRule(DailyRuleLogic $dailyRuleLogic)
  82. {
  83. if (empty($this->param['rule'])) return resultArray(['error' => '缺少规则参数!']);
  84. $dailyRuleLogic->setWorkLogRule($this->param['rule']);
  85. return resultArray(['data' => '设置成功!']);
  86. }
  87. /**
  88. * 获取日程规则
  89. * @param DailyRuleLogic $dailyRuleLogic
  90. * @return \think\response\Json
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\ModelNotFoundException
  93. * @throws \think\exception\DbException
  94. */
  95. public function scheduleList(DailyRuleLogic $dailyRuleLogic){
  96. $data = $dailyRuleLogic->schedule();
  97. return resultArray(['data' => $data]);
  98. }
  99. /**
  100. * 设置日程自定义规则
  101. * @param DailyRuleLogic $dailyRuleLogic
  102. * @return \think\response\Json
  103. * @throws \think\Exception
  104. * @throws \think\exception\PDOException
  105. */
  106. public function setSchedule(DailyRuleLogic $dailyRuleLogic){
  107. if(empty($this->param['id'])) return resultArray(['error'=>'缺少参数']);
  108. $dailyRuleLogic->setSchedule($this->param);
  109. return resultArray(['data' => '设置成功!']);
  110. }
  111. /**
  112. * 添加日程自定义规则
  113. * @param DailyRuleLogic $dailyRuleLogic
  114. * @return \think\response\Json
  115. */
  116. public function addSchedule(DailyRuleLogic $dailyRuleLogic){
  117. if(empty($this->param['name'])) return resultArray(['error'=>'缺少参数']);
  118. $dailyRuleLogic->addSchedule($this->param);
  119. return resultArray(['data' => '添加成功!']);
  120. }
  121. /**
  122. * 删除日程自定义规则
  123. * @param DailyRuleLogic $dailyRuleLogic
  124. * @return \think\response\Json
  125. */
  126. public function delSchedule(DailyRuleLogic $dailyRuleLogic){
  127. if(empty($this->param['id'])) return resultArray(['error'=>'缺少参数']);
  128. $dailyRuleLogic->delSchedule($this->param['id']);
  129. return resultArray(['data' => '删除成功!']);
  130. }
  131. }