xuhy
2024-12-11 0a1533fd30ec1a2f4624ccda4ff11f2535ea8a46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?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.ruoyi.system.mapper.TOrderMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.TOrder">
        <id column="id" property="id" />
        <result column="code" property="code" />
        <result column="user_id" property="userId" />
        <result column="good_type" property="goodType" />
        <result column="good_id" property="goodId" />
        <result column="order_amount" property="orderAmount" />
        <result column="discount_amount" property="discountAmount" />
        <result column="payment_amount" property="paymentAmount" />
        <result column="payment_status" property="paymentStatus" />
        <result column="payment_type" property="paymentType" />
        <result column="serial_number" property="serialNumber" />
        <result column="create_time" property="createTime" />
        <result column="refund_amount" property="refundAmount" />
        <result column="pay_time" property="payTime" />
        <result column="is_delete" property="isDelete" />
        <result column="refund_status" property="refundStatus" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, code, user_id, good_type, good_id, order_amount, discount_amount, payment_amount, payment_status, payment_type, serial_number, create_time, refund_amount, pay_time, is_delete, refund_status
    </sql>
    <select id="pageList" resultType="com.ruoyi.system.domain.TOrder">
        SELECT
        t1.*,
        t2.NAME AS name,
        t2.phone AS phone,
        t2.avatar AS avatar,
        CONCAT( t2.NAME, ' ', t2.phone ) AS user_search,
        COALESCE ( t_course.course_name, t_information.information_name,t_generated_records.recordsName ) AS good_name,
        COALESCE ( t_course.course_cover, t_information.information_cover ) AS cover,
        CONCAT(COALESCE ( t_course.course_name, t_information.information_name ),' ',t1.code) as orderSearch
        FROM
        t_order t1
        LEFT JOIN t_app_user t2 ON t1.user_id = t2.id
        LEFT JOIN ( SELECT id, course_name AS course_name,course_cover FROM t_course ) t_course ON t1.good_id = t_course.id
        AND t1.good_type = 1
        LEFT JOIN ( SELECT id, information_name AS information_name,information_cover FROM t_information ) t_information ON t1.good_id = t_information.id
        AND t1.good_type = 2
        LEFT JOIN ( SELECT id, `name` AS recordsName,user_id FROM t_generated_records order by create_time DESC limit 1) t_generated_records ON t1.user_id = t_generated_records.user_id
        AND t1.good_type = 3
        <where>
            t1.is_delete = 0
            <if test="orderQuery.orderSearch != null and orderQuery.orderSearch != ''">
               AND ( t1.code LIKE concat('%',#{orderQuery.orderSearch},'%')
                or t_course.course_name LIKE concat('%',#{orderQuery.orderSearch},'%')
                or t_information.information_name LIKE concat('%',#{orderQuery.orderSearch},'%')
                or t_generated_records.recordsName LIKE concat('%',#{orderQuery.orderSearch},'%'))
            </if>
            <if test="orderQuery.userSearch != null and orderQuery.userSearch != ''">
                AND (t2.name LIKE concat('%',#{orderQuery.userSearch},'%') OR t2.phone LIKE concat('%',#{orderQuery.userSearch},'%'))
            </if>
            <if test="orderQuery.goodType != null ">
                AND t1.good_type = #{orderQuery.goodType}
            </if>
            <if test="orderQuery.paymentStatus != null">
                AND t1.payment_status = #{orderQuery.paymentStatus}
            </if>
            <if test="orderQuery.paymentType != null">
                AND t1.payment_type = #{orderQuery.paymentType}
            </if>
            <if test="orderQuery.createTime1 != null">
                AND DATE(t1.create_time) >= #{orderQuery.createTime1}
            </if>
            <if test="orderQuery.createTime2 != null">
                AND DATE(t1.create_time) &lt;= #{orderQuery.createTime2}
            </if>
            <if test="orderQuery.userId != null ">
                AND t1.user_id = #{orderQuery.userId}
            </if>
        </where>
        order by t1.create_time desc
    </select>
    <select id="totalCount" resultType="java.util.Map">
 
 
        SELECT
        SUM(CASE WHEN o.payment_status = 1 THEN 1 ELSE 0 END) AS pending_count,
        SUM(CASE WHEN o.payment_status = 2 THEN 1 ELSE 0 END) AS paid_count,
        SUM(CASE WHEN o.payment_status = 3 THEN 1 ELSE 0 END) AS cancelled_count,
        count(1) AS refunded_count,
        <if test="orderQuery.paymentType != null and orderQuery.paymentType == 1">
            SUM(CASE WHEN o.payment_status = 1 THEN o.payment_amount ELSE 0 END) AS payment_amount
        </if>
        <if test="orderQuery.paymentType != null and orderQuery.paymentType == 2">
            SUM(CASE WHEN o.payment_status = 2 THEN o.payment_amount ELSE 0 END) AS payment_amount
        </if>
        <if test="orderQuery.paymentType != null and orderQuery.paymentType == 3">
            SUM(CASE WHEN o.payment_status = 3 THEN o.payment_amount ELSE 0 END) AS payment_amount
        </if>
        <if test="orderQuery.paymentType == null">
            SUM(CASE WHEN (o.payment_status = 1 OR o.payment_status = 2 OR o.payment_status = 3) THEN o.payment_amount ELSE 0 END) AS payment_amount
        </if>
        from (
        SELECT
        t1.*,
        t2.NAME AS user_name,
        t2.phone AS user_phone,
        CONCAT( t2.NAME, ' ', t2.phone ) AS user_search,
        COALESCE ( t_course.course_name, t_information.information_name ) AS good_name,
        COALESCE ( t_course.course_cover, t_information.information_cover ) AS cover,
        CONCAT(COALESCE ( t_course.course_name, t_information.information_name ),' ',t1.code) as orderSearch
        FROM
        t_order t1
        LEFT JOIN t_app_user t2 ON t1.user_id = t2.id
        LEFT JOIN ( SELECT id, course_name AS course_name,course_cover FROM t_course ) t_course ON t1.good_id = t_course.id
        AND t1.good_type = 1
        LEFT JOIN ( SELECT id, information_name AS information_name,information_cover FROM t_information ) t_information ON t1.good_id = t_information.id
        AND t1.good_type = 2
        LEFT JOIN ( SELECT id, `name` AS recordsName,user_id FROM t_generated_records order by create_time DESC limit 1) t_generated_records ON t1.user_id = t_generated_records.user_id
        AND t1.good_type = 3
        <where>
            t1.is_delete = 0
            <if test="orderQuery.orderSearch != null and orderQuery.orderSearch != ''">
                AND ( t1.code LIKE concat('%',#{orderQuery.orderSearch},'%')
                    or t_course.course_name LIKE concat('%',#{orderQuery.orderSearch},'%')
                    or t_information.information_name LIKE concat('%',#{orderQuery.orderSearch},'%')
                    or t_generated_records.recordsName LIKE concat('%',#{orderQuery.orderSearch},'%'))
            </if>
            <if test="orderQuery.userSearch != null and orderQuery.userSearch != ''">
                AND (t2.name LIKE concat('%',#{orderQuery.userSearch},'%') OR t2.phone LIKE concat('%',#{orderQuery.userSearch},'%'))
            </if>
            <if test="orderQuery.goodType != null ">
                AND t1.good_type = #{orderQuery.goodType}
            </if>
            <if test="orderQuery.paymentStatus != null">
                AND t1.payment_status = #{orderQuery.paymentStatus}
            </if>
            <if test="orderQuery.paymentType != null">
                AND t1.payment_type = #{orderQuery.paymentType}
            </if>
            <if test="orderQuery.createTime1 != null">
                AND DATE(t1.create_time) >= #{orderQuery.createTime1}
            </if>
            <if test="orderQuery.createTime2 != null">
                AND DATE(t1.create_time) &lt;= #{orderQuery.createTime2}
            </if>
            <if test="orderQuery.userId != null ">
                AND t1.user_id = #{orderQuery.userId}
            </if>
        </where>
        ) o
 
 
    </select>
 
</mapper>