123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 工作台及基础
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\controller;
  8. use think\Hook;
  9. use think\Request;
  10. class Index extends ApiCommon
  11. {
  12. /**
  13. * 用于判断权限
  14. * @permission 无限制
  15. * @allow 登录用户可访问
  16. * @other 其他根据系统设置
  17. */
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $action = [
  22. 'permission' => [],
  23. 'allow' => ['fields', 'fieldrecord', 'authlist','sort','updatesort',
  24. 'importnum','importinfo','importlist'],
  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. * @param
  36. * @return
  37. */
  38. public function fields()
  39. {
  40. $param = $this->param;
  41. $userInfo = $this->userInfo;
  42. $param['user_id'] = $userInfo['id'];
  43. $fieldModel = model('Field');
  44. $field_arr = $fieldModel->getField($param);
  45. # 转form_type类型,用于场景筛选和创建自定义场景
  46. foreach ($field_arr AS $key => $value) {
  47. if ($value['field'] == 'address') $field_arr[$key]['form_type'] = 'map_address';
  48. if ($value['field'] == 'deal_status') $field_arr[$key]['form_type'] = 'deal_status';
  49. if ($value['field'] == 'check_status') $field_arr[$key]['form_type'] = 'check_status';
  50. }
  51. return resultArray(['data' => $field_arr]);
  52. }
  53. /**
  54. * 获取字段修改记录
  55. * @param
  56. * @return
  57. */
  58. public function fieldRecord()
  59. {
  60. $param = $this->param;
  61. $userInfo = $this->userInfo;
  62. $param['user_id'] = $userInfo['id'];
  63. $actionRecordModel = model('ActionRecord');
  64. $data = $actionRecordModel->getDataList($param);
  65. if (!$data) {
  66. return resultArray(['data' => '暂无数据']);
  67. }
  68. return resultArray(['data' => $data]);
  69. }
  70. /**
  71. * 权限数据返回
  72. * @param
  73. * @return
  74. */
  75. public function authList()
  76. {
  77. $userInfo = $this->userInfo;
  78. $userModel = model('User');
  79. $dataList = $userModel->getMenuAndRule($userInfo['id']);
  80. return resultArray(['data' => $dataList['authList']]);
  81. }
  82. /**
  83. * todo
  84. * 顶部菜单栏展示
  85. * @return mixed
  86. */
  87. //todo admin_sort 表数据未完善
  88. public function sort(){
  89. $param = $this->param;
  90. $userModel = model('User');
  91. $userInfo = $this->userInfo;
  92. $param['user_id']= $param['user_id']?:$userInfo['id'];
  93. $dataList = $userModel->sortList($param);
  94. return resultArray(['data' => $dataList]);
  95. }
  96. /**
  97. *顶部菜单栏编辑
  98. */
  99. public function updateSort(){
  100. $param = $this->param;
  101. $userInfo = $this->userInfo;
  102. $userModel = model('User');
  103. $param['value']=$param;
  104. $param['user_id']= $param['user_id']?:$userInfo['id'];
  105. $dataList = $userModel->updateSort($param);
  106. if (!$dataList) {
  107. return resultArray(['data' => '编辑失败']);
  108. }
  109. return resultArray(['data' => '编辑成功']);
  110. }
  111. /**
  112. * 导入中
  113. * @return \think\response\Json
  114. */
  115. public function importNum(){
  116. $excelModel = model('Excel');
  117. $data = $excelModel->importNum();
  118. return resultArray(['data'=>$data]);
  119. }
  120. /**
  121. * 导入成功返回值
  122. * @return \think\response\Json
  123. */
  124. public function importInfo(){
  125. $excelModel = model('Excel');
  126. $data = $excelModel->importInfo();
  127. return resultArray(['data'=>$data]);
  128. }
  129. /**
  130. * 导入历史
  131. * @return \think\response\Json
  132. */
  133. public function importList(){
  134. $param = $this->param;
  135. $userInfo = $this->userInfo;
  136. $param['user_id'] = $userInfo['id'];
  137. $excelModel = model('Excel');
  138. $data = $excelModel->importList($param);
  139. return resultArray(['data'=>$data]);
  140. }
  141. }