Helius
2022-03-16 4db1c06713cc8133d9858bee3c1cd1206588d61a
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.xcong.excoin.modules.otc.dao.OtcOrderDao">
 
    <select id="selectOrderListUnFinish" resultType="com.xcong.excoin.modules.otc.entity.OtcOrder">
        select * from otc_order
        where status in (1,2) and member_id=#{memberId} and entrust_order_id=#{entrustOrderId}
    </select>
 
 
    <select id="selectOrdderListInPage" resultType="com.xcong.excoin.modules.otc.vo.OrderListVo">
        select
            a.id,
            a.order_no orderNo,
            a.unit_price unitPrice,
            a.coin_amount amount,
            a.status status,
            a.total_amount totalAmount,
            a.create_time creatTime,
            a.order_type orderType,
            b.name name
        from otc_order a
        inner join member b on a.opposite_member_id=b.id
        <where>
            <if test="record!=null">
                <if test="record.status != null and record.status == 1">
                    and a.status in (1, 2)
                </if>
                <if test="record.status != null and record.status == 2">
                    and a.status = 3
                </if>
                <if test="record.status != null and record.status == 3">
                    and a.status = 4
                </if>
                <if test="record.memberId != null">
                    and a.member_id = ${record.memberId}
                </if>
            </if>
        </where>
        order by a.create_time desc
    </select>
 
    <update id="updateOrderStatusByOrderNo">
        update otc_order
        set status=#{status}
        <if test="payName != null and payName != ''">
            , pay_name = #{payName}
        </if>
        where order_no=#{orderNo}
    </update>
 
    <select id="selectOrderByOrderNoAndType" resultType="com.xcong.excoin.modules.otc.entity.OtcOrder">
        select * from otc_order
        where order_no=#{orderNo} and order_type=#{orderType}
    </select>
 
    <select id="selectOrderListWithStatusAndType" resultType="com.xcong.excoin.modules.otc.entity.OtcOrder">
        select * from otc_order
        where order_type=#{type} and status=#{status}
    </select>
 
    <select id="selectMemberCntForEntrust" resultType="java.lang.Integer">
        select count(distinct member_id) from otc_order
        where entrust_member_id=#{entrustMemberId} and status != 4 and entrust_member_id!=member_id
    </select>
 
    <select id="selectTotalOrderCount" resultType="java.lang.Integer">
        select count(1) from otc_order
        where member_id=#{entrustMemberId}
        <if test="status != null">
            and status = #{status}
        </if>
        <if test="type != null and type!=''">
            and order_type = #{type}
        </if>
    </select>
 
    <select id="selectMemberAvgPayTime" resultType="java.math.BigDecimal">
        select
               IFNULL(sum(timestampdiff(SECOND, create_time, pay_time))/count(1), 0)
        from otc_order
        where status=3 and member_id=#{memberId} and order_type='B'
    </select>
 
    <select id="selectMemberAvgCoinTime" resultType="java.math.BigDecimal">
        select
            IFNULL(sum(timestampdiff(SECOND, pay_time, finish_time))/count(1), 0)
        from otc_order
        where status=3 and member_id=40 and order_type='S'
    </select>
 
    <select id="selectOrderListForUser" resultType="com.xcong.excoin.modules.otc.entity.OtcOrder">
        select * from otc_order
        where member_id=#{memberId}
        <!-- 查询除完成以外所有订单 -->
        <if test="status != null">
            and status = #{status}
        </if>
    </select>
 
    <select id="selectOrderTotalAmount" resultType="java.math.BigDecimal">
        select IFNULL(sum(total_amount), 0) from otc_order
        where member_id=#{memberId} and status = 3
    </select>
 
    <select id="selectByMemberIdAndTargetId" resultType="com.xcong.excoin.modules.otc.vo.ChatOrderVo">
        select
            order_no orderNo,
            member_id memberId,
            unit_price unitPrice,
            coin_amount usdtAmount,
            total_amount totalAmount,
            status status,
            order_type orderType
        from otc_order
        where ((member_id=#{memberId} and opposite_member_id=#{targetId})
            or
              (member_id=#{targetId} and opposite_member_id=#{memberId}))
            and status in (1,2)
        order by create_time desc
 
    </select>
 
    <select id="selectOneByMemberIdAndTargetId" resultType="com.xcong.excoin.modules.otc.vo.ChatOrderVo">
        select
            order_no orderNo,
            member_id memberId,
            unit_price unitPrice,
            coin_amount usdtAmount,
            total_amount totalAmount,
            status status,
            order_type orderType
        from otc_order
        where ((member_id=#{memberId} and opposite_member_id=#{targetId})
            or
               (member_id=#{targetId} and opposite_member_id=#{memberId}))
        order by create_time desc
            LIMIT 2
 
    </select>
 
    <update id="updateIsReturnByOrderNo">
        update otc_order
        set is_return=#{isReturn}
        where order_no=#{orderNo}
    </update>
 
    <select id="selectOrderUnEntrust" resultType="com.xcong.excoin.modules.otc.entity.OtcOrder">
        select * from otc_order
        where order_no=#{orderNo} and member_id!=entrust_member_id
    </select>
 
</mapper>