<% @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>
|
<%
|
Set rs = Server.CreateObject("ADODB.Recordset")
|
Set rsDt = Server.CreateObject("ADODB.Recordset")
|
|
ServiceOrdID = trim(request("ServiceOrdID"))
|
StartAddress = trim(request("StartAddress"))
|
EndAddress = trim(request("EndAddress"))
|
ServiceBranch = trim(request("ServiceBranch"))
|
|
If ServiceOrdID<>"" Then
|
sql="select ServiceOrdClass,ServiceOrdTraStreet,ServiceOrdTraVia,ServiceOrdTraEnd from ServiceOrder where ServiceOrdID="&ServiceOrdID
|
rs.open Sql,objConn,1,1
|
If not rs.Eof Then
|
ServiceBranch = rs("ServiceOrdClass")
|
StartAddress = trim(rs("ServiceOrdTraStreet"))
|
If rs("ServiceOrdTraVia")<>"" Then StartAddress=rs("ServiceOrdTraVia")
|
EndAddress = trim(rs("ServiceOrdTraEnd"))
|
End If
|
rs.close()
|
End If
|
|
If ServiceBranch="" Then ServiceBranch="BF"
|
errcode=0
|
OrderPrice=0
|
StartAddress_lat=0
|
StartAddress_lng=0
|
EndAddress_lat=0
|
EndAddress_lng=0
|
|
If StartAddress="" Then
|
errcode=40020
|
errmsg="invalid StartAddress"
|
ElseIf EndAddress="" Then
|
errcode=40021
|
errmsg="invalid EndAddress"
|
End If
|
|
'出发地坐标
|
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="http://api.map.baidu.com/geocoder/v2/"
|
args1="address="&StartAddress&"&output=json&ak=rGQBbHKGjAtVQy23OckafQkC6nNlaGmi"
|
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
|
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="http://api.map.baidu.com/geocoder/v2/"
|
args1="address="&EndAddress&"&output=json&ak=rGQBbHKGjAtVQy23OckafQkC6nNlaGmi"
|
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
|
|
|
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()
|
|
'计算所属地区
|
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)))"
|
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
|
|
|
|
'路线规划距离(公里)
|
TraDistance=0
|
appUrl="http://api.map.baidu.com/direction/v2/driving"
|
args1="origin="&StartAddress_lat&","&StartAddress_lng&"&destination="&EndAddress_lat&","&EndAddress_lng&"&ak=rGQBbHKGjAtVQy23OckafQkC6nNlaGmi"
|
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
|
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
|
|
|
|
'费用计算
|
IRPrice=0
|
If errcode=0 Then
|
'距离报价
|
OrderPrice=TraDistance*ServiceUnitPrice
|
If OrderPrice<ServiceMinPrice Then OrderPrice=ServiceMinPrice
|
|
'地区基础费用
|
If TraDistance<ServiceLong Then
|
appUrl="http://api.map.baidu.com/geocoder/v2/"
|
args1="location="&Region_lat&","&Region_lng&"&output=json&latest_admin=1&ak=rGQBbHKGjAtVQy23OckafQkC6nNlaGmi"
|
HTMLCODE= GetBody(appUrl,args1)
|
json = 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 StartProvince<>"" And StartCity<>"" And StartArea<>"" And IRPrice=0 Then
|
sql="select IRPrice from IntroducerRegion where IRState=1 and IRUnitID="&UnitID&" and (IRProvince='"&StartProvince&"' and IRCity='"&StartCity&"' and IRArea='"&StartArea&"')"
|
rs.open sql,objConn,1,1
|
If Not rs.eof Then
|
IRPrice=rs("IRPrice")
|
End If
|
rs.close()
|
End If
|
If StartProvince<>"" And StartCity<>"" And IRPrice=0 Then
|
sql="select IRPrice from IntroducerRegion where IRState=1 and IRUnitID="&UnitID&" and (IRProvince='"&StartProvince&"' and IRCity='"&StartCity&"' and IRArea='')"
|
rs.open sql,objConn,1,1
|
If Not rs.eof Then
|
IRPrice=rs("IRPrice")
|
End If
|
rs.close()
|
End If
|
If StartProvince<>"" And IRPrice=0 Then
|
sql="select IRPrice from IntroducerRegion where IRState=1 and IRUnitID="&UnitID&" and (IRProvince='"&StartProvince&"' and IRCity='' and IRArea='')"
|
rs.open sql,objConn,1,1
|
If Not rs.eof Then
|
IRPrice=rs("IRPrice")
|
End If
|
rs.close()
|
End If
|
If IRPrice=0 Then
|
sql="select IRPrice from IntroducerRegion where IRState=1 and IRUnitID="&UnitID&" and (IRProvince='其它')"
|
rs.open sql,objConn,1,1
|
If Not rs.eof Then
|
IRPrice=rs("IRPrice")
|
End If
|
rs.close()
|
End If
|
OrderPrice=OrderPrice+IRPrice
|
addressComponent=StartProvince
|
If StartCity<>"" Then addressComponent=addressComponent&"-"&StartCity
|
If StartArea<>"" Then addressComponent=addressComponent&"-"&StartArea
|
Else
|
addressComponent="长途"
|
End If
|
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&"""}"
|
|
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
|
%>
|