123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. ];
  48. return resultArray(['data' => $data]);
  49. }
  50. /**
  51. * 初始化数据
  52. *
  53. * @param InitializeLogic $initializeLogic
  54. * @return \think\response\Json
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @throws \think\exception\DbException
  58. */
  59. public function update(InitializeLogic $initializeLogic)
  60. {
  61. $userInfo = $this->userInfo;
  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. # 系统操作日志
  68. SystemActionLog($userInfo['id'], 'admin_user','work_task', 1, 'update', '重置数据' , '', '','重置了数据');
  69. return resultArray(['data' => $initializeLogic->log]);
  70. }
  71. /**
  72. * 验证密码
  73. *
  74. * @param InitializeLogic $initializeLogic
  75. * @return \think\response\Json
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @throws \think\exception\DbException
  79. */
  80. public function verification(InitializeLogic $initializeLogic)
  81. {
  82. if (empty($this->param['password'])) return resultArray(['error' => '参数错误!']);
  83. if (!$initializeLogic->verification($this->userInfo['id'], $this->param['password'])) return resultArray(['error' => '密码错误!']);
  84. return resultArray(['data' => '密码正确!']);
  85. }
  86. }