index.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /**
  2. * 客户管理API接口
  3. * @module api/crm/customer
  4. */
  5. import request from '@/utils/request';
  6. import type {
  7. CustomerQuery,
  8. CustomerForm,
  9. CustomerVO,
  10. ContactQuery,
  11. ContactForm,
  12. ContactVO,
  13. CustomerFollowQuery,
  14. CustomerFollowForm,
  15. CustomerFollowVO,
  16. CustomerPoolQuery,
  17. CustomerPoolForm,
  18. CustomerPoolVO,
  19. CustomerTransferParams,
  20. CustomerIntoPoolParams,
  21. CustomerClaimParams,
  22. CustomerStatisticsOverview
  23. } from './types';
  24. // ==================== 客户管理接口 ====================
  25. /**
  26. * 查询客户列表(分页)
  27. * @param query 查询参数
  28. */
  29. export function listCustomer(query: CustomerQuery) {
  30. return request({
  31. url: '/crm/customer/list',
  32. method: 'get',
  33. params: query
  34. });
  35. }
  36. /**
  37. * 查询客户详情
  38. * @param id 客户ID(兼容字符串和数字类型)
  39. */
  40. export function getCustomer(id: number | string) {
  41. return request({
  42. url: `/crm/customer/${id}`,
  43. method: 'get'
  44. });
  45. }
  46. /**
  47. * 新增客户
  48. * @param data 客户表单数据
  49. * @returns 成功时 data 为新客户主键 id(用于关联开票信息等)
  50. */
  51. export function addCustomer(data: CustomerForm) {
  52. return request({
  53. url: '/crm/customer',
  54. method: 'post',
  55. data: data
  56. });
  57. }
  58. /**
  59. * 修改客户
  60. * @param data 客户表单数据
  61. */
  62. export function updateCustomer(data: CustomerForm) {
  63. return request({
  64. url: '/crm/customer',
  65. method: 'put',
  66. data: data
  67. });
  68. }
  69. /**
  70. * 删除客户
  71. * @param ids 客户ID数组(兼容字符串和数字类型)
  72. */
  73. export function delCustomer(ids: number | string | (number | string)[]) {
  74. return request({
  75. url: `/crm/customer/${ids}`,
  76. method: 'delete'
  77. });
  78. }
  79. /**
  80. * 批量转移客户
  81. * @param data 转移参数
  82. */
  83. export function transferCustomer(data: CustomerTransferParams) {
  84. return request({
  85. url: '/crm/customer/transfer',
  86. method: 'put',
  87. data: data
  88. });
  89. }
  90. /**
  91. * 批量放入公海池
  92. * @param data 放入公海参数
  93. */
  94. export function intoPool(data: CustomerIntoPoolParams) {
  95. return request({
  96. url: '/crm/customer/intoPool',
  97. method: 'put',
  98. data: data
  99. });
  100. }
  101. /**
  102. * 导出客户
  103. * @param query 查询参数
  104. */
  105. export function exportCustomer(query: CustomerQuery) {
  106. return request({
  107. url: '/crm/customer/export',
  108. method: 'post',
  109. data: query,
  110. responseType: 'blob'
  111. });
  112. }
  113. /**
  114. * 下载导入模板
  115. */
  116. export function importTemplate() {
  117. return request({
  118. url: '/crm/customer/importTemplate',
  119. method: 'post',
  120. responseType: 'blob'
  121. });
  122. }
  123. /**
  124. * 查询公海池客户列表
  125. * @param query 查询参数
  126. */
  127. export function listPoolCustomer(query: CustomerQuery) {
  128. return request({
  129. url: '/crm/customer/pool/list',
  130. method: 'get',
  131. params: query
  132. });
  133. }
  134. /**
  135. * 领取公海客户
  136. * @param data 领取参数
  137. */
  138. export function claimCustomer(data: CustomerClaimParams) {
  139. return request({
  140. url: '/crm/customer/claim',
  141. method: 'put',
  142. data: data
  143. });
  144. }
  145. /**
  146. * 查询待跟进客户
  147. * @param query 查询参数
  148. */
  149. export function listToFollowCustomer(query: CustomerQuery) {
  150. return request({
  151. url: '/crm/customer/toFollow',
  152. method: 'get',
  153. params: query
  154. });
  155. }
  156. /**
  157. * 查询我的客户
  158. * @param query 查询参数
  159. */
  160. export function listMyCustomer(query: CustomerQuery) {
  161. return request({
  162. url: '/crm/customer/mine',
  163. method: 'get',
  164. params: query
  165. });
  166. }
  167. /**
  168. * 查询重点客户
  169. * @param query 查询参数
  170. */
  171. export function listKeyCustomer(query: CustomerQuery) {
  172. return request({
  173. url: '/crm/customer/key',
  174. method: 'get',
  175. params: query
  176. });
  177. }
  178. /**
  179. * 查询成交客户
  180. * @param query 查询参数
  181. */
  182. export function listDealedCustomer(query: CustomerQuery) {
  183. return request({
  184. url: '/crm/customer/dealed',
  185. method: 'get',
  186. params: query
  187. });
  188. }
  189. /**
  190. * 查询本周新增客户
  191. * @param query 查询参数
  192. */
  193. export function listWeekNewCustomer(query: CustomerQuery) {
  194. return request({
  195. url: '/crm/customer/weekNew',
  196. method: 'get',
  197. params: query
  198. });
  199. }
  200. /**
  201. * 查询长期未跟进客户
  202. * @param query 查询参数
  203. */
  204. export function listLongTimeNoFollowCustomer(query: CustomerQuery) {
  205. return request({
  206. url: '/crm/customer/longTimeNoFollow',
  207. method: 'get',
  208. params: query
  209. });
  210. }
  211. // ==================== 联系人管理接口 ====================
  212. /**
  213. * 查询联系人列表(分页)
  214. * @param query 查询参数
  215. */
  216. export function listContact(query: ContactQuery) {
  217. return request({
  218. url: '/crm/contact/list',
  219. method: 'get',
  220. params: query
  221. });
  222. }
  223. /**
  224. * 查询联系人详情
  225. * @param id 联系人ID
  226. */
  227. export function getContact(id: number) {
  228. return request({
  229. url: `/crm/contact/${id}`,
  230. method: 'get'
  231. });
  232. }
  233. /**
  234. * 根据客户ID查询联系人列表
  235. * @param customerId 客户ID
  236. */
  237. export function getContactByCustomerId(customerId: number | string) {
  238. return request({
  239. url: `/crm/contact/customer/${customerId}`,
  240. method: 'get'
  241. });
  242. }
  243. /**
  244. * 新增联系人
  245. * @param data 联系人表单数据
  246. */
  247. export function addContact(data: ContactForm) {
  248. return request({
  249. url: '/crm/contact',
  250. method: 'post',
  251. data: data
  252. });
  253. }
  254. /**
  255. * 修改联系人
  256. * @param data 联系人表单数据
  257. */
  258. export function updateContact(data: ContactForm) {
  259. return request({
  260. url: '/crm/contact',
  261. method: 'put',
  262. data: data
  263. });
  264. }
  265. /**
  266. * 删除联系人
  267. * @param ids 联系人ID数组
  268. */
  269. export function delContact(ids: number | number[]) {
  270. return request({
  271. url: `/crm/contact/${ids}`,
  272. method: 'delete'
  273. });
  274. }
  275. /**
  276. * 设置主要联系人
  277. * @param id 联系人ID
  278. */
  279. export function setPrimaryContact(id: number) {
  280. return request({
  281. url: `/crm/contact/setPrimary/${id}`,
  282. method: 'put'
  283. });
  284. }
  285. /**
  286. * 导出联系人
  287. * @param query 查询参数
  288. */
  289. export function exportContact(query: ContactQuery) {
  290. return request({
  291. url: '/crm/contact/export',
  292. method: 'post',
  293. data: query,
  294. responseType: 'blob'
  295. });
  296. }
  297. /**
  298. * 查询决策人联系人列表(分页)
  299. * @param query 查询参数
  300. */
  301. export function listDecisionContact(query: ContactQuery) {
  302. return request({
  303. url: '/crm/contact/decision',
  304. method: 'get',
  305. params: query
  306. });
  307. }
  308. /**
  309. * 查询主联系人列表(分页)
  310. * @param query 查询参数
  311. */
  312. export function listPrimaryContact(query: ContactQuery) {
  313. return request({
  314. url: '/crm/contact/primary',
  315. method: 'get',
  316. params: query
  317. });
  318. }
  319. /**
  320. * 查询本月生日联系人列表(分页)
  321. * @param query 查询参数
  322. */
  323. export function listBirthdayContact(query: ContactQuery) {
  324. return request({
  325. url: '/crm/contact/birthday',
  326. method: 'get',
  327. params: query
  328. });
  329. }
  330. // ==================== 客户跟进记录接口 ====================
  331. /**
  332. * 查询跟进记录列表(分页)
  333. * @param query 查询参数
  334. */
  335. export function listCustomerFollow(query: CustomerFollowQuery) {
  336. return request({
  337. url: '/crm/customer/follow/list',
  338. method: 'get',
  339. params: query
  340. });
  341. }
  342. /**
  343. * 查询跟进记录详情
  344. * @param id 跟进记录ID
  345. */
  346. export function getCustomerFollow(id: number) {
  347. return request({
  348. url: `/crm/customer/follow/${id}`,
  349. method: 'get'
  350. });
  351. }
  352. /**
  353. * 根据客户ID查询跟进记录列表
  354. * @param customerId 客户ID
  355. */
  356. export function getFollowByCustomerId(customerId: number) {
  357. return request({
  358. url: `/crm/customer/follow/customer/${customerId}`,
  359. method: 'get'
  360. });
  361. }
  362. /**
  363. * 新增跟进记录
  364. * @param data 跟进记录表单数据
  365. */
  366. export function addCustomerFollow(data: CustomerFollowForm) {
  367. return request({
  368. url: '/crm/customer/follow',
  369. method: 'post',
  370. data: data
  371. });
  372. }
  373. /**
  374. * 修改跟进记录
  375. * @param data 跟进记录表单数据
  376. */
  377. export function updateCustomerFollow(data: CustomerFollowForm) {
  378. return request({
  379. url: '/crm/customer/follow',
  380. method: 'put',
  381. data: data
  382. });
  383. }
  384. /**
  385. * 删除跟进记录
  386. * @param ids 跟进记录ID数组
  387. */
  388. export function delCustomerFollow(ids: number | number[]) {
  389. return request({
  390. url: `/crm/customer/follow/${ids}`,
  391. method: 'delete'
  392. });
  393. }
  394. /**
  395. * 导出跟进记录
  396. * @param query 查询参数
  397. */
  398. export function exportCustomerFollow(query: CustomerFollowQuery) {
  399. return request({
  400. url: '/crm/customer/follow/export',
  401. method: 'post',
  402. data: query,
  403. responseType: 'blob'
  404. });
  405. }
  406. // ==================== 客户公海池规则接口 ====================
  407. /**
  408. * 查询公海池规则列表(分页)
  409. * @param query 查询参数
  410. */
  411. export function listCustomerPool(query: CustomerPoolQuery) {
  412. return request({
  413. url: '/crm/customer/pool/list',
  414. method: 'get',
  415. params: query
  416. });
  417. }
  418. /**
  419. * 查询公海池规则详情
  420. * @param id 规则ID
  421. */
  422. export function getCustomerPool(id: number) {
  423. return request({
  424. url: `/crm/customer/pool/${id}`,
  425. method: 'get'
  426. });
  427. }
  428. /**
  429. * 新增公海池规则
  430. * @param data 规则表单数据
  431. */
  432. export function addCustomerPool(data: CustomerPoolForm) {
  433. return request({
  434. url: '/crm/customer/pool',
  435. method: 'post',
  436. data: data
  437. });
  438. }
  439. /**
  440. * 修改公海池规则
  441. * @param data 规则表单数据
  442. */
  443. export function updateCustomerPool(data: CustomerPoolForm) {
  444. return request({
  445. url: '/crm/customer/pool',
  446. method: 'put',
  447. data: data
  448. });
  449. }
  450. /**
  451. * 删除公海池规则
  452. * @param ids 规则ID数组
  453. */
  454. export function delCustomerPool(ids: number | number[]) {
  455. return request({
  456. url: `/crm/customer/pool/${ids}`,
  457. method: 'delete'
  458. });
  459. }
  460. /**
  461. * 启用/禁用公海规则
  462. * @param id 规则ID
  463. * @param status 状态
  464. */
  465. export function updatePoolStatus(id: number, status: string) {
  466. return request({
  467. url: `/crm/customer/pool/rule/status/${id}/${status}`,
  468. method: 'put'
  469. });
  470. }
  471. /**
  472. * 手动执行公海池规则
  473. */
  474. export function executePoolRules() {
  475. return request({
  476. url: '/crm/customer/pool/rule/execute',
  477. method: 'post'
  478. });
  479. }
  480. /**
  481. * 导出公海池规则
  482. * @param query 查询参数
  483. */
  484. export function exportCustomerPool(query: CustomerPoolQuery) {
  485. return request({
  486. url: '/crm/customer/pool/export',
  487. method: 'post',
  488. data: query,
  489. responseType: 'blob'
  490. });
  491. }
  492. // ==================== 统计分析接口 ====================
  493. /**
  494. * 客户统计概览
  495. * @param params 查询参数
  496. */
  497. export function getStatisticsOverview(params?: any) {
  498. return request({
  499. url: '/crm/customer/statistics/overview',
  500. method: 'get',
  501. params: params
  502. });
  503. }
  504. /**
  505. * 客户来源统计
  506. * @param params 查询参数
  507. */
  508. export function getStatisticsBySource(params?: any) {
  509. return request({
  510. url: '/crm/customer/statistics/source',
  511. method: 'get',
  512. params: params
  513. });
  514. }
  515. /**
  516. * 客户级别分布
  517. */
  518. export function getStatisticsByLevel() {
  519. return request({
  520. url: '/crm/customer/statistics/level',
  521. method: 'get'
  522. });
  523. }
  524. /**
  525. * 客户行业分布
  526. */
  527. export function getStatisticsByIndustry() {
  528. return request({
  529. url: '/crm/customer/statistics/industry',
  530. method: 'get'
  531. });
  532. }
  533. /**
  534. * 客户成交趋势
  535. * @param params 查询参数
  536. */
  537. export function getStatisticsTrend(params?: any) {
  538. return request({
  539. url: '/crm/customer/statistics/trend',
  540. method: 'get',
  541. params: params
  542. });
  543. }
  544. /**
  545. * 负责人客户统计
  546. * @param params 查询参数
  547. */
  548. export function getStatisticsByOwner(params?: any) {
  549. return request({
  550. url: '/crm/customer/statistics/owner',
  551. method: 'get',
  552. params: params
  553. });
  554. }
  555. /**
  556. * 客户跟进统计
  557. * @param params 查询参数
  558. */
  559. export function getStatisticsFollow(params?: any) {
  560. return request({
  561. url: '/crm/customer/statistics/follow',
  562. method: 'get',
  563. params: params
  564. });
  565. }
  566. // ==================== 客户成交与重复检测 ====================
  567. /**
  568. * 客户成交
  569. * @param data 成交数据
  570. */
  571. export function dealCustomer(data: { id: number; dealAmount: number; dealTime?: string; remark?: string }) {
  572. return request({
  573. url: `/crm/customer/deal/${data.id}`,
  574. method: 'put',
  575. data: data
  576. });
  577. }
  578. /**
  579. * 客户重复检测
  580. * @param data 检测参数
  581. */
  582. export function checkDuplicateCustomer(data: { mobile?: string; customerName?: string; excludeId?: number }) {
  583. return request({
  584. url: '/crm/customer/checkDuplicate',
  585. method: 'post',
  586. data: data
  587. });
  588. }
  589. // ==================== 公海池管理 ====================
  590. /**
  591. * 分配公海池客户(管理员功能)
  592. * @param data 分配参数
  593. */
  594. export function assignPoolCustomers(data: { ids: number[]; ownerUserId: number; remark?: string }) {
  595. return request({
  596. url: '/crm/customer/pool/assign',
  597. method: 'put',
  598. data: data
  599. });
  600. }
  601. /**
  602. * 获取所在园区列表(去重)
  603. */
  604. export function getParkAreaList() {
  605. return request({
  606. url: '/crm/customer/parkAreaList',
  607. method: 'get'
  608. });
  609. }