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