liujie
2023-06-12 9c47fbfef3cc65bf67fb44917e33162177bf4f9c
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
<?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.stylefeng.guns.modular.system.dao.TOrderMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TOrder">
        <id column="id" property="id" />
        <result column="user_id" property="userId" />
        <result column="shipment_date" property="shipmentDate" />
        <result column="state" property="state" />
        <result column="city" property="city" />
        <result column="port" property="port" />
        <result column="accessorial" property="accessorial" />
        <result column="accessorial_str" property="accessorialStr" />
        <result column="delivery_str" property="deliveryStr" />
        <result column="startLon" property="startLon" />
        <result column="startLat" property="startLat" />
        <result column="s_name" property="sName" />
        <result column="s_email" property="sEmail" />
        <result column="s_phone" property="sPhone" />
        <result column="delivery_date" property="deliveryDate" />
        <result column="type" property="type" />
        <result column="zip_code" property="zipCode" />
        <result column="warehouse" property="warehouse" />
        <result column="company_id" property="companyId" />
        <result column="e_address" property="eAddress" />
        <result column="e_city" property="eCity" />
        <result column="e_state" property="eState" />
        <result column="e_zip_code" property="eZipCode" />
        <result column="e_zip_z" property="eZipZ" />
        <result column="e_company_name" property="eCompanyName" />
        <result column="e_name" property="eName" />
        <result column="e_email" property="eEmail" />
        <result column="e_phone" property="ePhone" />
        <result column="exam_site" property="examSite" />
        <result column="s_driverId" property="sDriverid" />
        <result column="s_driverId_one" property="sDriverIdOne" />
        <result column="e_driverId" property="eDriverid" />
        <result column="e_driverId_one" property="eDriverIdOne" />
        <result column="status" property="status" />
        <result column="invoice_number" property="invoiceNumber" />
        <result column="allTotal" property="allTotal" />
        <result column="paid" property="paid" />
        <result column="pay_time" property="payTime" />
        <result column="pay_status" property="payStatus" />
        <result column="pay_money" property="payMoney" />
        <result column="success_time" property="successTime" />
        <result column="send_to_customer" property="sendToCustomer" />
        <result column="remark" property="remark" />
        <result column="pay_info_state" property="payInfoState" />
        <result column="pay_audit" property="payAudit" />
        <result column="order_ok_time" property="orderOkTime" />
        <result column="order_type" property="orderType" />
        <result column="carriers_id" property="carriersId" />
        <result column="carriers_pay_status" property="carriersPayStatus" />
        <result column="pay_carriers_time" property="payCarriersTime" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, shipment_date, state, city, port, accessorial, accessorial_str, startLon, startLat, s_name, s_email, s_phone, delivery_date, type, zip_code, warehouse, company_id, e_address, e_city, e_state, e_zip_code, e_zip_z, e_company_name, e_name, e_email, e_phone, exam_site, s_driverId, e_driverId, status, create_time
    </sql>
    <insert id="addOrderFile">
        insert into t_order_file (id,
                                    order_id,
                                    file,
                                    name,
                                    create_time
                                    ) value (null ,#{orderId},#{url},#{name},now())
    </insert>
 
    <update id="agreePay">
        update t_order set pay_audit =1 where id=#{number}
    </update>
 
    <update id="noAgreePay">
         update t_order set pay_audit =2,remark=#{remark} where id=#{number}
    </update>
 
    <update id="agreeOfPayment">
        update t_order set pay_status =1 where id =#{number}
    </update>
 
    <select id="getReceivable" resultType="com.stylefeng.guns.modular.system.model.ReceivableVo">
        select t1.id,t1.create_time invoiceDate,t1.company_id userId,sum(t1.pay_money) as total,t2.name userName from t_order t1 left join t_company t2 on t1.company_id=t2.id
        where t1.status !=0
        <if test="name !=null and name !=''">
            and  t2.name like concat("%",#{name},"%")
        </if>
        group by t1.company_id
    </select>
 
    <select id="getTwentyDay" resultType="java.lang.Double">
        select sum(pay_money) from t_order where company_id = #{userId} and success_time between #{time1} and #{time}
    </select>
 
    <select id="getNineDay" resultType="java.lang.Double">
        select sum(pay_money) from t_order where company_id = #{userId} and #{time3}  > pay_time
    </select>
 
    <select id="getPayList" resultType="com.stylefeng.guns.modular.system.model.ShouldPayVo">
        select t1.id,t1.success_time billDate,t1.carriers_id userId,sum(t1.pay_money) as total,
        t2.company_name userName from t_order t1 left join t_carriers t2 on t1.carriers_id=t2.id
        where t1.status !=0
        <if test="name !=null and name !=''">
            and  t2.company_name like concat("%",#{name},"%")
        </if>
        group by t1.carriers_id
    </select>
    <select id="getTwentyDayPay" resultType="java.lang.Double">
            select sum(t1.pay_money*(t2.commission/100)) from t_order  t1 LEFT JOIN t_carriers t2  on t1.carriers_id = t2 .id where t1.carriers_id = #{userId} and t1.pay_carriers_time between #{time1} and #{time}
    </select>
    <select id="getNineDayPay" resultType="java.lang.Double">
        select sum(t1.pay_money*(t2.commission/100)) from t_order  t1 LEFT JOIN t_carriers t2  on t1.carriers_id = t2 .id  where t1.carriers_id = #{userId} and #{time3}  > t1.pay_carriers_time
    </select>
    <select id="listOfReceivables" resultType="com.stylefeng.guns.modular.system.model.ReceivablesList">
        select t1.invoice_number invoiceNumber,t1.id orderId,t1.user_id userId,t1.pay_money total,t1.pay_time invoicesTime,t2.company_name userName
         from t_order t1 LEFT JOIN t_user t2 on t1.user_id=t2.id
        where t1.status = 1
        <if test="sTime !=null ">
            and t1.pay_time between #{sTime} and #{eTime}
        </if>
        <if test="name !=null and name !='' ">
            and t2.company_name like concat("%",#{name},"%")
        </if>
        <if test="invoicesId !=null and invoicesId !='' ">
            and t1.id =#{invoicesId}
        </if>
        <if test="orderId !=null and orderId !='' ">
            and t1.id =#{orderId}
        </if>
        <if test="state !=null and state !='' and state==1 ">
            and t1.pay_status > t1.paid=0
        </if>
        <if test="state !=null and state !='' and state==2 ">
            and t1.pay_money = 1
        </if>
 
    </select>
    <select id="getPayStatus" resultType="java.lang.Integer">
        select id from t_order where pay_status =1
    </select>
    <select id="listOfPay" resultType="com.stylefeng.guns.modular.system.model.PayList">
        select t1.id orderId,t1.carriers_id companyId,t2.company_name companyName,t1.pay_carriers_time billTime,t1.pay_time dueDate,t1.carriers_pay_status paystatus,t1.pay_audit payAudit,(t1.pay_money*(t2.commission/100) ) as total  FROM t_order  t1 LEFT JOIN t_carriers t2 on t1.carriers_id =t2.id
        where t1.status = 1
        <if test="sTime !=null">
            and t1.pay_carriers_time between #{sTime} and #{eTime}
        </if>
        <if test="name !=null and name != ''">
            and t2.company_name like concat("%",#{name},"%")
        </if>
        <if test="billId !=null and billId != ''">
            and t1.id =#{billId}
        </if>
        <if test="orderId !=null and orderId != ''">
            and t1.id =#{orderId}
        </if>
        <if test="state !=null and state !='' and state==1 ">
            and t1.carriers_pay_status =0
        </if>
        <if test="state !=null and state !='' and state==2 ">
            and t1.carriers_pay_status =1
        </if>
    </select>
    <select id="getIndexTotal" resultType="java.math.BigDecimal">
        select sum(allTotal-pay_money) from t_order where `status` !=0
    </select>
    <select id="getOrderListOne" resultType="com.stylefeng.guns.modular.system.model.OrderListVo">
        SELECT
    t1.id orderId,
    t2.container_number container,
    t3.company_name customerName,
    t4.address port,
    t1.shipment_date pickupDate,
    t1.delivery_date deliveryDate,
    t1.status status,
    t1.e_address destination
FROM
    t_order t1
    LEFT JOIN t_goods t2 ON t1.id = t2.order_id
    LEFT JOIN t_user t3 on t1.user_id =t3.id
    LEFT JOIN t_port t4 on t1.`port` = t4.id
    LEFT JOIN t_group t5 on t3.group_id = t5.id
    where t1.company_id = #{companyId} and t1.order_type=#{type}
    <if test="sTime !=null">
        and (t1.shipment_date between  #{sTime} and #{eTime} or t1.delivery_date between  #{sTime} and #{eTime})
    </if>
    <if test="customerName !=null and customerName !=''">
        and (t3.id = #{customerName} or t3.company_name like concat("%",#{customerName},"%"))
    </if>
    <if test="id !=null and id !='' ">
        and t1.id =#{id}
    </if>
    <if test="groupId !=null and groupId !=''">
        and t5.id =#{groupId}
    </if>
    <if test="saleId !=null and saleId !=''">
        and t5.sales_id =#{saleId}
    </if>
    <if test="state !=null and state !=''">
        and t1.status =#{state}
    </if>
GROUP BY
    t1.id
 
 
    </select>
    <select id="getCompanyIncome" resultType="java.lang.Double">
        select sum(pay_money) from t_order where pay_status=1 and company_id=#{companyId}
        <if test="sTime !=null">
            and success_time BETWEEN #{sTime} and #{eTime}
        </if>
    </select>
    <select id="getOrderListIndex" resultType="com.stylefeng.guns.modular.system.model.vo.OrderInfoVo">
        select t7.phone phone,CONCAT(t2.`name`,t3.`name`) start,1 type,t1.id orderId,t1.status,CONCAT(t1.e_address,t4.name,t5.name,t1.e_zip_code) end,t1.shipment_date pickUpTime,t6.container_number ccontainerNumber,t1.type sendType from t_order t1
        left JOIN t_port t2 on t1.`port` = t2.id
        LEFT JOIN t_country t3 on t2.city =t3.id
        left JOIN t_country t4 on t1.e_city =t4.id
        left JOIN t_country t5 on t1.e_state = t5.id
        LEFT JOIN t_goods t6 on t6.order_id = t1.id
        left join t_user t7 on t1.user_id = t7.id
        where (t1.s_driverId = #{id} or t1.s_driverId_one=#{id} or t1.e_driverId_one = #{id} or t1.e_driverId = #{id} )
        <if test="containerNo !=null and containerNo !=''">
            and t6.container_number like concat("%",#{containerNo},"%")
        </if>
        <if test="sTime !=null">
            and t1.shipment_date between #{sTime} and #{eTime}
        </if>
        <if test="type ==1">
            and t1.status !=1
        </if>
        <if test="type !=1">
            and t1.status =1
        </if>
<!--        union all-->
<!--        select t7.phone phone, CONCAT(t2.`name`,t3.`name`) start,2 type,t1.id orderId,t1.status,CONCAT(t1.e_address,t4.name,t5.name,t1.e_zip_code) end,t1.shipment_date pickUpTime,t6.container_number ccontainerNumber ,t1.type sendType from t_order t1-->
<!--        left JOIN t_port t2 on t1.`port` = t2.id-->
<!--        LEFT JOIN t_country t3 on t2.city =t3.id-->
<!--        left JOIN t_country t4 on t1.e_city =t4.id-->
<!--        left JOIN t_country t5 on t1.e_state = t5.id-->
<!--        LEFT JOIN t_goods t6 on t6.order_id = t1.id-->
<!--        left join t_user t7 on t1.user_id = t7.id-->
<!--        where (t1.s_driverId_one = #{id} )-->
<!--        <if test="containerNo !=null and containerNo !=''">-->
<!--            and t6.container_number like concat("%",#{containerNo},"%")-->
<!--        </if>-->
<!--        <if test="sTime !=null">-->
<!--            and t1.shipment_date between #{sTime} and #{eTime}-->
<!--        </if>-->
<!--        <if test="type ==1">-->
<!--            and t1.status !=1-->
<!--        </if>-->
<!--        <if test="type !=1">-->
<!--            and t1.status =1-->
<!--        </if>-->
<!--        union all-->
<!--        select t7.phone phone, CONCAT(t2.`name`,t3.`name`) start,3 type,t1.id orderId,t1.status,CONCAT(t1.e_address,t4.name,t5.name,t1.e_zip_code) end,t1.shipment_date pickUpTime,t6.container_number ccontainerNumber,t1.type sendType from t_order t1-->
<!--        left JOIN t_port t2 on t1.`port` = t2.id-->
<!--        LEFT JOIN t_country t3 on t2.city =t3.id-->
<!--        left JOIN t_country t4 on t1.e_city =t4.id-->
<!--        left JOIN t_country t5 on t1.e_state = t5.id-->
<!--        LEFT JOIN t_goods t6 on t6.order_id = t1.id-->
<!--        left join t_user t7 on t1.user_id = t7.id-->
<!--        where ( t1.e_driverId_one = #{id})-->
<!--        <if test="containerNo !=null and containerNo !=''">-->
<!--            and t6.container_number like concat("%",#{containerNo},"%")-->
<!--        </if>-->
<!--        <if test="sTime !=null">-->
<!--            and t1.shipment_date between #{sTime} and #{eTime}-->
<!--        </if>-->
<!--        <if test="type ==1">-->
<!--            and t1.status !=1-->
<!--        </if>-->
<!--        <if test="type !=1">-->
<!--            and t1.status =1-->
<!--        </if>-->
<!--        union all-->
<!--        select t7.phone phone, CONCAT(t2.`name`,t3.`name`) start,4 type,t1.id orderId,t1.status,CONCAT(t1.e_address,t4.name,t5.name,t1.e_zip_code) end,t1.shipment_date pickUpTime,t6.container_number ccontainerNumber ,t1.type sendType from t_order t1-->
<!--        left JOIN t_port t2 on t1.`port` = t2.id-->
<!--        LEFT JOIN t_country t3 on t2.city =t3.id-->
<!--        left JOIN t_country t4 on t1.e_city =t4.id-->
<!--        left JOIN t_country t5 on t1.e_state = t5.id-->
<!--        LEFT JOIN t_goods t6 on t6.order_id = t1.id-->
<!--        left join t_user t7 on t1.user_id = t7.id-->
<!--        where ( t1.e_driverId = #{id} )-->
<!--        <if test="containerNo !=null and containerNo !=''">-->
<!--            and t6.container_number like concat("%",#{containerNo},"%")-->
<!--        </if>-->
<!--        <if test="sTime !=null">-->
<!--            and t1.shipment_date between #{sTime} and #{eTime}-->
<!--        </if>-->
<!--        <if test="type ==1">-->
<!--            and t1.status !=1-->
<!--        </if>-->
<!--        <if test="type !=1">-->
<!--            and t1.status =1-->
<!--        </if>-->
    </select>
 
</mapper>