123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 工作台及基础
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\controller;
  8. use app\crm\logic\CustomerPoolLogic;
  9. use think\Hook;
  10. use think\Request;
  11. class Index extends ApiCommon
  12. {
  13. /**
  14. * 用于判断权限
  15. * @permission 无限制
  16. * @allow 登录用户可访问
  17. * @other 其他根据系统设置
  18. */
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $action = [
  23. 'permission' => [],
  24. 'allow' => ['fields', 'fieldrecord', 'authlist','sort','updatesort',
  25. 'importnum','importinfo','importlist','readnotice'],
  26. ];
  27. Hook::listen('check_auth', $action);
  28. $request = Request::instance();
  29. $a = strtolower($request->action());
  30. if (!in_array($a, $action['permission'])) {
  31. parent::_initialize();
  32. }
  33. }
  34. /**
  35. * 获取字段属性,用于筛选或其他操作
  36. * @param
  37. * @return
  38. */
  39. public function fields()
  40. {
  41. $param = $this->param;
  42. # 多公海高级筛选参数列表
  43. if (!empty($param['types']) && $param['types'] == 'crm_customer_pool') {
  44. $customerPoolLogic = new CustomerPoolLogic();
  45. return resultArray(['data' => $customerPoolLogic->getAdvancedFilterFieldList()]);
  46. }
  47. $userInfo = $this->userInfo;
  48. $param['user_id'] = $userInfo['id'];
  49. $fieldModel = model('Field');
  50. $field_arr = $fieldModel->getField($param);
  51. # 转form_type类型,用于场景筛选和创建自定义场景
  52. foreach ($field_arr AS $key => $value) {
  53. if ($value['field'] == 'address') $field_arr[$key]['form_type'] = 'map_address';
  54. if ($value['field'] == 'deal_status') $field_arr[$key]['form_type'] = 'deal_status';
  55. if ($value['field'] == 'check_status') $field_arr[$key]['form_type'] = 'check_status';
  56. if ($param['types'] == 'crm_visit' && $value['field'] == 'owner_user_id') $field_arr[$key]['name'] = '回访人';
  57. }
  58. return resultArray(['data' => $field_arr]);
  59. }
  60. /**
  61. * 获取字段修改记录
  62. * @param
  63. * @return
  64. */
  65. public function fieldRecord()
  66. {
  67. $param = $this->param;
  68. $userInfo = $this->userInfo;
  69. $param['user_id'] = $userInfo['id'];
  70. $actionRecordModel = model('ActionRecord');
  71. $data = $actionRecordModel->getDataList($param);
  72. if (!$data) {
  73. return resultArray(['data' => '暂无数据']);
  74. }
  75. return resultArray(['data' => $data]);
  76. }
  77. /**
  78. * 权限数据返回
  79. * @param
  80. * @return
  81. */
  82. public function authList()
  83. {
  84. $userInfo = $this->userInfo;
  85. $userModel = model('User');
  86. $dataList = $userModel->getMenuAndRule($userInfo['id']);
  87. return resultArray(['data' => $dataList['authList']]);
  88. }
  89. /**
  90. * todo
  91. * 顶部菜单栏展示
  92. * @return mixed
  93. */
  94. //todo admin_sort 表数据未完善
  95. public function sort(){
  96. $param = $this->param;
  97. $userModel = model('User');
  98. $userInfo = $this->userInfo;
  99. $param['user_id']= $param['user_id']?:$userInfo['id'];
  100. $dataList = $userModel->sortList($param);
  101. return resultArray(['data' => $dataList]);
  102. }
  103. /**
  104. *顶部菜单栏编辑
  105. */
  106. public function updateSort(){
  107. $param = $this->param;
  108. $userInfo = $this->userInfo;
  109. $userModel = model('User');
  110. $param['value']=$param;
  111. $param['user_id']= $param['user_id']?:$userInfo['id'];
  112. $dataList = $userModel->updateSort($param);
  113. if (!$dataList) {
  114. return resultArray(['data' => '编辑失败']);
  115. }
  116. return resultArray(['data' => '编辑成功']);
  117. }
  118. /**
  119. * 导入中
  120. * @return \think\response\Json
  121. */
  122. public function importNum(){
  123. $excelModel = model('Excel');
  124. $data = $excelModel->importNum();
  125. return resultArray(['data'=>$data]);
  126. }
  127. /**
  128. * 导入成功返回值
  129. * @return \think\response\Json
  130. */
  131. public function importInfo(){
  132. $excelModel = model('Excel');
  133. $data = $excelModel->importInfo();
  134. return resultArray(['data'=>$data]);
  135. }
  136. /**
  137. * 导入历史
  138. * @return \think\response\Json
  139. */
  140. public function importList(){
  141. $param = $this->param;
  142. $userInfo = $this->userInfo;
  143. $param['user_id'] = $userInfo['id'];
  144. $excelModel = model('Excel');
  145. $data = $excelModel->importList($param);
  146. return resultArray(['data'=>$data]);
  147. }
  148. /**
  149. * 升级公告
  150. * @author fanqi
  151. * @date 2021-03-15
  152. * @return \think\response\Json
  153. */
  154. public function readNotice()
  155. {
  156. $userInfo = $this->userInfo;
  157. if (!empty($userInfo['id'])) db('admin_user')->where('id', $userInfo['id'])->update(['is_read_notice' => 1]);
  158. return resultArray(['data' => '']);
  159. }
  160. }