ChannelCustomerMapper.xml 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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.xlk.mapper.ChannelCustomerMapper">
  4. <select id="getProfileList" resultType="com.yunzhi.marketing.xlk.entity.ChannelCustomer">
  5. SELECT
  6. t.*,
  7. s.building_name,
  8. IFNULL( m.`name`, m.nickname ) AS recommend_person_name,
  9. IFNULL( m.tel, m.phone ) AS recommend_phone
  10. FROM
  11. xlk_channel_customer t
  12. LEFT JOIN ta_building s ON t.building_id = s.building_id
  13. INNER JOIN ta_person m ON t.recommend_person = m.person_id
  14. WHERE
  15. t.org_id = #{orgId}
  16. <if test="institutionIds != null and institutionIds.size > 0">
  17. AND t.institution_id in
  18. <foreach collection="institutionIds" item="item" open="(" close=")" separator=",">
  19. #{item}
  20. </foreach>
  21. </if>
  22. <if test="buildingId != null and buildingId != ''">
  23. AND t.building_id = #{buildingId}
  24. </if>
  25. <if test="name != null and name != ''">
  26. AND t.`name` LIKE CONCAT( '%', #{name}, '%' )
  27. </if>
  28. <if test="phone != null and phone != ''">
  29. AND t.phone LIKE CONCAT( '%', #{phone}, '%' )
  30. </if>
  31. <if test="recommendPersonName != null and recommendPersonName != ''">
  32. AND m.nickname LIKE CONCAT( '%', #{recommendPersonName}, '%' )
  33. </if>
  34. <if test="recommendPhone != null and recommendPhone != ''">
  35. AND m.phone LIKE CONCAT( '%', #{recommendPhone}, '%' )
  36. </if>
  37. <if test="status != null and status != ''">
  38. AND t.`status` = #{status}
  39. </if>
  40. <if test="status == null or status == ''">
  41. AND t.`status` &gt; -1
  42. </if>
  43. <if test="type == 'customer'">
  44. AND t.channel_id is null
  45. </if>
  46. <if test="type == 'channel'">
  47. AND t.channel_id is not null
  48. </if>
  49. ORDER BY
  50. t.create_date DESC
  51. </select>
  52. <select id="getRanklist" resultType="com.yunzhi.marketing.po.CustomerRankListVO">
  53. SELECT
  54. COUNT(1) as number,
  55. t.recommend_person,
  56. p.`name`,
  57. p.avatarurl
  58. FROM
  59. xlk_channel_customer t
  60. INNER JOIN xlk_customer_visit v on t.customer_id = v.customer_id
  61. LEFT JOIN ta_person p on t.recommend_person = p.person_id
  62. WHERE t.channel_id = #{params.channelId}
  63. <if test="params.startDate != null or params.endDate != null">
  64. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  65. </if>
  66. <if test="params.startDate == null or params.endDate == null">
  67. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  68. </if>
  69. GROUP BY t.recommend_person
  70. ORDER BY number desc
  71. LIMIT 3
  72. </select>
  73. <select id="getCustomersIRecommended" resultType="com.yunzhi.marketing.po.MineRecommendCustomerPO">
  74. SELECT
  75. a.*,
  76. b.avatarurl ,
  77. ifnull(c.`status`, 1) as customer_status,
  78. if(c.customer_id is null, "report", "customer") as type,
  79. IF(a.recommend_person_type = 'broker', m.expiration_days, d.expiration_date) as expiration_date,
  80. d.building_name
  81. FROM
  82. xlk_channel_customer a
  83. LEFT JOIN ta_person b ON a.person_id = b.person_id
  84. left join ta_recommend_customer c on a.customer_id = c.customer_id
  85. LEFT JOIN ta_building d on a.building_id = d.building_id
  86. LEFT JOIN bk_agreement m ON a.building_id = m.building_id
  87. WHERE
  88. a.recommend_person = #{params.personId}
  89. and a.org_id = #{params.orgId}
  90. <if test="params.status != null and params.status !=''">
  91. and c.status = #{params.status}
  92. </if>
  93. <if test="params.name != null and params.name !=''">
  94. and a.name like CONCAT('%',#{params.name}, '%')
  95. </if>
  96. <if test="params.startDate != null and params.startDate != null">
  97. AND a.create_date >= #{params.startDate}
  98. </if>
  99. <if test="params.endDate != null and params.endDate != null">
  100. AND (a.visit_date &lt;= #{params.endDate} or a.preparatory_date &lt;= #{params.endDate} or a.signed_date &lt;= #{params.endDate} or a.commission_date &lt;= #{params.endDate})
  101. </if>
  102. ORDER BY
  103. a.create_date desc
  104. </select>
  105. <select id="getNewCustomer" resultType="java.lang.Integer">
  106. SELECT
  107. COUNT(1)
  108. FROM
  109. xlk_channel_customer t
  110. WHERE t.channel_id = #{params.channelId}
  111. <if test="params.startDate != null or params.endDate != null">
  112. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  113. </if>
  114. <if test="params.startDate == null or params.endDate == null">
  115. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  116. </if>
  117. </select>
  118. <select id="getSuccessCustomer" resultType="java.lang.Integer">
  119. SELECT
  120. COUNT(1)
  121. FROM
  122. xlk_channel_customer t
  123. LEFT join ta_recommend_customer r on t.customer_id = r.customer_id
  124. WHERE t.channel_id = #{params.channelId}
  125. and r.`status` in (4,5)
  126. <if test="params.startDate != null or params.endDate != null">
  127. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  128. </if>
  129. <if test="params.startDate == null or params.endDate == null">
  130. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  131. </if>
  132. </select>
  133. <select id="getNewCustomerDetail" resultType="com.yunzhi.marketing.xlk.vo.CustomerDetailVO">
  134. SELECT
  135. <if test="params.type == 'day'">
  136. date_format( t.create_date, '%Y-%m-%d' ) as coordinate,
  137. </if>
  138. <if test="params.type == 'month'">
  139. date_format( t.create_date, '%Y-%m' ) as coordinate,
  140. </if>
  141. COUNT(1) as customerNum
  142. FROM
  143. xlk_channel_customer t
  144. WHERE t.channel_id = #{params.channelId}
  145. <if test="params.startDate != null or params.endDate != null">
  146. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  147. </if>
  148. <if test="params.startDate == null or params.endDate == null">
  149. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  150. </if>
  151. <if test="params.type == 'day'">
  152. group by date_format( t.create_date, '%Y-%m-%d' )
  153. </if>
  154. <if test="params.type == 'month'">
  155. group by date_format( t.create_date, '%Y-%m' )
  156. </if>
  157. </select>
  158. <select id="getSuccessCustomerDetail" resultType="com.yunzhi.marketing.xlk.vo.CustomerDetailVO">
  159. SELECT
  160. <if test="params.type == 'day'">
  161. date_format( t.create_date, '%Y-%m-%d' ) as coordinate,
  162. </if>
  163. <if test="params.type == 'month'">
  164. date_format( t.create_date, '%Y-%m' ) as coordinate,
  165. </if>
  166. COUNT(1) as customerNum
  167. FROM
  168. xlk_channel_customer t
  169. LEFT join ta_recommend_customer r on t.customer_id = r.customer_id
  170. WHERE t.channel_id = #{params.channelId}
  171. and r.`status` in (4,5)
  172. <if test="params.startDate != null or params.endDate != null">
  173. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  174. </if>
  175. <if test="params.startDate == null or params.endDate == null">
  176. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  177. </if>
  178. <if test="params.type == 'day'">
  179. group by date_format( t.create_date, '%Y-%m-%d' )
  180. </if>
  181. <if test="params.type == 'month'">
  182. group by date_format( t.create_date, '%Y-%m' )
  183. </if>
  184. </select>
  185. <select id="getMoreInfoById" resultType="com.yunzhi.marketing.xlk.entity.ChannelCustomer">
  186. SELECT
  187. t.*,
  188. s.channel_name,
  189. IFNULL(m.`name`, m.nickname) as recommend_person_name
  190. FROM
  191. xlk_channel_customer t
  192. LEFT JOIN ta_channel s ON t.channel_id = s.channel_id
  193. LEFT JOIN ta_person m ON m.person_id = t.recommend_person
  194. WHERE 1 = 1
  195. <if test="channelCustomerId != null and channelCustomerId != ''">
  196. AND t.channel_customer_id = #{channelCustomerId}
  197. </if>
  198. <if test="customerId != null and customerId != ''">
  199. AND t.customer_id = #{customerId}
  200. </if>
  201. </select>
  202. <select id="getRecommendedOrExpired" resultType="com.yunzhi.marketing.xlk.entity.ChannelCustomer">
  203. SELECT
  204. t.*
  205. FROM
  206. xlk_channel_customer t
  207. LEFT JOIN xlk_building_channel s ON t.building_id = s.building_id
  208. AND s.channel_id IS NOT NULL
  209. AND t.channel_id = s.channel_id
  210. LEFT JOIN bk_agreement m ON t.building_id = s.building_id
  211. AND s.channel_id IS NULL
  212. WHERE
  213. t.building_id = #{buildingId}
  214. AND t.phone = #{phone}
  215. AND (
  216. t.`status` = 2
  217. OR (
  218. t.`status` = 1
  219. AND IFNULL( s.expiration_date, IFNULL( m.expiration_days, 0 ) ) &lt;= TIMESTAMPDIFF( DAY, t.create_date, now( ) )
  220. )
  221. )
  222. </select>
  223. <select id="getPageByBroker" resultType="com.yunzhi.marketing.xlk.entity.ChannelCustomer">
  224. SELECT
  225. t.channel_customer_id,
  226. t.create_date,
  227. t.org_id,
  228. t.building_id,
  229. fun_mix_str ( t.phone, 4 ) AS phone,
  230. t.`name`,
  231. t.picture,
  232. t.sex,
  233. t.person_id,
  234. t.`status`,
  235. t.channel_id,
  236. t.recommend_person,
  237. t.realty_consultant,
  238. t.remark,
  239. t.customer_id,
  240. t.visit_date,
  241. t.preparatory_date,
  242. t.signed_date,
  243. t.commission_date,
  244. t.institution_id,
  245. t.recommend_person_type,
  246. t.total_commission,
  247. t.unsettled_commission,
  248. t.settled_commission,
  249. s.building_name
  250. FROM
  251. xlk_channel_customer t
  252. INNER JOIN ta_building s ON t.building_id = s.building_id
  253. WHERE
  254. t.recommend_person = #{recommendPerson}
  255. <if test="name != null and name != ''">
  256. AND t.`name` LIKE CONCAT( '%', #{name}, '%' )
  257. </if>
  258. <if test="phone != null and phone != ''">
  259. AND t.phone LIKE CONCAT( '%', #{phone}, '%' )
  260. </if>
  261. AND t.`status` = 2
  262. -- AND t.`status` &gt; -1
  263. ORDER BY
  264. t.create_date DESC
  265. </select>
  266. </mapper>