TaRecommendCustomerMapper.xml 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.yunzhi.marketing.mapper.TaRecommendCustomerMapper">
  4. <select id="getMyCutsomerNum" resultType="int">
  5. SELECT
  6. count(*) AS total
  7. FROM
  8. ta_recommend_customer t
  9. WHERE
  10. t.recommend_person = #{personId}
  11. AND t.status &gt; -1
  12. </select>
  13. <select id="getCustomerPersonId" resultType="java.lang.String">
  14. SELECT
  15. person_id
  16. FROM
  17. ta_customer_person
  18. WHERE
  19. customer_id = #{customerId}
  20. </select>
  21. <select id="getCustomerDetail" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  22. SELECT
  23. a.*,
  24. (select c.visit_time FROM ta_person_visit_record c where c.person_id = #{personId} ORDER BY c.visit_time asc LIMIT 1) as visitTime,
  25. (SELECT SUM(d.visit_duration) FROM ta_person_visit_record d WHERE d.person_id= #{personId}) as duration
  26. FROM
  27. ta_recommend_customer a
  28. LEFT JOIN ta_person_visit_record c ON a.person_id = c.person_id
  29. where a.customer_id = #{customerId}
  30. GROUP BY a.customer_id
  31. </select>
  32. <select id="getRecCustomerList" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  33. SELECT
  34. a.*,
  35. a.customer_id as customerId,
  36. c.phone as recommendTel,
  37. c.nickname as recommendName
  38. FROM
  39. ta_recommend_customer a
  40. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  41. <where>
  42. a.status > 0
  43. and a.report_recommend_status = 2
  44. <if test="orgId != null">
  45. and a.org_id = #{orgId}
  46. </if>
  47. <if test="building != null and building !=''">
  48. and a.building_id = #{building}
  49. </if>
  50. <if test="name != null and name !=''">
  51. and a.name like CONCAT('%',#{name}, '%')
  52. </if>
  53. <if test="tel != null and tel!=''">
  54. and a.phone like CONCAT('%',#{tel}, '%')
  55. </if>
  56. <if test="consultName != null and consultName !=''">
  57. and c.nickname like CONCAT('%',#{consultName}, '%')
  58. </if>
  59. <if test="consultTel != null and consultTel !=''">
  60. and c.phone like CONCAT('%',#{consultTel}, '%')
  61. </if>
  62. <if test="entryType != null and entryType !=''">
  63. and a.entry_type = #{entryType}
  64. </if>
  65. <if test="verifyStatus != null and verifyStatus !=''">
  66. and a.verify_status = #{verifyStatus}
  67. </if>
  68. <if test="sex != null and sex !=''">
  69. and a.sex = #{sex}
  70. </if>
  71. <if test="personBuildingList != null and personBuildingList.size > 0">
  72. AND a.building_id in
  73. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  74. #{personBuilding.buildingId}
  75. </foreach>
  76. </if>
  77. </where>
  78. order by a.create_date desc
  79. </select>
  80. <select id="getIndependentAgents" resultType="com.yunzhi.marketing.entity.TaPerson">
  81. SELECT
  82. a.*,
  83. tc.channel_name as channelName
  84. FROM
  85. ta_person a
  86. left join ta_channel_person tcp on a.person_id = tcp.person_id
  87. left join ta_channel tc on tc.channel_id = tcp.channel_id
  88. <where>
  89. a.person_type in ('estate agent', 'channel agent')
  90. and a.status >0
  91. <if test="name != null and name !=''">
  92. and a.nickname = #{name}
  93. </if>
  94. <if test="tel != null and tel!=''">
  95. and a.phone = #{tel}
  96. </if>
  97. <if test="orgId != null">
  98. and a.org_id = #{orgId}
  99. </if>
  100. </where>
  101. ORDER BY
  102. create_date DESC
  103. </select>
  104. <select id="getRepCustomerList" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  105. SELECT
  106. a.*,
  107. a.customer_id AS customerId,
  108. IFNULL(d.user_name, b.name) as consultantName,
  109. IFNULL(d.phone, b.tel) as consultTel,
  110. c.building_name as intentionName
  111. FROM
  112. ta_recommend_customer a
  113. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  114. LEFT JOIN ta_user d on a.realty_consultant = d.user_id
  115. LEFT JOIN ta_building c ON a.building_id = c.building_id
  116. <where>
  117. a.status > 0
  118. and a.report_recommend_status = 1
  119. <if test="orgId != null">
  120. and a.org_id = #{orgId}
  121. </if>
  122. <if test="building != null and building !=''">
  123. and a.building_id = #{building}
  124. </if>
  125. <if test="name != null and name !=''">
  126. and a.name = #{name}
  127. </if>
  128. <if test="tel != null and tel!=''">
  129. and a.phone like concat(concat("%",#{tel}),"%")
  130. </if>
  131. <if test="consultName != null and consultName !=''">
  132. and IFNULL(d.user_name, b.name) like CONCAT('%',#{consultName}, '%')
  133. </if>
  134. <if test="consultTel != null and consultTel !=''">
  135. and IFNULL(d.phone, b.tel) = #{consultTel}
  136. </if>
  137. <if test="entryType != null and entryType !=''">
  138. and a.entry_type = #{entryType}
  139. </if>
  140. <if test="verifyStatus != null and verifyStatus !=''">
  141. and a.verify_status = #{verifyStatus}
  142. </if>
  143. <if test="sex != null">
  144. and a.sex = #{sex}
  145. </if>
  146. <if test="personBuildingList != null and personBuildingList.size > 0">
  147. AND a.building_id in
  148. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  149. #{personBuilding.buildingId}
  150. </foreach>
  151. </if>
  152. </where>
  153. order by a.create_date desc
  154. </select>
  155. <select id="getCustomerList" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  156. SELECT
  157. a.*,
  158. IFNULL( t2.building_name, '暂无' ) AS buildingName,
  159. a.customer_id as customerId,
  160. IFNULL(b.name,d.user_name) as consultantName,
  161. IFNULL(b.tel,d.phone) as consultTel,
  162. c.nickname as recommendName,
  163. c.tel as recommendTel,
  164. IFNULL(c.name,c.nickname) AS sharePersonName
  165. FROM
  166. ta_recommend_customer a
  167. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  168. LEFT JOIN ta_user d on d.user_id = a.realty_consultant
  169. LEFT JOIN ta_person_from_record p ON a.person_id = p.person_id AND p.is_first_time = 1
  170. <if test="orgId != null">
  171. and p.org_id = #{orgId}
  172. </if>
  173. -- LEFT JOIN ta_person c on p.share_person_id = c.person_id
  174. -- LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
  175. LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
  176. LEFT JOIN ta_person p2 ON a.person_id = p2.person_id
  177. LEFT JOIN ta_person c ON p2.recommend_person = c.person_id
  178. LEFT JOIN ta_building t2 ON a.building_id = t2.building_id
  179. <where>
  180. a.status > 0
  181. and a.verify_status = 1
  182. and a.realty_consultant is not null
  183. and a.realty_consultant != ''
  184. <if test="orgId != null">
  185. and a.org_id = #{orgId}
  186. </if>
  187. <if test="building != null and building !=''">
  188. and a.building_id = #{building}
  189. </if>
  190. <if test="name != null and name !=''">
  191. and a.name like CONCAT('%',#{name}, '%')
  192. </if>
  193. <if test="tel != null and tel!=''">
  194. and a.phone like CONCAT('%',#{tel}, '%')
  195. </if>
  196. <if test="consultName != null and consultName !=''">
  197. and IFNULL(b.name,d.user_name) like CONCAT('%',#{consultName}, '%')
  198. </if>
  199. <if test="consultTel != null and consultTel !=''">
  200. and IFNULL(b.tel,d.phone) like CONCAT('%',#{consultTel}, '%')
  201. </if>
  202. <if test="entryType != null and entryType !=''">
  203. and a.entry_type = #{entryType}
  204. </if>
  205. <if test="verifyStatus != null and verifyStatus !=''">
  206. and a.verify_status = #{verifyStatus}
  207. </if>
  208. <if test="status != null and status !=''">
  209. and a.status = #{status}
  210. </if>
  211. <if test="sex != null and sex !=''">
  212. and a.sex = #{sex}
  213. </if>
  214. <if test="startCreateDate != null and startCreateDate !=''">
  215. and a.create_Date >= #{startCreateDate}
  216. </if>
  217. <if test="endCreateDate != null and endCreateDate !=''">
  218. and a.create_Date &lt;= #{endCreateDate}
  219. </if>
  220. <if test="sharePersonName != null and sharePersonName !=''">
  221. and (c.nickName like CONCAT('%',#{sharePersonName}, '%') or c.name like CONCAT('%',#{sharePersonName},
  222. '%'))
  223. </if>
  224. <if test="personBuildingList != null and personBuildingList.size > 0">
  225. AND a.building_id in
  226. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  227. #{personBuilding.buildingId}
  228. </foreach>
  229. </if>
  230. <if test="sceneType !=null and sceneType !=''">
  231. and p.scene_type = #{sceneType}
  232. </if>
  233. </where>
  234. order by a.create_date desc
  235. </select>
  236. <select id="getCustomerById" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  237. SELECT
  238. a.*,
  239. b.name as consultantName
  240. FROM
  241. ta_recommend_customer a
  242. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  243. WHERE a.customer_id = #{customerId}
  244. </select>
  245. <select id="getPublicCustomerList" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  246. SELECT
  247. t.*,
  248. IFNULL( t2.building_name, '暂无' ) AS buildingName,
  249. ifnull( t3.nickname, t3.NAME ) AS sharePersonName
  250. FROM
  251. ta_recommend_customer t
  252. LEFT JOIN ta_building t2 ON t.building_id = t2.building_id
  253. LEFT JOIN ta_person t6 ON t.person_id = t6.person_id
  254. LEFT JOIN ta_person t3 ON t6.recommend_person = t3.person_id
  255. LEFT JOIN ta_person_from_record t4 ON t.person_id = t4.person_id AND t4.is_first_time = 1 AND t4.org_id = #{orgId}
  256. LEFT JOIN td_wx_dict t5 ON t4.scene_id = t5.scene_id
  257. <where>
  258. t.`status` > 0
  259. AND t.verify_status = 1
  260. AND ( t.realty_consultant IS NULL OR t.realty_consultant = '' )
  261. AND t.org_id = #{orgId}
  262. <if test="buildingId != null and buildingId !=''">
  263. and t.building_id = #{buildingId}
  264. </if>
  265. <if test="name != null and name !=''">
  266. and t.name like CONCAT('%',#{name}, '%')
  267. </if>
  268. <if test="tel != null and tel!=''">
  269. and t.phone like CONCAT('%',#{tel}, '%')
  270. </if>
  271. <if test="entryType != null and entryType !=''">
  272. and t.entry_type = #{entryType}
  273. </if>
  274. <if test="verifyStatus != null and verifyStatus !=''">
  275. and t.verify_status = #{verifyStatus}
  276. </if>
  277. <if test="sex != null and sex !=''">
  278. and t.sex = #{sex}
  279. </if>
  280. <if test="startCreateDate != null and startCreateDate !=''">
  281. and t.create_Date >= #{startCreateDate}
  282. </if>
  283. <if test="endCreateDate != null and endCreateDate !=''">
  284. and t.create_Date &lt;= #{endCreateDate}
  285. </if>
  286. <if test="sharePersonName != null and sharePersonName !=''">
  287. and (t3.nickName like CONCAT('%',#{sharePersonName}, '%') or t3.name like CONCAT('%',#{sharePersonName},
  288. '%'))
  289. </if>
  290. <if test="personBuildingList != null and personBuildingList.size > 0">
  291. AND t.building_id in
  292. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  293. #{personBuilding.buildingId}
  294. </foreach>
  295. </if>
  296. <if test="sceneType !=null and sceneType !=''">
  297. and t4.scene_type = #{sceneType}
  298. </if>
  299. <if test="belongStatus == 0">
  300. and (t.building_id = '' OR t.building_id is null )
  301. </if>
  302. </where>
  303. order by t.create_date desc
  304. </select>
  305. <select id="getRecCustomerExport" resultType="com.yunzhi.marketing.excel.ExcelRecommendCustomer">
  306. SELECT
  307. a.name as name,
  308. a.phone as phone,
  309. a.intention as intention,
  310. a.create_date as createDate,
  311. if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
  312. c.nickname as recommend,
  313. c.phone as recommendTel,
  314. if(a.verify_status = 0, '待审核', if(a.verify_status = 1, '已通过', if(a.verify_status = 2, '未通过', ''))) as
  315. verifyStatusName
  316. FROM
  317. ta_recommend_customer a
  318. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  319. <where>
  320. a.status > 0
  321. and a.report_recommend_status = 2
  322. <if test="orgId != null">
  323. and a.org_id = #{orgId}
  324. </if>
  325. <if test="personBuildingList != null and personBuildingList.size > 0">
  326. AND a.building_id in
  327. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  328. #{personBuilding.buildingId}
  329. </foreach>
  330. </if>
  331. </where>
  332. order by a.create_date desc
  333. limit #{pageCode}, #{pageSize}
  334. </select>
  335. <select id="getRecCustomerExportCount" resultType="java.lang.Integer">
  336. SELECT
  337. count(*)
  338. FROM
  339. ta_recommend_customer a
  340. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  341. <where>
  342. a.status > 0
  343. and a.report_recommend_status = 2
  344. <if test="orgId != null">
  345. and a.org_id = #{orgId}
  346. </if>
  347. <if test="personBuildingList != null and personBuildingList.size > 0">
  348. AND a.building_id in
  349. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  350. #{personBuilding.buildingId}
  351. </foreach>
  352. </if>
  353. </where>
  354. </select>
  355. <select id="getRepCustomerReportCount" resultType="java.lang.Integer">
  356. SELECT
  357. count(*)
  358. FROM
  359. ta_recommend_customer a
  360. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  361. LEFT JOIN ta_building c ON a.building_id = c.building_id
  362. <where>
  363. a.status > 0
  364. and a.report_recommend_status = 1
  365. <if test="orgId != null">
  366. and a.org_id = #{orgId}
  367. </if>
  368. <if test="building != null and building !=''">
  369. and a.building_id = #{building}
  370. </if>
  371. <if test="name != null and name !=''">
  372. and a.name = #{name}
  373. </if>
  374. <if test="tel != null and tel!=''">
  375. and a.phone like concat(concat("%",#{tel}),"%")
  376. </if>
  377. <if test="consultName != null and consultName !=''">
  378. and b.name like CONCAT('%',#{consultName}, '%')
  379. </if>
  380. <if test="consultTel != null and consultTel !=''">
  381. and b.tel = #{consultTel}
  382. </if>
  383. <if test="entryType != null and entryType !=''">
  384. and a.entry_type = #{entryType}
  385. </if>
  386. <if test="verifyStatus != null and verifyStatus !=''">
  387. and a.verify_status = #{verifyStatus}
  388. </if>
  389. <if test="sex != null and sex !=''">
  390. and a.sex = #{sex}
  391. and a.org_id = #{orgid}
  392. </if>
  393. <if test="personBuildingList != null and personBuildingList.size > 0">
  394. AND a.building_id in
  395. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  396. #{personBuilding.buildingId}
  397. </foreach>
  398. </if>
  399. </where>
  400. order by a.create_date desc
  401. </select>
  402. <select id="getRepCustomerReportExport" resultType="com.yunzhi.marketing.excel.ReporRecommendCustomer">
  403. SELECT
  404. a.name as name,
  405. a.phone as phone,
  406. c.building_name as intentionName,
  407. if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
  408. IFNULL(d.user_name, b.name) as consultantName,
  409. IFNULL(d.phone, b.tel) as consultTel
  410. FROM
  411. ta_recommend_customer a
  412. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  413. LEFT JOIN ta_user d on a.realty_consultant = d.user_id
  414. LEFT JOIN ta_building c ON a.building_id = c.building_id
  415. <where>
  416. a.status > 0
  417. and a.report_recommend_status = 1
  418. <if test="orgId != null">
  419. and a.org_id = #{orgId}
  420. </if>
  421. <if test="building != null and building !=''">
  422. and a.building_id = #{building}
  423. </if>
  424. <if test="name != null and name !=''">
  425. and a.name = #{name}
  426. </if>
  427. <if test="tel != null and tel!=''">
  428. and a.phone like concat(concat("%",#{tel}),"%")
  429. </if>
  430. <if test="consultName != null and consultName !=''">
  431. and IFNULL(d.user_name, b.name) like CONCAT('%',#{consultName}, '%')
  432. </if>
  433. <if test="consultTel != null and consultTel !=''">
  434. and IFNULL(d.phone, b.tel) = #{consultTel}
  435. </if>
  436. <if test="entryType != null and entryType !=''">
  437. and a.entry_type = #{entryType}
  438. </if>
  439. <if test="verifyStatus != null and verifyStatus !=''">
  440. and a.verify_status = #{verifyStatus}
  441. </if>
  442. <if test="sex != null and sex !=''">
  443. and a.sex = #{sex}
  444. and a.org_id = #{orgid}
  445. </if>
  446. <if test="personBuildingList != null and personBuildingList.size > 0">
  447. AND a.building_id in
  448. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  449. #{personBuilding.buildingId}
  450. </foreach>
  451. </if>
  452. </where>
  453. order by a.create_date desc
  454. limit #{pageCode}, #{pageSize}
  455. </select>
  456. <select id="getIndependentAgentsCount" resultType="java.lang.Integer">
  457. SELECT
  458. count(*)
  459. FROM
  460. ta_person a
  461. left join ta_channel_person tcp on a.person_id = tcp.person_id
  462. left join ta_channel tc on tc.channel_id = tcp.channel_id
  463. <where>
  464. a.person_type = 'estate agent'
  465. and a.status >0
  466. <if test="orgId != null">
  467. and a.org_id = #{orgId}
  468. </if>
  469. </where>
  470. ORDER BY
  471. a.create_date DESC
  472. </select>
  473. <select id="getIndependentAgentsExport" resultType="com.yunzhi.marketing.excel.AgentsRecommendCustomer">
  474. SELECT
  475. a.nickname as nickname,
  476. a.phone as phone,
  477. if(a.gender = '1', '男', if(a.gender = '2', '女', '未知')) as gender,
  478. if(ifnull(tc.channel_name, '') != '', '渠道经纪人', '独立经纪人') as personType,
  479. tc.channel_name as channelName,
  480. (
  481. SELECT
  482. count( 1 )
  483. FROM
  484. ta_person tp
  485. WHERE
  486. tp.recommend_agent = a.person_id
  487. ) AS agentCount,
  488. (
  489. SELECT
  490. count( 1 )
  491. FROM
  492. ta_recommend_customer tarc
  493. WHERE
  494. tarc.recommend_person = a.person_id
  495. and tarc.status = 1
  496. and tarc.org_id = #{orgId}
  497. ) AS recommedCount
  498. FROM
  499. ta_person a
  500. left join ta_channel_person tcp on a.person_id = tcp.person_id
  501. left join ta_channel tc on tc.channel_id = tcp.channel_id
  502. <where>
  503. ifnull(a.person_type, '') in ('channel agent', 'estate agent')
  504. and a.status >0
  505. <if test="orgId != null">
  506. and a.org_id = #{orgId}
  507. </if>
  508. </where>
  509. ORDER BY
  510. a.create_date DESC
  511. limit #{pageCode}, #{pageSize}
  512. </select>
  513. <select id="getPublicCustomerExportListCount" resultType="Integer">
  514. SELECT
  515. count(1)
  516. FROM
  517. ta_person b
  518. <where>
  519. b.status > 0
  520. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  521. <if test="name != null and name !=''">
  522. and b.nickname like CONCAT('%',#{name}, '%')
  523. </if>
  524. <if test="tel != null and tel!=''">
  525. and b.phone like CONCAT('%',#{tel}, '%')
  526. </if>
  527. <if test="entryType != null and entryType !=''">
  528. and b.entry_type = #{entryType}
  529. </if>
  530. <if test="sex != null and sex !=''">
  531. and b.sex = #{sex}
  532. </if>
  533. <if test="orgId != null">
  534. and b.org_id = #{orgId}
  535. </if>
  536. <if test="consultTel != null and consultTel !=''">
  537. and b.tel like CONCAT('%',#{consultTel}, '%')
  538. </if>
  539. and NOT EXISTS ( select * from ta_recommend_customer a where a.org_id = #{orgId} and a.recommend_person =
  540. b.person_id)
  541. </where>
  542. order by b.create_date desc
  543. </select>
  544. <select id="getPublicCustomerExportList" resultType="com.yunzhi.marketing.excel.PublicCustomerExport">
  545. SELECT
  546. t.NAME AS nickname,
  547. t.phone,
  548. IF( t.sex = 1, '男', IF ( t.sex = 2, '女', '未知' ) ) AS sex,
  549. t.create_date,
  550. concat( t.country, t.province ) AS province,
  551. t.intention,
  552. IF(t.building_id = null or t.building_id = '','否','是') AS belongStatus,
  553. IFNULL( t2.building_name, '暂无' ) AS buildingName,
  554. t5.scene_alias as sceneType,
  555. ifnull( t3.nickname, t3.NAME ) AS sharePersonName ,
  556. t6.points
  557. FROM
  558. ta_recommend_customer t
  559. LEFT JOIN ta_building t2 ON t.building_id = t2.building_id
  560. LEFT JOIN ta_person t7 ON t.person_id = t7.person_id
  561. LEFT JOIN ta_person t3 ON t7.recommend_person = t3.person_id
  562. LEFT JOIN ta_person_from_record t4 ON t.person_id = t4.person_id AND t4.is_first_time = 1 AND t4.org_id =
  563. #{orgId}
  564. LEFT JOIN td_wx_dict t5 ON t4.scene_id = t5.scene_id
  565. LEFT JOIN (select sum(points_amount) as points,person_id from ta_points_records where org_id = #{orgId} GROUP BY
  566. person_id) t6 on t.person_id = t6.person_id
  567. WHERE
  568. t.`status` > 0
  569. AND t.verify_status = 1
  570. AND ( t.realty_consultant IS NULL OR t.realty_consultant = '' )
  571. AND t.org_id = #{orgId}
  572. <if test="buildingId != null and buildingId !=''">
  573. and t.building_id = #{buildingId}
  574. </if>
  575. <if test="name != null and name !=''">
  576. and t.name like CONCAT('%',#{name}, '%')
  577. </if>
  578. <if test="tel != null and tel!=''">
  579. and t.phone like CONCAT('%',#{tel}, '%')
  580. </if>
  581. <if test="entryType != null and entryType !=''">
  582. and t.entry_type = #{entryType}
  583. </if>
  584. <if test="verifyStatus != null and verifyStatus !=''">
  585. and t.verify_status = #{verifyStatus}
  586. </if>
  587. <if test="sex != null and sex !=''">
  588. and t.sex = #{sex}
  589. </if>
  590. <if test="startCreateDate != null and startCreateDate !=''">
  591. and t.create_Date >= #{startCreateDate}
  592. </if>
  593. <if test="endCreateDate != null and endCreateDate !=''">
  594. and t.create_Date &lt;= #{endCreateDate}
  595. </if>
  596. <if test="personBuildingList != null and personBuildingList.size > 0">
  597. AND t.building_id in
  598. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  599. #{personBuilding.buildingId}
  600. </foreach>
  601. </if>
  602. <if test="sceneType !=null and sceneType !=''">
  603. and t4.scene_type = #{sceneType}
  604. </if>
  605. <if test="belongStatus == 0">
  606. and (t.building_id = '' OR t.building_id is null )
  607. </if>
  608. </select>
  609. <!-- limit #{pageCode}, #{pageSize}-->
  610. <select id="getCustomerExportListCount" resultType="Integer">
  611. SELECT
  612. count(1)
  613. FROM
  614. ta_recommend_customer a
  615. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  616. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  617. <where>
  618. a.status > 0
  619. and a.verify_status = 1
  620. and realty_consultant is not null
  621. <if test="orgId != null">
  622. and a.org_id = #{orgId}
  623. </if>
  624. <if test="building != null and building !=''">
  625. and a.building_id = #{building}
  626. </if>
  627. <if test="name != null and name !=''">
  628. and a.name like CONCAT('%',#{name}, '%')
  629. </if>
  630. <if test="tel != null and tel!=''">
  631. and a.phone like CONCAT('%',#{tel}, '%')
  632. </if>
  633. <if test="consultName != null and consultName !=''">
  634. and b.name like CONCAT('%',#{consultName}, '%')
  635. </if>
  636. <if test="consultTel != null and consultTel !=''">
  637. and b.tel like CONCAT('%',#{consultTel}, '%')
  638. </if>
  639. <if test="entryType != null and entryType !=''">
  640. and a.entry_type = #{entryType}
  641. </if>
  642. <if test="verifyStatus != null and verifyStatus !=''">
  643. and a.verify_status = #{verifyStatus}
  644. </if>
  645. <if test="status != null and status !=''">
  646. and a.status = #{status}
  647. </if>
  648. <if test="sex != null and sex !=''">
  649. and a.sex = #{sex}
  650. </if>
  651. <if test="startCreateDate != null and startCreateDate !=''">
  652. and a.create_Date >= #{startCreateDate}
  653. </if>
  654. <if test="endCreateDate != null and endCreateDate !=''">
  655. and a.create_Date &lt;= #{endCreateDate}
  656. </if>
  657. <if test="personBuildingList != null and personBuildingList.size > 0">
  658. AND a.building_id in
  659. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  660. #{personBuilding.buildingId}
  661. </foreach>
  662. </if>
  663. </where>
  664. order by a.create_date desc
  665. </select>
  666. <select id="getCustomerExportList" resultType="com.yunzhi.marketing.excel.PrivateCustomerExport">
  667. SELECT
  668. a.name AS name,
  669. a.phone as phone,
  670. if(a.sex = 1, '男', if(a.sex = 2, '女', '未知')) as sex,
  671. CASE
  672. WHEN b.NAME IS NULL THEN
  673. d.user_name ELSE b.NAME
  674. END AS consultantName,
  675. CASE
  676. WHEN b.tel IS NULL THEN
  677. d.phone ELSE b.tel
  678. END AS consultTel,
  679. t.building_name,
  680. z.intention,
  681. a.create_date,
  682. concat(tp.country, tp.province) as province,
  683. w.scene_alias as scene_type,
  684. IFNULL( c.NAME, c.nickname ) AS sharePersonName,
  685. s.points
  686. FROM
  687. ta_recommend_customer a
  688. left join ta_person tp on tp.person_id = a.person_id
  689. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  690. LEFT JOIN ta_user d on d.user_id = a.realty_consultant
  691. LEFT JOIN ta_person_from_record p ON a.person_id = p.person_id AND p.is_first_time = 1 and p.org_id = #{orgId}
  692. LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
  693. LEFT JOIN ta_person p2 ON a.person_id = p2.person_id
  694. LEFT JOIN ta_person c ON p2.recommend_person = c.person_id
  695. left join ta_building t on a.building_id = t.building_id
  696. -- LEFT JOIN ta_person c ON p.share_person_id = c.person_id
  697. -- left join ta_building t on a.building_id = t.building_id
  698. -- LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
  699. left JOIN (select sum(points_amount) as points,person_id from ta_points_records where org_id = #{orgId} GROUP BY
  700. person_id) s on a.person_id = s.person_id
  701. left join (select sum(t.intention) as intention,t.person_id From ta_person_intention_record t where t.org_id =
  702. #{orgId} group by t.person_id) z on z.person_id = a.person_id
  703. <where>
  704. a.status > 0
  705. and a.verify_status = 1
  706. and a.realty_consultant is not null
  707. and a.realty_consultant != ''
  708. <if test="orgId != null">
  709. and a.org_id = #{orgId}
  710. </if>
  711. <if test="building != null and building !=''">
  712. and a.building_id = #{building}
  713. </if>
  714. <if test="name != null and name !=''">
  715. and a.name like CONCAT('%',#{name}, '%')
  716. </if>
  717. <if test="tel != null and tel!=''">
  718. and a.phone like CONCAT('%',#{tel}, '%')
  719. </if>
  720. <if test="consultName != null and consultName !=''">
  721. and b.name like CONCAT('%',#{consultName}, '%')
  722. </if>
  723. <if test="consultTel != null and consultTel !=''">
  724. and b.tel like CONCAT('%',#{consultTel}, '%')
  725. </if>
  726. <if test="entryType != null and entryType !=''">
  727. and a.entry_type = #{entryType}
  728. </if>
  729. <if test="verifyStatus != null and verifyStatus !=''">
  730. and a.verify_status = #{verifyStatus}
  731. </if>
  732. <if test="status != null and status !=''">
  733. and a.status = #{status}
  734. </if>
  735. <if test="sex != null and sex !=''">
  736. and a.sex = #{sex}
  737. </if>
  738. <if test="startCreateDate != null and startCreateDate !=''">
  739. and a.create_Date >= #{startCreateDate}
  740. </if>
  741. <if test="endCreateDate != null and endCreateDate !=''">
  742. and a.create_Date &lt;= #{endCreateDate}
  743. </if>
  744. <if test="personBuildingList != null and personBuildingList.size > 0">
  745. AND a.building_id in
  746. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  747. #{personBuilding.buildingId}
  748. </foreach>
  749. </if>
  750. <if test="sceneType !=null and sceneType !=''">
  751. and p.scene_type = #{sceneType}
  752. </if>
  753. </where>
  754. group by a.customer_id,a.building_id
  755. order by a.create_date desc
  756. </select>
  757. <!-- limit #{pageCode}, #{pageSize}-->
  758. <select id="getMyCustStatistics" resultType="java.util.Map">
  759. SELECT
  760. sum( IF ( STATUS = 4 AND verify_status = 1, 1, 0 ) ) AS clinchSum,
  761. sum( IF ( STATUS != 4 AND verify_status = 1, 1, 0 ) ) AS followSum
  762. FROM
  763. ta_recommend_customer
  764. WHERE
  765. org_id = #{orgId}
  766. AND ( realty_consultant = #{personId}
  767. <if test="userId != null and userId != ''">
  768. OR realty_consultant = #{userId}
  769. </if>
  770. )
  771. </select>
  772. <select id="getMyCustFollowOrClinch" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  773. SELECT
  774. *
  775. FROM
  776. ta_recommend_customer
  777. WHERE
  778. org_id = #{orgId}
  779. AND ( realty_consultant = #{personId} OR realty_consultant = #{userId} )
  780. <if test="type == 'follow'">
  781. AND STATUS != 4
  782. AND verify_status = 1
  783. <if test="name != null and name !=''">
  784. and (`name` like CONCAT('%',#{name}, '%') or phone like CONCAT('%',#{name}, '%'))
  785. </if>
  786. <if test="phone != null and phone !=''">
  787. and phone like CONCAT('%',#{phone}, '%')
  788. </if>
  789. <if test="status != null and status !=''">
  790. and status = #{status}
  791. </if>
  792. <if test="startReportDate != null and startReportDate !=''">
  793. and date_format( report_date, '%Y-%m-%d' ) >= #{startReportDate}
  794. </if>
  795. <if test="endReportDate != null and endReportDate !=''">
  796. and date_format( report_date, '%Y-%m-%d' ) &lt;= #{endReportDate}
  797. </if>
  798. <if test="startArrivalDate != null and startArrivalDate !=''">
  799. and date_format( arrival_date, '%Y-%m-%d' ) >= #{startArrivalDate}
  800. </if>
  801. <if test="endArrivalDate != null and endArrivalDate !=''">
  802. and date_format( arrival_date, '%Y-%m-%d' ) &lt;= #{endArrivalDate}
  803. </if>
  804. </if>
  805. <if test="type == 'clinch'">
  806. AND STATUS = 4
  807. </if>
  808. </select>
  809. <select id="getMyCustDetailById" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  810. SELECT
  811. *
  812. FROM
  813. ta_recommend_customer
  814. where customer_id = #{customerId}
  815. </select>
  816. <select id="getCustomerIntentions" resultType="com.yunzhi.marketing.entity.PersonIntention">
  817. SELECT
  818. SUM( a.intention ) AS intention,
  819. a.building_id,
  820. b.building_name
  821. FROM
  822. ta_person_intention_record a
  823. left join ta_building b on a.building_id = b.building_id
  824. WHERE
  825. a.person_id = #{personId}
  826. <if test="personBuildingList != null and personBuildingList.size > 0">
  827. AND a.building_id in
  828. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  829. #{personBuilding.buildingId}
  830. </foreach>
  831. </if>
  832. GROUP BY
  833. a.building_id
  834. ORDER BY
  835. intention DESC
  836. </select>
  837. <select id="getCustomersIRecommended" resultType="com.yunzhi.marketing.po.TaRecommendCustomerPO">
  838. select a.customer_id AS id,
  839. a.NAME,
  840. a.phone,
  841. a.picture,
  842. a.sex,
  843. "customer" AS type,
  844. a.building_id AS buildingId,
  845. a.create_date,
  846. a.building_id,
  847. a.realty_consultant AS consultant,
  848. a.STATUS AS customerStatus,
  849. NULL AS channelStatus,
  850. b.avatarurl
  851. from ta_recommend_customer a left join ta_person b on a.person_id = b.person_id
  852. where a.recommend_person = #{customerId}
  853. <if test="status != null and status !=''">
  854. and a.status = #{status}
  855. </if>
  856. <if test="startDate != null or endDate != null">
  857. AND a.create_date BETWEEN #{startDate} and #{endDate}
  858. </if>
  859. and a.org_id = #{orgId}
  860. <if test="personBuildingList != null and personBuildingList.size > 0">
  861. AND a.building_id in
  862. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  863. #{personBuilding.buildingId}
  864. </foreach>
  865. </if>
  866. union all
  867. SELECT
  868. a.channel_customer_id AS id,
  869. a.NAME,
  870. a.phone,
  871. a.picture,
  872. a.sex,
  873. a.building_id,
  874. "report" AS type,
  875. NULL AS buildingId,
  876. a.create_date,
  877. NULL AS consultant,
  878. "1" AS customerStatus,
  879. a.STATUS AS channelStatus,
  880. b.avatarurl
  881. FROM
  882. xlk_channel_customer a
  883. LEFT JOIN ta_person b ON a.person_id = b.person_id
  884. where a.recommend_person = #{customerId}
  885. and a.status = 1
  886. <if test="status != null and status !=''">
  887. and a.status = #{status}
  888. </if>
  889. <if test="startDate != null or endDate != null">
  890. AND a.create_date BETWEEN #{startDate} and #{endDate}
  891. </if>
  892. and a.org_id = #{orgId}
  893. <if test="personBuildingList != null and personBuildingList.size > 0">
  894. AND a.building_id in
  895. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  896. #{personBuilding.buildingId}
  897. </foreach>
  898. </if>
  899. ORDER BY create_date
  900. </select>
  901. <select id="getCustomerListOfConsultant" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  902. select s.*, t.avatarurl, s.report_date as visit_time
  903. from ta_recommend_customer s
  904. left join ta_person t on t.person_id = s.person_id
  905. where s.org_id = #{orgId}
  906. and (s.realty_consultant = #{userId}
  907. <if test="personId != null">
  908. or s.realty_consultant = #{personId}
  909. </if>
  910. )
  911. <if test="startDate != null">
  912. and s.create_date BETWEEN #{startDate} and #{endDate}
  913. </if>
  914. <if test="buildingId != null and buildingId !=''">
  915. and s.building_id = #{buildingId}
  916. </if>
  917. and s.status &gt; 0
  918. order by s.report_date desc
  919. </select>
  920. <select id="getConsultantCustomerList" resultType="com.yunzhi.marketing.entity.TaRecommendCustomer">
  921. SELECT
  922. *
  923. FROM
  924. ta_recommend_customer t
  925. WHERE
  926. t.org_id = #{orgId}
  927. AND t.STATUS > 0
  928. AND t.verify_status = 1
  929. AND t.realty_consultant IN ( #{userId}, #{personId})
  930. </select>
  931. <select id="checkCustomerBy" resultType="java.util.Map">
  932. SELECT
  933. count( 1 ) AS orgNum,
  934. <!-- sum( IF ( t.building_id IN ( 'foo', 'bar' ), 1, 0 ) ) AS consultNum, -->
  935. <choose>
  936. <when test="consultBuildingIds != null and consultBuildingIds.size > 0">
  937. COALESCE(sum( IF ( t.building_id IN <foreach collection="consultBuildingIds" item="id" open="(" close=")" separator=",">#{id}</foreach>
  938. </when>
  939. <otherwise>
  940. COALESCE(sum( IF ( t.building_id IN ('****')
  941. </otherwise>
  942. </choose>
  943. , 1, 0 ) ), 0) AS consultBuildingNum,
  944. <choose>
  945. <when test="consultBuildingIds != null and consultBuildingIds.size > 0">
  946. COALESCE(sum( IF ( t.building_id IN <foreach collection="consultBuildingIds" item="id" open="(" close=")" separator=",">#{id}</foreach>
  947. </when>
  948. <otherwise>
  949. COALESCE(sum( IF ( t.building_id IN ('****')
  950. </otherwise>
  951. </choose>
  952. AND IFNULL(t.realty_consultant, '') != '', 1, 0 ) ), 0) AS consultNum,
  953. COALESCE(sum( IF ( t.building_id = #{buildingId}, 1, 0 ) ), 0) AS buildingNum
  954. FROM
  955. ta_recommend_customer t
  956. WHERE
  957. t.org_id = #{orgId}
  958. AND t.person_id = #{personId}
  959. AND t.status > -1
  960. </select>
  961. <select id="getMarkingCustList" resultType="com.yunzhi.marketing.po.TaRecommendCustomerPO">
  962. SELECT
  963. t.customer_id AS id,
  964. t.NAME,
  965. t.phone,
  966. t.picture,
  967. t.sex,
  968. "customer" AS type,
  969. t.building_id as buildingId,
  970. t.realty_consultant as consultant,
  971. t.status as customerStatus,
  972. null as channelStatus
  973. FROM
  974. ta_recommend_customer t
  975. -- INNER JOIN ta_person p ON t.recommend_person = p.person_id
  976. WHERE
  977. t.building_id = #{buildingId}
  978. and t.entry_type = "verify"
  979. <if test="keywords != null and keywords !=''">
  980. and t.name like CONCAT('%',#{keywords}, '%')
  981. </if>
  982. UNION ALL
  983. SELECT
  984. channel_customer_id AS id,
  985. NAME,
  986. phone,
  987. picture,
  988. sex,
  989. "report" AS type,
  990. null as buildingId,
  991. null as consultant,
  992. null as customerStatus,
  993. status as channelStatus
  994. FROM
  995. xlk_channel_customer
  996. WHERE
  997. building_id = #{buildingId}
  998. <if test="keywords != null and keywords !=''">
  999. and name like CONCAT('%',#{keywords}, '%')
  1000. </if>
  1001. </select>
  1002. </mapper>