xiaoyong931011
2022-09-23 7df8d05903fb7fdfc04d5a71dc6e3ce4c9d22c50
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?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="cc.mrbird.febs.mall.mapper.MallOrderInfoMapper">
 
    <select id="selectInPage" resultMap="OrderInfoMap">
        select
            a.*,
            b.id item_id,
            b.order_id,
            b.goods_id,
            b.sku_id,
            b.goods_name,
            b.style_name,
            b.sku_name,
            b.sku_image,
            b.cnt,
            b.price,
            b.amount,
            c.name leader_name,
            c.phone leader_phone,
            c.address_pic,
            c.address_area,
            c.province,
            c.city,
            c.township,
            c.detail_address
        from mall_order_info a
        inner join mall_order_item b on a.id=b.order_id
        inner join mall_team_leader c on a.take_unique_code=c.unique_code
        <where>
            a.del_flag=2
            <if test="record.status == 4 and record.status != 0">
                and a.status in (5,6)
            </if>
            <if test="record.status != 4 and record.status != 0 and record.status != 5">
                and a.status = #{record.status}
            </if>
            <if test="record.status == 5">
                and a.status = 7
            </if>
            <if test="record.memberId != null">
                and a.member_id=#{record.memberId}
            </if>
            <if test="record.orderType != null">
                and a.order_type=#{record.orderType}
            </if>
            <if test="record.deliveryType != null">
                and a.delivery_type=#{record.deliveryType}
            </if>
            <if test="record.takeUniqueCode != null">
                and a.take_unique_code=#{record.takeUniqueCode}
            </if>
        </where>
        order by a.created_time desc
    </select>
 
    <select id="selectOrderByMemberIdAndId" resultMap="OrderInfoMap">
        select
            a.*,
            b.goods_name from mall_order_info a
                          inner join mall_order_item b on a.id=b.order_id where a.member_id=#{memberId} and a.id=#{id}
    </select>
 
    <select id="selectOrderListInPage" resultType="cc.mrbird.febs.mall.vo.AdminMallOrderInfoVo">
        select a.*,
               b.name memberName,
               b.bind_phone memberBindPhone,
               b.phone memberPhone,
               c.name leaderName
        from mall_order_info a
        left join mall_member b on a.member_id = b.id
        left join mall_team_leader c on a.take_unique_code = c.unique_code
        <where>
            a.del_flag=2
            <if test="record != null">
                <if test="record.payResult != null and record.payResult != ''">
                    and a.pay_result = #{record.payResult}
                </if>
                <if test="record.orderType != null">
                    and a.order_type = #{record.orderType}
                </if>
                <if test="record.status != null and record.status != ''">
                    and a.status = #{record.status}
                </if>
                <if test="record.deliveryType != null and record.deliveryType != ''">
                    and a.delivery_type = #{record.deliveryType}
                </if>
                <if test="record.isHome != null and record.isHome != ''">
                    and a.is_home = #{record.isHome}
                </if>
                <if test="record.orderNo != null and record.orderNo != ''">
                    and a.order_no like CONCAT('%', CONCAT(#{record.orderNo}, '%'))
                </if>
                <if test="record.name != null and record.name != ''">
                    and b.name like CONCAT('%', CONCAT(#{record.name}, '%'))
                </if>
                <if test="record.uniqueCode != null and record.uniqueCode != ''">
                    and a.take_unique_code = #{record.uniqueCode}
                </if>
                <if test="record.startTime != null and record.startTime != ''">
                    and a.order_time &gt;= #{record.startTime}
                </if>
                <if test="record.endTime != null and record.endTime != ''">
                    and a.order_time &lt;= #{record.endTime}
                </if>
            </if>
        </where>
        GROUP BY a.id  order by a.created_time desc
    </select>
 
    <select id="getMallOrderInfoById" resultType="cc.mrbird.febs.mall.vo.AdminMallOrderVo">
        select * from mall_order_info where id = #{id}
    </select>
 
 
    <resultMap id="OrderInfoMap" type="cc.mrbird.febs.mall.entity.MallOrderInfo">
        <id column="id" property="id" />
        <result column="order_no" property="orderNo" />
        <result column="member_id" property="memberId" />
        <result column="order_time" property="orderTime" />
        <result column="pay_time" property="payTime" />
        <result column="amount" property="amount" />
        <result column="pay_method" property="payMethod" />
        <result column="pay_order_no" property="payOrderNo" />
        <result column="pay_result" property="payResult" />
        <result column="status" property="status" />
        <result column="cancel_type" property="cancelType" />
        <result column="name" property="name" />
        <result column="phone" property="phone" />
        <result column="address" property="address" />
        <result column="longitude" property="longitude" />
        <result column="latitude" property="latitude" />
        <result column="order_type" property="orderType" />
        <result column="comment_state" property="commentState" />
        <result column="carriage" property="carriage" />
        <result column="remark" property="remark" />
        <result column="take_code" property="takeCode" />
        <result column="take_unique_code" property="takeUniqueCode" />
        <result column="delivery_state" property="deliveryState" />
        <result column="is_home" property="isHome" />
        <result column="del_flag" property="delFlag" />
        <result column="leader_name" property="leaderName" />
        <result column="leader_phone" property="leaderPhone" />
        <result column="address_pic" property="addressPic" />
        <result column="address_area" property="addressArea" />
        <result column="province" property="province" />
        <result column="leaderLongitude" property="leaderLongitude" />
        <result column="leaderLatitude" property="leaderLatitude" />
        <result column="province" property="province" />
        <result column="city" property="city" />
        <result column="township" property="township" />
        <result column="detail_address" property="detailAddress" />
        <collection property="items" ofType="cc.mrbird.febs.mall.entity.MallOrderItem">
            <id property="id" column="item_id" />
            <result property="orderId" column="order_id" />
            <result property="goodsId" column="goods_id" />
            <result property="skuId" column="sku_id" />
            <result property="goodsName" column="goods_name" />
            <result property="styleName" column="style_name" />
            <result property="skuName" column="sku_name" />
            <result property="skuImage" column="sku_image" />
            <result property="cnt" column="cnt" />
            <result property="price" column="price" />
            <result property="amount" column="amount" />
            <result property="isNormal" column="is_normal" />
            <result property="state" column="state" />
        </collection>
    </resultMap>
 
    <select id="selectApiOrderListInPage" resultType="cc.mrbird.febs.mall.entity.MallOrderInfo">
        select
               a.*,
               c.name leaderName,
               c.phone leaderPhone,
               c.address_pic addressPic,
               c.address_area addressArea,
               c.province,
               c.city,
               c.township,
               c.detail_address detailAddress
        from mall_order_info a
        inner join mall_order_item b on a.id=b.order_id
        inner join mall_team_leader c on a.take_unique_code=c.unique_code
        <where>
            a.del_flag=2
            <if test="record.memberId != null">
                and a.member_id=#{record.memberId}
            </if>
            <if test="record.status == 4 and record.status != 0">
                and a.status = 4
            </if>
            <if test="record.status != 4 and record.status != 0 and record.status != 5">
                and a.status = #{record.status}
            </if>
            <if test="record.status == 5">
                and a.status = 7 or b.state in (2,3)
            </if>
            <if test="record.query != null and record.query != ''">
                and (b.goods_name like CONCAT('%', CONCAT(#{record.query}, '%')) or b.style_name like CONCAT('%', CONCAT(#{record.query}, '%')) or b.sku_name like CONCAT('%', CONCAT(#{record.query}, '%')))
            </if>
            <if test="record.orderType != null">
                and a.order_type=#{record.orderType}
            </if>
        </where>
        order by a.created_time desc
    </select>
 
    <select id="selectOrderDetailsById" resultMap="OrderInfoMap">
        select
            a.*,
            b.id item_id,
            b.order_id,
            b.goods_id,
            b.sku_id,
            b.goods_name,
            b.style_name,
            b.sku_name,
            b.sku_image,
            b.state,
            b.cnt,
            b.price,
            b.amount,
            b.is_normal,
            c.name leader_name,
            c.phone leader_phone,
            c.address_pic,
            c.address_area,
            c.province,
            c.city,
            c.township,
            c.longitude leaderLongitude,
            c.latitude leaderLatitude,
            c.detail_address
        from mall_order_info a
             inner join mall_order_item b on a.id=b.order_id
             inner join mall_team_leader c on a.take_unique_code=c.unique_code
        where a.id=#{id}
    </select>
 
    <select id="selectMemberOrderStatusCnt" resultType="java.util.Map">
        select
            a.status,
            count(1) cnt
        from mall_order_info a
                 inner join mall_team_leader c on a.take_unique_code=c.unique_code
        where a.del_flag=2 and a.member_id=#{memberId}
        group by a.status
    </select>
 
    <select id="getMallOrderDetailById" resultType="cc.mrbird.febs.mall.vo.AdminOrderDetailVo">
        select * from mall_order_info a where a.id = #{id}
    </select>
 
    <select id="getMallOrderItemByOrderId" resultType="cc.mrbird.febs.mall.entity.MallOrderItem">
        select * from mall_order_item where order_id = #{id}
    </select>
 
    <select id="selectOrderInfoByStatus" resultType="cc.mrbird.febs.mall.entity.MallOrderInfo">
        select * from mall_order_info where status=#{status}
    </select>
 
    <select id="selectOrderInfoUpTime" resultType="cc.mrbird.febs.mall.entity.MallOrderInfo">
        select * from mall_order_info where status=#{status} and now() > date_add(order_time,interval 15 minute)
    </select>
 
    <select id="selectCntDirectOrTeam" resultType="java.lang.Integer">
        select IFNULL(count(1), 0) from mall_order_info a
          inner join mall_member b on a.member_id=b.ID
        <where>
            a.status in (2,3,4)
            <if test="type == 1">
                and b.referrer_id=#{inviteId}
            </if>
            <if test="type == 2">
                and find_in_set(#{inviteId}, b.referrer_ids)
            </if>
        </where>
    </select>
 
    <select id="selectCntDirect" resultType="java.lang.Integer">
        select count(1) from (
        select a.invite_id, count(1)
        from mall_member a
           inner join mall_order_info b on a.ID=b.member_id
        where a.referrer_id=#{inviteId} and b.status in (2,3,4)
        group by a.invite_id
         ) a
    </select>
 
    <select id="selectTotalAmount" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(amount,0)),0) from mall_order_info
        where member_id=#{memberId} and status in (2, 3, 4) and order_type=1
    </select>
 
    <select id="selectTotalAmountForDate" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(amount,0)),0) from mall_order_info
        where status = 4
        <if test="member != null">
            and member_id=#{memberId}
        </if>
        <if test="date != null">
            and date_format(a.receiving_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
        </if>
    </select>
 
    <select id="selectTotalAmountUnCostForDate" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(b.amount,0) - IFNULL(b.cost_price*b.cnt, 0)),0)
        from mall_order_info a
        inner join mall_order_item b on a.id=b.order_id
        where a.order_type=1
        <if test="isNormal == 2">
            and a.status in (2, 3, 4) and b.is_normal = 2 and b.has_settle=1
        </if>
        <if test="isNormal == 1">
            and a.status=4 and b.is_normal = 1 and b.has_settle=1
        </if>
        <if test="member != null">
            and member_id=#{memberId}
        </if>
        <if test='date != null and dateType == "D"'>
            and date_format(a.pay_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
        </if>
        <if test='date != null and dateType == "M"'>
            and date_format(a.pay_time, '%Y-%m') = date_format(#{date}, '%Y-%m')
        </if>
        <if test='date != null and dateType == "Y"'>
            and date_format(a.pay_time, '%Y') = date_format(#{date}, '%Y')
        </if>
    </select>
 
    <select id="selectByOrderNo" resultType="cc.mrbird.febs.mall.entity.MallOrderInfo">
        select * from mall_order_info where order_no=#{orderNo}
    </select>
 
    <update id="updateOrderConfirmStatus">
        update mall_order_info
        set status=4,
            receiving_time=#{updateTime}
        where status=3 and date_format(pay_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
    </update>
 
    <select id="selectOrderInfoWithNormalGoods" resultMap="OrderInfoMap">
        select * from mall_order_info a
        inner join mall_order_item b on a.id=b.order_id and b.is_normal=1
        where date_format(pay_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
    </select>
 
    <select id="selectSumAmountByPayMethodAndStatue" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(amount,0)),0) from mall_order_info
        where pay_method = #{payMethod} and status = #{statue}
    </select>
 
    <update id="updateOrderStateAndDeliveryState">
        update mall_order_info
        set status = #{orderState},
            delivery_state = #{deliveryState}
        where id = #{orderId}
    </update>
 
    <select id="selectMemberOrderStatusCntByUniquecode" resultType="java.util.Map">
        select
            status,
            count(1) cnt
        from mall_order_info
        where del_flag = 2 and take_unique_code = #{uniqueCode}
        group by status
    </select>
 
    <select id="selectOrderByStatusAndPayTime" resultType="cc.mrbird.febs.mall.entity.MallOrderInfo">
        select * from mall_order_info where status=#{status}
         and date_format(pay_time, '%Y-%m-%d') = date_format(#{paytime}, '%Y-%m-%d')
    </select>
</mapper>