ChannelCustomerMapper.xml 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. d.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. WHERE
  87. a.recommend_person = #{params.personId}
  88. and a.org_id = #{params.orgId}
  89. <if test="params.status != null and params.status !=''">
  90. and c.status = #{params.status}
  91. </if>
  92. <if test="params.name != null and params.name !=''">
  93. and a.name like CONCAT('%',#{params.name}, '%')
  94. </if>
  95. <if test="params.startDate != null and params.startDate != null">
  96. AND a.create_date >= #{params.startDate}
  97. </if>
  98. <if test="params.endDate != null and params.endDate != null">
  99. 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})
  100. </if>
  101. ORDER BY
  102. a.create_date desc
  103. </select>
  104. <select id="getNewCustomer" resultType="java.lang.Integer">
  105. SELECT
  106. COUNT(1)
  107. FROM
  108. xlk_channel_customer t
  109. WHERE t.channel_id = #{params.channelId}
  110. <if test="params.startDate != null or params.endDate != null">
  111. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  112. </if>
  113. <if test="params.startDate == null or params.endDate == null">
  114. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  115. </if>
  116. </select>
  117. <select id="getSuccessCustomer" resultType="java.lang.Integer">
  118. SELECT
  119. COUNT(1)
  120. FROM
  121. xlk_channel_customer t
  122. LEFT join ta_recommend_customer r on t.customer_id = r.customer_id
  123. WHERE t.channel_id = #{params.channelId}
  124. and r.`status` in (4,5)
  125. <if test="params.startDate != null or params.endDate != null">
  126. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  127. </if>
  128. <if test="params.startDate == null or params.endDate == null">
  129. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  130. </if>
  131. </select>
  132. <select id="getNewCustomerDetail" resultType="com.yunzhi.marketing.xlk.vo.CustomerDetailVO">
  133. SELECT
  134. <if test="params.type == 'day'">
  135. date_format( t.create_date, '%Y-%m-%d' ) as coordinate,
  136. </if>
  137. <if test="params.type == 'month'">
  138. date_format( t.create_date, '%Y-%m' ) as coordinate,
  139. </if>
  140. COUNT(1) as customerNum
  141. FROM
  142. xlk_channel_customer t
  143. WHERE t.channel_id = #{params.channelId}
  144. <if test="params.startDate != null or params.endDate != null">
  145. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  146. </if>
  147. <if test="params.startDate == null or params.endDate == null">
  148. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  149. </if>
  150. <if test="params.type == 'day'">
  151. group by date_format( t.create_date, '%Y-%m-%d' )
  152. </if>
  153. <if test="params.type == 'month'">
  154. group by date_format( t.create_date, '%Y-%m' )
  155. </if>
  156. </select>
  157. <select id="getSuccessCustomerDetail" resultType="com.yunzhi.marketing.xlk.vo.CustomerDetailVO">
  158. SELECT
  159. <if test="params.type == 'day'">
  160. date_format( t.create_date, '%Y-%m-%d' ) as coordinate,
  161. </if>
  162. <if test="params.type == 'month'">
  163. date_format( t.create_date, '%Y-%m' ) as coordinate,
  164. </if>
  165. COUNT(1) as customerNum
  166. FROM
  167. xlk_channel_customer t
  168. LEFT join ta_recommend_customer r on t.customer_id = r.customer_id
  169. WHERE t.channel_id = #{params.channelId}
  170. and r.`status` in (4,5)
  171. <if test="params.startDate != null or params.endDate != null">
  172. AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
  173. </if>
  174. <if test="params.startDate == null or params.endDate == null">
  175. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  176. </if>
  177. <if test="params.type == 'day'">
  178. group by date_format( t.create_date, '%Y-%m-%d' )
  179. </if>
  180. <if test="params.type == 'month'">
  181. group by date_format( t.create_date, '%Y-%m' )
  182. </if>
  183. </select>
  184. <select id="getMoreInfoById" resultType="com.yunzhi.marketing.xlk.entity.ChannelCustomer">
  185. SELECT
  186. t.*,
  187. s.channel_name,
  188. IFNULL(m.`name`, m.nickname) as recommend_person_name
  189. FROM
  190. xlk_channel_customer t
  191. LEFT JOIN ta_channel s ON t.channel_id = s.channel_id
  192. LEFT JOIN ta_person m ON m.person_id = t.recommend_person
  193. WHERE 1 = 1
  194. <if test="channelCustomerId != null and channelCustomerId != ''">
  195. AND t.channel_customer_id = #{channelCustomerId}
  196. </if>
  197. <if test="customerId != null and customerId != ''">
  198. AND t.customer_id = #{customerId}
  199. </if>
  200. </select>
  201. <select id="getRecommendedOrExpired" resultType="com.yunzhi.marketing.xlk.entity.ChannelCustomer">
  202. SELECT
  203. t.*
  204. FROM
  205. xlk_channel_customer t
  206. LEFT JOIN xlk_building_channel s ON t.building_id = s.building_id
  207. AND s.channel_id IS NOT NULL
  208. AND t.channel_id = s.channel_id
  209. LEFT JOIN bk_agreement m ON t.building_id = s.building_id
  210. AND s.channel_id IS NULL
  211. WHERE
  212. t.building_id = #{buildingId}
  213. AND t.phone = #{phone}
  214. AND (
  215. t.`status` = 2
  216. OR (
  217. t.`status` = 1
  218. AND IFNULL( s.expiration_date, IFNULL( m.expiration_days, 0 ) ) &lt;= TIMESTAMPDIFF( DAY, t.create_date, now( ) )
  219. )
  220. )
  221. </select>
  222. </mapper>