|
@@ -660,153 +660,94 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
</select>
|
|
</select>
|
|
|
|
|
|
|
|
<select id="selectOrderSaleStatisticsList" resultType="com.fs.hisStore.vo.OrderStatisticsVo">
|
|
<select id="selectOrderSaleStatisticsList" resultType="com.fs.hisStore.vo.OrderStatisticsVo">
|
|
|
- SELECT * FROM ( SELECT
|
|
|
|
|
|
|
+ SELECT * FROM (
|
|
|
|
|
+ SELECT
|
|
|
cu.user_id,
|
|
cu.user_id,
|
|
|
cu.user_name,
|
|
cu.user_name,
|
|
|
cu.nick_name,
|
|
cu.nick_name,
|
|
|
c.company_name,
|
|
c.company_name,
|
|
|
c.company_id,
|
|
c.company_id,
|
|
|
- SUM(fso.`status` != 0) AS totalNum,
|
|
|
|
|
- SUM(
|
|
|
|
|
- CASE
|
|
|
|
|
- WHEN fso.`status` != 0 THEN
|
|
|
|
|
- fso.total_price
|
|
|
|
|
- ELSE
|
|
|
|
|
- 0
|
|
|
|
|
- END
|
|
|
|
|
- ) totalPrice,
|
|
|
|
|
- SUM(fso.`status` = 5) AS dealNum,
|
|
|
|
|
- SUM(
|
|
|
|
|
- CASE
|
|
|
|
|
- WHEN fso.`status` = 5 THEN
|
|
|
|
|
- fso.total_price
|
|
|
|
|
- ELSE
|
|
|
|
|
- 0
|
|
|
|
|
- END
|
|
|
|
|
- ) AS dealPrice,
|
|
|
|
|
- SUM(
|
|
|
|
|
- fso.`status` = 1
|
|
|
|
|
- OR fso.`status` = -2
|
|
|
|
|
- ) AS cancelNum,
|
|
|
|
|
- SUM(
|
|
|
|
|
- CASE
|
|
|
|
|
- WHEN fso.`status` = 1
|
|
|
|
|
- OR fso.`status` = -2 THEN
|
|
|
|
|
- fso.total_price
|
|
|
|
|
- ELSE
|
|
|
|
|
- 0
|
|
|
|
|
- END
|
|
|
|
|
- ) AS cancelPrice,
|
|
|
|
|
- SUM(
|
|
|
|
|
- fso.`status` = 2
|
|
|
|
|
- AND (
|
|
|
|
|
- fso.delivery_pay_status = 0
|
|
|
|
|
- OR fso.delivery_pay_status IS NULL
|
|
|
|
|
- )
|
|
|
|
|
- ) AS pendingNum,
|
|
|
|
|
- SUM(
|
|
|
|
|
- CASE
|
|
|
|
|
- WHEN fso.`status` = 2
|
|
|
|
|
- AND (
|
|
|
|
|
- fso.delivery_pay_status = 0
|
|
|
|
|
- OR fso.delivery_pay_status IS NULL
|
|
|
|
|
- ) THEN
|
|
|
|
|
- fso.total_price
|
|
|
|
|
- ELSE
|
|
|
|
|
- 0
|
|
|
|
|
- END
|
|
|
|
|
- ) AS pendingPrice,
|
|
|
|
|
- SUM(
|
|
|
|
|
- fso.`status` = 3
|
|
|
|
|
- AND fso.delivery_pay_status > 0
|
|
|
|
|
- ) AS invoiceNum,
|
|
|
|
|
- SUM(
|
|
|
|
|
- CASE
|
|
|
|
|
- WHEN fso.`status` = 3
|
|
|
|
|
- AND fso.delivery_pay_status > 0 THEN
|
|
|
|
|
- fso.total_price
|
|
|
|
|
- ELSE
|
|
|
|
|
- 0
|
|
|
|
|
- END
|
|
|
|
|
- ) AS invoicePrice,
|
|
|
|
|
- IFNULL(
|
|
|
|
|
- SUM(
|
|
|
|
|
- fso.`status` > 3
|
|
|
|
|
- AND fso.delivery_pay_status = 3
|
|
|
|
|
- ),
|
|
|
|
|
- 0
|
|
|
|
|
- ) AS signForNum,
|
|
|
|
|
- SUM(
|
|
|
|
|
- CASE
|
|
|
|
|
- WHEN fso.`status` > 3
|
|
|
|
|
- AND fso.delivery_pay_status = 3 THEN
|
|
|
|
|
- fso.total_price
|
|
|
|
|
- ELSE
|
|
|
|
|
- 0
|
|
|
|
|
- END
|
|
|
|
|
- ) AS signFPrice,
|
|
|
|
|
- SUM(
|
|
|
|
|
- fso.`status` = -1
|
|
|
|
|
- AND fso.refund_status = 2
|
|
|
|
|
- ) AS chargebackNum,
|
|
|
|
|
- SUM(
|
|
|
|
|
- CASE
|
|
|
|
|
- WHEN fso.`status` = -1
|
|
|
|
|
- AND fso.refund_status = 2 THEN
|
|
|
|
|
- fso.total_price
|
|
|
|
|
- ELSE
|
|
|
|
|
- 0
|
|
|
|
|
- END
|
|
|
|
|
- ) AS chargebackPrice
|
|
|
|
|
|
|
+ COUNT(DISTINCT fso.id) AS totalNum,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` != 0 THEN fso.total_price ELSE 0 END) AS totalPrice,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` != 0 THEN fso.pay_price ELSE 0 END) AS actualPaymentAmount,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` = 5 THEN 1 ELSE 0 END) AS dealNum,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` = 5 THEN fso.total_price ELSE 0 END) AS dealPrice,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` = 1 OR fso.`status` = -2 THEN 1 ELSE 0 END) AS cancelNum,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` = 1 OR fso.`status` = -2 THEN fso.total_price ELSE 0 END) AS cancelPrice,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` = 2 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` = 2 AND (fso.delivery_pay_status = 0 OR fso.delivery_pay_status IS NULL) THEN fso.total_price ELSE 0 END) AS pendingPrice,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` = 3 AND fso.delivery_pay_status > 0 THEN 1 ELSE 0 END) AS invoiceNum,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` = 3 AND fso.delivery_pay_status > 0 THEN fso.total_price ELSE 0 END) AS invoicePrice,
|
|
|
|
|
+ IFNULL(SUM(CASE WHEN fso.`status` > 3 AND fso.delivery_pay_status = 3 THEN 1 ELSE 0 END), 0) AS signForNum,
|
|
|
|
|
+ SUM(CASE WHEN fso.`status` > 3 AND fso.delivery_pay_status = 3 THEN fso.total_price ELSE 0 END) AS signFPrice,
|
|
|
|
|
+ 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.total_price ELSE 0 END) AS chargebackPrice
|
|
|
FROM
|
|
FROM
|
|
|
company_user cu
|
|
company_user cu
|
|
|
INNER JOIN company c ON cu.company_id = c.company_id
|
|
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
|
|
LEFT JOIN fs_store_order_scrm fso ON cu.user_id = fso.company_user_id
|
|
|
- INNER JOIN fs_store_order_item_scrm fsoi ON fso.id = fsoi.order_id
|
|
|
|
|
- INNER JOIN fs_store_product_scrm fsp ON fsoi.product_id = fsp.product_id
|
|
|
|
|
- INNER JOIN fs_store_product_category_scrm fspc ON fspc.cate_id = fsp.cate_id
|
|
|
|
|
WHERE
|
|
WHERE
|
|
|
fso.is_del = '0'
|
|
fso.is_del = '0'
|
|
|
AND fso.`status` != 0
|
|
AND fso.`status` != 0
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 公司ID条件 -->
|
|
|
<if test="param.companyId != null and param.companyId != ''">
|
|
<if test="param.companyId != null and param.companyId != ''">
|
|
|
- AND c.company_id = #{param.companyId}
|
|
|
|
|
|
|
+ AND c.company_id = #{param.companyId}
|
|
|
</if>
|
|
</if>
|
|
|
|
|
|
|
|
|
|
+ <!-- 员工账号条件 -->
|
|
|
<if test="param.userName != null and param.userName != ''">
|
|
<if test="param.userName != null and param.userName != ''">
|
|
|
- AND cu.user_name Like CONCAT('%',#{param.userName},'%')
|
|
|
|
|
|
|
+ AND cu.user_name LIKE CONCAT('%', #{param.userName}, '%')
|
|
|
</if>
|
|
</if>
|
|
|
|
|
|
|
|
|
|
+ <!-- 销售名称条件 -->
|
|
|
<if test="param.companyUser != null and param.companyUser != ''">
|
|
<if test="param.companyUser != null and param.companyUser != ''">
|
|
|
- AND cu.nick_name Like CONCAT('%',#{param.companyUser},'%')
|
|
|
|
|
|
|
+ AND cu.nick_name LIKE CONCAT('%', #{param.companyUser}, '%')
|
|
|
</if>
|
|
</if>
|
|
|
|
|
|
|
|
- <if test="param.productId != null and param.productId != ''">
|
|
|
|
|
- AND fsp.product_id = #{param.productId}
|
|
|
|
|
|
|
+ <!-- 时间条件 -->
|
|
|
|
|
+ <if test="param.startDate != null">
|
|
|
|
|
+ AND DATE_FORMAT(fso.pay_time, '%Y-%m') >= DATE_FORMAT(#{param.startDate}, '%Y-%m')
|
|
|
</if>
|
|
</if>
|
|
|
-
|
|
|
|
|
- <if test="param.productName != null and param.productName != ''">
|
|
|
|
|
- AND fsp.product_name Like CONCAT('%',#{param.productName},'%')
|
|
|
|
|
|
|
+ <if test="param.endDate != null">
|
|
|
|
|
+ AND DATE_FORMAT(fso.pay_time, '%Y-%m') <= DATE_FORMAT(#{param.endDate}, '%Y-%m')
|
|
|
</if>
|
|
</if>
|
|
|
|
|
|
|
|
- <if test="param.cateName != null and param.cateName != ''">
|
|
|
|
|
- AND fspc.cate_name Like CONCAT('%',#{param.cateName},'%')
|
|
|
|
|
- </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.cateId != null and param.cateId != ''">
|
|
|
|
|
- AND fspc.cate_id = #{param.cateId}
|
|
|
|
|
- </if>
|
|
|
|
|
|
|
+ <if test="param.productId != null and param.productId != ''">
|
|
|
|
|
+ AND fsp.product_id = #{param.productId}
|
|
|
|
|
+ </if>
|
|
|
|
|
|
|
|
- <if test="param.startDate != null">
|
|
|
|
|
- AND DATE_FORMAT(fso.pay_time,'%Y-%m') >= DATE_FORMAT(#{param.startDate},'%Y-%m')
|
|
|
|
|
- </if>
|
|
|
|
|
|
|
+ <if test="param.productName != null and param.productName != ''">
|
|
|
|
|
+ AND fsp.product_name LIKE CONCAT('%', #{param.productName}, '%')
|
|
|
|
|
+ </if>
|
|
|
|
|
|
|
|
- <if test="param.endDate != null">
|
|
|
|
|
- AND DATE_FORMAT(fso.pay_time,'%Y-%m') <= DATE_FORMAT(#{param.endDate},'%Y-%m')
|
|
|
|
|
|
|
+ <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>
|
|
</if>
|
|
|
|
|
+
|
|
|
GROUP BY
|
|
GROUP BY
|
|
|
- cu.user_id
|
|
|
|
|
- ) a ORDER BY
|
|
|
|
|
- a.company_id DESC,a.totalNum DESC
|
|
|
|
|
|
|
+ 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>
|
|
|
|
|
|
|
|
|
|
|