123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. if ($param['types'] == 'crm_visit' && $value['field'] == 'owner_user_id') $field_arr[$key]['name'] = '回访人';
  51. }
  52. return resultArray(['data' => $field_arr]);
  53. }
  54. /**
  55. * 获取字段修改记录
  56. * @param
  57. * @return
  58. */
  59. public function fieldRecord()
  60. {
  61. $param = $this->param;
  62. $userInfo = $this->userInfo;
  63. $param['user_id'] = $userInfo['id'];
  64. $actionRecordModel = model('ActionRecord');
  65. $data = $actionRecordModel->getDataList($param);
  66. if (!$data) {
  67. return resultArray(['data' => '暂无数据']);
  68. }
  69. return resultArray(['data' => $data]);
  70. }
  71. /**
  72. * 权限数据返回
  73. * @param
  74. * @return
  75. */
  76. public function authList()
  77. {
  78. $userInfo = $this->userInfo;
  79. $userModel = model('User');
  80. $dataList = $userModel->getMenuAndRule($userInfo['id']);
  81. return resultArray(['data' => $dataList['authList']]);
  82. }
  83. /**
  84. * todo
  85. * 顶部菜单栏展示
  86. * @return mixed
  87. */
  88. //todo admin_sort 表数据未完善
  89. public function sort(){
  90. $param = $this->param;
  91. $userModel = model('User');
  92. $userInfo = $this->userInfo;
  93. $param['user_id']= $param['user_id']?:$userInfo['id'];
  94. $dataList = $userModel->sortList($param);
  95. return resultArray(['data' => $dataList]);
  96. }
  97. /**
  98. *顶部菜单栏编辑
  99. */
  100. public function updateSort(){
  101. $param = $this->param;
  102. $userInfo = $this->userInfo;
  103. $userModel = model('User');
  104. $param['value']=$param;
  105. $param['user_id']= $param['user_id']?:$userInfo['id'];
  106. $dataList = $userModel->updateSort($param);
  107. if (!$dataList) {
  108. return resultArray(['data' => '编辑失败']);
  109. }
  110. return resultArray(['data' => '编辑成功']);
  111. }
  112. /**
  113. * 导入中
  114. * @return \think\response\Json
  115. */
  116. public function importNum(){
  117. $excelModel = model('Excel');
  118. $data = $excelModel->importNum();
  119. return resultArray(['data'=>$data]);
  120. }
  121. /**
  122. * 导入成功返回值
  123. * @return \think\response\Json
  124. */
  125. public function importInfo(){
  126. $excelModel = model('Excel');
  127. $data = $excelModel->importInfo();
  128. return resultArray(['data'=>$data]);
  129. }
  130. /**
  131. * 导入历史
  132. * @return \think\response\Json
  133. */
  134. public function importList(){
  135. $param = $this->param;
  136. $userInfo = $this->userInfo;
  137. $param['user_id'] = $userInfo['id'];
  138. $excelModel = model('Excel');
  139. $data = $excelModel->importList($param);
  140. return resultArray(['data'=>$data]);
  141. }
  142. }