<%@ Page Language="C#" AutoEventWireup="true" Inherits="User_PayOnline_WX_checkstatus" Codebehind="checkstatus.aspx.cs" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
<script runat="server">
    string orderId = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        string flag = KSCMS.S("ordertype");
        orderId = Utils.ChkSQL(KSCMS.S("orderId"));
        if (string.IsNullOrEmpty(orderId)) KSCMS.Die("");
        if (flag == "1")
        {
            CheckcourseOrder(); //课程支付成功
        }
        else if(flag=="10")
        {
            CheckCollageOrder(); //拼团支付成功
        }
        else if (flag == "3")
        {
            CheckShopOrder(); //单个支付订单
        }
        else if (flag == "2") //套餐包
        {
            FeePackages();
        }else if (flag == "5")
        {
            CheckFormPay(); //自定义表单支付
        }
        else  if (flag == "12")
        {
            CheckCosPakeagesOrder(); //课程包支付
        }
        else if (flag == "100")
        {
            CheckModelOrder();//内容模型
        }
        else {  //在线充值
            YFKCZ();
        }
        KSCMS.Die("");
    }
    private void CheckcourseOrder()
    {
        #region 课程订单
        using (DataTable dt = DataFactory.GetDataTable("select top 1 id from ks_CosOrder where status=1 and  courseorder='" + orderId + "'"))
        {
            if (dt.Rows.Count > 0)
            {
                KSCMS.Die("success|" + BaseFun.GetRewriteUrl("user", "a-course/f-learnstudy"));

            }
        }
        #endregion
    }
    private void CheckCollageOrder()
    {
        #region 拼团订单
        using (DataTable dt = DataFactory.GetDataTable("SELECT top 1 ID  FROM KS_CosCollageDetail WHERE Status=1 AND PayOrder='" + orderId + "'"))
        {
            if (dt.Rows.Count > 0)
            {

                KSCMS.Die("success|" + BaseFun.GetRewriteUrl("user", "a-course/f-mycoursecollage"));
                //KSCMS.Die("success|" + BaseFun.GetRewriteUrl("user", "a-course/f-learnstudy"));

            }
        }
        #endregion
    }
    private void CheckCosPakeagesOrder()
    {
        #region 课程包
        using (DataTable dt = DataFactory.GetDataTable("SELECT TOP 1 id FROM KS_EnterPriseCosPackagesSell WHERE PayStatus=1 AND orderId='" + orderId + "'"))
        {
            if (dt.Rows.Count > 0)
            {
                KSCMS.Die("success|" + BaseFun.GetRewriteUrl("user"));

            }
        }
        #endregion
    }
    private void CheckFormPay()
    {
        #region 自定义表单
        using(DataTable dt=DataFactory.GetDataTable("select top 1 * From KS_LogMoney Where OrderID='" + orderId + "'"))
        {
            if (dt.Rows.Count > 0)
            {
                KSCMS.Die("success|/user/index.aspx?mainurl=form.aspx?formid="+orderId.Split(',')[1]);

            }
        }
        #endregion
    }
    /// <summary>
    /// 内容模型支付订单
    /// </summary>
    private void CheckModelOrder()
    {
        using(DataTable dt=DataFactory.GetDataTable("select top 1 a.*,b.classid From KS_LogMoney a Inner Join KS_InfoList b on a.infoid=b.infoid Where a.OrderID='" + orderId + "'"))
        {
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                int channelId = Utils.StrToInt(dr["channelid"].ToString());
                int classId = Utils.StrToInt(dr["classId"].ToString());
                int infoId = Utils.StrToInt(dr["infoid"].ToString());

                KSCMS.Die("success|"+Kesion.HtmlTags.BasicField.GetItemUrl(channelId,infoId,classId));

            }
        }
    }
    /// <summary>
    /// 商城订单
    /// </summary>
    private void CheckShopOrder()
    {
        #region 商城订单
        using (DataTable dt = DataFactoryUser.GetDataTable("Select top 1 id From KS_ProOrder Where MoneyReceipt>0 and payOrderID='" + orderId + "'"))
        {
            if (dt.Rows.Count > 0)
            {

                KSCMS.Die("success|" + BaseFun.GetRewriteUrl("user", "a-Shop/f-ShowMyOrder/id-" + dt.Rows[0][0].ToString()));
            }
        }
        #endregion

    }
    /// <summary>
    /// 合并支付订单
    /// </summary>
    private void ShopMergerOrder()
    {
        #region 合并支付订单
        using (DataTable dt = DataFactoryUser.GetDataTable("Select top 1 id From KS_ProOrder Where MoneyReceipt>0 and payorderid='" + orderId + "'"))
        {
            if (dt.Rows.Count >0)
            {
                KSCMS.Die("success|" + BaseFun.GetRewriteUrl("user", "a-Shop/f-myorder"));

            }
        }
        #endregion

    }
    /// <summary>
    /// 预付款充值
    /// </summary>
    private void YFKCZ()
    {
        #region 预付款充值
        using (DataTable dt = DataFactoryUser.GetDataTable("Select top 1 * From KS_RechargeRecords Where status>0 and OrderID='" + orderId + "'"))
        {
            if (dt.Rows.Count >0)
            {

                if (KSCMS.S("ordertype") == "6")
                {
                    KSCMS.Die("success|/Seller/Index.aspx");
                }
                else
                {
                    KSCMS.Die("success|" + BaseFun.GetRewriteUrl("user")+"#/user/account");
                }
            }
        }
        #endregion
    }

    private void FeePackages()
    {
        #region 套餐包
        using(DataTable dt=DataFactory.GetDataTable("select top 1 * From KS_LogMoney Where OrderID='" + orderId + "'"))
        {
            if (dt.Rows.Count > 0)
            {
                KSCMS.Die("success|" + BaseFun.GetRewriteUrl("user", "a-basic/f-MyFeePackages"));
            }
        }
        #endregion
    }


</script>