【调度系统】广东民航医疗快线调度系统源代码
wanglizhong
2025-06-24 a51d070d364b0da8e5f8ea9203a6e50c8b4c0af3
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %> 
<% Session.CodePage=65001 %> 
<% Response.charset = "utf-8" %>
<!--#include virtual="/inc/odbc.asp"-->
<!--#include virtual="/inc/function.asp"-->
<!--#include virtual="/inc/core.asp"-->
<script language="JScript" runat="Server"> 
function toObject(json) { 
    eval("var o=" + json); 
    return o; 
function toArray(s){
    var dic = Server.CreateObject("Scripting.Dictionary")
    eval("var a=" + json);
    for(var i=0;i<a.length;i++){
        var obj = Server.CreateObject("Scripting.Dictionary")
        for(x in a[i]) obj.Add(x,a[i][x])
        dic.Add(i, obj);
    }
    return dic
}
</script> 
 
<script language="jscript" runat="server">
Array.prototype.get = function(i)
{
 return this[i]; 
};
function getjson(str){
 try{
  eval("var jsonStr = (" + str + ")");
 }catch(ex){
  var jsonStr = null;
 }
 return jsonStr;
}
</script>
<%
'百度地图
'ak="lA7jbMtGXprDlUfbvAGNRuXm4phHhk7b" 'vicgame
ak="rGQBbHKGjAtVQy23OckafQkC6nNlaGmi" 'vicgame_NS1
'ak="U4ff8syGj0qRZyVc9G0eFH0NxuDY3oKd"    '良
 
Set rs = Server.CreateObject("ADODB.Recordset")
Set rsDt = Server.CreateObject("ADODB.Recordset")
method="OrderPrice_v2"
V                = trim(request("V"))                '公式版本
If V="" Then V="1.0"
 
adminID    = trim(request("adminID"))
ServiceOrdID    = trim(request("ServiceOrdID"))        '服务单号
StartAddress    = trim(request("StartAddress"))        '派车地址
ViaAddress        = trim(request("ViaAddress"))        '转出地址
EndAddress        = trim(request("EndAddress"))        '转入地址
ServiceBranch    = trim(request("ServiceBranch"))    '所属地区/分公司
 
TraDistance        = trim(request("TraDistance"))        '任务单程公里数
NursingLevel    = trim(request("NursingLevel"))        '医护护理级别
IsVentilato        = trim(request("IsVentilato"))        '是否使用呼吸机
IsWarmBox        = trim(request("IsWarmBox"))        '是否使用温箱
IsFerry            = trim(request("IsFerry"))            '是否轮渡
LiftingInt        = trim(request("LiftingInt"))        '抬楼层数:默认0
WaitingInt        = trim(request("WaitingInt"))        '等待时长:默认0
ICUInt            = trim(request("ICUInt"))            '居家ICU服务时长:默认0
 
IsCoupon        = trim(request("IsCoupon"))            '是否使用优惠券:默认1
If IsCoupon="" Then IsCoupon="1"
IsIntegral        = trim(request("IsIntegral"))        '是否使用积分:默认0
If IsIntegral="" Then IsIntegral="0"
 
IRid            = trim(request("IRid"))                '方案ID
StartProvince    = trim(request("StartProvince"))
StartCity        = trim(request("StartCity"))
StartArea        = trim(request("StartArea"))
U_UnitShort        = trim(request("U_UnitShort"))
U_TraDistance    = trim(request("U_TraDistance"))
AgeGroup    = trim(request("AgeGroup"))    '病人年龄段(1成年人 (12岁以上),2儿童(0-3岁(含3岁)),3儿童(3-6岁(含6岁)),4儿童(6-12岁),5新生儿 (出生至28天以内))
If U_TraDistance="" Then U_TraDistance=0
OrdIsCoupon="0"
 
IRState="IRState"    '方案状态
 
If V="0.1" Then
    IRState="IRwxState"
ElseIf V="2.0" Then
    newborn        = trim(request("newborn"))    '新生儿
    direction    = trim(request("direction"))'转运方向
    symptom        = trim(request("symptom"))    '病人症状
    Ventilato    = trim(request("Ventilato"))'呼吸机
    IsMedical    = trim(request("IsMedical"))'是否需要医护人员
    If LiftingInt="" Or Not IsNumeric(LiftingInt) Then LiftingInt=0
    If newborn="" Then newborn=2
    If direction="" Then direction=1
    If symptom="" Then symptom=1
    If IsMedical="" Then IsMedical=0
    If Ventilato="" Then Ventilato=0
    '新生儿
    If newborn="1" Then
        IsWarmBox=1
        ServiceTXT="新生儿温箱、"
    End If
    
    '病情
    If symptom="1" And IsWarmBox<>"1" Then    '轻症                        
        NursingLevel=1
        ServiceTXT="我们将为您配备专业救护车和司机。"
        If IsMedical="2" Then
            NursingLevel=2
        ElseIf IsMedical="3" Or Ventilato="2" Or Ventilato="3" Then
            NursingLevel=3
        End If
    ElseIf symptom="2" And IsWarmBox<>"1" Then    '病情稳定
        NursingLevel=2
        ServiceTXT="我们将为您配备专业救护车和护士、司机。并提供"&ServiceTXT&"氧气、吸痰机、微泵、监护仪。"
        If IsMedical="1" Then
            NursingLevel=1
        ElseIf IsMedical="3" Or Ventilato="2" Or Ventilato="3" Then
            NursingLevel=3
        End If
    ElseIf (IsWarmBox="1") And (symptom="1" Or symptom="2") Then    '温箱
        NursingLevel=3
        ServiceTXT="我们将为您配备专业救护车和医生、护士、司机。并提供"&ServiceTXT&"氧气、吸痰机、微泵、心电监护仪、急救药品。"
    ElseIf symptom="4" Or symptom="3" Then    '危重/濒危
        NursingLevel=3
        IsVentilato=1
        ServiceTXT="我们将为您配备专业救护车和医生、护士、司机。并提供"&ServiceTXT&"专业呼吸机、氧气、吸痰机、4组微泵、除颤监护仪、急救药品。"
    End If
    '呼吸机
    If Ventilato="2" Or Ventilato="3" Then
        IsVentilato=1
        NursingLevel=3
        ServiceTXT="呼吸机、"
    ElseIf Ventilato="1" Then
        IsVentilato=0
    End If
    ServiceTXT=""
    IRState="IRwxState"
End If
 
If ServiceOrdID="undefined" Then ServiceOrdID=""
If TraDistance="" Or Not IsNumeric(TraDistance) Then TraDistance=0
If NursingLevel="" Or Not IsNumeric(NursingLevel) Then NursingLevel=0
If IsVentilato="" Or Not IsNumeric(IsVentilato) Then IsVentilato=0
If IsWarmBox="" Or Not IsNumeric(IsWarmBox) Then IsWarmBox=0
If IsFerry="" Or Not IsNumeric(IsFerry) Then IsFerry=0
If LiftingInt="" Or Not IsNumeric(LiftingInt) Then LiftingInt=0
If WaitingInt="" Or Not IsNumeric(WaitingInt) Then WaitingInt=0
If ICUInt="" Or Not IsNumeric(ICUInt) Then ICUInt=0
If IRid="" Or Not IsNumeric(IRid) Then IRid=0
TraDistance=CLng(TraDistance)
LiftingInt=CLng(LiftingInt)-1
 
If ServiceBranch="" Then ServiceBranch="BF"
errcode=0
OrderPrice=0
StartAddress_lat=0
StartAddress_lng=0
EndAddress_lat=0
EndAddress_lng=0
 
If ServiceOrdID<>""  Then
    sql="select ServiceOrdUserID,ServiceOrdClass,ServiceOrdTraStreet,ServiceOrdTraVia,ServiceOrdTraEnd,ServiceOrdUnitRemarks,ServiceOrdApptDate from ServiceOrder where ServiceOrdID="&ServiceOrdID
    rs.open Sql,objConn,1,1
    If not rs.Eof Then
        UserID=rs("ServiceOrdUserID")
        ServiceBranch    = rs("ServiceOrdClass")
        StartAddress    = trim(rs("ServiceOrdTraStreet"))
        If rs("ServiceOrdTraVia")<>"" Then StartAddress=rs("ServiceOrdTraVia")    '出发地址按转出地址计算
        EndAddress        = trim(rs("ServiceOrdTraEnd"))
        ServiceOrdUnitRemarks = trim(rs("ServiceOrdUnitRemarks"))
        ServiceOrdApptDate=rs("ServiceOrdApptDate")
        If (ServiceOrdUnitRemarks="高铁转运" Or ServiceOrdUnitRemarks="民航转运" Or ServiceOrdUnitRemarks="医疗包机" Or ServiceOrdUnitRemarks="直升机") And IRState="IRwxState" Then
            IsCoupon        = trim(request("IsCoupon"))            '是否使用优惠券:默认0
            If IsCoupon="" Then IsCoupon="0"
            '优惠券查询
            OrdCoupon=0
            If UserID<>"" And ServiceOrdID<>"" Then
                rs.close()
                If ServiceOrdUnitRemarks="高铁转运" Then
                    CouponName="高铁"
                Else
                    CouponName="航空"
                End If
                sql="select CouponNO,CouponMoney from Coupon where CouponDate_Ent>=getdate() and ToUserID="&UserID&" and CouponState=0 and CouponName like '%"&CouponName&"%' order by CouponMoney desc"
                rs.open sql,objConn,1,1
                If Not rs.Eof Then
                    CouponNO=rs("CouponNO")
                    CouponMoney=rs("CouponMoney")
                    OrdCoupon = CouponMoney
                    OrdIsCoupon="1"
                End If
                rs.close()
                If IsCoupon="1" And OrdCoupon>0 Then
                    OrderPriceTXT = OrderPriceTXT&",客户希望使用优惠券:-"&OrdCoupon&"元\n"
                ElseIf IsIntegral="1" Then
                    OrderPriceTXT = OrderPriceTXT&",客户希望使用积分\n"
                End If
                sql="delete from ServiceOrder_Options where ServiceOptionsID in (-1,1000,1001) and ServiceOrdSoID="&ServiceOrdID
                objConn.Execute sql
                sql="Insert into ServiceOrder_Options (ServiceOrdSoID,ServiceOptionsID,ServiceOptionsValue) values ("&ServiceOrdID&",1000,'报价说明:"&OrderPriceTXT&"')"
                objConn.Execute sql
            End If
            webJson="{""APPID"":"""&APPID&""",""method"":"""&method&""",""result"":1,""OrderPrice"":"""&OrderPrice&""",""TraDistance"":"""&TraDistance&""",""addressComponent"":"""&addressComponent&""",""StartAddress"":"""&StartAddress&""",""EndAddress"":"""&EndAddress&""",""origin"":"""&StartAddress_lat&","&StartAddress_lng&""",""destination"":"""&EndAddress_lat&","&EndAddress_lng&""",""OrderPriceFRM"":"""&OrderPriceFRM&""",""OrderPriceTXT"":"""&OrderPriceTXT&""",""IRid"":"""&IRid&""",""NursingLevel"":"""&NursingLevel&""",""ServiceTXT"":"""&ServiceTXT&""",""StartProvince"":"""&StartProvince&""",""StartCity"":"""&StartCity&""",""StartArea"":"""&StartArea&""",""U_UnitShort"":"""&U_UnitShort&""",""U_TraDistance"":"""&U_TraDistance&""",""OrdIsCoupon"":"""&OrdIsCoupon&""",""OrdCoupon"":"""&OrdCoupon&"""}"
            Response.Write webJson
            Response.End
        End If
    End If
    rs.close()
End If
 
 
 
If StartAddress="" Then
    errcode=40020
    errmsg="invalid StartAddress"
ElseIf EndAddress="" Then
    errcode=40021
    errmsg="invalid EndAddress"
End If
 
If TraDistance=0 or StartProvince="" Then
    '出发地坐标
    If InStr(StartAddress,",")>1 And errcode=0 Then
        StartAddressSP=SPLIT(StartAddress,",")
        If UBOUND(StartAddressSP)=1 Then
            If IsNumeric(StartAddressSP(0)) And IsNumeric(StartAddressSP(1)) Then
                StartAddress_lat=StartAddressSP(0)
                StartAddress_lng=StartAddressSP(1)
            End If
        End If
    End If
    If StartAddress_lat=0 And errcode=0 Then
        sql="select HopsProvince+HopsCity+HopsArea+HospAddress from HospData where HospName='"&StartAddress&"'"
        rs.open Sql,objConn,1,1
        If not rs.Eof Then
            StartAddress=rs(0)
        End If
        rs.close()
        appUrl="https://api.map.baidu.com/geocoding/v3/"
        args1="address="&StartAddress&"&output=json&ak="&ak
        HTMLCODE= GetBody(appUrl,args1)
        'Response.Write HTMLCODE
        'Response.End
        json    = HTMLCODE
        str=json
        set obj = getjson(str)
        status        = obj.status
        If status=0 Then
            StartAddress_lat        = obj.result.location.lat
            StartAddress_lng        = obj.result.location.lng
            'OrderPriceTXT="出发:"&StartAddress_lng&","&StartAddress_lat
            OrderPriceTXT="转出"
        End if
    End If
 
    '目的地坐标
    If InStr(EndAddress,",")>1 And errcode=0 Then
        EndAddressSP=SPLIT(EndAddress,",")
        If UBOUND(EndAddressSP)=1 Then
            If IsNumeric(EndAddressSP(0)) And IsNumeric(EndAddressSP(1)) Then
                EndAddress_lat=EndAddressSP(0)
                EndAddress_lng=EndAddressSP(1)
                
            End If
        End If
    End If
    If EndAddress_lat=0 And errcode=0 Then
        sql="select HopsProvince+HopsCity+HopsArea+HospAddress from HospData where HospName='"&EndAddress&"'"
        rs.open Sql,objConn,1,1
        If not rs.Eof Then
            EndAddress=rs(0)
        End If
        rs.close()
        appUrl="https://api.map.baidu.com/geocoding/v3/"
        args1="address="&EndAddress&"&output=json&ak="&ak
        HTMLCODE= GetBody(appUrl,args1)
        'Response.Write HTMLCODE
        'Response.End
        json    = HTMLCODE
        str=json
        set obj = getjson(str)
        status        = obj.status
        If status=0 Then
            EndAddress_lat        = obj.result.location.lat
            EndAddress_lng        = obj.result.location.lng
        End If
    End If
    'OrderPriceTXT=OrderPriceTXT&" 目的:"&EndAddress_lng&","&EndAddress_lat
    OrderPriceTXT=OrderPriceTXT&"至转入"
End If
 
If (StartAddress_lat<>0 And EndAddress_lat<>0) And errcode=0 Then
    '实时距离
    '机构参数
    sql="select * from IntroducerUnitData where ServiceBranch='"&ServiceBranch&"' and UnitState<>0 order by UnitID desc"
    rs.open sql,objConn,1,1
    If Not rs.eof Then
        UnitID        = rs("UnitID")
        ServiceBranch    = rs("ServiceBranch")
        ServiceMinPrice    = rs("ServiceMinPrice")
        ServiceUnitPrice= rs("ServiceUnitPrice")
        ServiceLong        = rs("ServiceLong")
        ServiceAddress_lat=rs("ServiceAddress_lat")
        ServiceAddress_lng=rs("ServiceAddress_lng")
    Else
        errcode=40024
        errmsg="invalid ServiceBranch"
    End If
    rs.close()
    
    If 1=2 Then
        '计算所属地区(按离机构近的计算)
        sql="select (cast((6378137.0*ACOS(SIN("&ServiceAddress_lat&"/180*PI())*SIN(cast("&StartAddress_lat&" as decimal(15,10))/180*PI())+COS("&ServiceAddress_lat&"/180*PI())*COS(cast("&StartAddress_lat&" as decimal(15,10))/180*PI())*COS(("&ServiceAddress_lng&"-cast("&StartAddress_lng&" as decimal(15,10)))/180*PI()))) as decimal(15,0))),(cast((6378137.0*ACOS(SIN("&ServiceAddress_lat&"/180*PI())*SIN(cast("&EndAddress_lat&" as decimal(15,10))/180*PI())+COS("&ServiceAddress_lat&"/180*PI())*COS(cast("&EndAddress_lat&" as decimal(15,10))/180*PI())*COS(("&ServiceAddress_lng&"-cast("&EndAddress_lng&" as decimal(15,10)))/180*PI()))) as decimal(15,0)))"
        'Response.Write sql
        rs.open Sql,objConn,1,1
        StartDistance=clng(rs(0))
        EndDistance=clng(rs(1))
        rs.close()
        If StartDistance<EndDistance Then
            Region_lat=StartAddress_lat
            Region_lng=StartAddress_lng
        Else
            Region_lat=EndAddress_lat
            Region_lng=EndAddress_lng
        End If
    Else
        '计算所属地区(按出发地计算)
        Region_lat=StartAddress_lat
        Region_lng=StartAddress_lng
    End If
 
            
    '地区报价方案
    appUrl="https://api.map.baidu.com/reverse_geocoding/v3/"
    args1="location="&Region_lat&","&Region_lng&"&output=json&latest_admin=1&ak="&ak
    HTMLCODE= GetBody(appUrl,args1)
    json    = HTMLCODE
    'Response.Write HTMLCODE
    str=json
    set obj = getjson(str)
    status        = obj.status
    If status=0 Then
        StartProvince    = obj.result.addressComponent.province
        StartCity    = obj.result.addressComponent.city
        StartArea    = obj.result.addressComponent.district
    End If
 
    If TraDistance=0 Then
         'StartAddress_lat=FormatNumber(StartAddress_lat, 6)
         'StartAddress_lng=FormatNumber(StartAddress_lng, 6)
         'EndAddress_lat=FormatNumber(EndAddress_lat, 6)
         'EndAddress_lng=FormatNumber(EndAddress_lng, 6)
        '路线规划距离(公里)
        appUrl="https://api.map.baidu.com/directionlite/v1/driving"
        args1="origin="&StartAddress_lat&","&StartAddress_lng&"&destination="&EndAddress_lat&","&EndAddress_lng&"&coord_type=bd09ll&ak="&ak
        'Response.Write args1
        HTMLCODE= GetBody(appUrl,args1)
        json    = HTMLCODE
        'Response.Write HTMLCODE
        str=json
        set obj = getjson(str)
        status        = obj.status
        If status=0 Then
            str=json
            str=right(str,len(str)-instr(str,"[")+1)
            str=left(str,InstrRev(str,"]"))
            set obj = getjson(str)
            for i=0 to obj.length-1
                TraDistance        = obj.get(i).distance            '行程距离(米)
            Next
        End If
        If TraDistance>1000 And IsNumeric(TraDistance) Then
            TraDistance=CInt(TraDistance/1000)
        ElseIf TraDistance>0 And IsNumeric(TraDistance) Then
            TraDistance=1
        End If
        OrderPriceTXT=OrderPriceTXT&" 规划距离:"&TraDistance&"公里 "
 
        '各机构距离计算
        sql="select COUNT(*) from IntroducerRegion where IRCity='"&StartCity&"'"
        rs.open sql,objConn,1,1
        StartCityIRInt=rs(0)
        rs.close()
        If StartCityIRInt>0 And V<>"0.1" Then
            U_TraDistance=10000
            U_UnitShort=""
            sql="select UnitID,UnitShort,ServiceAddress,ServiceAddress_lat,ServiceAddress_lng from IntroducerUnitData where UnitState<>0 and ServiceAddress_lat<>0 and ServiceAddress_lng<>0 and ServiceAddress like '%"&StartCity&"%'"    'UnitID=14
            rs.open sql,objConn,1,1
            do while not rs.Eof
                U_UnitID            = rs("UnitID")            '机构ID
                U_ServiceAddress    = rs("ServiceAddress")    '机构出发地址
                U_ServiceAddress_lat    = rs("ServiceAddress_lat")            '机构出发坐标
                U_ServiceAddress_lng    = rs("ServiceAddress_lng")    '机构出发坐标
                '机构到出发地 路线规划距离(公里)
                appUrl="https://api.map.baidu.com/directionlite/v1/driving"
                args1="origin="&U_ServiceAddress_lat&","&U_ServiceAddress_lng&"&destination="&StartAddress_lat&","&StartAddress_lng&"&coord_type=wgs84&ak="&ak
                HTMLCODE= GetBody(appUrl,args1)
                
                json    = HTMLCODE
                str=json
                set obj = getjson(str)
                status        = obj.status
                If status=0 Then
                    str=json
                    str=right(str,len(str)-instr(str,"[")+1)
                    str=left(str,InstrRev(str,"]"))
                    set obj = getjson(str)
                    for i=0 to obj.length-1
                        new_U_TraDistance        = obj.get(i).distance            '行程距离(米)
                    Next
                End If
                If new_U_TraDistance>1000 And IsNumeric(new_U_TraDistance) Then
                    new_U_TraDistance=CInt(new_U_TraDistance/1000)
                ElseIf new_U_TraDistance>0 And IsNumeric(new_U_TraDistance) Then
                    new_U_TraDistance=1
                End If
                If new_U_TraDistance<U_TraDistance Then
                    U_TraDistance=new_U_TraDistance
                    U_UnitShort    = Replace(rs("UnitShort"),"微信小程序","广州总部")    '机构名称
                End If
            rs.movenext
            loop
            rs.close()
            OrderPriceTXT="出发机构:"&U_UnitShort&" "&U_TraDistance&"公里 "&OrderPriceTXT
        End If
    End If
Else
    '缓存距离
    OrderPriceTXT=OrderPriceTXT&" 规划距离:"&TraDistance&"公里 "
    If U_TraDistance<>"" And U_TraDistance<>"0" Then OrderPriceTXT="出发机构:"&U_UnitShort&" "&U_TraDistance&"公里 "&OrderPriceTXT
End If
 
'Response.Write OrderPriceTXT
    
If TraDistance>0 Then
    '费用计算
    IRPrice=0
    OrderPrice=0
    If errcode=0 Then
        '地址屏蔽黑名单
        'If StartArea="增城区" or  StartArea="花都区" or  StartArea="从化区" or  StartArea="南沙区" or  StartArea="番禺区" Then
        If StartArea="1" Then
            IRid=0
        Else
            If StartProvince<>"" And StartCity<>"" And StartArea<>"" And StartAddress<>"" And IRid=0 Then
                sql="select IRid,IRNursingLevel from IntroducerRegion where "&IRState&"=1 and (IRProvince='"&StartProvince&"' and IRCity='"&StartCity&"' and IRArea='"&StartArea&"' and '"&StartAddress&"' like '%'+IRkeyword+'%') and IRPrice>0 order by IRUnitID desc,IRNursingLevel desc"
                rs.open sql,objConn,1,1
                do while not rs.Eof
                    IRid            = rs("IRid")            '报价方案ID
                    IRNursingLevel    = rs("IRNursingLevel")    '医护护理级别
                    If CLng(IRNursingLevel)=CLng(NursingLevel) Then exit do
                rs.movenext
                loop
                rs.close()
            End If
            If StartProvince<>"" And StartCity<>"" And StartArea<>"" And IRid=0 Then
                sql="select IRid,IRNursingLevel from IntroducerRegion where "&IRState&"=1 and (IRProvince='"&StartProvince&"' and IRCity='"&StartCity&"' and IRArea='"&StartArea&"' and IRkeyword='') and IRPrice>0 order by IRUnitID desc,IRNursingLevel desc"
                rs.open sql,objConn,1,1
                do while not rs.Eof
                    IRid            = rs("IRid")            '报价方案ID
                    IRNursingLevel    = rs("IRNursingLevel")    '医护护理级别
                    If CLng(IRNursingLevel)=CLng(NursingLevel) Then exit do
                rs.movenext
                loop
                rs.close()
            End If
            If StartProvince<>"" And StartCity<>"" And IRid=0 Then
                sql="select IRid,IRNursingLevel from IntroducerRegion where "&IRState&"=1 and (IRProvince='"&StartProvince&"' and IRCity='"&StartCity&"' and IRArea='' and IRkeyword='') and IRPrice>0 order by IRUnitID desc,IRNursingLevel desc"
                rs.open sql,objConn,1,1
                do while not rs.Eof
                    IRid            = rs("IRid")            '报价方案ID
                    IRNursingLevel    = rs("IRNursingLevel")    '医护护理级别
                    If CLng(IRNursingLevel)=CLng(NursingLevel) Then exit do
                rs.movenext
                loop
                rs.close()
            End If
            If StartProvince<>"" And IRid=0 Then
                sql="select IRid,IRNursingLevel from IntroducerRegion where "&IRState&"=1 and (IRProvince='"&StartProvince&"' and IRCity='' and IRArea='' and IRkeyword='') and IRPrice>0 order by IRUnitID desc,IRNursingLevel desc"
                rs.open sql,objConn,1,1
                do while not rs.Eof
                    IRid            = rs("IRid")            '报价方案ID
                    IRNursingLevel    = rs("IRNursingLevel")    '医护护理级别
                    If CLng(IRNursingLevel)=CLng(NursingLevel) Then exit do
                rs.movenext
                loop
                rs.close()
            End If
            If IRid=0 Then
                sql="select IRid,IRNursingLevel from IntroducerRegion where "&IRState&"=1 and (IRProvince='其它') and IRPrice>0 order by IRUnitID,IRNursingLevel desc"
                rs.open sql,objConn,1,1
                do while not rs.Eof
                    IRid            = rs("IRid")            '报价方案ID
                    IRNursingLevel    = rs("IRNursingLevel")    '医护护理级别
                    If CLng(IRNursingLevel)=CLng(NursingLevel) Then exit do
                rs.movenext
                loop
                rs.close()
            End If
        End If
        If IRid<>0 Then
            sql="select IRid,Unitlimit,UnitPrice,IRPrice,IRNursingLevel,IRVentilatorCost,IRWarmBoxCost,IRLiftingCost,IRWaitingCost,IRFerryCost from IntroducerRegion where IRid="&IRid
            rs.open sql,objConn,1,1
            If Not rs.eof Then
                IRid            = rs("IRid")            '报价方案ID
                Unitlimit        = rs("Unitlimit")        '派车点免费距离
                UnitPrice        = rs("UnitPrice")        '派车点收费金额
                IRPrice            = rs("IRPrice")            '起步价
                IRNursingLevel    = rs("IRNursingLevel")    '医护护理级别
                IRVentilatorCost= rs("IRVentilatorCost")'呼吸机费用
                IRWarmBoxCost    = rs("IRWarmBoxCost")    '温箱费用
                IRLiftingCost    = rs("IRLiftingCost")    '每层抬楼费用
                IRWaitingCost    = rs("IRWaitingCost")    '每半小时等待费用
                IRFerryCost        = rs("IRFerryCost")        '轮渡费用
                IRICUCost        = 1000                    '每小时居家ICU费用
                IRDtPriceTimes    = 1
                If AgeGroup="2" Or AgeGroup="5" Then    '儿童固定起步价(2儿童(0-3岁(含3岁)),3儿童(3-6岁(含6岁)),4儿童(6-12岁),5新生儿 (出生至28天以内))
                    IRPrice=IRPrice*1.2    '基础费1.2倍
                    IRDtPriceTimes=1.2    
                ElseIf AgeGroup="3" Then
                    IRPrice=IRPrice*1.1    '基础费1.1倍
                    IRDtPriceTimes=1.1    
                ElseIf AgeGroup="4" Then
                    IRPrice=IRPrice*1.05    '基础费1.05倍
                    IRDtPriceTimes=1.05    
                End If
            End If
            rs.close()
        End If
        addressComponent=StartProvince
        If StartCity<>"" Then addressComponent=addressComponent&"-"&StartCity
        If StartArea<>"" Then addressComponent=addressComponent&"-"&StartArea
        
        '计算报价
        OrderPriceFRM=""
        'OrderPriceTXT=""
        If IRPrice>0 And TraDistance>0 Then
            '基础报价
            'Response.Write IRid
            If CLng(U_TraDistance)>CLng(Unitlimit) And UnitPrice>0 Then    '派车价
                OrderUnitlimit=U_TraDistance-Unitlimit
                OrderUnitPrice=OrderUnitlimit * UnitPrice
                OrderPrice=OrderUnitPrice
                OrderPriceFRM = "("&U_TraDistance&"-"&Unitlimit &")*"& UnitPrice &"+"
                OrderPriceTXT = OrderPriceTXT&"派车价(超"&OrderUnitlimit&"公里):"&OrderUnitlimit*UnitPrice&"元\n"
            End If
            OrderPrice=OrderPrice+IRPrice    '起步价
            If IRDtPriceTimes>1 Then OrderPriceFRM=OrderPriceFRM&"("
            OrderPriceFRM = OrderPriceFRM & (IRPrice/IRDtPriceTimes)
            OrderPriceTXT = OrderPriceTXT&"起步价(20公里内):"&IRPrice&"元\n"
            sql="select IRDtlimit,IRDtPrice from came.dbo.IntroducerRegionDt where IRDt_id="&IRid&" and IRDtlimit<="&TraDistance&" order by IRDtlimit"
            rs.open sql,objConn,1,1
            RegionDt=""
            r=1
            IRDtlimit1=0
            IRDtlimit2=0
            do while not rs.Eof
                IRDtlimit1=rs("IRDtlimit")
                'OrderPriceTXT=replace(OrderPriceTXT,"#起步公里#",IRDtlimit1)
                IRDtPrice=rs("IRDtPrice")*IRDtPriceTimes
                rs.movenext
                If not rs.Eof Then
                    IRDtlimit2=rs("IRDtlimit")
                Else
                    IRDtlimit2=TraDistance
                End If
                IRDtDistance=IRDtlimit2-IRDtlimit1
                'If IRDtDistance<IRDtlimit2 Then IRDtDistance=IRDtlimit2
                OrderPrice=OrderPrice+IRDtDistance*IRDtPrice
                If IRDtDistance>0 Then
                    OrderPriceFRM = OrderPriceFRM & "+"&IRDtDistance&"*"&IRDtPrice/IRDtPriceTimes
                    If IRDtlimit2=TraDistance Or IRDtlimit2="" Then
                        OrderPriceTXT = OrderPriceTXT&IRDtlimit1&"公里以上:"&IRDtPrice&"元/公里\n"
                    Else
                        OrderPriceTXT = OrderPriceTXT&IRDtlimit1&"公里至"&IRDtlimit2&"公里:"&IRDtPrice&"元/公里\n"
                    End If
                End If
            loop
            rs.close()
            If IRDtPriceTimes>1 Then OrderPriceFRM=OrderPriceFRM&")*"&IRDtPriceTimes
 
            '服务报价
            If CLng(IsVentilato)=1 Then    '是否使用呼吸机
                OrderPrice=OrderPrice+IRVentilatorCost
                OrderPriceFRM = OrderPriceFRM & "+"&IRVentilatorCost
                OrderPriceTXT = OrderPriceTXT&"呼吸机费用:"&IRVentilatorCost&"元\n"
            End If
            If CLng(IsWarmBox)=1 Then    '是否使用温箱
                OrderPrice=OrderPrice+IRWarmBoxCost
                OrderPriceFRM = OrderPriceFRM & "+"&IRWarmBoxCost
                OrderPriceTXT = OrderPriceTXT&"温箱费用:"&IRWarmBoxCost&"元\n"
            End If
            If CLng(IsFerry)=1 Then    '是否要轮渡
                OrderPrice=OrderPrice+IRFerryCost
                OrderPriceFRM = OrderPriceFRM & "+"&IRFerryCost
                OrderPriceTXT = OrderPriceTXT&"轮渡费用:"&IRFerryCost&"元\n"
            End If
            If CLng(LiftingInt)>0 Then    '抬楼层数
                OrderPrice=OrderPrice+IRLiftingCost*LiftingInt
                OrderPriceFRM = OrderPriceFRM & "+"&IRLiftingCost&"*"&LiftingInt
                OrderPriceTXT = OrderPriceTXT&"抬楼费用:"&IRLiftingCost*CLng(LiftingInt)&"元\n"
            End If
            If round(WaitingInt,1)>0 Then    '等待费用(每半小时)
                OrderPrice=OrderPrice+WaitingInt*2*IRWaitingCost
                OrderPriceFRM = OrderPriceFRM & "+"&WaitingInt&"*2*"&IRWaitingCost
                OrderPriceTXT = OrderPriceTXT&"等待费用:"&WaitingInt*2*IRWaitingCost&"元\n"
            End If
            If CLng(ICUInt)>0 Then    '居家ICU 前6小时1000元,超6小时500元/小时
                If CLng(ICUInt)<=6 Then
                    OrderPrice=OrderPrice+IRICUCost*ICUInt
                    OrderPriceFRM = OrderPriceFRM & "+"&IRICUCost&"*"&ICUInt
                    OrderPriceTXT = OrderPriceTXT&"居家ICU费用:"&IRICUCost*ICUInt&"元\n"
                Else
                    OrderPrice=OrderPrice+IRICUCost*6+500*(ICUInt-6)
                    OrderPriceFRM = OrderPriceFRM & "+"&IRICUCost&"*6+500*"&(ICUInt-6)
                    OrderPriceTXT = OrderPriceTXT&"居家ICU费用:"&IRICUCost*6+500*(ICUInt-6)&"元\n"
                End If
            End If
            If ServiceOrdApptDate<>"" And ServiceOrdApptDate<>"1900/1/1" And ServiceOrdApptDate<>"1900-1-1" Then    '夜间服务费用,20:00-00:00加收300  00:01-06:30加收500
                If hour(ServiceOrdApptDate)>=20 Then
                    OrderPrice=OrderPrice+300
                    OrderPriceFRM = OrderPriceFRM & "+300"
                    OrderPriceTXT = OrderPriceTXT&"夜间服务费用:300元\n"
                ElseIf hour(ServiceOrdApptDate)<6 or (hour(ServiceOrdApptDate)=6 And Minute(ServiceOrdApptDate)<=30) Then
                    OrderPrice=OrderPrice+500
                    OrderPriceFRM = OrderPriceFRM & "+500"
                    OrderPriceTXT = OrderPriceTXT&"夜间服务费用:500元\n"
                End If
            End If
 
        OrderPriceTXT1=OrderPriceTXT
            '自动使用优惠券
            ServiceOrdTraPriceReason=""
            OrdCoupon=0
            If UserID<>"" And ServiceOrdID<>"" Then
                sql="select CouponNO,CouponMoney from Coupon where CouponDate_Ent>=getdate() and ToUserID="&UserID&" and CouponState=0 order by CouponMoney desc"
                rs.open sql,objConn,1,1
                do while not rs.Eof
                    CouponNO=rs("CouponNO")
                    CouponMoney=rs("CouponMoney")
                    If CouponMoney=500 And TraDistance>=500 Then
                        If IsCoupon="1" Then
                            OrderPrice=OrderPrice-CouponMoney
                            OrderPriceFRM = OrderPriceFRM & "-"&CouponMoney
                            OrderPriceTXT = OrderPriceTXT&"活动优惠券:-"&CouponMoney&"元 "&CouponNO&"\n"
                            OrderPriceTips="已使用代金券,共计优惠:"&CouponMoney&"元"
                            ServiceOrdTraPriceReason="优惠券:"&CouponNO&" "&CouponMoney&"元"
                        End If
                        OrdCoupon = CouponMoney
                        OrdIsCoupon="1"
                        Exit Do
                    ElseIf CouponMoney=200 And TraDistance>=100 Then
                        If IsCoupon="1" Then
                            OrderPrice=OrderPrice-CouponMoney
                            OrderPriceFRM = OrderPriceFRM & "-"&CouponMoney
                            OrderPriceTXT = OrderPriceTXT&"活动优惠券:-"&CouponMoney&"元 "&CouponNO&"\n"
                            OrderPriceTips="已使用代金券,共计优惠:"&CouponMoney&"元"
                            ServiceOrdTraPriceReason="优惠券:"&CouponNO&" "&CouponMoney&"元"
                        End If
                        OrdCoupon = CouponMoney
                        OrdIsCoupon="1"
                        Exit Do
                    ElseIf CouponMoney=50 Then
                        If IsCoupon="1" Then
                            OrderPrice=OrderPrice-CouponMoney
                            OrderPriceFRM = OrderPriceFRM & "-"&CouponMoney
                            OrderPriceTXT = OrderPriceTXT&"活动优惠券:-"&CouponMoney&"元 "&CouponNO&"\n"
                            OrderPriceTips="已使用代金券,共计优惠:"&CouponMoney&"元"
                            ServiceOrdTraPriceReason="优惠券:"&CouponNO&" "&CouponMoney&"元"
                        End If
                        OrdCoupon = CouponMoney
                        OrdIsCoupon="1"
                        Exit Do
                    End If
                    rs.movenext
                loop
                rs.close()
                sql="update ServiceOrder set ServiceOrdTraPriceReason='"&ServiceOrdTraPriceReason&"' where ServiceOrdID="&ServiceOrdID
                objConn.Execute sql
            End If
            OrderPriceFRM = OrderPriceFRM&"="&OrderPrice
            OrderPriceTXT = OrderPriceTXT&"总费用:"&OrderPrice&"元\n"
        Else
            OrderPrice=0
            OrderPriceFRM="暂不报价"
            OrderPriceTXT="客服报价"
            IsCoupon        = trim(request("IsCoupon"))            '是否使用优惠券:默认0
            If IsCoupon="" Then IsCoupon="0"
            '优惠券查询
            OrdCoupon=0
            If UserID<>"" And ServiceOrdID<>"" And TraDistance>0 Then
                sql="select CouponNO,CouponMoney from Coupon where CouponDate_Ent>=getdate() and ToUserID="&UserID&" and CouponState=0 order by CouponMoney desc"
                rs.open sql,objConn,1,1
                do while not rs.Eof
                    CouponNO=rs("CouponNO")
                    CouponMoney=rs("CouponMoney")
                    If CouponMoney=500 And TraDistance>=500 Then
                        OrdCoupon = CouponMoney
                        OrdIsCoupon="1"
                        Exit Do
                    ElseIf CouponMoney=200 And TraDistance>=100 Then
                        OrdCoupon = CouponMoney
                        OrdIsCoupon="1"
                        Exit Do
                    ElseIf CouponMoney=50 Then
                        OrdCoupon = CouponMoney
                        OrdIsCoupon="1"
                        Exit Do
                    End If
                    rs.movenext
                loop
                rs.close()
                If IsCoupon="1" And OrdCoupon>0 Then
                    OrderPriceTXT = OrderPriceTXT&",客户希望使用优惠券:-"&OrdCoupon&"元\n"
                ElseIf IsIntegral="1" Then
                    OrderPriceTXT = OrderPriceTXT&",客户希望使用积分\n"
                End If
            End If
        End If
 
    End If
    
    If ServiceTXT<>"" Then ServiceTXT="您的转运距离约"&TraDistance&"公里。"&ServiceTXT
    If ServiceOrdID<>"" And ServiceOrdID<>"0" And V="2.0" Then
        sql="delete from ServiceOrder_Options where ServiceOptionsID in (-1,1000,1001) and ServiceOrdSoID="&ServiceOrdID
        objConn.Execute sql
        ServiceOptionsValue="转运距离约"&TraDistance&"公里"
        If U_UnitShort<>"" Then
            ServiceOptionsValue=ServiceOptionsValue&",建议执行单位:"&U_UnitShort
        End If
        sql="Insert into ServiceOrder_Options (ServiceOrdSoID,ServiceOptionsID,ServiceOptionsValue) values ("&ServiceOrdID&",-1,'"&ServiceOptionsValue&"')"
        objConn.Execute sql
        sql="Insert into ServiceOrder_Options (ServiceOrdSoID,ServiceOptionsID,ServiceOptionsValue) values ("&ServiceOrdID&",1000,'报价说明:"&OrderPriceTXT&"')"
        objConn.Execute sql
        sql="Insert into ServiceOrder_Options (ServiceOrdSoID,ServiceOptionsID,ServiceOptionsValue) values ("&ServiceOrdID&",1001,'报价公式:"&OrderPriceFRM&"')"
        objConn.Execute sql
    ElseIf adminID<>"" Then
        U_UnitShort    = Replace(U_UnitShort,"微信小程序","广州总部")    '机构名称
        OrderPricelog=U_UnitShort&" 预估距离:"&TraDistance&"公里"
        If U_TraDistance<>"" Then OrderPricelog=OrderPricelog&" 派车距离:"&U_TraDistance&"公里"
        OrderPricelog=OrderPricelog&" 自动报价:"&OrderPrice&"元 报价说明:"&OrderPriceTXT1&"报价公式:"&OrderPriceFRM&""
        sql="Insert into API_Json (method,Json,Json_time,reserve) values ('报价工具','"&OrderPricelog&"',getdate(),'"&adminID&"')"
        objConn.Execute sql
    End If
    If ServiceOrdID<>"" And ServiceOrdID<>"0" And OrderPrice<>"" And OrderPrice<>"0" And IsNumeric(OrderPrice) Then
        sql="update ServiceOrder set OrderPrice_Auto="&OrderPrice&" where ServiceOrdID="&ServiceOrdID
        objConn.Execute sql
    End If
    OrderPriceTXT=""
    OrderPriceTXT=OrderPriceTips
    webJson="{""APPID"":"""&APPID&""",""method"":"""&method&""",""result"":1,""OrderPrice"":"""&OrderPrice&""",""TraDistance"":"""&TraDistance&""",""addressComponent"":"""&addressComponent&""",""StartAddress"":"""&StartAddress&""",""EndAddress"":"""&EndAddress&""",""origin"":"""&StartAddress_lat&","&StartAddress_lng&""",""destination"":"""&EndAddress_lat&","&EndAddress_lng&""",""OrderPriceFRM"":"""&OrderPriceFRM&""",""OrderPriceTXT"":"""&OrderPriceTXT&""",""OrderPriceTXT1"":"""&OrderPriceTXT1&""",""IRid"":"""&IRid&""",""NursingLevel"":"""&NursingLevel&""",""ServiceTXT"":"""&ServiceTXT&""",""StartProvince"":"""&StartProvince&""",""StartCity"":"""&StartCity&""",""StartArea"":"""&StartArea&""",""U_UnitShort"":"""&U_UnitShort&""",""U_TraDistance"":"""&U_TraDistance&""",""OrdIsCoupon"":"""&OrdIsCoupon&""",""OrdCoupon"":"""&OrdCoupon&"""}"
 
Else
    errcode=40022
    errmsg="invalid Address"
End If
 
 
If Left(errcode,1)="4" Or webJson="" Then
    If errcode="" Then
        errcode=-1
        errmsg="error"
    End If
    webJson="{""APPID"":"""&APPID&""",""method"":"""&method&""",""result"":2,""errcode"":"&errcode&",""errmsg"":"""&errmsg&"""}"
    'Call OA_Running(UnitID,webJson)
Else
    OkJson="{""APPID"":"""&APPID&""",""method"":"""&method&""",""result"":1,""Running"":"""&sParaRunning&"""}"
    'Call OA_Running(UnitID,OkJson)
End If
 
Response.Write webJson
Response.End
%>