This commit is contained in:
Lx 2025-07-09 11:23:52 +08:00
parent 7a5532b658
commit 32ab7f6652

View File

@ -309,6 +309,7 @@
dsco.order_remark, dsco.order_remark,
dsco.cashier_confirm, dsco.cashier_confirm,
dsco.cashier_confirm_remark, dsco.cashier_confirm_remark,
dsco.cashier_confirm_time,
dss.source, dss.source,
dsco.payment_account, dsco.payment_account,
MAX(CASE WHEN dsp.subject = 2 THEN COALESCE(dsp.coach_name, '') END) AS subject2CoachName, MAX(CASE WHEN dsp.subject = 2 THEN COALESCE(dsp.coach_name, '') END) AS subject2CoachName,
@ -367,18 +368,17 @@
<if test="entity.isSign != null"> <if test="entity.isSign != null">
AND dsco.is_sign = #{entity.isSign} AND dsco.is_sign = #{entity.isSign}
</if> </if>
<if test="entity.cashierConfirm != ''">
<if test="entity.cashierConfirm != null and entity.cashierConfirm != '' ">
<choose> <choose>
<when test="entity.cashierConfirm == '1'"> <when test="entity.cashierConfirm == 1">
AND dsco.cashier_confirm = 1 AND dsco.cashier_confirm = 1
</when> </when>
<when test="entity.cashierConfirm == '0'"> <when test="entity.cashierConfirm == 0">
AND dsco.cashier_confirm = 0 AND dsco.cashier_confirm = 0
</when> </when>
<otherwise> <when test="entity.cashierConfirm == null">
AND dsco.cashier_confirm IS NULL AND dsco.cashier_confirm IS NULL
</otherwise> </when>
</choose> </choose>
</if> </if>
<if test="entity.source != null and entity.source != '' "> <if test="entity.source != null and entity.source != '' ">
@ -420,16 +420,15 @@
<select id="getOrderStatistics" resultType="cn.iocoder.yudao.module.course.vo.CourseOrderStatisticsVO"> <select id="getOrderStatistics" resultType="cn.iocoder.yudao.module.course.vo.CourseOrderStatisticsVO">
SELECT SELECT
COUNT(DISTINCT dsco.user_id) AS studentCount, COUNT(DISTINCT dss.user_id) AS studentCount,
SUM(dsco.reserve_money) AS totalAmount, SUM(dsco.reserve_money) AS totalAmount,
SUM(IFNULL(sub.subject2Deduct, 0)) AS subject2DeductTotal, SUM(IFNULL(sub.subject2Deduct, 0)) AS subject2DeductTotal,
SUM(IFNULL(sub.subject3Deduct, 0)) AS subject3DeductTotal SUM(IFNULL(sub.subject3Deduct, 0)) AS subject3DeductTotal
FROM drive_school_course_order dsco FROM drive_school_student dss
LEFT JOIN drive_school_course_order dsco
LEFT JOIN drive_school_student dss ON dss.user_id = dsco.user_id
ON dsco.user_id = dss.user_id AND dss.deleted = 0 AND dsco.deleted = 0
AND dsco.if_end = 0
-- 子查询先聚合提成,防止 JOIN 多条数据导致金额翻倍
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
dscd.course_id, dscd.course_id,
@ -449,19 +448,35 @@
) )
) )
) )
WHERE dss.deleted = 0
WHERE dsco.deleted = 0 AND dsco.user_id IS NOT NULL
AND dsco.if_end = 0 AND dsco.is_sign = 1
<!-- 筛选条件部分 --> <!-- 筛选条件部分 -->
<if test="entity.courseId != null and entity.courseId != '' "> <if test="entity.studentName != null and entity.studentName != '' ">
AND dsco.course_id = #{entity.courseId} AND dss.name LIKE CONCAT('%', #{entity.studentName}, '%')
</if> </if>
<if test="entity.studentPhone != null and entity.studentPhone != '' "> <if test="entity.studentPhone != null and entity.studentPhone != '' ">
AND dsco.user_phone LIKE CONCAT('%', #{entity.studentPhone}, '%') AND dss.phone LIKE CONCAT('%', #{entity.studentPhone}, '%')
</if> </if>
<if test="entity.studentName != null and entity.studentName != '' "> <if test="entity.source != null and entity.source != '' ">
AND dsco.user_name LIKE CONCAT('%', #{entity.studentName}, '%') AND dss.source = #{entity.source}
</if>
<if test="entity.studentIdCard != null and entity.studentIdCard != '' ">
<choose>
<when test="entity.studentIdCard.length() == 18">
AND dss.id_card = #{entity.studentIdCard}
</when>
<when test="entity.studentIdCard.length() == 4">
AND RIGHT(dss.id_card, 4) = #{entity.studentIdCard}
</when>
<otherwise>
AND dss.id_card LIKE CONCAT('%', #{entity.studentIdCard}, '%')
</otherwise>
</choose>
</if>
<if test="entity.courseId != null and entity.courseId != '' ">
AND dsco.course_id = #{entity.courseId}
</if> </if>
<if test="entity.coachId != null and entity.coachId != '' "> <if test="entity.coachId != null and entity.coachId != '' ">
AND dsco.coach_user_id = #{entity.coachId} AND dsco.coach_user_id = #{entity.coachId}
@ -493,33 +508,17 @@
<if test="entity.isSign != null"> <if test="entity.isSign != null">
AND dsco.is_sign = #{entity.isSign} AND dsco.is_sign = #{entity.isSign}
</if> </if>
<if test="entity.cashierConfirm != null and entity.cashierConfirm != '' "> <if test="entity.cashierConfirm != ''">
<choose> <choose>
<when test="entity.cashierConfirm == '1'"> <when test="entity.cashierConfirm == 1">
AND dsco.cashier_confirm = 1 AND dsco.cashier_confirm = 1
</when> </when>
<when test="entity.cashierConfirm == '0'"> <when test="entity.cashierConfirm == 0">
AND dsco.cashier_confirm = 0 AND dsco.cashier_confirm = 0
</when> </when>
<otherwise> <when test="entity.cashierConfirm == null">
AND dsco.cashier_confirm IS NULL AND dsco.cashier_confirm IS NULL
</otherwise>
</choose>
</if>
<if test="entity.source != null and entity.source != '' ">
AND dss.source = #{entity.source}
</if>
<if test="entity.studentIdCard != null and entity.studentIdCard != '' ">
<choose>
<when test="entity.studentIdCard.length() == 18">
AND dsco.user_no = #{entity.studentIdCard}
</when> </when>
<when test="entity.studentIdCard.length() == 4">
AND RIGHT(dsco.user_no, 4) = #{entity.studentIdCard}
</when>
<otherwise>
AND dsco.user_no LIKE CONCAT('%', #{entity.studentIdCard}, '%')
</otherwise>
</choose> </choose>
</if> </if>
</select> </select>