MonthlyCustomersDao.xml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. <if test="startDate != null and startDate.trim() != ''">
  157. and DATE_FORMAT(o.pay_time,'%Y-%m') &gt;= #{startDate}
  158. </if>
  159. <if test="endDate != null and endDate.trim() != ''">
  160. and DATE_FORMAT(o.pay_time,'%Y-%m') &lt;= #{endDate}
  161. </if>
  162. <if test="merchSn != null">
  163. and m.merch_sn = #{merchSn}
  164. </if>
  165. </where>
  166. GROUP BY
  167. cg.parent_id
  168. limit 20
  169. </select>
  170. <select id="monthlyCategory" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
  171. SELECT
  172. sum( og.number ) AS sales,
  173. cg.NAME AS cgname,
  174. sum( o.order_price ) AS totalSales,
  175. DATE_FORMAT(o.pay_time,'%Y-%m')
  176. FROM
  177. mall_order o
  178. LEFT JOIN mall_order_goods og ON o.id = og.order_id
  179. LEFT JOIN mall_product_store_rela a ON a.goods_id = og.goods_id
  180. LEFT JOIN mall_category cg ON a.category_id = cg.id
  181. <where>
  182. o.is_onffline_order = '1'
  183. AND o.order_biz_type = '10'
  184. AND o.pay_status = '2'
  185. AND DATE_FORMAT(o.pay_time,'%Y-%m') &gt;= #{startMonth}
  186. AND DATE_FORMAT(o.pay_time,'%Y-%m') &lt;= #{endMonth}
  187. <if test="merchSn != null">
  188. and m.merch_sn = #{merchSn}
  189. </if>
  190. </where>
  191. GROUP BY
  192. cg.parent_id,DATE_FORMAT(o.pay_time,'%Y-%m')
  193. </select>
  194. </mapper>