MaTechnicianMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ylx.massage.mapper.MaTechnicianMapper">
  6. <resultMap type="MaTechnician" id="MaTechnicianResult">
  7. <result property="id" column="id" />
  8. <result property="teName" column="te_name" />
  9. <result property="teNickName" column="te_nick_name" />
  10. <result property="teSex" column="te_sex" />
  11. <result property="tePhone" column="te_phone" />
  12. <result property="teAddress" column="te_address" />
  13. <result property="teAreaCode" column="te_area_code" />
  14. <result property="teAge" column="te_age" />
  15. <result property="teAvatar" column="te_avatar" />
  16. <result property="openService" column="openService" />
  17. <result property="lifePhotos" column="life_photos" />
  18. <result property="avatar" column="avatar" />
  19. <result property="teBrief" column="te_brief" />
  20. <result property="avatar" column="avatar" />
  21. <result property="idCard" column="id_card" />
  22. <result property="healthCertificate" column="health_certificate" />
  23. <result property="qualificationCertificate" column="qualification_certificate" />
  24. <result property="noCrimeRecord" column="no_crime_record" />
  25. <result property="commitmentPdf" column="commitment_pdf" />
  26. <result property="commitmentAudio" column="commitment_audio" />
  27. <result property="commitmentVideo" column="commitment_video" />
  28. <result property="serviceState" column="service_state" />
  29. <result property="nStatus2" column="n_status2" />
  30. <result property="merchantStatus" column="merchant_status" />
  31. <result property="postState" column="post_state" />
  32. <result property="techType" column="tech_type" />
  33. <result property="teIsEnable" column="te_is_enable" />
  34. <result property="auditStatus" column="audit_status" />
  35. <result property="createBy" column="create_by" />
  36. <result property="updateBy" column="update_by" />
  37. <result property="createTime" column="create_time" />
  38. <result property="updateTime" column="update_time" />
  39. <result property="isDelete" column="is_delete" />
  40. <result property="nStar" column="n_star" />
  41. <result property="nNum" column="n_num" />
  42. <result property="isRecommend" column="is_recommend" />
  43. </resultMap>
  44. <sql id="selectMaTechnicianVo">
  45. select id, te_name, te_nick_name, te_sex, te_phone, te_address, te_area_code, te_age, te_avatar,
  46. openService, life_photos, avatar, te_brief, service_state, ns_status2, merchant_status,
  47. post_state, tech_type, te_is_enable, audit_status, create_user, update_user, create_time,
  48. update_time, is_delete, n_star, n_num, is_recommend
  49. from ma_technician
  50. </sql>
  51. <select id="selectMaTechnicianList" parameterType="MaTechnician" resultMap="MaTechnicianResult">
  52. <include refid="selectMaTechnicianVo"/>
  53. <where>
  54. <if test="teName != null and teName != ''"> and te_name like concat('%', #{teName}, '%')</if>
  55. <if test="teNickName != null and teNickName != ''"> and te_nick_name like concat('%', #{teNickName}, '%')</if>
  56. <if test="teSex != null "> and te_sex = #{teSex}</if>
  57. <if test="tePhone != null and tePhone != ''"> and te_phone = #{tePhone}</if>
  58. <if test="teAddress != null and teAddress != ''"> and te_address = #{teAddress}</if>
  59. <if test="openService != null "> and openService = #{openService}</if>
  60. <if test="teAge != null "> and te_age = #{teAge}</if>
  61. <if test="teAvatar != null and teAvatar != ''"> and te_avatar = #{teAvatar}</if>
  62. <if test="lifePhotos != null and lifePhotos != ''"> and life_photos = #{lifePhotos}</if>
  63. <if test="teBrief != null and teBrief != ''"> and te_brief = #{teBrief}</if>
  64. <if test="serviceState != null "> and service_state = #{serviceState}</if>
  65. <if test="nsStatus2 != null "> and ns_status2 = #{nsStatus2}</if>
  66. <if test="merchantStatus != null and merchantStatus != ''"> and merchant_status = #{merchantStatus}</if>
  67. <if test="postState != null "> and post_state = #{postState}</if>
  68. <if test="techType != null "> and tech_type = #{techType}</if>
  69. <if test="teIsEnable != null "> and te_is_enable = #{teIsEnable}</if>
  70. <if test="auditStatus != null "> and audit_status = #{auditStatus}</if>
  71. <if test="isRecommend != null "> and is_recommend = #{isRecommend}</if>
  72. <if test="createUser != null "> and create_user = #{createUser}</if>
  73. <if test="updateUser != null "> and update_user = #{updateUser}</if>
  74. <if test="isDelete != null "> and is_delete = #{isDelete}</if>
  75. </where>
  76. </select>
  77. <select id="selectMaTechnicianById" parameterType="Long" resultMap="MaTechnicianResult">
  78. <include refid="selectMaTechnicianVo"/>
  79. where id = #{id}
  80. </select>
  81. <insert id="insertMaTechnician" parameterType="MaTechnician" useGeneratedKeys="true" keyProperty="id">
  82. insert into ma_technician
  83. <trim prefix="(" suffix=")" suffixOverrides=",">
  84. <if test="teName != null and teName != ''">te_name,</if>
  85. <if test="teNickName != null and teNickName != ''">te_nick_name,</if>
  86. <if test="teSex != null">te_sex,</if>
  87. <if test="tePhone != null and tePhone != ''">te_phone,</if>
  88. <if test="teAddress != null">te_address,</if>
  89. <if test="teAreaCode != null and teAreaCode != ''">te_area_code,</if>
  90. <if test="teAge != null">te_age,</if>
  91. <if test="teAvatar != null and teAvatar != ''">te_avatar,</if>
  92. <if test="openService != null">openService,</if>
  93. <if test="teProject != null and teProject != ''">te_project,</if>
  94. <if test="lifePhotos != null and lifePhotos != ''">life_photos,</if>
  95. <if test="avatar != null and avatar != ''">avatar,</if>
  96. <if test="teBrief != null and teBrief != ''">te_brief,</if>
  97. <if test="serviceState != null">service_state,</if>
  98. <if test="nStatus2 != null">n_status2,</if>
  99. <if test="merchantStatus != null and merchantStatus != ''">merchant_status,</if>
  100. <if test="postState != null">post_state,</if>
  101. <if test="techType != null">tech_type,</if>
  102. <if test="teIsEnable != null">te_is_enable,</if>
  103. <if test="auditStatus != null">audit_status,</if>
  104. <if test="createBy != null">create_by,</if>
  105. <if test="updateBy != null">update_by,</if>
  106. <if test="createTime != null">create_time,</if>
  107. <if test="updateTime != null">update_time,</if>
  108. <if test="isDelete != null">is_delete,</if>
  109. <if test="nStar != null">n_star,</if>
  110. <if test="nNum != null">n_num,</if>
  111. <if test="isRecommend != null">is_recommend,</if>
  112. </trim>
  113. <trim prefix="values (" suffix=")" suffixOverrides=",">
  114. <if test="teName != null and teName != ''">#{teName},</if>
  115. <if test="teNickName != null and teNickName != ''">#{teNickName},</if>
  116. <if test="teSex != null">#{teSex},</if>
  117. <if test="tePhone != null and tePhone != ''">#{tePhone},</if>
  118. <if test="teAddress != null">#{teAddress},</if>
  119. <if test="teAreaCode != null and teAreaCode != ''">#{teAreaCode},</if>
  120. <if test="teAge != null">#{teAge},</if>
  121. <if test="teAvatar != null and teAvatar != ''">#{teAvatar},</if>
  122. <if test="openService != null">#{openService},</if>
  123. <if test="teProject != null and teProject != ''">#{teProject},</if>
  124. <if test="lifePhotos != null and lifePhotos != ''">#{lifePhotos},</if>
  125. <if test="avatar != null and avatar != ''">#{avatar},</if>
  126. <if test="teBrief != null and teBrief != ''">#{teBrief},</if>
  127. <if test="serviceState != null">#{serviceState},</if>
  128. <if test="nStatus2 != null">#{nStatus2},</if>
  129. <if test="merchantStatus != null and merchantStatus != ''">#{merchantStatus},</if>
  130. <if test="postState != null">#{postState},</if>
  131. <if test="techType != null">#{techType},</if>
  132. <if test="teIsEnable != null">#{teIsEnable},</if>
  133. <if test="auditStatus != null">#{auditStatus},</if>
  134. <if test="createBy != null">#{createBy},</if>
  135. <if test="updateBy != null">#{updateBy},</if>
  136. <if test="createTime != null">#{createTime},</if>
  137. <if test="updateTime != null">#{updateTime},</if>
  138. <if test="isDelete != null">#{isDelete},</if>
  139. <if test="nStar != null">#{nStar},</if>
  140. <if test="nNum != null">#{nNum},</if>
  141. <if test="isRecommend != null">#{isRecommend},</if>
  142. </trim>
  143. </insert>
  144. <update id="updateMaTechnician" parameterType="MaTechnician">
  145. update ma_technician
  146. <trim prefix="SET" suffixOverrides=",">
  147. <if test="teName != null and teName != ''">te_name = #{teName},</if>
  148. <if test="teNickName != null and teNickName != ''">te_nick_name = #{teNickName},</if>
  149. <if test="teSex != null">te_sex = #{teSex},</if>
  150. <if test="tePhone != null and tePhone != ''">te_phone = #{tePhone},</if>
  151. <if test="teAddress != null and teAddress != ''">te_address = #{teAddress},</if>
  152. <if test="teAreaCode != null and teAreaCode != ''">te_area_code = #{teAreaCode},</if>
  153. <if test="teAge != null">te_age = #{teAge},</if>
  154. <if test="teAvatar != null and teAvatar != ''">te_avatar = #{teAvatar},</if>
  155. <if test="openService != null">openService = #{openService},</if>
  156. <if test="lifePhotos != null and lifePhotos != ''">life_photos = #{lifePhotos},</if>
  157. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  158. <if test="teBrief != null and teBrief != ''">te_brief = #{teBrief},</if>
  159. <if test="serviceState != null">service_state = #{serviceState},</if>
  160. <if test="nsStatus2 != null">ns_status2 = #{nsStatus2},</if>
  161. <if test="merchantStatus != null and merchantStatus != ''">merchant_status = #{merchantStatus},</if>
  162. <if test="postState != null">post_state = #{postState},</if>
  163. <if test="techType != null">tech_type = #{techType},</if>
  164. <if test="teIsEnable != null">te_is_enable = #{teIsEnable},</if>
  165. <if test="auditStatus != null">audit_status = #{auditStatus},</if>
  166. <if test="createUser != null">create_user = #{createUser},</if>
  167. <if test="updateUser != null">update_user = #{updateUser},</if>
  168. <if test="createTime != null">create_time = #{createTime},</if>
  169. <if test="updateTime != null">update_time = #{updateTime},</if>
  170. <if test="isDelete != null">is_delete = #{isDelete},</if>
  171. <if test="nStar != null">n_star = #{nStar},</if>
  172. <if test="nNum != null">n_num = #{nNum},</if>
  173. <if test="isRecommend != null">is_recommend = #{isRecommend},</if>
  174. </trim>
  175. where id = #{id}
  176. </update>
  177. <delete id="deleteMaTechnicianById" parameterType="Long">
  178. delete from ma_technician where id = #{id}
  179. </delete>
  180. <delete id="deleteMaTechnicianByIds" parameterType="String">
  181. delete from ma_technician where id in
  182. <foreach item="id" collection="array" open="(" separator="," close=")">
  183. #{id}
  184. </foreach>
  185. </delete>
  186. <resultMap type="com.ylx.massage.domain.vo.MaTechnicianMerchantListVO" id="MaTechnicianMerchantListResult">
  187. <result property="merchantId" column="merchant_id"/>
  188. <result property="teName" column="te_name"/>
  189. <result property="teNickName" column="te_nick_name"/>
  190. <result property="teSex" column="te_sex"/>
  191. <result property="teSexName" column="te_sex_name"/>
  192. <result property="teAvatar" column="te_avatar"/>
  193. <result property="tePhone" column="te_phone"/>
  194. <result property="nStar" column="n_star"/>
  195. <result property="serviceState" column="service_state"/>
  196. <result property="serviceStateName" column="service_state_name"/>
  197. <result property="nNum" column="n_num"/>
  198. <result property="onlineTime" column="online_time"/>
  199. <result property="teProject" column="te_project"/>
  200. <result property="postState" column="post_state"/>
  201. <result property="isRecommend" column="is_recommend"/>
  202. <result property="techType" column="tech_type"/>
  203. <result property="techTypeName" column="tech_type_name"/>
  204. <result property="merchantStatus" column="merchant_status"/>
  205. <result property="merchantStatusName" column="merchant_status_name"/>
  206. <result property="createTime" column="create_time"/>
  207. </resultMap>
  208. <resultMap type="com.ylx.massage.domain.vo.MaTechnicianMerchantDetailVO" id="MaTechnicianMerchantDetailResult">
  209. <result property="merchantId" column="merchant_id"/>
  210. <result property="teName" column="te_name"/>
  211. <result property="teNickName" column="te_nick_name"/>
  212. <result property="teSex" column="te_sex"/>
  213. <result property="teSexName" column="te_sex_name"/>
  214. <result property="tePhone" column="te_phone"/>
  215. <result property="openService" column="openService"/>
  216. <result property="serviceCategoryName" column="service_category_name"/>
  217. <result property="projectIds" column="project_ids"/>
  218. <result property="serviceProjectName" column="service_project_name"/>
  219. <result property="techType" column="tech_type"/>
  220. <result property="techTypeName" column="tech_type_name"/>
  221. <result property="isRecommend" column="is_recommend"/>
  222. <result property="isRecommendName" column="is_recommend_name"/>
  223. </resultMap>
  224. <resultMap type="com.ylx.massage.domain.vo.MaTechnicianAuditListVO" id="MaTechnicianAuditListResult">
  225. <result property="merchantId" column="merchant_id"/>
  226. <result property="teName" column="te_name"/>
  227. <result property="teSex" column="te_sex"/>
  228. <result property="teSexName" column="te_sex_name"/>
  229. <result property="tePhone" column="te_phone"/>
  230. <result property="teNickName" column="te_nick_name"/>
  231. <result property="avatar" column="avatar"/>
  232. <result property="teAddress" column="te_address"/>
  233. <result property="teBrief" column="te_brief"/>
  234. <result property="openServiceName" column="open_service_name"/>
  235. <result property="applyTime" column="apply_time"/>
  236. <result property="auditStatus" column="audit_status"/>
  237. <result property="auditStatusName" column="audit_status_name"/>
  238. <result property="techType" column="tech_type"/>
  239. </resultMap>
  240. <select id="selectMerchantAuditList" resultMap="MaTechnicianAuditListResult">
  241. SELECT
  242. t.id AS merchant_id,
  243. t.te_name,
  244. t.te_sex,
  245. CASE t.te_sex
  246. WHEN 0 THEN '女'
  247. WHEN 1 THEN '男'
  248. ELSE ''
  249. END AS te_sex_name,
  250. t.te_phone,
  251. t.te_nick_name,
  252. t.avatar,
  253. t.te_address,
  254. t.te_brief,
  255. COALESCE((
  256. SELECT GROUP_CONCAT(DISTINCT sc.name ORDER BY sc.sort, sc.id SEPARATOR '/')
  257. FROM service_category sc
  258. WHERE FIND_IN_SET(sc.id, t.openService)
  259. AND sc.is_delete = 0
  260. ), '') AS open_service_name,
  261. t.create_time AS apply_time,
  262. t.audit_status,
  263. CASE t.audit_status
  264. WHEN 0 THEN '待入驻'
  265. WHEN 1 THEN '待审核'
  266. WHEN 2 THEN '审核通过'
  267. WHEN 3 THEN '审核驳回'
  268. ELSE ''
  269. END AS audit_status_name,
  270. t.tech_type
  271. FROM ma_technician t
  272. <where>
  273. t.is_delete = 0
  274. <if test="dto != null">
  275. <choose>
  276. <when test="dto.auditStatus != null">
  277. AND t.audit_status = #{dto.auditStatus}
  278. </when>
  279. <otherwise>
  280. AND t.audit_status IN (0, 1, 2, 3)
  281. </otherwise>
  282. </choose>
  283. <if test="dto.teName != null and dto.teName != ''">
  284. AND t.te_name LIKE CONCAT('%', #{dto.teName}, '%')
  285. </if>
  286. <if test="dto.teNickName != null and dto.teNickName != ''">
  287. AND t.te_nick_name LIKE CONCAT('%', #{dto.teNickName}, '%')
  288. </if>
  289. <if test="dto.techType != null">
  290. AND t.tech_type = #{dto.techType}
  291. </if>
  292. <if test="dto.tePhone != null and dto.tePhone != ''">
  293. AND t.te_phone LIKE CONCAT('%', #{dto.tePhone}, '%')
  294. </if>
  295. <if test="dto.beginApplyTime != null and dto.beginApplyTime != ''">
  296. AND t.create_time &gt;= #{dto.beginApplyTime}
  297. </if>
  298. <if test="dto.endApplyTime != null and dto.endApplyTime != ''">
  299. AND t.create_time &lt;= #{dto.endApplyTime}
  300. </if>
  301. <if test="dto.teSex != null">
  302. AND t.te_sex = #{dto.teSex}
  303. </if>
  304. </if>
  305. <if test="dto == null">
  306. AND t.audit_status IN (0, 1, 2, 3)
  307. </if>
  308. </where>
  309. ORDER BY t.create_time DESC
  310. </select>
  311. <select id="selectMerchantList" resultMap="MaTechnicianMerchantListResult">
  312. SELECT
  313. t.id AS merchant_id,
  314. t.te_name,
  315. t.te_nick_name,
  316. t.te_sex,
  317. CASE t.te_sex
  318. WHEN 0 THEN '女'
  319. WHEN 1 THEN '男'
  320. ELSE ''
  321. END AS te_sex_name,
  322. t.te_avatar,
  323. t.te_phone,
  324. t.n_star,
  325. t.service_state,
  326. CASE t.service_state
  327. WHEN 0 THEN '服务中'
  328. WHEN 1 THEN '待接单'
  329. WHEN 2 THEN '休息中'
  330. ELSE ''
  331. END AS service_state_name,
  332. t.n_num,
  333. IFNULL(sign_data.online_time, 0) AS online_time,
  334. t.te_project,
  335. t.post_state,
  336. t.is_recommend,
  337. t.tech_type,
  338. CASE t.tech_type
  339. WHEN 0 THEN '正式用户'
  340. WHEN 1 THEN '虚拟用户'
  341. ELSE ''
  342. END AS tech_type_name,
  343. t.merchant_status,
  344. CASE t.merchant_status
  345. WHEN '0' THEN '正常'
  346. WHEN '1' THEN '限制接单'
  347. WHEN '2' THEN '冻结'
  348. WHEN '3' THEN '注销'
  349. ELSE ''
  350. END AS merchant_status_name,
  351. t.create_time
  352. FROM ma_technician t
  353. LEFT JOIN (
  354. SELECT js_id, SUM(IFNULL(online_time, 0)) AS online_time
  355. FROM t_sign
  356. WHERE is_delete = 0
  357. GROUP BY js_id
  358. ) sign_data ON sign_data.js_id = t.id
  359. <where>
  360. t.is_delete = 0
  361. <if test="dto != null">
  362. <!-- 商户姓名 -->
  363. <if test="dto.teName != null and dto.teName != ''">
  364. AND t.te_name LIKE CONCAT('%', #{dto.teName}, '%')
  365. </if>
  366. <!-- 商户昵称 -->
  367. <if test="dto.teNickName != null and dto.teNickName != ''">
  368. AND t.te_nick_name LIKE CONCAT('%', #{dto.teNickName}, '%')
  369. </if>
  370. <!-- 服务类目 -->
  371. <if test="dto.openService != null">
  372. AND FIND_IN_SET(#{dto.openService}, t.openService)
  373. </if>
  374. <!-- 手机号 -->
  375. <if test="dto.tePhone != null and dto.tePhone != ''">
  376. AND t.te_phone LIKE CONCAT('%', #{dto.tePhone}, '%')
  377. </if>
  378. <!-- 注册开始时间 -->
  379. <if test="dto.beginCreateTime != null and dto.beginCreateTime != ''">
  380. AND t.create_time &gt;= #{dto.beginCreateTime}
  381. </if>
  382. <!-- 注册结束时间 -->
  383. <if test="dto.endCreateTime != null and dto.endCreateTime != ''">
  384. AND t.create_time &lt;= #{dto.endCreateTime}
  385. </if>
  386. <!-- 上架状态 -->
  387. <if test="dto.postState != null">
  388. AND t.post_state = #{dto.postState}
  389. </if>
  390. <!-- 性别 -->
  391. <if test="dto.teSex != null">
  392. AND t.te_sex = #{dto.teSex}
  393. </if>
  394. <!-- 服务状态 -->
  395. <if test="dto.serviceState != null">
  396. AND t.service_state = #{dto.serviceState}
  397. </if>
  398. <!-- 用户类型 -->
  399. <if test="dto.techType != null">
  400. AND t.tech_type = #{dto.techType}
  401. </if>
  402. </if>
  403. </where>
  404. ORDER BY t.create_time DESC
  405. </select>
  406. <select id="selectMerchantDetailById" resultMap="MaTechnicianMerchantDetailResult">
  407. SELECT
  408. t.id AS merchant_id,
  409. t.te_name,
  410. t.te_nick_name,
  411. t.te_sex,
  412. CASE t.te_sex
  413. WHEN 0 THEN '女'
  414. WHEN 1 THEN '男'
  415. ELSE ''
  416. END AS te_sex_name,
  417. t.te_phone,
  418. t.openService,
  419. COALESCE(project_data.service_category_name, (
  420. SELECT GROUP_CONCAT(DISTINCT sc.name ORDER BY sc.sort, sc.id SEPARATOR '/')
  421. FROM service_category sc
  422. WHERE FIND_IN_SET(sc.id, t.openService)
  423. AND sc.is_delete = 0
  424. ), '') AS service_category_name,
  425. project_data.project_ids,
  426. COALESCE(project_data.service_project_name, t.te_project, '') AS service_project_name,
  427. t.tech_type,
  428. CASE t.tech_type
  429. WHEN 0 THEN '正式商户'
  430. WHEN 1 THEN '虚拟商户'
  431. ELSE ''
  432. END AS tech_type_name,
  433. t.is_recommend,
  434. CASE t.is_recommend
  435. WHEN 1 THEN '是'
  436. WHEN 0 THEN '否'
  437. ELSE ''
  438. END AS is_recommend_name
  439. FROM ma_technician t
  440. LEFT JOIN (
  441. SELECT
  442. mtp.te_id,
  443. GROUP_CONCAT(DISTINCT p.id ORDER BY p.id SEPARATOR ',') AS project_ids,
  444. GROUP_CONCAT(DISTINCT p.title ORDER BY p.id SEPARATOR '/') AS service_project_name,
  445. GROUP_CONCAT(DISTINCT sc2.name ORDER BY sc2.sort, sc2.id SEPARATOR '/') AS service_category_name
  446. FROM ma_te_project mtp
  447. LEFT JOIN project p ON p.id = mtp.project_id AND p.is_delete = 0
  448. LEFT JOIN service_category sc2 ON sc2.id = p.type AND sc2.is_delete = 0
  449. GROUP BY mtp.te_id
  450. ) project_data ON project_data.te_id = t.id
  451. WHERE t.is_delete = 0
  452. AND t.id = #{id}
  453. </select>
  454. <!-- 首页按摩商户推荐列表-->
  455. <select id="getMerchantRecommend" resultType="com.ylx.massage.domain.vo.MerchantVo">
  456. SELECT
  457. t.id AS merchantId,
  458. t.te_name AS teName,
  459. t.n_star AS nStar,
  460. COALESCE(o.sales, 0) AS nNum,
  461. COALESCE(p.min_price, 0) AS price,
  462. t.avatar AS avatar,
  463. CASE
  464. WHEN t.dist_meters IS NULL THEN NULL
  465. WHEN t.dist_meters &lt; 1000 THEN CONCAT(ROUND(t.dist_meters, 0), 'm')
  466. ELSE CONCAT(ROUND(t.dist_meters / 1000, 1), 'km')
  467. END AS distanceShow
  468. FROM (
  469. SELECT
  470. t.id,
  471. t.te_name,
  472. t.n_star,
  473. t.avatar,
  474. ROUND(ST_Distance_Sphere(POINT(a.longitude, a.latitude), POINT(#{dto.longitude}, #{dto.latitude})), 0) AS dist_meters
  475. FROM ma_technician t
  476. LEFT JOIN (
  477. SELECT merchant_id, longitude, latitude
  478. FROM t_address
  479. WHERE user_type = 2 AND type = 1 AND is_delete = 0
  480. ) a ON t.id = a.merchant_id
  481. WHERE t.is_delete = 0
  482. AND t.audit_status = 2
  483. AND t.n_status2 = 0
  484. AND t.merchant_status = 0
  485. AND t.te_area_code = #{dto.cityCode}
  486. ) t
  487. LEFT JOIN (
  488. SELECT merchant_id, COUNT(*) AS sales
  489. FROM t_order
  490. WHERE is_delete = 0 AND status = 6 AND project_type = 1
  491. GROUP BY merchant_id
  492. ) o ON t.id = o.merchant_id
  493. INNER JOIN (
  494. SELECT merchant_id, MIN(project_current_price) AS min_price
  495. FROM ma_project
  496. WHERE is_delete = 0 AND audit_status = 1 AND merchant_type = 1 AND project_is_enable = 1
  497. GROUP BY merchant_id
  498. ) p ON t.id = p.merchant_id
  499. ORDER BY COALESCE(o.sales, 0) DESC
  500. LIMIT 5
  501. </select>
  502. <!-- 首页热门陪玩商户推荐列表-->
  503. <select id="getHotCompanionMerchantList" resultType="com.ylx.companion.domain.vo.HotCompanionMerchantVO">
  504. SELECT
  505. t.id AS merchantId,
  506. t.te_name AS merchantName,
  507. t.n_star AS nStar,
  508. COALESCE(o.sales, 0) AS nNum,
  509. COALESCE(p.min_price, 0) AS price,
  510. t.avatar AS avatar,
  511. CASE
  512. WHEN t.dist_meters IS NULL THEN NULL
  513. WHEN t.dist_meters &lt; 1000 THEN CONCAT(ROUND(t.dist_meters, 0), 'm')
  514. ELSE CONCAT(ROUND(t.dist_meters / 1000, 1), 'km')
  515. END AS distanceShow
  516. FROM (
  517. SELECT
  518. t.id,
  519. t.te_name,
  520. t.n_star,
  521. t.avatar,
  522. ROUND(ST_Distance_Sphere(POINT(a.longitude, a.latitude), POINT(#{dto.longitude}, #{dto.latitude})), 0) AS dist_meters
  523. FROM ma_technician t
  524. LEFT JOIN (
  525. SELECT merchant_id, longitude, latitude
  526. FROM t_address
  527. WHERE user_type = 2 AND type = 1 AND is_delete = 0
  528. ) a ON t.id = a.merchant_id
  529. WHERE t.is_delete = 0
  530. AND t.audit_status = 2
  531. AND t.n_status2 = 0
  532. AND t.merchant_status = 0
  533. AND t.te_area_code = #{dto.cityCode}
  534. ) t
  535. LEFT JOIN (
  536. SELECT o.merchant_id, COUNT(*) AS sales
  537. FROM t_order o
  538. INNER JOIN project pt ON o.project_id = pt.id
  539. WHERE o.is_delete = 0 AND o.status = 6 AND o.project_type = 2
  540. AND pt.category_id = #{dto.categoryId}
  541. GROUP BY merchant_id
  542. ) o ON t.id = o.merchant_id
  543. INNER JOIN (
  544. SELECT merchant_id, MIN(project_current_price) AS min_price
  545. FROM ma_project p
  546. INNER JOIN project pt ON p.project_id = pt.id
  547. WHERE p.is_delete = 0 AND p.audit_status = 1 AND pt.type = 2 AND p.project_is_enable = 1
  548. AND pt.category_id = #{dto.categoryId} <!-- 通过 project 表关联 category_id -->
  549. GROUP BY merchant_id
  550. ) p ON t.id = p.merchant_id
  551. ORDER BY COALESCE(o.sales, 0) DESC
  552. LIMIT 5
  553. </select>
  554. <select id="getMerchantPage" resultType="com.ylx.merchant.domain.vo.MerchantListVO">
  555. SELECT
  556. t.id,
  557. t.te_name AS name,
  558. t.te_avatar AS avatar,
  559. MIN(p.project_current_price) AS price,
  560. SUM(p.project_users_num) AS service_count,
  561. <!-- 1. 计算距离 (单位:米),MySQL 8.0 专用函数 -->
  562. ST_Distance_Sphere(
  563. POINT(ANY_VALUE(ta.longitude), ANY_VALUE(ta.latitude)),
  564. POINT(#{dto.longitude}, #{dto.latitude})
  565. ) / 1000 AS distance,
  566. <!-- 2. 评分处理:如果为null或0,默认为5.0 -->
  567. GREATEST(IFNULL(t.n_star, 0), 4.5) AS score
  568. FROM ma_technician t
  569. <!-- 关联项目表以获取价格和分类信息 -->
  570. LEFT JOIN ma_project p ON t.id = p.merchant_id AND p.audit_status = 1 AND p.is_delete = 0
  571. LEFT JOIN t_address ta ON t.id = ta.merchant_id AND ta.user_type = 2 AND ta.is_default = 1 AND ta.is_delete = 0
  572. <where>
  573. <!-- 基础状态过滤 -->
  574. AND t.audit_status = 1
  575. AND t.merchant_status = 0
  576. AND t.is_delete = 0
  577. AND p.project_is_enable = 0
  578. <!-- Tab分类筛选 -->
  579. <if test="dto.projectId != null">
  580. AND p.id = #{dto.projectId}
  581. </if>
  582. <!-- 筛选:极速达 (距离 <= 5km) -->
  583. <if test="dto.fastArrival != null and dto.fastArrival == true">
  584. AND ST_Distance_Sphere(
  585. POINT(ta.longitude, ta.latitude),
  586. POINT(#{dto.longitude}, #{dto.latitude})
  587. ) &lt;= 5000
  588. </if>
  589. <!-- 筛选:新人上线 (上次接单时间 > 30天前) -->
  590. <if test="dto.newMerchant != null and dto.newMerchant == true">
  591. AND NOT EXISTS (
  592. SELECT 1 FROM t_order o
  593. WHERE o.merchant_id = t.id
  594. AND o.is_delete = 0
  595. AND o.completed_time >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  596. )
  597. </if>
  598. <!-- 筛选:开通城市-->
  599. <if test="dto.cityCode != null and dto.cityCode != ''">
  600. AND t.te_area_code LIKE CONCAT(#{dto.cityCode}, '%')
  601. </if>
  602. </where>
  603. GROUP BY t.id
  604. <!-- 排序逻辑 -->
  605. ORDER BY distance ASC
  606. </select>
  607. </mapper>