NewCmClubMapper.xml 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  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.caimei.modules.user.dao.NewCmClubDao">
  4. <sql id="newCmClubColumns">
  5. a.checkMan as "checkMan",
  6. a.clubID AS "clubID",
  7. a.userID AS "userID",
  8. u.name AS "name",
  9. a.sname AS "sname",
  10. a.logo AS "logo",
  11. a.legalPerson AS "legalPerson",
  12. a.provinceID AS "provinceID",
  13. a.cityID AS "cityID",
  14. a.townID AS "townID",
  15. a.flag AS "flag",
  16. a.inviterBindID AS "inviterBindID",
  17. a.inviterName AS "inviterName",
  18. a.spID AS "spID",
  19. a.mainServiceProviderID AS "mainServiceProviderID",
  20. a.scanTime AS "scanTime",
  21. a.address AS "address",
  22. a.linkMan AS "linkMan",
  23. a.linkManIdentity AS "linkManIdentity",
  24. a.contractPhone AS "contractPhone",
  25. a.contractMobile AS "contractMobile",
  26. a.contractEmail AS "contractEmail",
  27. a.fax AS "fax",
  28. a.info AS "info",
  29. a.addTime AS "addTime",
  30. a.auditTime AS "auditTime",
  31. a.auditNote AS "auditNote",
  32. a.status AS "status",
  33. a.businessLicenseImage AS "businessLicenseImage",
  34. a.defaultServiceProviderID AS "defaultServiceProviderID",
  35. a.defaultServiceProviderUpdTime AS "defaultServiceProviderUpdTime",
  36. a.mainpro AS "mainpro",
  37. a.scanFlag AS "scanFlag",
  38. a.headpic AS "headpic",
  39. a.socialCreditCode AS "socialCreditCode",
  40. a.lastModify AS "lastModify",
  41. a.firstClubType AS "firstClubType",
  42. a.secondClubType AS "secondClubType",
  43. a.department AS "department",
  44. a.medicalPracticeLicenseImg AS "medicalPracticeLicenseImg",
  45. a.newDeal as "newDeal"
  46. </sql>
  47. <sql id="otherColumns">
  48. ,case sp.status when 91 then '采美默认协销经理(官方账号)' else sp.linkMan end AS "spName",
  49. d.name AS "province",
  50. c.name AS "city",
  51. b.name AS "town",
  52. u.account AS "account",
  53. u.registerTime AS "registerTime",
  54. u.registerIP AS "registerIP",
  55. u.userName AS "userName",
  56. u.bindMobile AS "bindMobile",
  57. u.email AS "email",
  58. u.userOrganizeID AS "userOrganizeID",
  59. u.userIdentity AS "userIdentity",
  60. if(csu.delFlag = '0' and now() <![CDATA[ < ]]> csu.endTime,1,0) as svipUserFlag
  61. </sql>
  62. <sql id="newCmClubJoins">
  63. LEFT JOIN user u ON u.userID = a.userID
  64. LEFT JOIN cm_svip_user csu ON csu.userId = u.userID
  65. LEFT JOIN serviceprovider sp ON sp.serviceProviderID = a.spID
  66. LEFT JOIN town b ON b.townID=a.townID
  67. LEFT JOIN city c ON c.cityID=a.cityID
  68. LEFT JOIN province d ON d.provinceID=a.provinceID
  69. </sql>
  70. <select id="get" resultType="NewCmClub">
  71. SELECT
  72. <include refid="newCmClubColumns"/>
  73. <include refid="otherColumns"/>
  74. FROM club a
  75. <include refid="newCmClubJoins"/>
  76. WHERE a.clubID = #{id}
  77. </select>
  78. <select id="getclubByUserId" resultType="com.caimei.modules.user.entity.NewCmClub">
  79. SELECT
  80. <include refid="newCmClubColumns"/>
  81. FROM club a
  82. <include refid="newCmClubJoins"/>
  83. WHERE a.userID = #{userID}
  84. </select>
  85. <select id="textUserValue" resultType="com.caimei.modules.user.entity.NewCmClub">
  86. SELECT userID as valueID, activeState, customerValue
  87. FROM cm_organ_value_system
  88. WHERE stage = 0
  89. AND delType = 1
  90. </select>
  91. <select id="findList" resultType="NewCmClub">
  92. SELECT
  93. <include refid="newCmClubColumns"/>
  94. <include refid="otherColumns"/>,u.userPermission,u.source, covs.activeState,covs.customerValue
  95. FROM club a
  96. <include refid="newCmClubJoins"/>
  97. LEFT JOIN (SELECT userID, activeState, customerValue FROM cm_organ_value_system WHERE stage = 0 AND delType = 1)
  98. covs ON a.userID = covs.userID
  99. <where>
  100. (u.userOrganizeID IN(0,1) or u.clubStatus != 92) and u.userOrganizeID != 4
  101. <if test="clubID != null and clubID != ''">
  102. AND a.clubID = #{clubID}
  103. </if>
  104. <if test="clubID == 0">
  105. AND a.clubID = #{clubID}
  106. </if>
  107. <if test="userID != null and userID != ''">
  108. AND a.userID = #{userID}
  109. </if>
  110. <if test="account != null and account != ''">
  111. AND u.account = #{account}
  112. </if>
  113. <if test="name != null and name != ''">
  114. AND u.name LIKE concat('%',#{name},'%')
  115. </if>
  116. <if test="userName != null and userName != ''">
  117. AND u.userName LIKE concat('%',#{userName},'%')
  118. </if>
  119. <if test="townID != null and townID != ''">
  120. AND d.provinceID = #{provinceID}
  121. </if>
  122. <if test="cityID != null and cityID != ''">
  123. AND c.cityID = #{cityID}
  124. </if>
  125. <if test="townID != null and townID != ''">
  126. AND b.townID = #{townID}
  127. </if>
  128. <if test="status != null and status != ''">
  129. AND a.status = #{status}
  130. </if>
  131. <if test="bindMobile != null and bindMobile != ''">
  132. AND u.bindMobile LIKE concat('%',#{bindMobile},'%')
  133. </if>
  134. <if test="email != null and email != ''">
  135. AND u.email LIKE concat('%',#{email},'%')
  136. </if>
  137. <if test="linkMan != null and linkMan != ''">
  138. AND a.linkMan LIKE concat('%',#{linkMan},'%')
  139. </if>
  140. <if test="startTime != null and startTime != ''">
  141. AND (u.registerTime &gt; #{startTime} OR u.registerTime = #{startTime})
  142. </if>
  143. <if test="endTime != null and endTime != ''">
  144. AND (u.registerTime &lt; #{endTime} OR u.registerTime = #{endTime})
  145. </if>
  146. <if test="userIdentity != null and userIdentity != '' and userIdentity != '8'.toString()">
  147. AND u.userIdentity = #{userIdentity}
  148. </if>
  149. <if test="userIdentity != null and userIdentity != '' and userIdentity == '8'.toString()">
  150. AND csu.delFlag = '0' and now() <![CDATA[ < ]]> csu.endTime
  151. </if>
  152. <if test="newDeal != null">
  153. AND a.newDeal =#{newDeal}
  154. </if>
  155. <if test="activeState != null and activeState != ''">
  156. AND covs.activeState = #{activeState}
  157. </if>
  158. <if test="customerValue != null and customerValue != ''">
  159. AND covs.customerValue = #{customerValue}
  160. </if>
  161. <if test="spID != null and spID != ''">
  162. AND sp.serviceProviderID = #{spID}
  163. </if>
  164. </where>
  165. <choose>
  166. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  167. ORDER BY ${page.orderBy}
  168. </when>
  169. <otherwise>
  170. ORDER BY case when a.status = 91 then 0 else 1 end desc, a.addTime DESC
  171. </otherwise>
  172. </choose>
  173. </select>
  174. <select id="spNameList" resultType="com.caimei.modules.project.model.ServiceProviderModel">
  175. SELECT serviceProviderID, name
  176. FROM serviceprovider
  177. WHERE NAME NOT LIKE concat('%', '测试', '%')
  178. AND validFlag = 1
  179. AND STATUS = 90
  180. </select>
  181. <select id="findAllList" resultType="NewCmClub">
  182. SELECT
  183. <include refid="newCmClubColumns"/>
  184. <include refid="otherColumns"/>
  185. FROM club a
  186. <include refid="newCmClubJoins"/>
  187. <where>
  188. </where>
  189. <choose>
  190. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  191. ORDER BY ${page.orderBy}
  192. </when>
  193. <otherwise>
  194. </otherwise>
  195. </choose>
  196. </select>
  197. <insert id="insert" parameterType="NewCmClub" keyProperty="clubID" useGeneratedKeys="true">
  198. INSERT INTO club(userID,
  199. name,
  200. sname,
  201. logo,
  202. legalPerson,
  203. provinceID,
  204. cityID,
  205. townID,
  206. flag,
  207. inviterBindID,
  208. inviterName,
  209. spID,
  210. mainServiceProviderID,
  211. scanTime,
  212. address,
  213. linkMan,
  214. linkManIdentity,
  215. contractPhone,
  216. contractMobile,
  217. contractEmail,
  218. fax,
  219. info,
  220. addTime,
  221. auditTime,
  222. auditNote,
  223. status,
  224. businessLicenseImage,
  225. defaultServiceProviderID,
  226. defaultServiceProviderUpdTime,
  227. mainpro,
  228. scanFlag,
  229. headpic,
  230. lastModify,
  231. firstClubType,
  232. socialCreditCode,
  233. secondClubType,
  234. department,
  235. medicalPracticeLicenseImg)
  236. VALUES (#{userID},
  237. #{name},
  238. #{sname},
  239. #{logo},
  240. #{legalPerson},
  241. #{provinceID},
  242. #{cityID},
  243. #{townID},
  244. #{flag},
  245. #{inviterBindID},
  246. #{inviterName},
  247. #{spID},
  248. #{mainServiceProviderID},
  249. #{scanTime},
  250. #{address},
  251. #{linkMan},
  252. #{linkManIdentity},
  253. #{contractPhone},
  254. #{contractMobile},
  255. #{contractEmail},
  256. #{fax},
  257. #{info},
  258. #{addTime},
  259. #{auditTime},
  260. #{auditNote},
  261. #{status},
  262. #{businessLicenseImage},
  263. #{defaultServiceProviderID},
  264. #{defaultServiceProviderUpdTime},
  265. #{mainpro},
  266. #{scanFlag},
  267. #{headpic},
  268. #{lastModify},
  269. #{firstClubType},
  270. #{socialCreditCode},
  271. #{secondClubType},
  272. #{department},
  273. #{medicalPracticeLicenseImg})
  274. </insert>
  275. <update id="update">
  276. UPDATE club SET
  277. <if test="checkMan != null and checkMan != ''">
  278. checkMan = #{checkMan},
  279. </if>
  280. <if test="name != null and name != ''">
  281. name = #{name},
  282. </if>
  283. <if test="sname != null">
  284. sname = #{sname},
  285. </if>
  286. <if test="logo != null and logo != ''">
  287. logo = #{logo},
  288. </if>
  289. <if test="legalPerson != null and legalPerson != ''">
  290. legalPerson = #{legalPerson},
  291. </if>
  292. <if test="provinceID != null and provinceID != ''">
  293. provinceID = #{provinceID},
  294. </if>
  295. <if test="cityID != null and cityID != ''">
  296. cityID = #{cityID},
  297. </if>
  298. <if test="townID != null and townID != ''">
  299. townID = #{townID},
  300. </if>
  301. <if test="flag != null and flag != ''">
  302. flag = #{flag},
  303. </if>
  304. <if test="inviterBindID != null and inviterBindID != ''">
  305. inviterBindID = #{inviterBindID},
  306. </if>
  307. <if test="inviterName != null and inviterName != ''">
  308. inviterName = #{inviterName},
  309. </if>
  310. <if test="spID != null and spID != ''">
  311. spID = #{spID},
  312. </if>
  313. <if test="mainServiceProviderID != null and mainServiceProviderID != ''">
  314. mainServiceProviderID = #{mainServiceProviderID},
  315. </if>
  316. <if test="scanTime != null">
  317. scanTime = #{scanTime},
  318. </if>
  319. <if test="address != null and address != ''">
  320. address = #{address},
  321. </if>
  322. <if test="linkMan != null and linkMan != ''">
  323. linkMan = #{linkMan},
  324. </if>
  325. <if test="linkManIdentity != null and linkManIdentity != ''">
  326. linkManIdentity = #{linkManIdentity},
  327. </if>
  328. <if test="contractPhone != null and contractPhone != ''">
  329. contractPhone = #{contractPhone},
  330. </if>
  331. <if test="contractMobile != null and contractMobile != ''">
  332. contractMobile = #{contractMobile},
  333. </if>
  334. <if test="contractEmail != null and contractEmail != ''">
  335. contractEmail = #{contractEmail},
  336. </if>
  337. <if test="fax != null and fax != ''">
  338. fax = #{fax},
  339. </if>
  340. <if test="info != null and info != ''">
  341. info = #{info},
  342. </if>
  343. <if test="addTime != null">
  344. addTime = #{addTime},
  345. </if>
  346. <if test="auditTime != null">
  347. auditTime = #{auditTime},
  348. </if>
  349. <if test="auditNote != null and auditNote != ''">
  350. auditNote = #{auditNote},
  351. </if>
  352. <if test="status != null and status != ''">
  353. status = #{status},
  354. </if>
  355. <if test="businessLicenseImage != null">
  356. businessLicenseImage = #{businessLicenseImage},
  357. </if>
  358. <if test="socialCreditCode != null and socialCreditCode != ''">
  359. socialCreditCode = #{socialCreditCode},
  360. </if>
  361. <if test="defaultServiceProviderID != null and defaultServiceProviderID != ''">
  362. defaultServiceProviderID = #{defaultServiceProviderID},
  363. </if>
  364. <if test="defaultServiceProviderUpdTime != null and defaultServiceProviderUpdTime != ''">
  365. defaultServiceProviderUpdTime = #{defaultServiceProviderUpdTime},
  366. </if>
  367. <if test="mainpro != null and mainpro != ''">
  368. mainpro = #{mainpro},
  369. </if>
  370. <if test="scanFlag != null and scanFlag != ''">
  371. scanFlag = #{scanFlag},
  372. </if>
  373. <if test="headpic != null">
  374. headpic = #{headpic},
  375. </if>
  376. <if test="lastModify != null and lastModify != ''">
  377. lastModify = DATE_FORMAT(#{lastModify},'%Y-%m-%d %H:%i:%s'),
  378. </if>
  379. <if test="firstClubType != null and firstClubType != ''">
  380. firstClubType=#{firstClubType},
  381. </if>
  382. <if test="secondClubType != null and secondClubType != ''">
  383. secondClubType=#{secondClubType},
  384. </if>
  385. <if test="department != null and department != ''">
  386. department=#{department},
  387. </if>
  388. <if test="medicalPracticeLicenseImg != null and medicalPracticeLicenseImg != ''">
  389. medicalPracticeLicenseImg=#{medicalPracticeLicenseImg},
  390. </if>
  391. userID = #{userID}
  392. WHERE clubID = #{clubID}
  393. </update>
  394. <delete id="delete">
  395. DELETE
  396. FROM club
  397. WHERE clubID = #{clubID}
  398. </delete>
  399. <select id="findClubById" resultType="com.caimei.modules.user.entity.NewCmClub">
  400. SELECT
  401. <include refid="newCmClubColumns"/>
  402. , CONCAT(d.name,c.name ,b.name ,a.`address` ) address
  403. FROM club a
  404. LEFT JOIN user u ON u.userID = a.userID
  405. LEFT JOIN town b ON a.townID =b.townID
  406. LEFT JOIN city c ON b.cityID=c.cityID
  407. JOIN province d ON c.`provinceID` =d.`provinceID`
  408. WHERE a.clubID=#{clubID}
  409. </select>
  410. <select id="findSpId" resultType="java.lang.Integer">
  411. select serviceProviderID
  412. from serviceprovider
  413. where serviceProviderID = #{spID}
  414. and status = 90
  415. </select>
  416. <select id="findRemarksList" resultType="com.caimei.modules.user.entity.CmClubRemarks">
  417. select DISTINCT ccr.id as remarksId,
  418. ccr.remarks,
  419. s.linkMan as spName,
  420. ccr.addTime,
  421. ccr.questionMan,
  422. ccr.consultType as consult,
  423. ccr.clubType,
  424. ccr.pinceSensitve,
  425. ccr.satisfied,
  426. ccr.followup,
  427. ccr.extra,
  428. (SELECT NAME FROM serviceprovider s WHERE s.serviceProviderID = csr.leaderId) AS leaderName
  429. from cm_club_remarks ccr
  430. left join serviceprovider s on ccr.serviceProviderId = s.serviceProviderID
  431. LEFT JOIN cm_serviceteam_group csg ON ccr.serviceProviderId = csg.serviceId
  432. LEFT JOIN cm_serviceteam_role csr ON csr.id = csg.teamId
  433. where clubId = #{clubId}
  434. order by addTime desc
  435. </select>
  436. <select id="getRemarksImageList" resultType="java.lang.String">
  437. select imageUrl
  438. from cm_club_remarks_file
  439. where remarksId = #{remarksId}
  440. and fileType = 1
  441. </select>
  442. <select id="getRemarksFileList" resultType="com.caimei.modules.user.entity.RemarksFileVo">
  443. select fileName, ossName
  444. from cm_club_remarks_file
  445. where remarksId = #{remarksId}
  446. and fileType = 2
  447. </select>
  448. <insert id="insertBeansHistory">
  449. INSERT INTO `user_beans_history` (`userId`, `type`, `beansType`, `orderId`,
  450. `num`, `pushStatus`, `addTime`, delFlag)
  451. VALUES (#{userId}, #{type}, #{beansType}, #{orderId},
  452. #{num}, #{pushStatus}, #{addTime}, 0)
  453. </insert>
  454. <update id="updateByStatus">
  455. UPDATE club
  456. SET status = #{clubStatus}
  457. WHERE userID = #{confirmUserId}
  458. </update>
  459. <select id="findLowOrder" resultType="com.caimei.modules.user.entity.UserBeansHistory">
  460. select userId, type, beansType, orderId, num, addTime
  461. from user_beans_history
  462. where orderId = #{orderId}
  463. and delFlag = 0
  464. and type = 2
  465. and num = 500
  466. </select>
  467. <select id="findRegistList" resultType="com.caimei.modules.user.entity.CmClubRemarks">
  468. SELECT DISTINCT
  469. ccr.id AS remarksId, ccr.remarks,s.linkman AS spName, ccr.addTime,ccr.questionMan,
  470. csr.leaderId AS leaderId,IFNULL(ccr.consultType,'') AS consult, c.Name AS
  471. clubName,ccr.clubType,ccr.pinceSensitve,ccr.satisfied,ccr.followup,ccr.extra,c.newDeal,c.contractMobile,
  472. (SELECT NAME FROM serviceprovider s WHERE s.serviceProviderID= csr.leaderId) AS leaderName,
  473. (SELECT mainImage FROM product p WHERE p.productID= ccre.productID) AS productMainImage,
  474. (SELECT NAME FROM product p WHERE p.productID= ccre.productID) AS proName,
  475. # (SELECT linkMan FROM serviceprovider s WHERE s.serviceProviderID= ccr.serviceProviderID) AS oldName
  476. ccre.reportText AS reportText,ccre.status AS reportStatus,ccre.auditName AS auditName,ccre.auditTime AS
  477. auditTime,p.mainImage
  478. AS mainImage,p.name AS productName,sh.name AS shopName
  479. FROM cm_club_remarks ccr
  480. LEFT JOIN serviceprovider s ON ccr.createServiceProviderId = s.serviceProviderID
  481. LEFT JOIN club c ON c.clubId=ccr.clubId
  482. # LEFT JOIN serviceprovider s ON ccr.serviceProviderId = s.serviceProviderID
  483. LEFT JOIN cm_serviceTeam_group csg ON ccr.createServiceProviderId = csg.serviceId
  484. LEFT JOIN cm_serviceTeam_role csr ON csr.id = csg.teamId
  485. LEFT JOIN cm_club_report ccre ON ccre.Id= ccr.reportID
  486. LEFT JOIN product p ON p.productID = ccr.productID
  487. LEFT JOIN shop sh ON sh.shopID = p.shopID
  488. <where>
  489. <if test="remarks != null and remarks !=''">
  490. AND ccr.remarks LIKE concat('%',#{remarks},'%')
  491. </if>
  492. <if test="clubId != null">
  493. AND c.clubID = #{clubId}
  494. </if>
  495. <if test="contractMobile != null and contractMobile != ''">
  496. AND c.contractMobile = #{contractMobile}
  497. </if>
  498. <if test="clubName !=null and clubName !=''">
  499. AND c.Name like concat('%',#{clubName},'%')
  500. </if>
  501. <if test="leaderId != null">
  502. and csr.leaderId = #{leaderId}
  503. </if>
  504. <if test="serviceProviderId != null">
  505. and csg.serviceId = #{serviceProviderId}
  506. </if>
  507. <if test="startAddTime != null and startAddTime != ''">
  508. and ccr.addTime <![CDATA[ > ]]> #{startAddTime}
  509. </if>
  510. <if test="endAddTime != null and endAddTime != ''">
  511. and ccr.addTime <![CDATA[ < ]]> #{endAddTime}
  512. </if>
  513. <if test="newDeal !=null">
  514. and c.newDeal=#{newDeal}
  515. </if>
  516. <if test="reportID !=null">
  517. and ccr.reportID=#{reportID}
  518. </if>
  519. </where>
  520. group by p.productID
  521. ORDER BY ADDTIME DESC
  522. <choose>
  523. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  524. ORDER BY ${page.orderBy}
  525. </when>
  526. </choose>
  527. </select>
  528. <select id="findConsults" resultType="com.caimei.modules.consult.entity.type.CmConsulttype">
  529. select id, className, createdTime
  530. from cm_consulttype
  531. where delflag = 0
  532. </select>
  533. <select id="findTeams" resultType="com.caimei.modules.user.entity.CmSaleMan">
  534. select csr.leaderId, s.name as leaderName
  535. from cm_serviceteam_role csr
  536. left join serviceprovider s on s.serviceProviderID = csr.leaderId
  537. where csr.delflag = 0
  538. </select>
  539. <select id="findGroup" resultType="com.caimei.modules.project.model.ServiceProviderModel">
  540. SELECT serviceId as serviceProviderID, s.name
  541. FROM cm_serviceteam_group csg
  542. LEFT JOIN cm_serviceTeam_role csr ON csr.id = csg.teamid
  543. LEFT JOIN serviceprovider s ON s.serviceProviderID = csg.serviceId
  544. WHERE csr.leaderId = #{leaderId}
  545. </select>
  546. <select id="findClassName" resultType="java.lang.String">
  547. select className
  548. from cm_consulttype
  549. where id = #{string}
  550. </select>
  551. <delete id="deleteRamarks">
  552. DELETE
  553. FROM `cm_remarks`
  554. WHERE remarksId = #{remarksId}
  555. </delete>
  556. <insert id="addRemarks">
  557. INSERT INTO `cm_remarks`(remarks, `addtime`)
  558. VALUES (#{remarks}, #{addtime})
  559. </insert>
  560. <update id="upremarks">
  561. UPDATE `cm_remarks`
  562. SET remarks = #{remarks}
  563. WHERE remarksId = #{remarksId}
  564. </update>
  565. <select id="upremakasList" resultType="java.lang.String">
  566. SELECT remarks
  567. FROM `cm_remarks`
  568. WHERE remarksId = #{remarksId}
  569. </select>
  570. <select id="ClubsIds" resultType="java.lang.Integer">
  571. select oldserviceProviderId
  572. FROM `cm_club_remarks`
  573. WHERE clubId = #{clubID}
  574. </select>
  575. <update id="oldname">
  576. UPDATE cm_club_remarks
  577. SET oldserviceProviderId = #{oldserviceProviderId},
  578. serviceProviderId=#{newSpID}
  579. WHERE clubId = #{clubID}
  580. AND serviceProviderId = #{oldSpID}
  581. </update>
  582. <update id="oldnames">
  583. UPDATE cm_club_remarks
  584. SET serviceProviderId=#{newSpID}
  585. WHERE clubId = #{clubID}
  586. AND serviceProviderId = #{oldSpID}
  587. </update>
  588. <select id="ReportList" resultType="com.caimei.modules.user.entity.CmReport">
  589. SELECT ccr.Id as reportId, p.mainImage AS mainImage,p.`name` AS productName,c.`name` AS clubName,ccr.reportName
  590. AS reportName,
  591. ccr.reportText AS reportText,ccr.addTime AS ADDTIME,ccr.status AS STATUS,ccr.auditName AS
  592. auditName,ccr.auditTime AS auditTime,c.newDeal,ccr.auditText
  593. FROM cm_club_report ccr
  594. LEFT JOIN product p ON p.productID = ccr.productID
  595. LEFT JOIN club c ON c.clubID = ccr.clubID
  596. <where>
  597. <if test="reportId!=null and reportId!=''">
  598. AND ccr.id=#{reportId}
  599. </if>
  600. <if test="productName!=null and productName!=''">
  601. AND p.name LIKE concat('%',#{productName},'%')
  602. </if>
  603. <if test="clubID != null">
  604. c.clubID = #{clubID}
  605. </if>
  606. <if test="clubName!=null and clubName!=''">
  607. AND c.name LIKE concat('%',#{clubName},'%')
  608. </if>
  609. <if test="newDeal!=null">
  610. AND c.newDeal =#{newDeal}
  611. </if>
  612. <if test="startAddTime != null and startAddTime != ''">
  613. and ccr.addTime <![CDATA[ > ]]> #{startAddTime}
  614. </if>
  615. <if test="endAddTime != null and endAddTime != ''">
  616. and ccr.addTime <![CDATA[ < ]]> #{endAddTime}
  617. </if>
  618. </where>
  619. group by p.productID
  620. ORDER BY ccr.`addTime` DESC
  621. </select>
  622. <select id="findRegistLists" resultType="com.caimei.modules.user.entity.VisitRemarkVo">
  623. SELECT DISTINCT
  624. ccr.id AS remarksId, ccr.remarks,s.name AS spName, ccr.addTime,ccr.questionMan,
  625. csr.leaderId AS leaderId,IFNULL(ccr.consultType,'') AS
  626. consult,ccr.clubType,ccr.pinceSensitve,ccr.satisfied,ccr.followup,ccr.extra,
  627. (SELECT linkMan FROM serviceprovider s WHERE s.serviceProviderID = ccr.serviceProviderId) AS serviceName,
  628. (SELECT NAME FROM serviceprovider s WHERE s.serviceProviderID = csr.leaderId) AS leaderName,
  629. (SELECT mainImage FROM product p WHERE p.productID= ccre.productID) AS productMainImage,
  630. (SELECT NAME FROM product p WHERE p.productID= ccre.productID) AS proName,
  631. ccre.reportText AS reportText,ccre.status AS reportStatus,ccre.auditName,ccre.auditTime AS auditTime,p.mainImage
  632. AS mainImage,p.name AS productName,sh.name AS shopName
  633. FROM cm_visitor_remarks ccr
  634. LEFT JOIN serviceprovider s ON ccr.serviceProviderId = s.serviceProviderID
  635. LEFT JOIN cm_serviceTeam_group csg ON ccr.serviceProviderId = csg.serviceId
  636. LEFT JOIN cm_serviceTeam_role csr ON csr.id = csg.teamId
  637. LEFT JOIN cm_club_report ccre ON ccre.Id= ccr.reportID
  638. LEFT JOIN product p ON p.productID = ccr.productID
  639. LEFT JOIN shop sh ON sh.shopID = p.shopID
  640. LEFT JOIN club c ON c.clubID = ccr.clubID
  641. <where>
  642. <if test="remarks != null and remarks !=''">
  643. AND ccr.remarks LIKE concat('%',#{remarks},'%')
  644. </if>
  645. <if test="leaderId != null">
  646. and csr.leaderId = #{leaderId}
  647. </if>
  648. <if test="serviceProviderId != null">
  649. and csg.serviceId = #{serviceProviderId}
  650. </if>
  651. <if test="startAddTime != '' and startAddTime != null">
  652. and ccr.addTime <![CDATA[ > ]]> #{startAddTime}
  653. </if>
  654. <if test="endAddTime != '' and endAddTime != null">
  655. and ccr.addTime <![CDATA[ < ]]> #{endAddTime}
  656. </if>
  657. <if test="reportID !=null">
  658. and ccr.reportID=#{reportID}
  659. </if>
  660. <if test="newDeal !=null">
  661. and c.newDeal=#{newDeal}
  662. </if>
  663. and ccr.remarks IS NOT NULL
  664. </where>
  665. group by p.productID
  666. ORDER BY ADDTIME DESC
  667. </select>
  668. <select id="visitorRemarksConut" resultType="integer">
  669. SELECT COUNT(*)
  670. FROM cm_visitor_remarks
  671. WHERE reportID = #{reportID}
  672. </select>
  673. <select id="clubRemarksConut" resultType="integer">
  674. SELECT COUNT(*)
  675. FROM cm_club_remarks
  676. WHERE reportID = #{reportID}
  677. </select>
  678. <update id="updateAuditRemarks">
  679. UPDATE cm_club_report
  680. SET status=#{status},
  681. auditName=#{auditName},
  682. auditText=#{auditText},
  683. auditTime=now()
  684. WHERE id = #{reportID}
  685. </update>
  686. <update id="updateClubRemarks">
  687. UPDATE cm_club_remarks
  688. SET reportID=null
  689. WHERE id = #{remarksId}
  690. </update>
  691. <update id="updateVisitorRemarks">
  692. UPDATE cm_visitor_remarks
  693. SET reportID=null
  694. WHERE id = #{remarksId}
  695. </update>
  696. <delete id="deleteClubRemarks">
  697. DELETE
  698. FROM cm_club_report
  699. WHERE id = #{reportID}
  700. </delete>
  701. <insert id="addRecordLinkage">
  702. INSERT INTO `record_link`(`describe`, `link`, clubId, addTime)
  703. VALUES (#{describe}, #{link}, #{clubId}, now())
  704. </insert>
  705. <select id="recordLinkage" resultType="string">
  706. SELECT link
  707. from record_link
  708. where clubId = #{clubId}
  709. ORDER BY id DESC
  710. LIMIT 1
  711. </select>
  712. <select id="recordDescribe" resultType="string">
  713. SELECT `describe`
  714. from record_link
  715. where clubId = #{clubId}
  716. ORDER BY id DESC
  717. LIMIT 1
  718. </select>
  719. <select id="selRegisterIP" resultType="com.caimei.modules.user.entity.CmBehaviorRecord">
  720. SELECT u.registerIP, u.ipAddress AS region, u.registerTime
  721. FROM USER u
  722. LEFT JOIN club c ON u.userID = c.userID
  723. WHERE c.clubID = #{clubId}
  724. </select>
  725. <select id="selStatisticsList" resultType="com.caimei.modules.user.entity.ClubStatistics">
  726. SELECT
  727. u.userId,
  728. c.clubID,
  729. c.name,
  730. c.linkMan,
  731. c.contractMobile,
  732. c.linkManIdentity,
  733. c.address,
  734. c.businessLicenseImage,
  735. u.userIdentity,
  736. c.sname,
  737. c.contractEmail,
  738. c.contractPhone,
  739. c.fax,
  740. c.headpic,
  741. c.socialCreditCode,
  742. c.info,
  743. (CASE WHEN c.linkManIdentity=1 THEN '老板'
  744. WHEN c.linkManIdentity=2 THEN '采购'
  745. WHEN c.linkManIdentity=3 THEN '运营'
  746. WHEN c.linkManIdentity=4 THEN '其他'
  747. END) AS linkManStatus,
  748. (CASE WHEN c.status = 1 THEN '待审核'
  749. WHEN c.status=91 THEN '已下线'
  750. WHEN c.status=90 THEN '已上线'
  751. WHEN c.status=92 THEN '审核未通过'
  752. WHEN c.status=93 THEN '已确认'
  753. ELSE '已冻结' END) AS clubStatus,
  754. (CASE WHEN u.userIdentity=2 THEN '资质机构'
  755. ELSE '个人机构' END) AS clubRank,
  756. (CASE WHEN c.firstClubType=1 THEN '医美'
  757. WHEN c.firstClubType=2 THEN '生美'
  758. WHEN c.firstClubType=3 THEN '项目公司'
  759. WHEN c.firstClubType=4 THEN '个人'
  760. ELSE '其他' END) AS firstClubType,
  761. (CASE WHEN c.secondClubType=1 THEN '诊所'
  762. WHEN c.secondClubType=2 THEN '门诊'
  763. WHEN c.secondClubType=3 THEN '医院'
  764. WHEN c.secondClubType=5 THEN '美容院'
  765. WHEN c.secondClubType=6 THEN '养生馆'
  766. WHEN c.secondClubType=7 THEN '其他'
  767. END) AS classify,
  768. c.addTime AS addTime,
  769. IF(csu.delFlag = '0' AND NOW() <![CDATA[ < ]]> csu.endTime,1,0) AS svipUserFlag,
  770. case sp.status when 91 then '采美默认协销经理(官方账号)' else sp.linkMan end AS spName,
  771. IFNULL(orderMonth.payTotalMonth,0) AS payTotalMonth,
  772. IFNULL(orderMonth.orderCountMonth,0) AS orderCountMonth,
  773. IFNULL(orderYesr.payTotalYesr,0) AS payTotalYear,
  774. IFNULL(orderYesr.orderCountYesr,0) AS orderCountYear,
  775. IFNULL(orderTotal.payTotal,0) AS payTotal,
  776. ordr.lastOrderTime AS lastOrderTime
  777. FROM club c
  778. # LEFT JOIN cm_order cor ON c.userID = cor.userID
  779. LEFT JOIN USER u ON u.userId=c.userId
  780. LEFT JOIN cm_svip_user csu ON csu.userId = u.userID
  781. LEFT JOIN serviceprovider sp ON sp.serviceProviderID = c.spID
  782. LEFT JOIN
  783. (SELECT userId,SUM(co.payTotalFee) AS payTotalMonth,
  784. COUNT(co.orderid) AS orderCountMonth
  785. FROM cm_order co
  786. <where>
  787. co.status NOT IN (0,6,7)
  788. <if test="monthStartTime != null and monthStartTime != '' and monthEndTime != null and monthEndTime != ''">
  789. AND co.orderTime BETWEEN #{monthStartTime} AND #{monthEndTime}
  790. </if>
  791. </where>
  792. GROUP BY co.userid) AS orderMonth ON c.userId=orderMonth.userId
  793. LEFT JOIN
  794. (SELECT userId,SUM(co.payTotalFee) AS payTotalYesr,
  795. COUNT(co.orderid) AS orderCountYesr
  796. FROM cm_order co
  797. <where>
  798. co.status NOT IN (0,6,7)
  799. <if test="yearStartTime != null and yearStartTime != '' and yearEndTime != null and yearEndTime != ''">
  800. AND co.orderTime BETWEEN #{yearStartTime} AND #{yearEndTime}
  801. </if>
  802. </where>
  803. GROUP BY co.userid) AS orderYesr ON c.userId=orderYesr.userId
  804. LEFT JOIN
  805. (SELECT userId,SUM(co.payTotalFee) AS payTotal,
  806. COUNT(co.orderid) AS 21OrderCount
  807. FROM cm_order co
  808. <where>
  809. co.status NOT IN (0,6,7)
  810. <if test="customStartTime != null and customStartTime != ''">
  811. AND (co.orderTime > #{customStartTime} or co.orderTime = #{customStartTime})
  812. </if>
  813. <if test="customEndTime != null and customEndTime != ''">
  814. AND co.orderTime <![CDATA[ <= ]]> #{customEndTime}
  815. </if>
  816. </where>
  817. GROUP BY co.userid) AS orderTotal ON c.userId=orderTotal.userId
  818. LEFT JOIN (
  819. SELECT userID, MAX(orderTime) AS lastOrderTime FROM cm_order GROUP BY userID
  820. ) AS ordr ON c.userID = ordr.userID
  821. <where>
  822. u.userOrganizeID != 4
  823. <if test="registerStartTime != null and registerStartTime != ''">
  824. AND (c.addTime > #{registerStartTime} or c.addTime = #{registerStartTime} )
  825. </if>
  826. <if test="registerEndTime != null and registerEndTime != ''">
  827. AND c.addTime <![CDATA[ <= ]]> #{registerEndTime}
  828. </if>
  829. <if test="searchStartTime != null and searchStartTime != ''">
  830. AND (ordr.lastOrderTime > #{searchStartTime} or ordr.lastOrderTime = #{searchStartTime} )
  831. </if>
  832. <if test=" searchEndTime != null and searchEndTime != ''">
  833. AND ordr.lastOrderTime <![CDATA[ <= ]]> #{searchEndTime}
  834. </if>
  835. <if test="customerValue != null and customerValue != ''">
  836. AND c.firstClubType = #{customerValue}
  837. </if>
  838. <if test="searchUserIdentity != null and searchUserIdentity != '' and searchUserIdentity != '8'.toString()">
  839. AND u.userIdentity = #{searchUserIdentity}
  840. </if>
  841. <if test="searchUserIdentity != null and searchUserIdentity != '' and searchUserIdentity == '8'.toString()">
  842. AND csu.delFlag = '0' and now() <![CDATA[ < ]]> csu.endTime
  843. </if>
  844. <if test="searchStatus != null and searchStatus != ''">
  845. AND c.status = #{searchStatus}
  846. </if>
  847. <if test="linkManIdentity != null and linkManIdentity != ''">
  848. AND c.linkManIdentity = #{linkManIdentity}
  849. </if>
  850. <if test="payTotalMonth != null and payTotalMonth != ''">
  851. <if test="payTotalMonth==1">
  852. AND orderMonth.payTotalMonth <![CDATA[ < ]]> 10000
  853. </if>
  854. <if test="payTotalMonth==2">
  855. AND orderMonth.payTotalMonth BETWEEN 10000 AND 100000
  856. </if>
  857. <if test="payTotalMonth==3">
  858. AND orderMonth.payTotalMonth BETWEEN 100000 AND 1000000
  859. </if>
  860. <if test="payTotalMonth==4">
  861. AND orderMonth.payTotalMonth <![CDATA[ > ]]> 1000000
  862. </if>
  863. </if>
  864. <if test="payTotalYear != null and payTotalYear != ''">
  865. <if test="payTotalYear==1">
  866. AND orderYesr.payTotalYesr <![CDATA[ < ]]> 10000
  867. </if>
  868. <if test="payTotalYear==2">
  869. AND orderYesr.payTotalYesr BETWEEN 10000 AND 100000
  870. </if>
  871. <if test="payTotalYear==3">
  872. AND orderYesr.payTotalYesr BETWEEN 100000 AND 1000000
  873. </if>
  874. <if test="payTotalYear==4">
  875. AND orderYesr.payTotalYesr <![CDATA[ > ]]> 1000000
  876. </if>
  877. </if>
  878. <if test="payTotal != null and payTotal != ''">
  879. <if test="payTotal==1">
  880. AND orderTotal.payTotal <![CDATA[ < ]]> 10000
  881. </if>
  882. <if test="payTotal==2">
  883. AND orderTotal.payTotal BETWEEN 10000 AND 100000
  884. </if>
  885. <if test="payTotal==3">
  886. AND orderTotal.payTotal BETWEEN 100000 AND 1000000
  887. </if>
  888. <if test="payTotal==4">
  889. AND orderTotal.payTotal <![CDATA[ > ]]> 1000000
  890. </if>
  891. </if>
  892. </where>
  893. GROUP BY c.userID ORDER BY
  894. <if test="payTotalMonthType == null and orderCountMonthType == null and payTotalYearType == null and orderCountYearType == null and payTotalType == null">
  895. ordr.lastOrderTime DESC
  896. </if>
  897. <if test="orderCountMonthType != null">
  898. <if test="orderCountMonthType == 0">
  899. orderMonth.orderCountMonth
  900. </if>
  901. <if test="orderCountMonthType == 1">
  902. orderMonth.orderCountMonth DESC
  903. </if>
  904. </if>
  905. <if test="orderCountYearType != null">
  906. <if test="orderCountYearType == 0">
  907. orderYesr.orderCountYesr
  908. </if>
  909. <if test="orderCountYearType == 1">
  910. orderYesr.orderCountYesr DESC
  911. </if>
  912. </if>
  913. <if test="payTotalMonthType != null">
  914. <if test="payTotalMonthType == 0">
  915. orderMonth.payTotalMonth
  916. </if>
  917. <if test="payTotalMonthType == 1">
  918. orderMonth.payTotalMonth DESC
  919. </if>
  920. </if>
  921. <if test="payTotalYearType != null">
  922. <if test="payTotalYearType == 0">
  923. orderYesr.payTotalYesr
  924. </if>
  925. <if test="payTotalYearType == 1">
  926. orderYesr.payTotalYesr DESC
  927. </if>
  928. </if>
  929. <if test="payTotalType != null">
  930. <if test="payTotalType == 0">
  931. orderTotal.payTotal
  932. </if>
  933. <if test="payTotalType == 1">
  934. orderTotal.payTotal DESC
  935. </if>
  936. </if>
  937. </select>
  938. <select id="selPageLable" resultType="com.caimei.modules.user.entity.CmBehaviorRecord">
  939. SELECT c.userID, COUNT(pageType) AS number, cbr.pageLabel
  940. FROM club c
  941. LEFT JOIN cm_behavior_record cbr ON cbr.userID = c.userID
  942. WHERE cbr.userID = c.userID
  943. AND cbr.pageType in (8, 9)
  944. GROUP BY c.userID, cbr.pageLabel
  945. </select>
  946. <select id="findExcelList" resultType="com.caimei.modules.user.entity.easyExcel">
  947. SELECT
  948. u.userId,
  949. c.clubID,
  950. c.name,
  951. c.linkMan,
  952. c.contractMobile,
  953. c.linkManIdentity,
  954. c.address,
  955. c.businessLicenseImage,
  956. u.userIdentity,
  957. c.sname,
  958. c.contractEmail,
  959. c.contractPhone,
  960. c.fax,
  961. c.headpic,
  962. c.socialCreditCode,
  963. c.info,
  964. (CASE WHEN c.linkManIdentity=1 THEN '老板'
  965. WHEN c.linkManIdentity=2 THEN '采购'
  966. WHEN c.linkManIdentity=3 THEN '运营'
  967. WHEN c.linkManIdentity=4 THEN '其他'
  968. END) AS linkManStatus,
  969. (CASE WHEN c.status = 1 THEN '待审核'
  970. WHEN c.status=91 THEN '已下线'
  971. WHEN c.status=90 THEN '已上线'
  972. WHEN c.status=92 THEN '审核未通过'
  973. WHEN c.status=93 THEN '已确认'
  974. ELSE '已冻结' END) AS clubStatus,
  975. (CASE WHEN u.userIdentity=2 THEN '资质机构'
  976. ELSE '个人机构' END) AS clubRank,
  977. (CASE WHEN c.firstClubType=1 THEN '医美'
  978. WHEN c.firstClubType=2 THEN '生美'
  979. WHEN c.firstClubType=3 THEN '项目公司'
  980. WHEN c.firstClubType=4 THEN '个人'
  981. ELSE '其他' END) AS firstClubType,
  982. (CASE WHEN c.secondClubType=1 THEN '诊所'
  983. WHEN c.secondClubType=2 THEN '门诊'
  984. WHEN c.secondClubType=3 THEN '医院'
  985. WHEN c.secondClubType=5 THEN '美容院'
  986. WHEN c.secondClubType=6 THEN '养生馆'
  987. WHEN c.secondClubType=7 THEN '其他'
  988. END) AS classify,
  989. c.addTime AS addTime,
  990. IF(csu.delFlag = '0' AND NOW() <![CDATA[ < ]]> csu.endTime,1,0) AS svipUserFlag,
  991. case sp.status when 91 then '采美默认协销经理(官方账号)' else sp.linkMan end AS spName,
  992. IFNULL(orderMonth.payTotalMonth,0) AS payTotalMonth,
  993. IFNULL(orderMonth.orderCountMonth,0) AS orderCountMonth,
  994. IFNULL(orderYesr.payTotalYesr,0) AS payTotalYear,
  995. IFNULL(orderYesr.orderCountYesr,0) AS orderCountYear,
  996. IFNULL(orderTotal.payTotal,0) AS payTotal,
  997. pb.pageLabel,
  998. ordr.lastOrderTime AS lastOrderTime
  999. FROM club c
  1000. # LEFT JOIN cm_order cor ON c.userID = cor.userID
  1001. LEFT JOIN USER u ON u.userId=c.userId
  1002. LEFT JOIN cm_svip_user csu ON csu.userId = u.userID
  1003. LEFT JOIN serviceprovider sp ON sp.serviceProviderID = c.spID
  1004. LEFT JOIN
  1005. (SELECT userId,SUM(co.payTotalFee) AS payTotalMonth,
  1006. COUNT(co.orderid) AS orderCountMonth
  1007. FROM cm_order co
  1008. <where>
  1009. co.status NOT IN (0,6,7)
  1010. <if test="monthStartTime != null and monthStartTime != '' and monthEndTime != null and monthEndTime != ''">
  1011. AND co.orderTime BETWEEN #{monthStartTime} AND #{monthEndTime}
  1012. </if>
  1013. </where>
  1014. GROUP BY co.userid) AS orderMonth ON c.userId=orderMonth.userId
  1015. LEFT JOIN
  1016. (SELECT userId,SUM(co.payTotalFee) AS payTotalYesr,
  1017. COUNT(co.orderid) AS orderCountYesr
  1018. FROM cm_order co
  1019. <where>
  1020. co.status NOT IN (0,6,7)
  1021. <if test="yearStartTime != null and yearStartTime != '' and yearEndTime != null and yearEndTime != ''">
  1022. AND co.orderTime BETWEEN #{yearStartTime} AND #{yearEndTime}
  1023. </if>
  1024. </where>
  1025. GROUP BY co.userid) AS orderYesr ON c.userId=orderYesr.userId
  1026. LEFT JOIN
  1027. (SELECT userId,SUM(co.payTotalFee) AS payTotal,
  1028. COUNT(co.orderid) AS 21OrderCount
  1029. FROM cm_order co
  1030. <where>
  1031. co.status NOT IN (0,6,7)
  1032. <if test="customStartTime != null and customStartTime != ''">
  1033. AND (co.orderTime > #{customStartTime} or co.orderTime = #{customStartTime})
  1034. </if>
  1035. <if test="customEndTime != null and customEndTime != ''">
  1036. AND co.orderTime <![CDATA[ <= ]]> #{customEndTime}
  1037. </if>
  1038. </where>
  1039. GROUP BY co.userid) AS orderTotal ON c.userId=orderTotal.userId
  1040. LEFT JOIN
  1041. (
  1042. SELECT c.userID, COUNT(cbr.pageLabel), cbr.pageLabel
  1043. FROM cm_behavior_record cbr
  1044. LEFT JOIN club c ON cbr.userID = c.userID
  1045. <where>cbr.userID = c.userID</where>
  1046. GROUP BY cbr.pageLabel) AS pb ON c.userID = pb.userID
  1047. LEFT JOIN (
  1048. SELECT userID, MAX(orderTime) AS lastOrderTime FROM cm_order GROUP BY userID
  1049. ) AS ordr ON c.userID = ordr.userID
  1050. <where>
  1051. <if test="registerStartTime != null and registerStartTime != ''">
  1052. AND (c.addTime > #{registerStartTime} or c.addTime = #{registerStartTime} )
  1053. </if>
  1054. <if test="registerEndTime != null and registerEndTime != ''">
  1055. AND c.addTime <![CDATA[ <= ]]> #{registerEndTime}
  1056. </if>
  1057. <if test="searchStartTime != null and searchStartTime != ''">
  1058. AND (ordr.lastOrderTime > #{searchStartTime} or ordr.lastOrderTime = #{searchStartTime} )
  1059. </if>
  1060. <if test=" searchEndTime != null and searchEndTime != ''">
  1061. AND ordr.lastOrderTime <![CDATA[ <= ]]> #{searchEndTime}
  1062. </if>
  1063. <if test="customerValue != null and customerValue != ''">
  1064. AND c.firstClubType = #{customerValue}
  1065. </if>
  1066. <if test="searchUserIdentity != null and searchUserIdentity != '' and searchUserIdentity != '8'.toString()">
  1067. AND u.userIdentity = #{searchUserIdentity}
  1068. </if>
  1069. <if test="searchUserIdentity != null and searchUserIdentity != '' and searchUserIdentity == '8'.toString()">
  1070. AND csu.delFlag = '0' and now() <![CDATA[ < ]]> csu.endTime
  1071. </if>
  1072. <if test="searchStatus != null and searchStatus != ''">
  1073. AND c.status = #{searchStatus}
  1074. </if>
  1075. <if test="linkManIdentity != null and linkManIdentity != ''">
  1076. AND c.linkManIdentity = #{linkManIdentity}
  1077. </if>
  1078. <if test="searchStatus != null and searchStatus != ''">
  1079. AND c.status = #{searchStatus}
  1080. </if>
  1081. <if test="payTotalMonth != null and payTotalMonth != ''">
  1082. <if test="payTotalMonth==1">
  1083. AND orderMonth.payTotalMonth <![CDATA[ < ]]> 10000
  1084. </if>
  1085. <if test="payTotalMonth==2">
  1086. AND orderMonth.payTotalMonth BETWEEN 10000 AND 100000
  1087. </if>
  1088. <if test="payTotalMonth==3">
  1089. AND orderMonth.payTotalMonth BETWEEN 100000 AND 1000000
  1090. </if>
  1091. <if test="payTotalMonth==4">
  1092. AND orderMonth.payTotalMonth <![CDATA[ > ]]> 1000000
  1093. </if>
  1094. </if>
  1095. <if test="payTotalYear != null and payTotalYear != ''">
  1096. <if test="payTotalYear==1">
  1097. AND orderYesr.payTotalYesr <![CDATA[ < ]]> 10000
  1098. </if>
  1099. <if test="payTotalYear==2">
  1100. AND orderYesr.payTotalYesr BETWEEN 10000 AND 100000
  1101. </if>
  1102. <if test="payTotalYear==3">
  1103. AND orderYesr.payTotalYesr BETWEEN 100000 AND 1000000
  1104. </if>
  1105. <if test="payTotalYear==4">
  1106. AND orderYesr.payTotalYesr <![CDATA[ > ]]> 1000000
  1107. </if>
  1108. </if>
  1109. <if test="payTotal != null and payTotal != ''">
  1110. <if test="payTotal==1">
  1111. AND orderTotal.payTotal <![CDATA[ < ]]> 10000
  1112. </if>
  1113. <if test="payTotal==2">
  1114. AND orderTotal.payTotal BETWEEN 10000 AND 100000
  1115. </if>
  1116. <if test="payTotal==3">
  1117. AND orderTotal.payTotal BETWEEN 100000 AND 1000000
  1118. </if>
  1119. <if test="payTotal==4">
  1120. AND orderTotal.payTotal <![CDATA[ > ]]> 1000000
  1121. </if>
  1122. </if>
  1123. </where>
  1124. GROUP BY c.userID ORDER BY ordr.lastOrderTime DESC
  1125. </select>
  1126. </mapper>