<!--#include file="Admin_Common.asp"-->
<!--#include file="../Include/PowerEasy.SendMail.asp"-->
<!--#include file="../Include/PowerEasy.Common.Front.asp"-->

<%
'**************************************************************
' Software name: PowerEasy SiteWeaver
' Web: http://www.powereasy.net
' Copyright (C) 2005－2009 佛山市动易网络科技有限公司 版权所有
'**************************************************************

Const NeedCheckComeUrl = True   '是否需要检查外部访问

Const PurviewLevel = 2      '0--不检查，1--超级管理员，2--普通管理员
Const PurviewLevel_Channel = 0   '0--不检查，1--频道管理员，2--栏目总编，3--栏目管理员
Const PurviewLevel_Others = "ShoppingCart"   '其他权限

SearchType = PE_CLng(Trim(Request("SearchType")))
strFileName = "Admin_ShoppingCart.asp?SearchType=" & SearchType

Response.Write "<html>" & vbCrLf
Response.Write "<head>" & vbCrLf
Response.Write "<title>购物车管理</title>" & vbCrLf
Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbCrLf
Response.Write "<link rel='stylesheet' href='Admin_Style.css'>" & vbCrLf
Response.Write "</head>" & vbCrLf
Response.Write "<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>" & vbCrLf
Response.Write "<table width='100%'  border='0' cellpadding='2' cellspacing='1' class='border'>" & vbCrLf
Call ShowPageTitle("购 物 车", 10047)
Response.Write "  <tr class='tdbg'>" & vbCrLf
Response.Write "<form name='myform' method='post' action='Admin_ShoppingCart.asp' onSubmit=""return confirm('确实要删除指定的购物车记录吗？')""><td>" & vbCrLf
Response.Write "如果购物车明细记录太多，影响了系统性能，可以删除一定时间段前的记录以加快速度。<br>" & vbCrLf
Response.Write "时间范围：<input type='radio' name='DatepartType' value='0'>1天前&nbsp;&nbsp;<input type='radio' name='DatepartType' value='1'>1个星期前&nbsp;&nbsp;<input type='radio' name='DatepartType' value='2'>1个月前&nbsp;&nbsp;<input type='radio' name='DatepartType' value='3' checked>3个月前" & vbCrLf
Response.Write "&nbsp;&nbsp;<input type='submit' name='submit1' value='删除记录'>" & vbCrLf
Response.Write "<input type='hidden' name='Action' value='Clear'>" & vbCrLf
Response.Write "</td></form>" & vbCrLf
Response.Write "  </tr>" & vbCrLf
Response.Write "</table>" & vbCrLf

Select Case Action
Case "Clear"
    Call Clear
Case "CartList"
    Call CartList
Case "CartInfo"
    Call CartInfo
Case "SendCartMail"
    Call SendCartMail

Case Else
    Call Main
End Select
If FoundErr = True Then
    Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Response.Write "</body></html>"
Call CloseConn

Sub Main()
    Dim sql, Querysql, rsCart
    Dim i
    Querysql = Querysql & " where 1=1 "
    
    sql = "select top " & MaxPerPage & " C.CartID,Sum(P.Price * C.Quantity) as TotalPrice, Max(C.UserName) as UserName,Max(C.UpdateTime) as UpdateTime from PE_ShoppingCarts C inner join PE_Product P on P.ProductID=C.ProductID"
    Response.Write "<br><table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_ShoppingCart.asp'>购物车管理</a>"
    
    If SystemDatabaseType = "SQL" Then
        totalPut = PE_CLng(Conn.Execute("Select Count(DISTINCT CartID) from PE_ShoppingCarts")(0))
    Else
        totalPut = PE_CLng(Conn.Execute("select Count(0) From (Select DISTINCT CartID from PE_ShoppingCarts)")(0))
    End If
    If CurrentPage < 1 Then
        CurrentPage = 1
    End If
    If (CurrentPage - 1) * MaxPerPage > totalPut Then
        If (totalPut Mod MaxPerPage) = 0 Then
            CurrentPage = totalPut \ MaxPerPage
        Else
            CurrentPage = totalPut \ MaxPerPage + 1
        End If
    End If
    If CurrentPage > 1 Then
        Querysql = Querysql & " and C.CartItemID < (select min(minCartItemID) from (select top " & ((CurrentPage - 1) * MaxPerPage) & " Min(C.CartItemID) as minCartItemID from PE_ShoppingCarts C " & Querysql & " group by C.cartID  order by Min(C.CartItemID) desc) as QueryCartItemID)"
    End If
    sql = sql & Querysql & " group by C.cartID order by min(C.CartItemID) desc"

    Response.Write "</td></tr></table>"
    If FoundErr = True Then Exit Sub
    
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr class='title' height='22' align='center'>"
    Response.Write "    <td width='140'><b>购物车时间</b></td>"
    Response.Write "    <td><b>购物车编号</b></td>"
    Response.Write "    <td width='120'><b>用户名</b></td>"
    Response.Write "    <td width='100'><b>预计金额</b></td>"
    Response.Write "    <td width='90'><b>操作</b></td>"
    Response.Write "    <td width='90'><b>手机催单</b></td>"
    Response.Write "    <td width='90'><b>邮件催单</b></td>"
    Response.Write "  </tr>"
    
    Set rsCart = Server.CreateObject("Adodb.RecordSet")
    rsCart.Open sql, Conn, 1, 1
    If rsCart.BOF And rsCart.EOF Then
        totalPut = 0
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何记录！</td></tr>"
    Else
        Do While Not rsCart.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "    <td width='140' align='center'>" & rsCart("UpdateTime") & "</td>"
            Response.Write "    <td align='center'><a href='Admin_ShoppingCart.asp?Action=CartInfo&CartID=" & rsCart("CartID") & "'>" & rsCart("CartID") & "</a></td>"
            Response.Write "    <td width='120' align='center'><a href='Admin_User.asp?Action=Show&InfoType=0&UserName=" & rsCart("UserName") & "'>" & rsCart("UserName") & "</a></td>"
            Response.Write "    <td width='100' align=center>" & FormatNumber(rsCart("TotalPrice"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
            Response.Write "    <td width='90' align='center'><a href='Admin_ShoppingCart.asp?Action=CartInfo&CartID=" & rsCart("CartID") & "'>查看购物车</a></td>"
            Response.Write "    <td align='center'><input type='button' name='Submit' value='发送短信' onClick=window.location.href='Admin_SMS.asp?SendTo=Order&UserName=" & rsCart("UserName") & "'></td>"
            Response.Write "    <td align='center'><input type='button' name='Submit' value='发送邮件' onClick=window.location.href='Admin_ShoppingCart.asp?Action=SendCartMail&CartID=" & rsCart("CartID")&"&UserName=" & rsCart("UserName") & "'></td>"
            Response.Write "  </tr>"
            i = i + 1
            If i >= MaxPerPage Then Exit Do
            rsCart.MoveNext
        Loop
    End If
    rsCart.Close
    Set rsCart = Nothing
    Response.Write "</table>"    
    Response.Write ShowPage(strFileName, totalPut, MaxPerPage, CurrentPage, True, True, "条购物车记录", True)

End Sub

Sub CartList()
    Dim MaxPerPage, TotalPut, CurrentPage, strFileName, i
    Dim sql, Querysql, rsCart
    MaxPerPage = PE_CLng(Trim(Request("MaxPerPage")))
    CurrentPage = PE_CLng(Trim(Request("Page")))
    If MaxPerPage <= 0 Then MaxPerPage = 20
    If CurrentPage <= 0 Then CurrentPage = 1
    strFileName = "Admin_ShoppingCart.asp?Action=CartList"
    Querysql = Querysql & " where 1=1 and UserName<>'' "

    sql = "select top " & MaxPerPage & " C.CartID,Max(C.State) as State, Sum(P.Price * C.Quantity) as TotalPrice, Max(C.UserName) as UserName,Max(C.UpdateTime) as UpdateTime from PE_ShoppingCarts C inner join PE_Product P on P.ProductID=C.ProductID"
    Response.Write "<br><table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_ShoppingCart.asp'>购物车管理</a>&nbsp;&gt;&gt;&nbsp;未提交订单"

    'totalPut = PE_CLng(Conn.Execute("Select Count(DISTINCT CartID) from PE_ShoppingCarts where UserName<>''")(0))
    TotalPut = PE_CLng(Conn.Execute("select Count(0) From (Select DISTINCT CartID from PE_ShoppingCarts where UserName<>'')")(0))
    If CurrentPage < 1 Then
        CurrentPage = 1
    End If
    If (CurrentPage - 1) * MaxPerPage > TotalPut Then
        If (TotalPut Mod MaxPerPage) = 0 Then
            CurrentPage = TotalPut \ MaxPerPage
        Else
            CurrentPage = TotalPut \ MaxPerPage + 1
        End If
    End If
    If CurrentPage > 1 Then
        Querysql = Querysql & " and C.CartItemID < (select min(minCartItemID) from (select top " & ((CurrentPage - 1) * MaxPerPage) & " Min(C.CartItemID) as minCartItemID from PE_ShoppingCarts C " & Querysql & " group by C.cartID  order by Min(C.CartItemID) desc) as QueryCartItemID)"
    End If
    sql = sql & Querysql & " group by C.cartID order by min(C.CartItemID) desc"

    Response.Write "</td></tr></table>"
    If FoundErr = True Then Exit Sub
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' >"
    Response.Write "  <tr align='center'>"
    Response.Write "    <td><b><font color=red>每日催隔日的未提交订单，请勿催当日的未提交订单！</font></b></td>"
    Response.Write "</tr></table>"
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr class='title' height='22' align='center'>"
    Response.Write "    <td width='90'><b>查看购物车</b></td>"
    Response.Write "    <td width='200'><b>购物车编号</b></td>"
    Response.Write "    <td><b>用户名</b></td>"
    Response.Write "    <td><b>催单</b></td>"
    Response.Write "    <td><b>已催</b></td>"
    Response.Write "    <td width='140'><b>购物车时间</b></td>"
    Response.Write "    <td width='100'><b>预计金额</b></td>"
    Response.Write "  </tr>"

    Set rsCart = Server.CreateObject("Adodb.RecordSet")
    rsCart.Open sql, Conn, 1, 1
    If rsCart.BOF And rsCart.EOF Then
        TotalPut = 0
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何记录！</td></tr>"
    Else
        Do While Not rsCart.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "    <td width='90' align='center'><a href='Admin_ShoppingCart.asp?Action=CartInfo&CartID=" & rsCart("CartID") & "'>查看购物车</a></td>"
            Response.Write "    <td width='200' align='center'>" & rsCart("CartID") & "</td>"
            Response.Write "    <td align='center'><a href='Admin_User.asp?Action=Show&InfoType=0&UserName=" & rsCart("UserName") & "'>" & rsCart("UserName") & "</a></td>"
            Response.Write "    <td align='center'><input type='button' name='Submit' value='手机催单' onClick=window.location.href='Admin_ShoppingCart.asp?Action=UpdateState&CartID=" & rsCart("CartID") & "&UserName=" & rsCart("UserName") & "'></td>"
            Response.Write "    <td align='center'>"
            If rsCart("State") = 1 Then
                Response.Write "√"
            Else
                Response.Write "<font color='red'>×</font>"
            End If
            Response.Write "    </td>"
            Response.Write "    <td width='140' align='center'>" & rsCart("UpdateTime") & "</td>"
            Response.Write "    <td width='100' align=center>" & FormatNumber(rsCart("TotalPrice"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
            Response.Write "  </tr>"
            i = i + 1
            If i >= MaxPerPage Then Exit Do
            rsCart.MoveNext
        Loop
    End If
    rsCart.Close
    Set rsCart = Nothing

    Response.Write ShowPage(strFileName, TotalPut, MaxPerPage, CurrentPage, True, True, "条购物车记录", True)
End Sub


Sub CartInfo()
    Dim CartID, UserName
    CartID = ReplaceBadChar(Trim(Request("CartID")))
    If CartID = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>请指定CartID！</li>"
        Exit Sub
    End If

    Dim rsCart
    Set rsCart = Conn.Execute("select top 1 * from PE_ShoppingCarts where CartID='" & CartID & "'")
    If rsCart.BOF And rsCart.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的购物车信息！</li>"
        rsCart.Close
        Set rsCart = Nothing
        Exit Sub
    End If
    UserName = rsCart("UserName")

    Dim sqlUser, GroupType, rsUser, UserSetting, Discount_Member
    Dim rsCartItem, dblAmount, dblTruePrice, dblTotal, dblPrice, dblSubtotal, dblTempPrice
    Dim strSaleType, PresentList


    Response.Write "<br><table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_ShoppingCart.asp'>购物车管理</a>&nbsp;&gt;&gt;&nbsp;购物车信息"
    Response.Write "</td></tr></table>"

    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr align='center' class='title'>"
    Response.Write "    <td height='22'><b>购 物 车 信 息</b>（购物车编号：" & CartID & "）</td>"
    Response.Write "  </tr>"
    Response.Write "  <tr>"
    Response.Write "    <td height='25'>"

    Response.Write "   <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1'>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>用户名：</td>"
    Response.Write "          <td width='38%'><a href='Admin_User.asp?Action=Show&InfoType=0&UserName=" & rsCart("UserName") & "'>" & rsCart("UserName") & "</a> </td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>购物车时间：</td>"
    Response.Write "          <td width='38%'>" & rsCart("UpdateTime") & "</td>"
    Response.Write "        </tr>"
    Dim ContacterName, Phone, Address, ZipCode, Email, Mobile
    If UserName = "" Then
        ContacterName = ""
        Phone = ""
        Address = ""
        ZipCode = ""
        Email = ""
        Mobile = ""
        GroupType = 0
        UserSetting = Split("0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", ",")
    Else
        sqlUser = "SELECT U.ContacterID,U.SpecialPermission,U.UserSetting,G.GroupType,G.GroupSetting FROM PE_User U inner join PE_UserGroup G on U.GroupID=G.GroupID WHERE UserName='" & UserName & "'"
        Set rsUser = Conn.Execute(sqlUser)
        If rsUser.BOF And rsUser.EOF Then
            ContacterName = ""
            Phone = ""
            Address = ""
            ZipCode = ""
            Email = ""
            Mobile = ""
            GroupType = 0
            UserSetting = Split("0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", ",")
        Else
            GroupType = rsUser("GroupType")
            If rsUser("SpecialPermission") = True Then
                UserSetting = Split(rsUser("UserSetting"), ",")
            Else
                UserSetting = Split(rsUser("GroupSetting"), ",")
            End If
            Dim rsContacter
            Set rsContacter = Conn.Execute("select TrueName,HomePhone,Address,ZipCode,Email,Mobile from PE_Contacter where ContacterID=" & rsUser("ContacterID") & "")
            If rsContacter.BOF And rsContacter.EOF Then
                ContacterName = ""
                Phone = ""
                Address = ""
                ZipCode = ""
                Email = ""
                Mobile = ""
            Else
                ContacterName = rsContacter("TrueName")
                Phone = rsContacter("HomePhone")
                Address = rsContacter("Address")
                ZipCode = rsContacter("ZipCode")
                Email = rsContacter("Email")
                Mobile = rsContacter("Mobile")
            End If
            rsContacter.Close
            Set rsContacter = Nothing
        End If
        rsUser.Close
        Set rsUser = Nothing
    End If
    rsCart.Close
    Set rsCart = Nothing

    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>收货人姓名：</td>"
    Response.Write "          <td width='38%'>" & ContacterName & "</td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>联系电话：</td>"
    Response.Write "          <td width='38%'>" & Phone & "</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg' valign='top'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>收货人地址：</td>"
    Response.Write "          <td width='38%'>" & Address & "</td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>邮政编码：</td>"
    Response.Write "          <td width='38%'>" & ZipCode & "</td>"
    Response.Write "        </tr>"
    Response.Write "        <tr class='tdbg'>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>收货人邮箱：</td>"
    Response.Write "          <td width='38%'>" & Email & "</td>"
    Response.Write "          <td width='12%' class='tdbg5' align='right'>收货人手机：</td>"
    Response.Write "          <td width='38%'>" & Mobile & "</td>"
    Response.Write "        </tr>"
    Response.Write "    </table>"
    Response.Write "    </td>"
    Response.Write "   </tr>"
    

    Response.Write "  <tr>"
    Response.Write "    <td>"
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' bgcolor='#0099FF'>"
    Response.Write "  <tr align='center' class='tdbg2' height='25'>"
    Response.Write "    <td><b>商 品 名 称</b></td>"
    Response.Write "    <td width='45'><b>单位</b></td>"
    Response.Write "    <td width='55'><b>数量</b></td>"
    Response.Write "    <td width='85'><b>原价</b></td>"
    Response.Write "    <td width='85'><b>实价</b></td>"
    Response.Write "    <td width='85'><b>金 额</b></td>"
    Response.Write "    <td width='65'><b>服务期限</b></td>"
    Response.Write "  </tr>"

    Discount_Member = PE_CDbl(UserSetting(11))
    PresentList = SelectCart(CartID, 1)
        
    Set rsCartItem = Conn.Execute("select P.*,C.Quantity,C.CartItemID from PE_Product P inner join PE_ShoppingCarts C on C.ProductID=P.ProductID where C.CartID='" & CartID & "' and C.PresentID=0 and P.ProductType<>4 order by C.CartItemID desc")
    Do While Not rsCartItem.EOF
        dblAmount = rsCartItem("Quantity")
        dblPrice = rsCartItem("Price_Original")
    
        If PE_CLng(UserSetting(30)) = 1 And rsCartItem("EnableWholesale") = True And dblAmount >= rsCartItem("Number_Wholesale1") Then
            strSaleType = "批发"
            If dblAmount < rsCartItem("Number_Wholesale2") Then
                dblTruePrice = rsCartItem("Price_Wholesale1")
            Else
                If dblAmount < rsCartItem("Number_Wholesale3") Then
                    dblTruePrice = rsCartItem("Price_Wholesale2")
                Else
                    dblTruePrice = rsCartItem("Price_Wholesale3")
                End If
            End If
        Else
            Select Case GroupType
            Case 0, 1 '未登录
                Select Case rsCartItem("ProductType")
                Case 1
                    dblTruePrice = rsCartItem("Price")
                    'strProductType = "正常销售"
                    'strDiscount = "─"
                Case 2
                    'strProductType = "涨价商品"
                    dblTruePrice = rsCartItem("Price")
                    'strDiscount = "─"
                Case 3
                    If Date < rsCartItem("BeginDate") Or Date > rsCartItem("EndDate") Then
                        dblTruePrice = dblPrice
                        'strProductType = "正常销售"
                        'strDiscount = "─"
                    Else
                        dblTruePrice = rsCartItem("Price")
                        'strProductType = "特价商品"
                        'strDiscount = rsCartItem("Discount") & "折"
                    End If
                Case 5
                    'strProductType = "降价商品"
                    dblTruePrice = rsCartItem("Price")
                    'strDiscount = rsCartItem("Discount") & "折"
                End Select
            Case 2, 3   '注册会员
                Select Case rsCartItem("ProductType")
                Case 1
                    If rsCartItem("Price_Member") > 0 Then '如果指定了会员价
                        dblTruePrice = rsCartItem("Price_Member")
                    Else
                        dblTruePrice = rsCartItem("Price") * Discount_Member / 100
                    End If
                Case 2
                    If rsCartItem("Price_Member") > 0 Then '如果指定了会员价
                        dblTruePrice = rsCartItem("Price_Member")
                    Else
                        dblTruePrice = rsCartItem("Price") * Discount_Member / 100
                    End If
                Case 3, 5
                    If rsCartItem("ProductType") = 3 Then
                        If Date < rsCartItem("BeginDate") Or Date > rsCartItem("EndDate") Then
                            dblTempPrice = dblPrice
                        Else
                            dblTempPrice = rsCartItem("Price")
                        End If
                    Else
                        dblTempPrice = rsCartItem("Price")
                    End If
                    If rsCartItem("Price_Member") > 0 Then '如果指定了会员价
                        If rsCartItem("Price_Member") <= dblTempPrice Then
                            dblTruePrice = rsCartItem("Price_Member")
                        Else
                            dblTruePrice = dblTempPrice
                        End If
                    Else
                        If PE_CLng(UserSetting(12)) = 1 Then '如可以享受折上折优惠
                            dblTruePrice = dblTempPrice * Discount_Member / 100
                        Else
                            If dblPrice * Discount_Member / 100 >= dblTempPrice Then
                                dblTruePrice = dblTempPrice
                            Else
                                dblTruePrice = dblPrice * Discount_Member / 100
                            End If
                        End If
                    End If
                Case Else
                    dblTruePrice = rsCart("Price")
                End Select
            Case 4  '代理商
                dblTempPrice = rsCartItem("Price")
                If rsCartItem("Price_Agent") > 0 Then '如果指定了代理价
                    dblTruePrice = rsCartItem("Price_Agent")
                Else
                    If Discount_Member = 100 Then
                        dblTruePrice = dblTempPrice
                    Else
                        If PE_CLng(UserSetting(12)) = 1 Then '如可以享受折上折优惠
                            dblTruePrice = dblTempPrice * Discount_Member / 100
                        Else
                            If rsCartItem("Price_Original") * Discount_Member / 100 >= dblTempPrice Then
                                dblTruePrice = rsCartItem("Price_Original") * Discount_Member / 100
                                'strDiscount = Round(Discount_Member / 10, 1) & "折"
                            Else
                                dblTruePrice = dblTempPrice
                            End If
                        End If
                    End If
                End If
            End Select
        End If
        dblSubtotal = dblTruePrice * dblAmount
        dblTotal = dblTotal + dblSubtotal
            
        Response.Write "  <tr valign='middle' class='tdbg' height='20'>"
        Response.Write "    <td width='*'><a href='Admin_Product.asp?Action=Show&ChannelID=1000&ProductID=" & rsCartItem("ProductID") & "' target='_blank'>" & rsCartItem("ProductName") & "</a>"
        Response.Write "</td>"
        Response.Write "    <td width='45' align=center>" & rsCartItem("Unit") & "</td>"
        Response.Write "    <td width='55' align='center'>" & dblAmount & "</td>"
        Response.Write "    <td width='85' align='right'>" & FormatNumber(dblPrice, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "    <td width='85' align='right'>" & FormatNumber(dblTruePrice, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "    <td width='85' align='right'>" & FormatNumber(dblSubtotal, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Response.Write "    <td width='65' align=center>"
        If rsCartItem("ServiceTerm") > 0 Then
            If DateAdd("yyyy", rsCartItem("ServiceTerm"), rsCartItem("BeginDate")) <= Now() Then
                Response.Write "<font color='red'>"
            End If
        End If
        Response.Write GetServiceTerm(rsCartItem("ServiceTerm"))
        Response.Write "</td>"
        Response.Write "  </tr>"

        If rsCartItem("SalePromotionType") > 0 And dblAmount >= rsCartItem("MinNumber") Then
            Dim PresentNumber
            If rsCartItem("SalePromotionType") = 3 Or rsCartItem("SalePromotionType") = 4 Then
                PresentNumber = rsCartItem("PresentNumber")
            Else
                PresentNumber = Int(dblAmount / rsCartItem("MinNumber")) * rsCartItem("PresentNumber")
            End If
            If rsCartItem("SalePromotionType") = 1 Or rsCartItem("SalePromotionType") = 3 Then
                If FoundInArr(PresentList, rsCartItem("ProductID"), ",") = True Then
                    Response.Write "  <tr valign='middle' class='tdbg' height='20'>"
                    Response.Write "    <td width='*'><a href='Admin_Product.asp?Action=Show&ChannelID=1000&ProductID=" & rsCartItem("ProductID") & "' target='_blank'>" & rsCartItem("ProductName") & " <font color='red'>（赠送）</font></a>"
                    Response.Write "</td>"
                    Response.Write "    <td width='45' align=center>" & rsCartItem("Unit") & "</td>"
                    Response.Write "    <td width='55' align='center'>" & PresentNumber & "</td>"
                    Response.Write "    <td width='85' align='right'>" & FormatNumber(dblPrice, 2, vbTrue, vbFalse, vbTrue) & "</td>"
                    Response.Write "    <td width='85' align='right'>0</td>"
                    Response.Write "    <td width='85' align='right'>0</td>"
                    Response.Write "    <td width='65' align=center>"
                    If rsCartItem("ServiceTerm") > 0 Then
                        If DateAdd("yyyy", rsCartItem("ServiceTerm"), rsCartItem("BeginDate")) <= Now() Then
                            Response.Write "<font color='red'>"
                        End If
                    End If
                    Response.Write GetServiceTerm(rsCartItem("ServiceTerm"))
                    Response.Write "</td>"
                    Response.Write "  </tr>"
                End If
            Else
                Dim rsPresent, strPresentType
                Set rsPresent = Conn.Execute("select * from PE_Product where ProductNum='" & rsCartItem("PresentID") & "' and ProductType=4")
                If Not (rsPresent.BOF And rsPresent.EOF) Then
                    If FoundInArr(PresentList, rsPresent("ProductID"), ",") = True Then
                        If rsPresent("Price") > 0 Then
                            strPresentType = "换购"
                        Else
                            strPresentType = "赠送"
                        End If
                        Response.Write "  <tr valign='middle' class='tdbg' height='20'>"
                        Response.Write "    <td width='*'><a href='Admin_Product.asp?Action=Show&ChannelID=1000&ProductID=" & rsPresent("ProductID") & "' target='_blank'>" & rsPresent("ProductName") & " <font color='red'>（" & strPresentType & "）</a>"
                        Response.Write "</td>"
                        Response.Write "    <td width='45' align=center>" & rsPresent("Unit") & "</td>"
                        Response.Write "    <td width='55' align='center'>" & PresentNumber & "</td>"
                        Response.Write "    <td width='85' align='right'>" & FormatNumber(rsPresent("Price_Original"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
                        Response.Write "    <td width='85' align='right'>" & FormatNumber(rsPresent("Price"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
                        Response.Write "    <td width='85' align='right'>" & FormatNumber(rsPresent("Price") * PresentNumber, 2, vbTrue, vbFalse, vbTrue) & "</td>"
                        Response.Write "    <td width='65' align=center>"
                        If rsPresent("ServiceTerm") > 0 Then
                            If DateAdd("yyyy", rsCartItem("ServiceTerm"), rsPresent("BeginDate")) <= Now() Then
                                Response.Write "<font color='red'>"
                            End If
                        End If
                        Response.Write GetServiceTerm(rsPresent("ServiceTerm"))
                        Response.Write "</td>"
                        Response.Write "  </tr>"
                        dblTotal = dblTotal + rsPresent("Price") * PresentNumber
                    End If
                End If
                Set rsPresent = Nothing
            End If
        End If

        rsCartItem.MoveNext
    Loop
    rsCartItem.Close
    Set rsCartItem = Nothing

    Response.Write "  <tr class='tdbg' height='30' >"
    Response.Write "    <td colspan='5' align='right'><b>合计：</b></td>"
    Response.Write "    <td align='right'><b>￥" & FormatNumber(dblTotal, 2, vbTrue, vbFalse, vbTrue) & "</b></td>"
    Response.Write "    <td> </td>"
    Response.Write "  </tr>"
    Response.Write "</table>"
    Response.Write "    </td>"
    Response.Write " </table>"

    
End Sub

Sub Clear()
    Dim DatepartType, TempDate, strDatepart
    DatepartType = PE_CLng(Trim(Request("DatepartType")))
    Select Case DatepartType
    Case 0
        TempDate = DateAdd("D", -1, Date)
        strDatepart = "1天前"
    Case 1
        TempDate = DateAdd("D", -7, Date)
        strDatepart = "1个星期前"
    Case 2
        TempDate = DateAdd("M", -1, Date)
        strDatepart = "1个月前"
    Case 3
        TempDate = DateAdd("M", -3, Date)
        strDatepart = "3个月前"
    End Select
    If SystemDatabaseType = "SQL" Then
        Conn.Execute ("delete from PE_ShoppingCarts where UpdateTime<'" & TempDate & "'")
    Else
        Conn.Execute ("delete from PE_ShoppingCarts where UpdateTime<#" & TempDate & "#")
    End If
    Call WriteSuccessMsg("成功删除了 " & strDatepart & " 的记录！", "Admin_ShoppingCart.asp")

End Sub

Function SelectCart(CartID, IsPresent)
    Dim rsCartItem, ProductList
    ProductList = ""
    If IsPresent = 1 Then
        Set rsCartItem = Conn.Execute("select ProductID from PE_ShoppingCarts where CartID='" & CartID & "' and PresentID=1 order by CartItemID desc")
    Else
        Set rsCartItem = Conn.Execute("select ProductID from PE_ShoppingCarts where CartID='" & CartID & "' and PresentID=0 order by CartItemID desc")
    End If
    Do While Not rsCartItem.EOF
        If ProductList = "" Then
            ProductList = rsCartItem("ProductID")
        Else
            ProductList = ProductList & "," & rsCartItem("ProductID")
        End If
        rsCartItem.MoveNext
    Loop
    SelectCart = ProductList
    Set rsCartItem = Nothing
End Function

Function GetServiceTerm(ServiceTerm)
    Dim strServiceTerm
    Select Case ServiceTerm
    Case -1
        strServiceTerm = "无限期"
    Case 0
        strServiceTerm = "无"
    Case 1
        strServiceTerm = "一年"
    Case 2
        strServiceTerm = "两年"
    Case 3
        strServiceTerm = "三年"
    Case 4
        strServiceTerm = "四年"
    Case 5
        strServiceTerm = "五年"
    Case Else
        strServiceTerm = "未知"
    End Select
    GetServiceTerm = strServiceTerm
End Function


Sub SendCartMail()
    Dim PE_Mail, CartID,strLink,rsProductList
    Dim rsCartItem, dblAmount, dblTruePrice, dblTotal, dblPrice, dblSubtotal, dblTempPrice,PresentList,Discount_Member
    Set PE_Mail = New SendMail
    Dim rsMail, Content, Username, umail, MailcartID
    Content = ""
    Username = ReplaceBadChar(Request("UserName"))
    CartID = Request("CartID")
    Dim ContacterName, Phone, Address, ZipCode, Email, Mobile, sqlUser, rsUSer
    If Username = "" Then
        UserSetting = Split("0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", ",")
    Else
        sqlUser = "SELECT U.ContacterID,U.SpecialPermission,U.UserSetting,G.GroupType,G.GroupSetting FROM PE_User U inner join PE_UserGroup G on U.GroupID=G.GroupID WHERE UserName='" & Username & "'"
        Set rsUSer = Conn.execute(sqlUser)
        If rsUSer.BOF And rsUSer.EOF Then
            UserSetting = Split("0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", ",")
        Else
            GroupType = rsUSer("GroupType")
            If rsUSer("SpecialPermission") = True Then
                UserSetting = Split(rsUSer("UserSetting"), ",")
            Else
                UserSetting = Split(rsUSer("GroupSetting"), ",")
            End If
        End If
        rsUSer.Close
        Set rsUSer = Nothing
    End If
	Content=Content &"尊敬的客户" & Username & ",您在<a href='"&SiteUrl&"'>"&SiteName&"</a>的购物尚未提交订单,你可以<a href='"&SiteUrl&"/user/user_login.asp'>登录</a>继续您的购物,你的购物车清单如下<br>"
    Content=Content & "<table width='100%'  style='font-size: 9pt;background-position:center;text-decoration: none;scrollbar-face-color: #f6f6f6;scrollbar-highlight-color: #ffffff; scrollbar-shadow-color: #cccccc; scrollbar-3dlight-color: #cccccc; scrollbar-arrow-color: #330000; scrollbar-track-color: #f6f6f6; scrollbar-darkshadow-color: #ffffff;' border='0' align='center' cellpadding='2' cellspacing='1'>"
    Content=Content & "  <tr align='center' style='background:#e0eef5;line-height: 120%;' height='25'>"
    Content=Content & "    <td><b>商 品 名 称</b></td>"
    Content=Content & "    <td width='45'><b>单位</b></td>"
    Content=Content & "    <td width='55'><b>数量</b></td>"
    Content=Content & "    <td width='85'><b>原价</b></td>"
    Content=Content & "    <td width='85'><b>实价</b></td>"
    Content=Content & "    <td width='85'><b>金 额</b></td>"
    Content=Content & "    <td width='65'><b>服务期限</b></td>"
	Discount_Member = PE_CDbl(UserSetting(11))
    PresentList = SelectCart(CartID, 1)

    Set rsCartItem = Conn.execute("select P.*,C.Quantity,C.CartItemID from PE_Product P inner join PE_ShoppingCarts C on C.ProductID=P.ProductID where C.CartID='" & CartID & "' and C.PresentID=0 and P.ProductType<>4 order by C.CartItemID desc")
    Do While Not rsCartItem.EOF
        dblAmount = rsCartItem("Quantity")
        dblPrice = rsCartItem("Price_Original")

        If PE_CLng(UserSetting(30)) = 1 And rsCartItem("EnableWholesale") = True And dblAmount >= rsCartItem("Number_Wholesale1") Then
            strSaleType = "批发"
            If dblAmount < rsCartItem("Number_Wholesale2") Then
                dblTruePrice = rsCartItem("Price_Wholesale1")
            Else
                If dblAmount < rsCartItem("Number_Wholesale3") Then
                    dblTruePrice = rsCartItem("Price_Wholesale2")
                Else
                    dblTruePrice = rsCartItem("Price_Wholesale3")
                End If
            End If
        Else
            Select Case GroupType
            Case 0, 1 '未登录
                Select Case rsCartItem("ProductType")
                Case 1
                    dblTruePrice = rsCartItem("Price")
                    'strProductType = "正常销售"
                    'strDiscount = "─"
                Case 2
                    'strProductType = "涨价商品"
                    dblTruePrice = rsCartItem("Price")
                    'strDiscount = "─"
                Case 3
                    If Date < rsCartItem("BeginDate") Or Date > rsCartItem("EndDate") Then
                        dblTruePrice = dblPrice
                        'strProductType = "正常销售"
                        'strDiscount = "─"
                    Else
                        dblTruePrice = rsCartItem("Price")
                        'strProductType = "特价商品"
                        'strDiscount = rsCartItem("Discount") & "折"
                    End If
                Case 5
                    'strProductType = "降价商品"
                    dblTruePrice = rsCartItem("Price")
                    'strDiscount = rsCartItem("Discount") & "折"
                End Select
            Case 2, 3   '注册会员
                Select Case rsCartItem("ProductType")
                Case 1
                    If rsCartItem("Price_Member") > 0 Then '如果指定了会员价
                        dblTruePrice = rsCartItem("Price_Member")
                    Else
                        dblTruePrice = rsCartItem("Price") * Discount_Member / 100
                    End If
                Case 2
                    If rsCartItem("Price_Member") > 0 Then '如果指定了会员价
                        dblTruePrice = rsCartItem("Price_Member")
                    Else
                        dblTruePrice = rsCartItem("Price") * Discount_Member / 100
                    End If
                Case 3, 5
                    If rsCartItem("ProductType") = 3 Then
                        If Date < rsCartItem("BeginDate") Or Date > rsCartItem("EndDate") Then
                            dblTempPrice = dblPrice
                        Else
                            dblTempPrice = rsCartItem("Price")
                        End If
                    Else
                        dblTempPrice = rsCartItem("Price")
                    End If
                    If rsCartItem("Price_Member") > 0 Then '如果指定了会员价
                        If rsCartItem("Price_Member") <= dblTempPrice Then
                            dblTruePrice = rsCartItem("Price_Member")
                        Else
                            dblTruePrice = dblTempPrice
                        End If
                    Else
                        If PE_CLng(UserSetting(12)) = 1 Then '如可以享受折上折优惠
                            dblTruePrice = dblTempPrice * Discount_Member / 100
                        Else
                            If dblPrice * Discount_Member / 100 >= dblTempPrice Then
                                dblTruePrice = dblTempPrice
                            Else
                                dblTruePrice = dblPrice * Discount_Member / 100
                            End If
                        End If
                    End If
                Case Else
                    dblTruePrice = rsCart("Price")
                End Select
            Case 4  '代理商
                dblTempPrice = rsCartItem("Price")
                If rsCartItem("Price_Agent") > 0 Then '如果指定了代理价
                    dblTruePrice = rsCartItem("Price_Agent")
                Else
                    If Discount_Member = 100 Then
                        dblTruePrice = dblTempPrice
                    Else
                        If PE_CLng(UserSetting(12)) = 1 Then '如可以享受折上折优惠
                            dblTruePrice = dblTempPrice * Discount_Member / 100
                        Else
                            If rsCartItem("Price_Original") * Discount_Member / 100 >= dblTempPrice Then
                                dblTruePrice = rsCartItem("Price_Original") * Discount_Member / 100
                                'strDiscount = Round(Discount_Member / 10, 1) & "折"
                            Else
                                dblTruePrice = dblTempPrice
                            End If
                        End If
                    End If
                End If
            End Select
        End If
        dblSubtotal = dblTruePrice * dblAmount
        dblTotal = dblTotal + dblSubtotal
        Content=Content & "  <tr valign='middle' class='tdbg' height='20'>"
        Content=Content & "    <td width='*'><a href=" & SiteUrl & "/" & GetInfoUrl(rsCartItem("ProductID"), "Product", 1) & ">" & rsCartItem("ProductName") & "</a>"
        Content=Content & "</td>"
        Content=Content & "    <td width='45' align=center>" & rsCartItem("Unit") & "</td>"
        Content=Content & "    <td width='55' align='center'>" & dblAmount & "</td>"
        Content=Content & "    <td width='85' align='right'>" & FormatNumber(dblPrice, 2, vbTrue, vbFalse, vbTrue) &  "</td>"
        Content=Content & "    <td width='85' align='right'>" & FormatNumber(dblTruePrice, 2, vbTrue, vbFalse, vbTrue) &  "</td>"
        Content=Content & "    <td width='85' align='right'>" & FormatNumber(dblSubtotal, 2, vbTrue, vbFalse, vbTrue) & "</td>"
        Content=Content & "    <td width='65' align=center>"
        If rsCartItem("ServiceTerm") > 0 Then
            If DateAdd("yyyy", rsCartItem("ServiceTerm"), rsCartItem("BeginDate")) <= Now() Then
                Content=Content & "<font color='red'>"
            End If
        End If
        Content=Content & GetServiceTerm(rsCartItem("ServiceTerm"))
        Content=Content & "</td>"
        Content=Content & "  </tr>"

        If rsCartItem("SalePromotionType") > 0 And dblAmount >= rsCartItem("MinNumber") Then
            Dim PresentNumber
            If rsCartItem("SalePromotionType") = 3 Or rsCartItem("SalePromotionType") = 4 Then
                PresentNumber = rsCartItem("PresentNumber")
            Else
                PresentNumber = Int(dblAmount / rsCartItem("MinNumber")) * rsCartItem("PresentNumber")
            End If
            If rsCartItem("SalePromotionType") = 1 Or rsCartItem("SalePromotionType") = 3 Then
                If FoundInArr(PresentList, rsCartItem("ProductID"), ",") = True Then
                    Content=Content & "  <tr valign='middle' class='tdbg' height='20'>"
                    Content=Content & "    <td width='*'>" & rsCartItem("ProductName") & " <font color='red'>（赠送）</font>"
                    Content=Content & "</td>"
                    Content=Content &"    <td width='45' align=center>" & rsCartItem("Unit") & "</td>"
                    Content=Content & "    <td width='55' align='center'>" & PresentNumber & "</td>"
                    Content=Content & "    <td width='85' align='right'>" & FormatNumber(dblPrice, 2, vbTrue, vbFalse, vbTrue) & "</td>"
                    Content=Content &"    <td width='85' align='right'>0</td>"
                    Content=Content &"    <td width='85' align='right'>0</td>"
                    Content=Content & "    <td width='65' align=center>"
                    If rsCartItem("ServiceTerm") > 0 Then
                        If DateAdd("yyyy", rsCartItem("ServiceTerm"), rsCartItem("BeginDate")) <= Now() Then
                            Content=Content & "<font color='red'>"
                        End If
                    End If
                    Content=Content & GetServiceTerm(rsCartItem("ServiceTerm"))
                    Content=Content & "</td>"
                    Content=Content & "  </tr>"
                End If
            Else
                Dim rsPresent, strPresentType
                Set rsPresent = Conn.execute("select * from PE_Product where ProductNum='" & rsCartItem("PresentID") & "' and ProductType=4")
                If Not (rsPresent.BOF And rsPresent.EOF) Then
                    If FoundInArr(PresentList, rsPresent("ProductID"), ",") = True Then
                        If rsPresent("Price") > 0 Then
                            strPresentType = "换购"
                        Else
                            strPresentType = "赠送"
                        End If
                        Content=Content & "  <tr valign='middle' class='tdbg' height='20'>"
                        Content=Content & "    <td width='*'><a href='"&strLink&"' target='_blank'>" & rsPresent("ProductName") & " <font color='red'>（" & strPresentType & "）</a>"
                        Content=Content & "</td>"
                        Content=Content & "    <td width='45' align=center>" & rsPresent("Unit") & "</td>"
                        Content=Content & "    <td width='55' align='center'>" & PresentNumber & "</td>"
                        Content=Content & "    <td width='85' align='right'>" & FormatNumber(rsPresent("Price_Original"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
                       Content=Content & "    <td width='85' align='right'>" & FormatNumber(rsPresent("Price"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
                        Content=Content & "    <td width='85' align='right'>" & FormatNumber(rsPresent("Price") * PresentNumber, 2, vbTrue, vbFalse, vbTrue) & "</td>"
                        Content=Content & "    <td width='65' align=center>"
                        If rsPresent("ServiceTerm") > 0 Then
                            If DateAdd("yyyy", rsCartItem("ServiceTerm"), rsPresent("BeginDate")) <= Now() Then
                                Content=Content & "<font color='red'>"
                            End If
                        End If
                        Content=Content & GetServiceTerm(rsPresent("ServiceTerm"))
                        Content=Content & "</td>"
                        Content=Content & "  </tr>"
                        dblTotal = dblTotal + rsPresent("Price") * PresentNumber
                    End If
                End If
                Set rsPresent = Nothing
            End If
        End If
        rsCartItem.MoveNext
    Loop
    rsCartItem.Close
    Set rsCartItem = Nothing
    Content=Content & "  <tr class='tdbg' height='30' >"
    Content=Content & "    <td colspan='5' align='right'><b>合计：</b></td>"
    Content=Content & "    <td align='right'><b>￥" & FormatNumber(dblTotal, 2, vbTrue, vbFalse, vbTrue) & "</b></td>"
    Content=Content & "    <td> </td>"
    Content=Content & "  </tr>"
    Content=Content & "</table>"
    Content=Content & "    </td>"
    Content=Content &" </table>"
    Set rsMail=Conn.execute("select * from PE_User where UserName='"&UserName&"'")
    umail = Trim(rsMail("Email"))
    If IsValidEmail(Trim(rsMail("Email"))) = True Then
          ErrMsg = PE_Mail.Send(umail, Username, "您尚未完成的购物", " " & Content & " ", SiteName, WebmasterEmail, 3)
        If ErrMsg = "" Then
            Response.Write "<li>成功向用户" & rsMail("UserName") & "（" & umail & "）发送邮件！</li>"
			Response.Write ">><a href='Admin_ShoppingCart.asp'>返回购物车管理</a>"
        End If
    End If
End Sub
%>

