123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. if(in_array($param['types'],['crm_customer','crm_customer_pool','crm_contacts','crm_business','crm_contract','crm_receivables'])){
  59. $field=[['field'=>'team_id','name'=>'相关团队','form_type'=>'user','setting'=>[]]];
  60. $field_arr=array_merge($field_arr,$field);
  61. }
  62. return resultArray(['data' => $field_arr]);
  63. }
  64. /**
  65. * 获取字段修改记录
  66. * @param
  67. * @return
  68. */
  69. public function fieldRecord()
  70. {
  71. $param = $this->param;
  72. $userInfo = $this->userInfo;
  73. $param['user_id'] = $userInfo['id'];
  74. $actionRecordModel = model('ActionRecord');
  75. $data = $actionRecordModel->getDataList($param);
  76. if (!$data) {
  77. return resultArray(['data' => '暂无数据']);
  78. }
  79. return resultArray(['data' => $data]);
  80. }
  81. /**
  82. * 权限数据返回
  83. * @param
  84. * @return
  85. */
  86. public function authList()
  87. {
  88. $userInfo = $this->userInfo;
  89. $userModel = model('User');
  90. $dataList = $userModel->getMenuAndRule($userInfo['id']);
  91. return resultArray(['data' => $dataList['authList']]);
  92. }
  93. /**
  94. * todo
  95. * 顶部菜单栏展示
  96. * @return mixed
  97. */
  98. //todo admin_sort 表数据未完善
  99. public function sort(){
  100. $param = $this->param;
  101. $userModel = model('User');
  102. $userInfo = $this->userInfo;
  103. $param['user_id']= $param['user_id']?:$userInfo['id'];
  104. $dataList = $userModel->sortList($param);
  105. return resultArray(['data' => $dataList]);
  106. }
  107. /**
  108. *顶部菜单栏编辑
  109. */
  110. public function updateSort(){
  111. $param = $this->param;
  112. $userInfo = $this->userInfo;
  113. $userModel = model('User');
  114. $param['value']=$param;
  115. $param['user_id']= $param['user_id']?:$userInfo['id'];
  116. $dataList = $userModel->updateSort($param);
  117. if (!$dataList) {
  118. return resultArray(['data' => '编辑失败']);
  119. }
  120. return resultArray(['data' => '编辑成功']);
  121. }
  122. /**
  123. * 导入中
  124. * @return \think\response\Json
  125. */
  126. public function importNum(){
  127. $excelModel = model('Excel');
  128. $data = $excelModel->importNum();
  129. return resultArray(['data'=>$data]);
  130. }
  131. /**
  132. * 导入成功返回值
  133. * @return \think\response\Json
  134. */
  135. public function importInfo(){
  136. $excelModel = model('Excel');
  137. $data = $excelModel->importInfo();
  138. return resultArray(['data'=>$data]);
  139. }
  140. /**
  141. * 导入历史
  142. * @return \think\response\Json
  143. */
  144. public function importList(){
  145. $param = $this->param;
  146. $userInfo = $this->userInfo;
  147. $param['user_id'] = $userInfo['id'];
  148. $excelModel = model('Excel');
  149. $data = $excelModel->importList($param);
  150. return resultArray(['data'=>$data]);
  151. }
  152. /**
  153. * 升级公告
  154. * @author fanqi
  155. * @date 2021-03-15
  156. * @return \think\response\Json
  157. */
  158. public function readNotice()
  159. {
  160. $userInfo = $this->userInfo;
  161. if (!empty($userInfo['id'])) db('admin_user')->where('id', $userInfo['id'])->update(['is_read_notice' => 1]);
  162. return resultArray(['data' => '']);
  163. }
  164. }