Initialize.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * 初始化控制器
  4. *
  5. * @author qifan
  6. * @date 2020-01-05
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\logic\InitializeLogic;
  10. use think\Hook;
  11. use think\Request;
  12. class Initialize extends ApiCommon
  13. {
  14. /**
  15. * 用于判断权限
  16. * @permission 无限制
  17. * @allow 登录用户可访问
  18. * @other 其他根据系统设置
  19. **/
  20. public function _initialize()
  21. {
  22. $action = [
  23. 'permission' => [],
  24. 'allow' => ['verification']
  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. * @return \think\response\Json
  37. */
  38. public function index()
  39. {
  40. $data = [
  41. ['type' => 1, 'name' => '全部应用'],
  42. ['type' => 2, 'name' => '客户管理'],
  43. ['type' => 3, 'name' => '任务/审批'],
  44. ['type' => 4, 'name' => '日志'],
  45. ['type' => 5, 'name' => '项目管理'],
  46. ['type' => 6, 'name' => '日历'],
  47. // ['type' => 7, 'name' => '知识库'],
  48. ];
  49. return resultArray(['data' => $data]);
  50. }
  51. /**
  52. * 初始化数据
  53. *
  54. * @param InitializeLogic $initializeLogic
  55. * @return \think\response\Json
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @throws \think\exception\DbException
  59. */
  60. public function update(InitializeLogic $initializeLogic)
  61. {
  62. if (empty($this->param['type']) || !is_array($this->param['type'])) return resultArray(['error' => '模块类型错误!']);
  63. if (!empty($this->param['password']) && !$initializeLogic->verification($this->userInfo['id'], $this->param['password'])) {
  64. return resultArray(['error' => '密码错误!']);
  65. }
  66. $initializeLogic->update($this->param['type']);
  67. return resultArray(['data' => $initializeLogic->log]);
  68. }
  69. /**
  70. * 验证密码
  71. *
  72. * @param InitializeLogic $initializeLogic
  73. * @return \think\response\Json
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. * @throws \think\exception\DbException
  77. */
  78. public function verification(InitializeLogic $initializeLogic)
  79. {
  80. if (empty($this->param['password'])) return resultArray(['error' => '参数错误!']);
  81. if (!$initializeLogic->verification($this->userInfo['id'], $this->param['password'])) return resultArray(['error' => '密码错误!']);
  82. return resultArray(['data' => '密码正确!']);
  83. }
  84. }