MonthlyCustomersDao.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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.kmall.admin.dao.statistics.MonthlyCustomersDao">
  4. <select id="queryMonthlyCustomers" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
  5. SELECT
  6. o.merch_sn AS merchSn,
  7. m.merch_name AS merchName,
  8. sum( o.order_price ) AS totalSales,
  9. sum( og.number) as totalNumber,
  10. count(DISTINCT o.pay_mobile) as totalCustomers,
  11. DATE_FORMAT(o.pay_time,'%Y-%m') as yearAndMonth
  12. FROM
  13. mall_order o
  14. LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
  15. LEFT JOIN mall_order_goods og ON o.id = og.order_id
  16. <where>
  17. o.is_onffline_order = '1'
  18. AND o.order_biz_type = '10'
  19. AND o.pay_status = '2'
  20. AND DATE_FORMAT(o.pay_time,'%Y-%m') &gt;= #{startMonth}
  21. AND DATE_FORMAT(o.pay_time,'%Y-%m') &lt;= #{endMonth}
  22. <if test="merchSn != null">
  23. and m.merch_sn = #{merchSn}
  24. </if>
  25. </where>
  26. group by DATE_FORMAT(o.pay_time,'%Y-%m')
  27. </select>
  28. <select id="queryWeeklyCustomers" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity">
  29. SELECT
  30. o.merch_sn AS merchSn,
  31. m.merch_name AS merchName,
  32. sum( o.order_price ) AS totalSales,
  33. sum( og.number) as totalNumber,
  34. count(DISTINCT o.id) as totalCustomers,
  35. DATE_FORMAT(o.pay_time,'%Y-%u') as yearAndWeek
  36. FROM
  37. mall_order o
  38. LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
  39. LEFT JOIN mall_order_goods og ON o.id = og.order_id
  40. <where>
  41. o.is_onffline_order = '1'
  42. AND o.order_biz_type = '10'
  43. AND o.pay_status = '2'
  44. AND DATE_FORMAT(o.pay_time,'%Y-%u') &gt;= #{startWeek}
  45. AND DATE_FORMAT(o.pay_time,'%Y-%u') &lt;= #{endWeek}
  46. <if test="merchSn != null">
  47. and m.merch_sn = #{merchSn}
  48. </if>
  49. </where>
  50. group by DATE_FORMAT(o.pay_time,'%Y-%u')
  51. </select>
  52. <select id="top10ForProduct" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
  53. SELECT
  54. m.merch_name AS merchName,
  55. og.goods_name as goodsName,
  56. og.goods_specification_name_value as goodsSpecificationNameValue,
  57. sum( og.number ) AS sales
  58. FROM
  59. mall_order o
  60. LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
  61. LEFT JOIN mall_order_goods og ON o.id = og.order_id
  62. <where>
  63. o.is_onffline_order = '1'
  64. AND o.order_biz_type = '10'
  65. AND o.pay_status = '2'
  66. <if test="month != null and month.trim() != ''">
  67. and DATE_FORMAT(o.pay_time,'%Y-%m') = #{month}
  68. </if>
  69. <if test="week != null and week.trim() != ''">
  70. and weekofyear(o.pay_time) = #{week}
  71. </if>
  72. <if test="merchSn != null">
  73. and m.merch_sn = #{merchSn}
  74. </if>
  75. </where>
  76. GROUP BY
  77. og.sku
  78. ORDER BY
  79. sales desc
  80. LIMIT 10
  81. </select>
  82. <select id="top10ByBrand" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
  83. SELECT
  84. m.merch_name AS merchName,
  85. g.brand as brand,
  86. og.goods_specification_name_value as goodsSpecificationNameValue,
  87. sum( og.number ) AS sales
  88. FROM
  89. mall_order o
  90. LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
  91. LEFT JOIN mall_order_goods og ON o.id = og.order_id
  92. LEFT JOIN mall_goods g ON g.id = og.goods_id
  93. <where>
  94. o.is_onffline_order = '1'
  95. AND o.order_biz_type = '10'
  96. AND o.pay_status = '2'
  97. <if test="startDate != null and startDate.trim() != ''">
  98. and DATE_FORMAT(o.pay_time,'%Y-%m-%d') &gt;= #{startDate}
  99. </if>
  100. <if test="endDate != null and endDate.trim() != ''">
  101. and DATE_FORMAT(o.pay_time,'%Y-%m-%d') &lt;= #{endDate}
  102. </if>
  103. <if test="merchSn != null">
  104. and m.merch_sn = #{merchSn}
  105. </if>
  106. </where>
  107. GROUP BY
  108. g.brand
  109. ORDER BY
  110. sales desc
  111. LIMIT 10
  112. </select>
  113. <select id="top10BySupplier" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
  114. SELECT
  115. m.merch_name AS merchName,
  116. s.child_supplier_name as supplier,
  117. og.goods_specification_name_value as goodsSpecificationNameValue,
  118. sum( og.number ) AS sales
  119. FROM
  120. mall_order o
  121. LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
  122. LEFT JOIN mall_order_goods og ON o.id = og.order_id
  123. LEFT JOIN mall_goods g ON g.id = og.goods_id
  124. LEFT JOIN mall_supplier s ON g.supplier_id = s.id
  125. <where>
  126. o.is_onffline_order = '1'
  127. AND o.order_biz_type = '10'
  128. AND o.pay_status = '2'
  129. <if test="startDate != null and startDate.trim() != ''">
  130. and DATE_FORMAT(o.pay_time,'%Y-%m') &gt;= #{startDate}
  131. </if>
  132. <if test="endDate != null and endDate.trim() != ''">
  133. and DATE_FORMAT(o.pay_time,'%Y-%m') &lt;= #{endDate}
  134. </if>
  135. <if test="merchSn != null">
  136. and m.merch_sn = #{merchSn}
  137. </if>
  138. </where>
  139. GROUP BY
  140. s.id
  141. ORDER BY
  142. sales desc
  143. LIMIT 10
  144. </select>
  145. <select id="salesByCategory" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity">
  146. SELECT
  147. sum( og.number ) AS sales,
  148. cg.NAME AS cgname
  149. FROM
  150. mall_order o
  151. LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
  152. LEFT JOIN mall_order_goods og ON o.id = og.order_id
  153. LEFT JOIN mall_product_store_rela a ON a.goods_id = og.goods_id
  154. LEFT JOIN mall_category cg ON a.category_id = cg.id
  155. <where>
  156. o.is_onffline_order = '1'
  157. AND o.order_biz_type = '10'
  158. AND o.pay_status = '2'
  159. <if test="startDate != null and startDate.trim() != ''">
  160. and DATE_FORMAT(o.pay_time,'%Y-%m') &gt;= #{startDate}
  161. </if>
  162. <if test="endDate != null and endDate.trim() != ''">
  163. and DATE_FORMAT(o.pay_time,'%Y-%m') &lt;= #{endDate}
  164. </if>
  165. <if test="merchSn != null">
  166. and m.merch_sn = #{merchSn}
  167. </if>
  168. </where>
  169. GROUP BY
  170. cg.parent_id
  171. limit 20
  172. </select>
  173. <select id="monthlyCategory" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
  174. SELECT
  175. sum( og.number ) AS sales,
  176. cg.NAME AS cgname,
  177. sum( o.order_price ) AS totalSales,
  178. DATE_FORMAT(o.pay_time,'%Y-%m') as yearAndMonth
  179. FROM
  180. mall_order o
  181. LEFT JOIN mall_order_goods og ON o.id = og.order_id
  182. LEFT JOIN mall_product_store_rela a ON a.goods_id = og.goods_id
  183. LEFT JOIN mall_category cg ON a.category_id = cg.id
  184. LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
  185. <where>
  186. o.is_onffline_order = '1'
  187. AND o.order_biz_type = '10'
  188. AND o.pay_status = '2'
  189. AND DATE_FORMAT(o.pay_time,'%Y-%m') &gt;= #{startMonth}
  190. AND DATE_FORMAT(o.pay_time,'%Y-%m') &lt;= #{endMonth}
  191. <if test="merchSn != null">
  192. and m.merch_sn = #{merchSn}
  193. </if>
  194. </where>
  195. GROUP BY
  196. cg.parent_id,DATE_FORMAT(o.pay_time,'%Y-%m')
  197. </select>
  198. </mapper>