wzy
2021-04-01 d388e2788b7ef088d7cd40f901b0acdcec460bc3
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?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.matrix.system.hive.dao.SysOrderFlowDao">
 
    <resultMap id="SysOrderFlowMap" type="SysOrderFlow">
        <id property="id" column="id" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="flowNo" column="flow_no" />
        <result property="orderId" column="order_id" />
        <result property="flowContent" column="flow_content" />
        <result property="flowType" column="flow_type" />
        <result property="amount" column="amount" />
        <result property="vipId" column="vip_id" />
        <result property="payMethod" column="pay_method" />
        <result property="cardId" column="card_id" />
        <result property="isGift" column="is_gift" />
 
        <result property="orderNo" column="order_no" />
    </resultMap>
 
    <insert id="insert" parameterType="SysOrderFlow" useGeneratedKeys="true"
            keyProperty="id">
        INSERT INTO sys_order_flow (
        ID,
        create_by,
        create_time,
        update_by,
        update_time,
        flow_no,
        order_id,
        flow_content,
        flow_type,
        amount,
        vip_id,
        pay_method,
        card_id,
        is_gift,
        shop_id,
        company_id
        )
        VALUES (
        #{id},
        #{createBy},
        now(),
        #{updateBy},
        now(),
        #{flowNo},
        #{orderId},
        #{flowContent},
        #{flowType},
        #{amount},
        #{vipId},
        #{payMethod},
        #{cardId},
        #{isGift},
        #{shopId},
        #{companyId}
        )
    </insert>
    <update id="updateTimeByOrderId">
        UPDATE sys_order_flow set
        create_time=#{payTime}
        where order_id=#{orderId}
    </update>
    <delete id="deleteByOrderId">
        delete from sys_order_flow where order_id=#{orderId}
    </delete>
 
    <select id="selectByOrderId" resultMap="SysOrderFlowMap">
        select a.*, b.order_no from sys_order_flow a
        left join sys_order b on a.order_id=b.id
        where order_id=#{orderId}
    </select>
 
    <select id="selectPayMethodsAmountByOrderId" resultMap="SysOrderFlowMap">
        select
            pay_method,
            sum(amount) amount
        from sys_order_flow
        where order_id=#{orderId}
        group by pay_method
    </select>
 
    <select id="selectInPage" resultType="com.matrix.system.hive.vo.OrderFlowVo">
        SELECT
        a.id,
        b.id as orderId,
        a.create_time as createTime,
        b.ORDER_NO as orderNo,
        a.flow_content as flowContent,
        a.flow_type as flowType,
        a.amount as amount,
        c.VIP_NAME as vipName,
        a.pay_method as payMethod,
        a.flow_no as flowNo,
        d.shop_short_name as shopName,
        e.su_name as staffName
        from sys_order_flow a
        LEFT JOIN sys_order b on a.order_id=b.ID
        LEFT JOIN sys_vip_info c on a.vip_id=c.ID
        LEFT JOIN sys_shop_info d on a.shop_id=d.ID
        LEFT JOIN sys_users e on e.su_id=b.STAFF_ID
        <where>
 
                and a.company_id=#{record.companyId}
 
            <if test="record.queryKey != null and record.queryKey != ''">
                and (instr(c.vip_name, #{record.queryKey}) or instr(c.phone, #{record.queryKey}) )
            </if>
            <if test="record.oprationMan != null and record.oprationMan != ''">
                and instr(e.su_name, #{record.oprationMan})
            </if>
            <if test="record.orderNo != null and record.orderNo != ''">
                and instr(b.ORDER_NO, #{record.orderNo})
            </if>
            <if test="record.payMethod != null and record.payMethod != ''">
                and a.pay_method=#{record.payMethod}
            </if>
 
            <if test="record.flowType != null and record.flowType != ''">
                and a.flow_type=#{record.flowType}
            </if>
 
            <if test="record.startTime != null ">
                and a.create_time >= #{record.startTime}
            </if>
            <if test="record.endTime != null   ">
                <![CDATA[and a.create_time <= #{record.endTime}]]>
            </if>
            <if test="record.shopId != null and record.shopId != ''">
                and a.shop_id=#{record.shopId}
            </if>
        </where>
        <if test="record.sort !=null">
            order by
            a.${record.sort} ${record.order}
        </if>
        <if test="record.offset >=0  and record.limit >0">
            limit
            #{record.offset},#{record.limit}
        </if>
 
 
    </select>
 
    <select id="selectTotal" resultType="java.lang.Integer">
        SELECT count(*)
        from sys_order_flow a
        LEFT JOIN sys_order b on a.order_id=b.ID
        LEFT JOIN sys_vip_info c on a.vip_id=c.ID
        LEFT JOIN sys_shop_info d on a.shop_id=d.ID
        LEFT JOIN sys_users e on e.su_id=b.STAFF_ID
        <where>
 
            and a.company_id=#{record.companyId}
 
            <if test="record.queryKey != null and record.queryKey != ''">
                and (instr(c.vip_name, #{record.queryKey}) or instr(c.phone, #{record.queryKey}) )
            </if>
            <if test="record.oprationMan != null and record.oprationMan != ''">
                and instr(e.su_name, #{record.oprationMan})
            </if>
            <if test="record.orderNo != null and record.orderNo != ''">
                and instr(b.ORDER_NO, #{record.orderNo})
            </if>
            <if test="record.payMethod != null and record.payMethod != ''">
                and a.pay_method=#{record.payMethod}
            </if>
 
            <if test="record.flowType != null and record.flowType != ''">
                and a.flow_type=#{record.flowType}
            </if>
 
            <if test="record.startTime != null ">
                and a.create_time >= #{record.startTime}
            </if>
            <if test="record.endTime != null   ">
                <![CDATA[and a.create_time <= #{record.endTime}]]>
            </if>
            <if test="record.shopId != null and record.shopId != ''">
                and a.shop_id=#{record.shopId}
            </if>
 
        </where>
    </select>
 
</mapper>