123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.kmall.admin.dao.statistics.MonthlyCustomersDao">
- <select id="queryMonthlyCustomers" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
- SELECT
- o.merch_sn AS merchSn,
- m.merch_name AS merchName,
- sum( o.order_price ) AS totalSales,
- sum( og.number) as totalNumber,
- count(DISTINCT o.pay_mobile) as totalCustomers,
- DATE_FORMAT(o.pay_time,'%Y-%m') as yearAndMonth
- FROM
- mall_order o
- LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
- LEFT JOIN mall_order_goods og ON o.id = og.order_id
- <where>
- o.is_onffline_order = '1'
- AND o.order_biz_type = '10'
- AND o.pay_status = '2'
- AND DATE_FORMAT(o.pay_time,'%Y-%m') >= #{startMonth}
- AND DATE_FORMAT(o.pay_time,'%Y-%m') <= #{endMonth}
- <if test="merchSn != null">
- and m.merch_sn = #{merchSn}
- </if>
- </where>
- group by DATE_FORMAT(o.pay_time,'%Y-%m')
- </select>
- <select id="queryWeeklyCustomers" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity">
- SELECT
- o.merch_sn AS merchSn,
- m.merch_name AS merchName,
- sum( o.order_price ) AS totalSales,
- sum( og.number) as totalNumber,
- count(DISTINCT o.id) as totalCustomers,
- DATE_FORMAT(o.pay_time,'%Y-%u') as yearAndWeek
- FROM
- mall_order o
- LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
- LEFT JOIN mall_order_goods og ON o.id = og.order_id
- <where>
- o.is_onffline_order = '1'
- AND o.order_biz_type = '10'
- AND o.pay_status = '2'
- AND DATE_FORMAT(o.pay_time,'%Y-%u') >= #{startWeek}
- AND DATE_FORMAT(o.pay_time,'%Y-%u') <= #{endWeek}
- <if test="merchSn != null">
- and m.merch_sn = #{merchSn}
- </if>
- </where>
- group by DATE_FORMAT(o.pay_time,'%Y-%u')
- </select>
- <select id="top10ForProduct" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
- SELECT
- m.merch_name AS merchName,
- og.goods_name as goodsName,
- og.goods_specification_name_value as goodsSpecificationNameValue,
- sum( og.number ) AS sales
- FROM
- mall_order o
- LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
- LEFT JOIN mall_order_goods og ON o.id = og.order_id
- <where>
- o.is_onffline_order = '1'
- AND o.order_biz_type = '10'
- AND o.pay_status = '2'
- <if test="month != null and month.trim() != ''">
- and DATE_FORMAT(o.pay_time,'%Y-%m') = #{month}
- </if>
- <if test="week != null and week.trim() != ''">
- and weekofyear(o.pay_time) = #{week}
- </if>
- <if test="merchSn != null">
- and m.merch_sn = #{merchSn}
- </if>
- </where>
- GROUP BY
- og.sku
- ORDER BY
- sales desc
- LIMIT 10
- </select>
- <select id="top10ByBrand" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
- SELECT
- m.merch_name AS merchName,
- g.brand as brand,
- og.goods_specification_name_value as goodsSpecificationNameValue,
- sum( og.number ) AS sales
- FROM
- mall_order o
- LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
- LEFT JOIN mall_order_goods og ON o.id = og.order_id
- LEFT JOIN mall_goods g ON g.id = og.goods_id
- <where>
- o.is_onffline_order = '1'
- AND o.order_biz_type = '10'
- AND o.pay_status = '2'
- <if test="startDate != null and startDate.trim() != ''">
- and DATE_FORMAT(o.pay_time,'%Y-%m-%d') >= #{startDate}
- </if>
- <if test="endDate != null and endDate.trim() != ''">
- and DATE_FORMAT(o.pay_time,'%Y-%m-%d') <= #{endDate}
- </if>
- <if test="merchSn != null">
- and m.merch_sn = #{merchSn}
- </if>
- </where>
- GROUP BY
- g.brand
- ORDER BY
- sales desc
- LIMIT 10
- </select>
- <select id="top10BySupplier" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
- SELECT
- m.merch_name AS merchName,
- s.child_supplier_name as supplier,
- og.goods_specification_name_value as goodsSpecificationNameValue,
- sum( og.number ) AS sales
- FROM
- mall_order o
- LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
- LEFT JOIN mall_order_goods og ON o.id = og.order_id
- LEFT JOIN mall_goods g ON g.id = og.goods_id
- LEFT JOIN mall_supplier s ON g.supplier_id = s.id
- <where>
- o.is_onffline_order = '1'
- AND o.order_biz_type = '10'
- AND o.pay_status = '2'
- <if test="startDate != null and startDate.trim() != ''">
- and DATE_FORMAT(o.pay_time,'%Y-%m') >= #{startDate}
- </if>
- <if test="endDate != null and endDate.trim() != ''">
- and DATE_FORMAT(o.pay_time,'%Y-%m') <= #{endDate}
- </if>
- <if test="merchSn != null">
- and m.merch_sn = #{merchSn}
- </if>
- </where>
- GROUP BY
- s.id
- ORDER BY
- sales desc
- LIMIT 10
- </select>
- <select id="salesByCategory" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity">
- SELECT
- sum( og.number ) AS sales,
- cg.NAME AS cgname
- FROM
- mall_order o
- LEFT JOIN mall_merch m ON o.merch_sn = m.merch_sn
- LEFT JOIN mall_order_goods og ON o.id = og.order_id
- LEFT JOIN mall_product_store_rela a ON a.goods_id = og.goods_id
- LEFT JOIN mall_category cg ON a.category_id = cg.id
- <where>
- <if test="startDate != null and startDate.trim() != ''">
- and DATE_FORMAT(o.pay_time,'%Y-%m') >= #{startDate}
- </if>
- <if test="endDate != null and endDate.trim() != ''">
- and DATE_FORMAT(o.pay_time,'%Y-%m') <= #{endDate}
- </if>
- <if test="merchSn != null">
- and m.merch_sn = #{merchSn}
- </if>
- </where>
- GROUP BY
- cg.parent_id
- limit 20
- </select>
- <select id="monthlyCategory" resultType="com.kmall.admin.entity.MonthlySalesGrowthEntity" >
- SELECT
- sum( og.number ) AS sales,
- cg.NAME AS cgname,
- sum( o.order_price ) AS totalSales,
- DATE_FORMAT(o.pay_time,'%Y-%m')
- FROM
- mall_order o
- LEFT JOIN mall_order_goods og ON o.id = og.order_id
- LEFT JOIN mall_product_store_rela a ON a.goods_id = og.goods_id
- LEFT JOIN mall_category cg ON a.category_id = cg.id
- <where>
- o.is_onffline_order = '1'
- AND o.order_biz_type = '10'
- AND o.pay_status = '2'
- AND DATE_FORMAT(o.pay_time,'%Y-%m') >= #{startMonth}
- AND DATE_FORMAT(o.pay_time,'%Y-%m') <= #{endMonth}
- <if test="merchSn != null">
- and m.merch_sn = #{merchSn}
- </if>
- </where>
- GROUP BY
- cg.parent_id,DATE_FORMAT(o.pay_time,'%Y-%m')
- </select>
- </mapper>
|