|
|
@@ -884,6 +884,114 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
) a ORDER BY
|
|
|
a.company_id DESC,a.totalNum DESC
|
|
|
</select>
|
|
|
+
|
|
|
+ <!--status: 0 待支付, 1 待发货, 2 待收货, 3 交易完成, -1退款中, -2已退款, -3已取消-->
|
|
|
+ <select id="selectHCLOrderDimensionStatisticsList" resultType="com.fs.hisStore.vo.OrderStatisticsVo">
|
|
|
+ SELECT * FROM (
|
|
|
+ SELECT
|
|
|
+ cu.user_id,
|
|
|
+ cu.user_name,
|
|
|
+ cu.nick_name,
|
|
|
+ c.company_name,
|
|
|
+ c.company_id,
|
|
|
+ -- 总单数 - 统计经过 WHERE 条件过滤后(即非 0 状态)的订单数量
|
|
|
+ COUNT(DISTINCT fso.id) AS totalNum,
|
|
|
+ -- 总金额 - 由于WHERE子句已过滤,无需CASE WHEN
|
|
|
+ SUM(fso.total_price) AS totalPrice,
|
|
|
+ -- 实付款总金额 - 由于WHERE子句已过滤,无需CASE WHEN
|
|
|
+ SUM(fso.pay_price) AS actualPaymentAmount,
|
|
|
+ -- 成交单数
|
|
|
+ SUM(CASE WHEN fso.`status` = 3 THEN 1 ELSE 0 END) AS dealNum,
|
|
|
+ -- 成交金额
|
|
|
+ SUM(CASE WHEN fso.`status` = 3 THEN fso.pay_price ELSE 0 END) AS dealPrice,
|
|
|
+ -- 取消单数 - 订单状态为 '已取消' (-3)
|
|
|
+ SUM(CASE WHEN fso.`status` = -3 THEN 1 ELSE 0 END) AS cancelNum,
|
|
|
+ -- 取消金额
|
|
|
+ SUM(CASE WHEN fso.`status` = -3 THEN fso.pay_price ELSE 0 END) AS cancelPrice,
|
|
|
+ -- 待发货单数 - 订单状态为 '待发货' (1)
|
|
|
+ SUM(CASE WHEN fso.`status` = 1 AND (fso.delivery_pay_status = 0 OR fso.delivery_pay_status IS NULL) THEN 1 ELSE 0 END) AS pendingNum,
|
|
|
+ -- 待发货金额
|
|
|
+ SUM(CASE WHEN fso.`status` = 1 AND (fso.delivery_pay_status = 0 OR fso.delivery_pay_status IS NULL) THEN fso.pay_price ELSE 0 END) AS pendingPrice,
|
|
|
+ -- 发货单数 - 订单状态为 '待收货' (2) 或 '交易完成' (3)
|
|
|
+ SUM(CASE WHEN fso.`status` IN (2, 3) THEN 1 ELSE 0 END) AS invoiceNum,
|
|
|
+ -- 发货金额
|
|
|
+ SUM(CASE WHEN fso.`status` IN (2, 3) THEN fso.pay_price ELSE 0 END) AS invoicePrice,
|
|
|
+ -- 签收单数 - 订单状态为 '交易完成' (3)
|
|
|
+ IFNULL(SUM(CASE WHEN fso.`status` = 3 THEN 1 ELSE 0 END), 0) AS signForNum,
|
|
|
+ -- 签收金额
|
|
|
+ IFNULL(SUM(CASE WHEN fso.`status` = 3 THEN fso.pay_price ELSE 0 END), 0) AS signFPrice,
|
|
|
+ -- 退单数 - 订单状态为 '退款中' (-1) 且退款状态为 '已退款' (2)
|
|
|
+ SUM(CASE WHEN fso.`status` = -1 AND fso.refund_status = 2 THEN 1 ELSE 0 END) AS chargebackNum,
|
|
|
+ -- 退单金额
|
|
|
+ SUM(CASE WHEN fso.`status` = -1 AND fso.refund_status = 2 THEN fso.pay_price ELSE 0 END) AS chargebackPrice
|
|
|
+ FROM
|
|
|
+ company_user cu
|
|
|
+ INNER JOIN company c ON cu.company_id = c.company_id
|
|
|
+ LEFT JOIN fs_store_order_scrm fso ON cu.user_id = fso.company_user_id
|
|
|
+ WHERE
|
|
|
+ fso.is_del = '0'
|
|
|
+ AND fso.`status` != 0
|
|
|
+
|
|
|
+ <!-- 公司ID条件 -->
|
|
|
+ <if test="param.companyId != null and param.companyId != ''">
|
|
|
+ AND c.company_id = #{param.companyId}
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <!-- 员工账号条件 -->
|
|
|
+ <if test="param.userName != null and param.userName != ''">
|
|
|
+ AND cu.user_name LIKE CONCAT('%', #{param.userName}, '%')
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <!-- 销售名称条件 -->
|
|
|
+ <if test="param.companyUser != null and param.companyUser != ''">
|
|
|
+ AND cu.nick_name LIKE CONCAT('%', #{param.companyUser}, '%')
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <!-- 时间条件 -->
|
|
|
+ <if test="param.startDate != null">
|
|
|
+ AND DATE_FORMAT(fso.pay_time, '%Y-%m') >= DATE_FORMAT(#{param.startDate}, '%Y-%m')
|
|
|
+ </if>
|
|
|
+ <if test="param.endDate != null">
|
|
|
+ AND DATE_FORMAT(fso.pay_time, '%Y-%m') <= DATE_FORMAT(#{param.endDate}, '%Y-%m')
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <!-- 商品和标签筛选(使用EXISTS避免重复计算) -->
|
|
|
+ <if test="param.productId != null and param.productId != ''
|
|
|
+ or param.productName != null and param.productName != ''
|
|
|
+ or param.cateId != null and param.cateId != ''
|
|
|
+ or param.cateName != null and param.cateName != ''">
|
|
|
+ AND EXISTS (
|
|
|
+ SELECT 1
|
|
|
+ FROM fs_store_order_item_scrm fsoi
|
|
|
+ INNER JOIN fs_store_product_scrm fsp ON fsoi.product_id = fsp.product_id
|
|
|
+ LEFT JOIN fs_store_product_category_scrm fspc ON fspc.cate_id = fsp.cate_id
|
|
|
+ WHERE fsoi.order_id = fso.id
|
|
|
+
|
|
|
+ <if test="param.productId != null and param.productId != ''">
|
|
|
+ AND fsp.product_id = #{param.productId}
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <if test="param.productName != null and param.productName != ''">
|
|
|
+ AND fsp.product_name LIKE CONCAT('%', #{param.productName}, '%')
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <if test="param.cateId != null and param.cateId != ''">
|
|
|
+ AND fspc.cate_id = #{param.cateId}
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <if test="param.cateName != null and param.cateName != ''">
|
|
|
+ AND fspc.cate_name LIKE CONCAT('%', #{param.cateName}, '%')
|
|
|
+ </if>
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+
|
|
|
+ GROUP BY
|
|
|
+ cu.user_id, cu.user_name, cu.nick_name, c.company_name, c.company_id
|
|
|
+ ) a
|
|
|
+ ORDER BY
|
|
|
+ a.company_id DESC, a.totalNum DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
<select id="selectFsStoreOrderCountsByDept" resultType="com.fs.hisStore.vo.FsStoreOrderCountsVO">
|
|
|
SELECT
|
|
|
o.dept_id,
|