MerchantMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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.chelvc.cloud.vehicle.server.dao.MerchantMapper">
  4. <sql id="BASIC_MERCHANT_SELECT">
  5. select mt.id, mt.user_id, mt.name, mt.logo, mt.banners, mt.liaison, mt.mobile, mt.opening, mt.address,mt.business_status,
  6. mt.score, mt.sale, mt.good_review,mt.region, mt.longitude, mt.latitude, mt.recommend, mt.status, mt.creator,
  7. mt.create_time,mt.updater, mt.update_time,mt.main_business,mt.ancillary_business
  8. from `merchant` mt
  9. </sql>
  10. <select id="listNearbyMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
  11. select mt.id, mt.name, mt.logo, mt.score, mt.sale,mt.opening, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
  12. round(st_distance_sphere(
  13. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  14. )) distance
  15. from `merchant` mt left join category c on mt.main_business = c.id
  16. where mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE'
  17. order by distance asc limit #{size}
  18. </select>
  19. <select id="listNearbyMerchantPaging" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
  20. select mt.id, mt.name, mt.logo, mt.score, mt.sale,mt.opening, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
  21. round(st_distance_sphere(
  22. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  23. )) distance
  24. from `merchant` mt left join category c on mt.main_business = c.id
  25. where mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE'
  26. order by distance asc
  27. </select>
  28. <select id="listRecommendMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
  29. select mt.id, mt.name, mt.logo, mt.score,mt.opening, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
  30. round(st_distance_sphere(
  31. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  32. )) distance
  33. from `merchant` mt left join category c on mt.main_business = c.id
  34. where mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE' and mt.recommend = 1
  35. order by distance asc limit #{size}
  36. </select>
  37. <select id="listRecommendMerchantPaging" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
  38. select mt.id, mt.name, mt.logo, mt.score, mt.opening,mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
  39. round(st_distance_sphere(
  40. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  41. )) distance
  42. from `merchant` mt left join category c on mt.main_business = c.id
  43. where mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE' and mt.recommend = 1
  44. order by distance asc
  45. </select>
  46. <select id="merchantPagingList" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
  47. select mt.id, mt.name, mt.logo, mt.score,mt.opening, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
  48. round(st_distance_sphere(
  49. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  50. )) distance
  51. from `merchant` mt left join category c on mt.main_business = c.id
  52. <where>
  53. mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE'
  54. <if test="param.keyword != null and !param.keyword.isEmpty()">
  55. and (mt.name like concat('%', #{param.keyword}, '%')
  56. or mt.id in (select gds.merchant_id from goods gds where gds.name like concat('%', #{param.keyword}, '%')
  57. or gds.description like concat('%', #{keyword}, '%')
  58. )
  59. or c.name like concat('%', #{keyword}, '%')
  60. )
  61. </if>
  62. <if test="param.categoryId != null">
  63. and (mt.main_business = #{param.categoryId} or mt.ancillary_business like concat('%',#{param.categoryId} , '%'))
  64. </if>
  65. </where>
  66. <if test="param.sort != null and param.sort.name == 'SYNTHESE'">
  67. order by mt.recommend desc
  68. </if>
  69. <if test="param.sort != null and param.sort.name == 'NEAREST'">
  70. order by distance desc
  71. </if>
  72. <if test="param.sort != null and param.sort.name == 'FAVORITE'">
  73. order by mt.score desc
  74. </if>
  75. <if test="param.sort != null and param.sort.name == 'BESTSELLING'">
  76. order by mt.sale desc
  77. </if>
  78. </select>
  79. <select id="listSimpleMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
  80. select mt.id, mt.name, mt.logo, mt.score,mt.opening, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
  81. round(st_distance_sphere(
  82. point(mt.longitude, mt.latitude), point(#{longitude}, #{latitude})
  83. )) distance
  84. from `merchant` mt left join category c on mt.main_business = c.id
  85. <where>
  86. <if test="offset != null">
  87. mt.id > #{offset}
  88. </if>
  89. mt.region between #{code} and #{boundary} and mt.status = 'ONLINE'
  90. <if test="keyword != null and !keyword.isEmpty()">
  91. and (mt.name like concat('%', #{keyword}, '%')
  92. or mt.id in (select gds.merchant_id from goods gds where gds.name like concat('%', #{keyword}, '%')
  93. or gds.description like concat('%', #{keyword}, '%')
  94. )
  95. or c.name like concat('%', #{keyword}, '%')
  96. )
  97. </if>
  98. <if test="categoryId != null">
  99. and (mt.main_business = #{categoryId} or mt.ancillary_business like concat('%',#{categoryId} , '%'))
  100. </if>
  101. </where>
  102. <if test="sort != null and sort.name == 'SYNTHESE'">
  103. order by mt.recommend desc
  104. </if>
  105. <if test="sort != null and sort.name == 'NEAREST'">
  106. order by distance desc
  107. </if>
  108. <if test="sort != null and sort.name == 'FAVORITE'">
  109. order by mt.score desc
  110. </if>
  111. <if test="sort != null and sort.name == 'BESTSELLING'">
  112. order by mt.sale desc
  113. </if>
  114. limit #{size}
  115. </select>
  116. <select id="getMerchantById" resultType="com.chelvc.cloud.vehicle.server.entity.Merchant">
  117. select mt.id, mt.user_id as userId, mt.name, mt.logo, mt.banners, mt.liaison, mt.mobile,
  118. mt.opening, mt.address, mt.score, mt.sale, mt.good_review as goodReview,mt.region, mt.longitude,
  119. mt.latitude, mt.recommend, mt.status, mt.creator,mt.business_status,mt.main_business,mt.ancillary_business,
  120. mt.create_time as createTime,
  121. round(st_distance_sphere(
  122. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  123. )) distance
  124. from `merchant` mt
  125. where mt.id = #{id}
  126. </select>
  127. <select id="merchantFavorite" resultType="java.lang.Integer">
  128. SELECT
  129. count(*)
  130. FROM
  131. favorite
  132. WHERE
  133. type = 'MERCHANT'
  134. AND content_id = #{merchantId}
  135. AND user_id = #{userId}
  136. </select>
  137. <select id="listRankMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantRankDTO">
  138. SELECT
  139. mt.id,
  140. mt.user_id as userId,
  141. mt.NAME,
  142. mt.logo,
  143. mt.score,
  144. mt.sale,
  145. mt.status,
  146. mt.address,
  147. SUM( om.pay_amount ) amount,
  148. count( om.id ) orderNum,
  149. round(
  150. st_distance_sphere ( POINT ( mt.longitude, mt.latitude ), POINT ( #{param.longitude}, #{param.latitude}) )) distance
  151. FROM
  152. `merchant` mt
  153. LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
  154. WHERE
  155. mt.main_business = #{categoryId}
  156. and om.STATUS = 4
  157. <if test="level == 1">
  158. and mt.province = #{regionId}
  159. </if>
  160. <if test="level == 2">
  161. and mt.city = #{regionId}
  162. </if>
  163. <if test="level == 3">
  164. and mt.district = #{regionId}
  165. </if>
  166. AND om.create_time >= #{monthStartLocalTime}
  167. GROUP BY
  168. mt.id
  169. ORDER BY
  170. amount DESC
  171. limit 10
  172. </select>
  173. <select id="getMerchantIds" resultType="java.lang.Long">
  174. select m.id from merchant m left join oms_cart_item ca on m.id = ca.merchant_id
  175. where ca.id is not null and ca.user_id = #{userId} and ca.delete_status = '0'
  176. </select>
  177. <update id="updateMerchantBusinessStatus">
  178. update merchant set business_status = #{businessStatus} ,automatic = #{automatic}
  179. where id = #{merchantId}
  180. </update>
  181. <select id="rankMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantRankCountDTO">
  182. SELECT
  183. mt.id,
  184. mt.user_id as userId,
  185. SUM( om.pay_amount ) amount
  186. FROM
  187. `merchant` mt
  188. LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
  189. WHERE
  190. mt.main_business = #{categoryId}
  191. and om.STATUS = 4
  192. <if test="level == 1">
  193. and mt.province = #{regionId}
  194. </if>
  195. <if test="level == 2">
  196. and mt.city = #{regionId}
  197. </if>
  198. <if test="level == 3">
  199. and mt.district = #{regionId}
  200. </if>
  201. AND (om.create_time between #{monthStartLocalTime} and #{monthEndLocalTime})
  202. GROUP BY
  203. mt.id
  204. ORDER BY
  205. amount DESC
  206. limit #{limit}
  207. </select>
  208. <select id="queryTotalCommissionAmountByLastMonth" resultType="java.math.BigDecimal">
  209. SELECT
  210. SUM( r.reality_amount ) amount
  211. FROM
  212. `merchant` mt
  213. LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
  214. LEFT JOIN currency_record r ON r.order_id = om.id
  215. WHERE
  216. mt.main_business = #{categoryId}
  217. and om.STATUS = 4
  218. and r.source_type = 3
  219. <if test="level == 1">
  220. and mt.province = #{regionId}
  221. </if>
  222. <if test="level == 2">
  223. and mt.city = #{regionId}
  224. </if>
  225. <if test="level == 3">
  226. and mt.district = #{regionId}
  227. </if>
  228. AND (om.create_time between #{monthStartLocalTime} and #{monthEndLocalTime})
  229. </select>
  230. <select id="operatConditions" resultType="java.util.Map">
  231. SELECT
  232. ( SELECT count( 0 ) FROM reservation WHERE DATE_FORMAT( create_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
  233. <if test="merchantId != null">
  234. and merchant_id = #{merchantId}
  235. </if>) todayresevation,
  236. (
  237. SELECT
  238. count( 0 )
  239. FROM
  240. reservation
  241. WHERE
  242. DATE_FORMAT( create_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
  243. <if test="merchantId != null">
  244. and merchant_id = #{merchantId}
  245. </if>) yesterresevation,
  246. ( SELECT count( 0 ) FROM oms_order WHERE DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
  247. <if test="merchantId != null">
  248. and merchant_id = #{merchantId}
  249. </if>) todayorder,
  250. (
  251. SELECT
  252. count( 0 )
  253. FROM
  254. oms_order
  255. WHERE
  256. DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
  257. <if test="merchantId != null">
  258. and merchant_id = #{merchantId}
  259. </if>) yesterorder,
  260. ( SELECT sum( pay_amount ) FROM oms_order WHERE DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
  261. <if test="merchantId != null">
  262. and merchant_id = #{merchantId}
  263. </if>) todayamount,
  264. (
  265. SELECT
  266. sum( pay_amount )
  267. FROM
  268. oms_order
  269. WHERE
  270. DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
  271. <if test="merchantId != null">
  272. and merchant_id = #{merchantId}
  273. </if>) yesteramount,
  274. (select
  275. sum(pay_amount)
  276. from
  277. oms_order where 1=1
  278. <if test="merchantId != null">
  279. and merchant_id = #{merchantId}
  280. </if>) totalAmount
  281. FROM
  282. DUAL
  283. </select>
  284. <select id="operatReportByYear" resultType="java.util.Map">
  285. SELECT
  286. t.*
  287. FROM
  288. (
  289. SELECT MONTH
  290. ( payment_time ) MONTH,
  291. sum( pay_amount ) monthAmount,
  292. YEAR ( payment_time ) YEAR,
  293. count( 0 ) orderCount
  294. FROM
  295. oms_order
  296. where 1=1
  297. <if test="merchantId != null">
  298. and merchant_id = #{merchantId}
  299. </if>
  300. GROUP BY
  301. MONTH ( payment_time ),
  302. YEAR ( payment_time )) t
  303. WHERE
  304. t.YEAR = #{year}
  305. order by t.`MONTH`
  306. </select>
  307. <select id="operatReportByMonth" resultType="java.util.Map">
  308. SELECT
  309. t.*
  310. FROM
  311. (
  312. SELECT MONTH
  313. ( payment_time ) MONTH,
  314. sum( pay_amount ) monthAmount,
  315. YEAR ( payment_time ) YEAR,
  316. DAY ( payment_time ) day,
  317. count( 0 ) orderCount
  318. FROM
  319. oms_order
  320. where 1=1
  321. <if test="merchantId != null">
  322. and merchant_id = #{merchantId}
  323. </if>
  324. GROUP BY
  325. MONTH ( payment_time ),
  326. DAY ( payment_time ),
  327. YEAR ( payment_time )) t
  328. WHERE
  329. t.YEAR = #{year}
  330. and t.month = #{month}
  331. order by t.`day`
  332. </select>
  333. <select id="getAddMerchantReportByYear" resultType="java.util.Map">
  334. SELECT
  335. t.*
  336. FROM
  337. (
  338. SELECT MONTH
  339. ( create_time ) MONTH,
  340. YEAR ( create_time ) YEAR,
  341. count( 0 ) registerCount
  342. FROM
  343. merchant
  344. where 1=1
  345. GROUP BY
  346. MONTH ( create_time ),
  347. YEAR ( create_time )) t
  348. WHERE
  349. t.YEAR = #{year}
  350. order by t.`MONTH`
  351. </select>
  352. <select id="getAddMerchantReportByMonth" resultType="java.util.Map">
  353. SELECT
  354. t.*
  355. FROM
  356. (
  357. SELECT MONTH
  358. ( create_time ) MONTH,
  359. YEAR ( create_time ) YEAR,
  360. DAY ( create_time ) day,
  361. count( 0 ) registerCount
  362. FROM
  363. merchant
  364. where 1=1
  365. GROUP BY
  366. MONTH ( create_time ),
  367. DAY ( create_time ),
  368. YEAR ( create_time )) t
  369. WHERE
  370. t.YEAR = #{year}
  371. and t.month = #{month}
  372. order by t.`day`
  373. </select>
  374. <select id="getAddMerchantReport" resultType="java.util.Map">
  375. SELECT
  376. count( 1) registerCount
  377. FROM
  378. merchant
  379. WHERE
  380. YEAR ( create_time ) = #{year}
  381. <if test="month != null">
  382. AND MONTH ( create_time ) = #{month}
  383. </if>
  384. <if test="day != null">
  385. AND DAY ( create_time ) = #{day}
  386. </if>
  387. GROUP BY
  388. YEAR ( create_time )
  389. <if test="month != null">
  390. ,MONTH ( create_time )
  391. </if>
  392. <if test="day != null">
  393. ,DAY ( create_time )
  394. </if>
  395. </select>
  396. </mapper>