Index.php 6.1KB

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