xiaoyong931011
2021-03-15 dfa29cdf223f2cb78184c4b15ab9f0824f3427c4
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
<?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.fenxiao.dao.ShopSalesmanOrderDao">
    <!-- 定义ShopSalesmanOrder 的复杂关联map -->
    <resultMap type="com.matrix.system.fenxiao.entity.ShopSalesmanOrder" id="ShopSalesmanOrderMap">
        <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="orderId " column="order_id " />
            <result property="userId" column="user_id" />
            <result property="salesUserId" column="sales_user_id" />
            <result property="revenueType" column="revenue_type" />
            <result property="amount" column="amount" />
            <result property="orderStatus" column="order_status" />
            <result property="settlementId" column="settlement_id" />
            <result property="companyId" column="company_id" />
    </resultMap>
    
    
    <!-- 定义ShopSalesmanOrder 的简单map  ,本map不添加其他的关联属性 -->
    <resultMap type="com.matrix.system.fenxiao.entity.ShopSalesmanOrder" id="ShopSalesmanOrderSimpleMap">
        <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="orderId " column="order_id " />
            <result property="userId" column="user_id" />
            <result property="salesUserId" column="sales_user_id" />
            <result property="revenueType" column="revenue_type" />
            <result property="amount" column="amount" />
            <result property="orderStatus" column="order_status" />
            <result property="settlementId" column="settlement_id" />
            <result property="companyId" column="company_id" />
    </resultMap>
 
    <select id="selectSalesManOrder" resultType="com.matrix.system.shopXcx.vo.SalesOrderVo">
        select
            a.order_id,
            a.create_time,
            a.amount,
            a.revenue_type,
            a.order_status,
            b.nick_name,
            b.avatar_url,
            c.order_no,
            c.order_money
        from shop_salesman_order a
                 left join biz_user b on b.open_id=a.user_id
                 left join shop_order c on a.order_id=c.id
        where
            a.sales_user_id=#{record.userId}
            and    a.revenue_type=#{record.revenueType}
        <if test="record.orderStatus!=null" >
            and a.order_status=#{record.orderStatus}
        </if>
        <if test="record.sort!=null and record.order!=null" >
        order by ${record.sort} ${record.order}
        </if>
 
    </select>
 
    <select id="selectFenxiaoOrderBasicByCompanyId" resultType="com.matrix.system.fenxiao.vo.LoadFenxiaoOrderBasicVo">
        SELECT
            COUNT(*) num,
            (SELECT IFNULL(sum(IFNULL(amount, 0)), 0)
                FROM shop_salesman_order
                WHERE order_status = 1 and company_id=#{companyId}) balance,
            (SELECT COUNT(*) FROM
                    (SELECT DISTINCT user_id
                        FROM shop_salesman_order
                        WHERE order_status = 1 and company_id=#{companyId} ) a) waitNum,
            (SELECT COUNT(*)
                FROM shop_salesman_order
                WHERE order_status = 1 and company_id=#{companyId}) waitOrderNum
        FROM
            shop_salesman_order
        where company_id=#{companyId}
    </select>
 
    <select id="findFenxiaoOrderList" resultType="com.matrix.system.fenxiao.vo.LoadFenxiaoOrderListVo">
        SELECT
        a.id id,
        (select order_no from shop_order where id = a.order_id) orderNo,
        (select order_money from shop_order where id = a.order_id) actualBalance,
        (select store_name  from shop_store where store_id = (select store_id from shop_order where id = a.order_id)) address,
        b.nick_name custom,
        (select nick_name from biz_user where open_id = b.parent_open_id) parentSale,
        a.revenue_type profitType,
        a.amount profitBalance,
        a.order_status settleType,
        c.order_no settleNo,
        c.create_time settleTime,
        (select nick_name from biz_user where c.user_id = open_id) settler
        FROM
        shop_salesman_order a
        LEFT JOIN biz_user b on a.user_id = b.open_id
        LEFT JOIN shop_saleman_settlement c on a.settlement_id = c.id
        <where>
            a.company_id = #{record.companyId}
            <if test="record.userName != null and record.userName != ''">
                and b.nick_name like concat('%',#{record.userName},'%')
            </if>
        </where>
        <if test="record.sort !=null">
            order by
            a.${record.sort} ${record.order}
        </if>
    </select>
 
    <select id="findSetOrderList" resultType="com.matrix.system.fenxiao.vo.LoadSetOrderListDtoVo">
        select
        a.id id,
        a.order_no orderNo,
        a.amount actualBalance,
        a.order_count setNum,
        a.man_count setManNum,
        a.create_time setTime,
        b.nick_name setMan,
        a.settlement_way settlementWay,
        a.remark remark
        from
        shop_saleman_settlement a
        left join biz_user b on a.user_id = b.open_id
        <where>
            a.company_id = #{record.companyId}
            <if test="record.userName != null and record.userName != ''">
                and b.nick_name like concat('%',#{record.userName},'%')
            </if>
        </where>
        <if test="record.sort !=null">
            order by
            a.${record.sort} ${record.order}
        </if>
    </select>
 
</mapper>