MerchantMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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.api.dto.MerchantDTO">
  11. select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,
  12. round(st_distance_sphere(
  13. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  14. )) distance
  15. from `merchant` mt
  16. where mt.region = #{param.region} and mt.status = 'ONLINE'
  17. order by distance asc limit #{size}
  18. </select>
  19. <select id="listRecommendMerchants" resultType="com.chelvc.cloud.vehicle.api.dto.MerchantDTO">
  20. select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,
  21. round(st_distance_sphere(
  22. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  23. )) distance
  24. from `merchant` mt
  25. where mt.region = #{param.region} and mt.status = 'ONLINE' and mt.recommend = 1
  26. order by distance asc limit #{size}
  27. </select>
  28. <select id="listSimpleMerchants" resultType="com.chelvc.cloud.vehicle.api.dto.MerchantDTO">
  29. select mt.id, mt.name, mt.logo, mt.score, mt.sale, mt.address,mt.business_status,
  30. round(st_distance_sphere(
  31. point(mt.longitude, mt.latitude), point(#{longitude}, #{latitude})
  32. )) distance
  33. from `merchant` mt
  34. <if test="categoryId != null or (keyword != null and !keyword.isEmpty())">
  35. left join `goods` gs on gs.merchant_id = mt.id
  36. <if test="categoryId != null">
  37. and gs.category_id = #{categoryId}
  38. </if>
  39. <if test="keyword != null and !keyword.isEmpty()">
  40. and (gs.name like concat('%', #{keyword}, '%') or gs.description like concat('%', #{keyword}, '%'))
  41. </if>
  42. and gs.status = 'ONLINE'
  43. </if>
  44. <where>
  45. <if test="offset != null">
  46. mt.id > #{offset}
  47. </if>
  48. mt.region = #{region} and mt.status = 'ONLINE'
  49. <if test="keyword != null and !keyword.isEmpty()">
  50. and mt.name like concat('%', #{keyword}, '%')
  51. </if>
  52. </where>
  53. <if test="sort != null and sort.name == 'SYNTHESE'">
  54. order by mt.recommend desc
  55. </if>
  56. <if test="sort != null and sort.name == 'NEAREST'">
  57. order by distance desc
  58. </if>
  59. <if test="sort != null and sort.name == 'FAVORITE'">
  60. order by mt.score desc
  61. </if>
  62. <if test="sort != null and sort.name == 'BESTSELLING'">
  63. order by mt.sale desc
  64. </if>
  65. limit #{size}
  66. </select>
  67. <select id="getMerchantById" resultType="com.chelvc.cloud.vehicle.server.entity.Merchant">
  68. select mt.id, mt.user_id as userId, mt.name, mt.logo, mt.banners, mt.liaison, mt.mobile,
  69. mt.opening, mt.address, mt.score, mt.sale, mt.good_review as goodReview,mt.region, mt.longitude,
  70. mt.latitude, mt.recommend, mt.status, mt.creator,mt.business_status,
  71. mt.create_time as createTime,
  72. round(st_distance_sphere(
  73. point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
  74. )) distance
  75. from `merchant` mt
  76. where mt.id = #{id} and mt.region = #{param.region}
  77. </select>
  78. <select id="merchantFavorite" resultType="java.lang.Integer">
  79. SELECT
  80. count(*)
  81. FROM
  82. favorite
  83. WHERE
  84. type = 'MERCHANT'
  85. AND content_id = #{merchantId}
  86. AND user_id = #{userId}
  87. </select>
  88. <select id="listRankMerchants" resultType="com.chelvc.cloud.vehicle.api.dto.MerchantRankDTO">
  89. SELECT
  90. mt.id,
  91. mt.user_id as userId,
  92. mt.NAME,
  93. mt.logo,
  94. mt.score,
  95. mt.sale,
  96. mt.status,
  97. mt.address,
  98. SUM( om.pay_amount ) amount,
  99. count( om.id ) orderNum,
  100. round(
  101. st_distance_sphere ( POINT ( mt.longitude, mt.latitude ), POINT ( #{param.longitude}, #{param.latitude}) )) distance
  102. FROM
  103. `merchant` mt
  104. LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
  105. WHERE
  106. om.STATUS = 4
  107. <if test="level == 1">
  108. and mt.province = #{regionId}
  109. </if>
  110. <if test="level == 2">
  111. and mt.city = #{regionId}
  112. </if>
  113. <if test="level == 3">
  114. and mt.district = #{regionId}
  115. </if>
  116. AND om.create_time >= #{monthStartLocalTime}
  117. GROUP BY
  118. mt.id
  119. ORDER BY
  120. amount DESC
  121. limit 10
  122. </select>
  123. <select id="getMerchantIds" resultType="java.lang.Long">
  124. select m.id from merchant m left join oms_cart_item ca on m.id = ca.merchant_id
  125. where ca.id is not null and ca.user_id = #{userId} and ca.delete_status = '0'
  126. </select>
  127. <update id="updateMerchantBusinessStatus">
  128. update merchant set business_status = #{businessStatus} ,automatic = #{automatic}
  129. where id = #{merchantId}
  130. </update>
  131. <select id="rankMerchants" resultType="com.chelvc.cloud.vehicle.api.dto.MerchantRankCountDTO">
  132. SELECT
  133. mt.id,
  134. mt.user_id as userId,
  135. SUM( om.pay_amount ) amount
  136. FROM
  137. `merchant` mt
  138. LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
  139. WHERE
  140. om.STATUS = 4
  141. <if test="level == 1">
  142. and mt.province = #{regionId}
  143. </if>
  144. <if test="level == 2">
  145. and mt.city = #{regionId}
  146. </if>
  147. <if test="level == 3">
  148. and mt.district = #{regionId}
  149. </if>
  150. AND (om.create_time between #{monthStartLocalTime} and #{monthEndLocalTime})
  151. GROUP BY
  152. mt.id
  153. ORDER BY
  154. amount DESC
  155. limit #{limit}
  156. </select>
  157. <select id="queryTotalCommissionAmountByLastMonth" resultType="java.math.BigDecimal">
  158. SELECT
  159. SUM( r.reality_amount ) amount
  160. FROM
  161. `merchant` mt
  162. LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
  163. LEFT JOIN currency_record r ON r.order_id = om.id
  164. WHERE
  165. om.STATUS = 4
  166. and r.source_type = 3
  167. <if test="level == 1">
  168. and mt.province = #{regionId}
  169. </if>
  170. <if test="level == 2">
  171. and mt.city = #{regionId}
  172. </if>
  173. <if test="level == 3">
  174. and mt.district = #{regionId}
  175. </if>
  176. AND (om.create_time between #{monthStartLocalTime} and #{monthEndLocalTime})
  177. </select>
  178. <select id="operatConditions" resultType="java.util.Map">
  179. SELECT
  180. ( SELECT count( 0 ) FROM reservation WHERE DATE_FORMAT( create_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
  181. <if test="merchantId != null">
  182. and merchant_id = #{merchantId}
  183. </if>) todayresevation,
  184. (
  185. SELECT
  186. count( 0 )
  187. FROM
  188. reservation
  189. WHERE
  190. DATE_FORMAT( create_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
  191. <if test="merchantId != null">
  192. and merchant_id = #{merchantId}
  193. </if>) yesterresevation,
  194. ( SELECT count( 0 ) FROM oms_order WHERE DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
  195. <if test="merchantId != null">
  196. and merchant_id = #{merchantId}
  197. </if>) todayorder,
  198. (
  199. SELECT
  200. count( 0 )
  201. FROM
  202. oms_order
  203. WHERE
  204. DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
  205. <if test="merchantId != null">
  206. and merchant_id = #{merchantId}
  207. </if>) yesterorder,
  208. ( SELECT sum( pay_amount ) FROM oms_order WHERE DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
  209. <if test="merchantId != null">
  210. and merchant_id = #{merchantId}
  211. </if>) todayamount,
  212. (
  213. SELECT
  214. sum( pay_amount )
  215. FROM
  216. oms_order
  217. WHERE
  218. DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
  219. <if test="merchantId != null">
  220. and merchant_id = #{merchantId}
  221. </if>) yesteramount
  222. FROM
  223. DUAL
  224. </select>
  225. <select id="operatReportByYear" resultType="java.util.Map">
  226. SELECT
  227. t.*
  228. FROM
  229. (
  230. SELECT MONTH
  231. ( payment_time ) MONTH,
  232. sum( pay_amount ) monthAmount,
  233. YEAR ( payment_time ) YEAR,
  234. count( 0 ) orderCount
  235. FROM
  236. oms_order
  237. where 1=1
  238. <if test="merchantId != null">
  239. and merchant_id = #{merchantId}
  240. </if>
  241. GROUP BY
  242. MONTH ( payment_time ),
  243. YEAR ( payment_time )) t
  244. WHERE
  245. t.YEAR = #{year}
  246. order by t.`MONTH`
  247. </select>
  248. <select id="operatReportByMonth" resultType="java.util.Map">
  249. SELECT
  250. t.*
  251. FROM
  252. (
  253. SELECT MONTH
  254. ( payment_time ) MONTH,
  255. sum( pay_amount ) monthAmount,
  256. YEAR ( payment_time ) YEAR,
  257. DAY ( payment_time ) day,
  258. count( 0 ) orderCount
  259. FROM
  260. oms_order
  261. where 1=1
  262. <if test="merchantId != null">
  263. and merchant_id = #{merchantId}
  264. </if>
  265. GROUP BY
  266. MONTH ( payment_time ),
  267. DAY ( payment_time ),
  268. YEAR ( payment_time )) t
  269. WHERE
  270. t.YEAR = #{year}
  271. and t.month = #{month}
  272. order by t.`day`
  273. </select>
  274. </mapper>