예제 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //this.lblMsg.InnerText = Request["msg"];
        LogManager.LogFielPrefix = "jsnx";
        LogManager.LogPath       = "C:/requestpag/";
        LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "进入回调页面");
        SortedDictionary <string, string> sPara = GetRequestPost();

        try
        {
            if (sPara == null || sPara.Count <= 0)
            {
                Response.Write("无通知参数");
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:无通知参数");
                return;
            }
            Notify aliNotify    = new Notify();
            bool   verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);
            if (!verifyResult)//验证失败
            {
                Response.Write("fail");
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:验证失败");
                return;
            }

            //企业订单号
            string out_trade_no = Common.NoHTML(Request.Form["out_trade_no"]);

            //支付宝交易号
            string trade_no = Common.NoHTML(Request.Form["trade_no"]);

            //交易状态
            string trade_status = Common.NoHTML(Request.Form["trade_status"]);

            decimal prepayPrice = 0;
            string  guid        = "";
            int     orderid     = 0;
            Hi.Model.PAY_RegisterLog        regM = new Hi.Model.PAY_RegisterLog();
            List <Hi.Model.PAY_RegisterLog> regL = new Hi.BLL.PAY_RegisterLog().GetList("", " Ordercode = '" + out_trade_no + "'", "");
            if (regL == null || regL.Count <= 0)
            {
                Response.Write("找不到" + out_trade_no);
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:找不到" + out_trade_no);
                return;
            }
            regM = regL[0];
            try
            {
                regM.Start         = trade_status;
                regM.ResultMessage = trade_no;
                new Hi.BLL.PAY_RegisterLog().Update(regM);
            }
            catch { }
            guid    = regM.number;
            orderid = regM.OrderId;
            Hi.Model.DIS_Order          orderModel = new Hi.BLL.DIS_Order().GetModel(orderid);
            Hi.Model.PAY_Payment        payM       = new Hi.Model.PAY_Payment();
            List <Hi.Model.PAY_Payment> payL       = new Hi.BLL.PAY_Payment().GetList("", " guid = '" + guid + "' ", "");
            if (payL == null || payL.Count <= 0)
            {
                Response.Write("找不到" + out_trade_no);
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:找不到" + out_trade_no);
                return;
            }
            payM = payL[0];
            if (payM.IsAudit == 1)
            {
                Response.Write("success");//请不要修改或删除,输出success后,支付宝将不再发送通知
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\n支付成功\r\n支付订单号:" + out_trade_no);
                return;
            }
            if (trade_status != "TRADE_SUCCESS")
            {
                Response.Write(GetTradeStatusByName(trade_status));
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:" + GetTradeStatusByName(trade_status) + "\r\n支付订单号:" + out_trade_no);
                return;
            }
            Hi.Model.PAY_PrePayment        prepayM = new Hi.Model.PAY_PrePayment();
            List <Hi.Model.PAY_PrePayment> prepayL = new Hi.BLL.PAY_PrePayment().GetList("", " vdef4 = '" + payM.ID + "' ", "");
            if (prepayL != null && prepayL.Count > 0)
            {
                prepayM     = prepayL[0];
                prepayPrice = prepayM.price * -1;
            }

            int           order  = 0;
            int           prepay = 0;
            int           pay    = 0;
            SqlConnection con    = new SqlConnection(LocalSqlServer);
            con.Open();
            SqlTransaction sqlTrans = con.BeginTransaction();
            try
            {
                order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderid, payM.PayPrice + prepayPrice, sqlTrans);
                pay   = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);
                if (prepayPrice > 0)
                {
                    prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                }
                else
                {
                    prepay = 1;
                }
                sqlTrans.Commit();
            }
            catch (Exception ex)
            {
                Response.Write("Error");
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:" + ex.Message + "\r\n支付订单号:" + out_trade_no);
                order  = 0;
                prepay = 0;
                pay    = 0;
                sqlTrans.Rollback();
            }
            finally
            {
                con.Close();
            }
            if (order <= 0 || prepay <= 0 || pay <= 0)
            {
                Response.Write("Error");
                LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\nError:支付成功,修改状态失败,等待下次页面通知\r\n支付订单号:" + out_trade_no);
                return;
            }

            try
            {
                new Common().GetWxService("2", orderModel.ID.ToString(), "1");
                if (orderModel.Otype != 9)
                {
                    OrderInfoType.AddIntegral(orderModel.CompID, orderModel.DisID, "1", 1, orderModel.ID, (prepayPrice + payM.PayPrice), "订单支付", "", orderModel.CreateUserID);
                }
            }
            catch { }
            if (orderModel.Otype == (int)Enums.OType.推送账单)
            {
                Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "账单支付", "支付:" + (prepayPrice + payM.PayPrice).ToString("0.00") + "元(支付宝支付)", payM.CreateUserID.ToString());
            }
            else
            {
                Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "订单支付", "支付:" + (prepayPrice + payM.PayPrice).ToString("0.00") + "元(支付宝支付)", payM.CreateUserID.ToString());
            }

            Response.Write("success");  //请不要修改或删除,输出success后,支付宝将不再发送通知
            LogManager.WriteLog(LogFile.Trace.ToString(), "时间:" + DateTime.Now.ToString("yyyy-MMdd HH:mm:ss") + "\r\n" + "退出回调页面\r\n支付成功\r\n支付订单号:" + out_trade_no);
            return;
        }
        catch (Exception ex)
        {
            LogManager.LogFielPrefix = "requestpag";
            LogManager.LogPath       = "C:/requestpag/";
            LogManager.WriteLog(LogFile.Error.ToString(), "Error:" + ex.Message + "\r\n");
            Response.Write(ex.Message);
            return;
        }
        finally
        {
            Response.End();
        }
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //ResultNotify resultNotify = new ResultNotify(this);
        //resultNotify.ProcessNotify();
        string resultFromWx = getPostStr();
        //设置支付参数
        var res = XDocument.Parse(resultFromWx);

        string return_code = res.Element("xml").Element("return_code").Value;

        string out_trade_no = res.Element("xml").Element("out_trade_no").Value;

        string result_code = res.Element("xml").Element("result_code").Value;

        string price = res.Element("xml").Element("total_fee").Value;

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //请在这里加上商户的业务逻辑程序代码
        //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
        //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

        if (return_code == "SUCCESS" || result_code == "SUCCESS")
        {
            //判断该笔订单是否在商户网站中已经做过处理
            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
            //如果有做过处理,不执行商户的业务程序

            string strWhere2 = string.Empty;
            if (out_trade_no != "")
            {
                strWhere2 += " number = '" + out_trade_no + "'";
            }
            Hi.Model.PAY_RegisterLog        regM = new Hi.Model.PAY_RegisterLog();
            List <Hi.Model.PAY_RegisterLog> regL = new Hi.BLL.PAY_RegisterLog().GetList("", strWhere2, "");
            if (regL == null || regL.Count <= 0)
            {
                //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到对应的支付记录!", false);
                //return;
                Console.WriteLine("未找到对应的支付记录!");
            }
            regM = regL[0];
            string strWhere = string.Empty;
            if (out_trade_no != "")
            {
                strWhere += " guid = '" + out_trade_no + "'";
            }
            strWhere += " and isnull(dr,0)=0";
            Hi.Model.PAY_Payment        payM = new Hi.Model.PAY_Payment();
            List <Hi.Model.PAY_Payment> payL = new Hi.BLL.PAY_Payment().GetList("", strWhere, "");
            if (payL == null || payL.Count <= 0)
            {
                //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到对应的支付记录!", false);
                // return;
                Console.WriteLine("未找到对应的支付记录!");
            }
            payM = payL[0];

            payM.PayDate = DateTime.Now;
            payM.ts      = DateTime.Now;
            payM.status  = 0;      //trade_status == "TRADE_FINISHED" ? 80 : 90;
            new Hi.BLL.PAY_Payment().Update(payM);
            regM.Start = "";       // trade_status;
            new Hi.BLL.PAY_RegisterLog().Update(regM);
            if (payM.IsAudit == 2) //该支付记录未修改成功进入,修改成功就不进入,请不要重复操作
            {
                //!!!支付成功 !!!
                decimal prepayPrice = 0;

                //企业钱包充值
                Hi.Model.PAY_PrePayment prepayMnew = new Hi.Model.PAY_PrePayment();
                string strWhere3 = string.Empty;
                if (out_trade_no != "")
                {
                    strWhere3 += " ID = " + payM.OrderID;
                }
                strWhere3 += " and isnull(dr,0)=0";
                List <Hi.Model.PAY_PrePayment> plist = new Hi.BLL.PAY_PrePayment().GetList("", strWhere3, "");
                if (plist.Count > 0)
                {
                    prepayMnew = plist[0];
                }

                //订单
                Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(payM.OrderID);
                if (orderModel != null)
                {
                    string strWhere1 = string.Empty;
                    strWhere1 += " vdef4 = '" + payM.ID + "'";
                    strWhere1 += " and isnull(dr,0)=0";
                    Hi.Model.PAY_PrePayment        prepayM = new Hi.Model.PAY_PrePayment();
                    List <Hi.Model.PAY_PrePayment> prepayL = new Hi.BLL.PAY_PrePayment().GetList("", strWhere1, "");
                    if (prepayL != null && prepayL.Count > 0)
                    {
                        prepayM     = prepayL[0];
                        prepayPrice = prepayM.price * -1;
                    }

                    int           order  = 0;
                    int           prepay = 0;
                    int           pay    = 0;
                    decimal       prices = Convert.ToDecimal(price);
                    SqlConnection con    = new SqlConnection(LocalSqlServer);
                    con.Open();
                    SqlTransaction sqlTrans = con.BeginTransaction();
                    try
                    {
                        order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderModel.ID, payM.PayPrice + prepayPrice - Convert.ToDecimal(payM.vdef5), sqlTrans);
                        pay   = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);


                        if (prepayPrice > 0)
                        {
                            prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                        }
                        else
                        {
                            prepay = 1;
                        }
                        sqlTrans.Commit();
                    }
                    catch
                    {
                        order  = 0;
                        prepay = 0;
                        pay    = 0;
                        sqlTrans.Rollback();
                    }
                    finally
                    {
                        con.Close();
                    }

                    if (order <= 0 || prepay <= 0 || pay <= 0)
                    {
                        Console.WriteLine("支付成功,但修改支付状态失败,请联系系统管理员,勿重复操作!");
                    }

                    try
                    {
                        //new Common().GetWxService("2", orderModel.ID.ToString(), "1");
                        if (orderModel.Otype != 9)
                        {
                            OrderInfoType.AddIntegral(orderModel.CompID, orderModel.DisID, "1", 1, orderModel.ID, (prepayPrice + prices), "订单支付", "", orderModel.CreateUserID);
                        }
                    }
                    catch { }
                    if (orderModel.Otype == (int)Enums.OType.推送账单)
                    {
                        Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "账单支付", "支付:" + (prepayPrice + prices).ToString("0.00") + "元(微信支付" + prices.ToString("0.00") + (prepayM.ID > 0 ? "+企业钱包支付" + prepayPrice.ToString("0.00") : "") + "【含手续费" + Convert.ToDecimal(payM.vdef5).ToString("0.00") + "元】)", payM.CreateUserID.ToString());
                    }
                    else
                    {
                        Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "订单支付", "支付:" + (prepayPrice + prices).ToString("0.00") + "元(微信支付" + prices.ToString("0.00") + (prepayM.ID > 0 ? "+企业钱包支付" + prepayPrice.ToString("0.00") : "") + "【含手续费" + Convert.ToDecimal(payM.vdef5).ToString("0.00") + "元】)", payM.CreateUserID.ToString());
                    }

                    //微信和安卓消息推送
                    try
                    {
                        new Common().GetWxService("2", orderModel.ID.ToString(), "1", prepayPrice + prices);
                    }
                    catch { }


                    Response.Write("success");  //请不要修改或删除
                }//钱包充值
                else if (prepayMnew != null)
                {
                    int           prepay = 0;
                    int           pay    = 0;
                    SqlConnection con    = new SqlConnection(LocalSqlServer);
                    con.Open();
                    SqlTransaction sqlTrans = con.BeginTransaction();
                    try
                    {
                        pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);
                        prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayMnew.ID, sqlTrans);
                        sqlTrans.Commit();
                    }
                    catch
                    {
                        pay    = 0;
                        prepay = 0;
                        sqlTrans.Rollback();
                    }
                    finally
                    {
                        con.Close();
                    }
                }
                else
                {
                    //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到该支付订单!", false);
                    //return;

                    Console.WriteLine("未找到该支付记录!");
                }
            }
            else
            {
                Console.WriteLine("success");
            }


            Response.Write("success");
        }
        else//验证失败
        {
            Response.Write("fail");
        }
    }
예제 #3
0
    /// <summary>
    /// 订单支付
    /// </summary>
    /// <param name="orderid">订单ID</param>
    /// <param name="txtPayOrder">支付金额</param>
    /// <param name="price">企业钱包金额</param>
    /// <param name="yfk">预付款</param>
    /// <param name="payPas"></param>
    public Wxpay_Url PayOrder(int orderid, decimal txtPayOrder, decimal price, int yfk, string payPas)
    {
        //使用企业钱包

        OrderModel = new Hi.BLL.DIS_Order().GetModel(orderid);
        disModel   = new Hi.BLL.BD_Distributor().GetModel(OrderModel.DisID);



        #region  界面上显示
        this.lblOrderNO.InnerText = OrderModel.ReceiptNo.Trim().ToString();
        this.fee.InnerText        = this.CompName;//收款方
        // this.lblOrderNO.HRef = "../neworder/orderdetail.aspx?KeyID=" + Common.DesEncrypt(orderid.ToString(), Common.EncryptKey);
        #endregion 界面上显示


        #region 企业钱包支付 begin

        if (disModel == null)
        {
            ErrMessage("数据异常,代理商有误", orderid.ToString());
        }

        decimal sumPrice = new Hi.BLL.PAY_PrePayment().sums(disModel.ID, disModel.CompID); //剩余企业钱包
        int     disid    = OrderModel.DisID;                                               //代理商ID
        string  password = disModel.Paypwd;

        if (yfk == 1)
        {
            if (payPas == null || payPas.Trim().ToString() == "")
            {
                ErrMessage("企业钱包密码不能为空", orderid.ToString());
            }
            payPas = payPas.Trim().ToString();
            if (password == Util.md5("123456"))
            {
                ErrMessage("请先修改企业钱包支付密码", orderid.ToString());
            }
            else
            {
                if (payPas == "")
                {
                    ErrMessage("密码不能为空", orderid.ToString());
                }
            }
        }

        decimal payPrice = 0;//支付金额
        if (txtPayOrder == 0)
        {
            ErrMessage("支付金额不能为0", orderid.ToString());
        }
        if (yfk == 1 && txtPayOrder < price)
        {
            ErrMessage("使用企业钱包大于支付金额!", orderid.ToString());
        }
        if (yfk == 1)
        {
            payPrice = txtPayOrder - price;
        }
        else
        {
            payPrice = txtPayOrder;
        }


        if (txtPayOrder > OrderModel.AuditAmount + OrderModel.OtherAmount - OrderModel.PayedAmount)
        {
            ErrMessage("支付金额大于未支付金额,不能支付!", orderid.ToString());
        }
        if (!((
                  (OrderModel.Otype == (int)Enums.OType.赊销订单 && (OrderModel.OState != (int)Enums.OrderState.退回 && OrderModel.OState != (int)Enums.OrderState.未提交 && OrderModel.OState != (int)Enums.OrderState.待审核) && (OrderModel.PayState == (int)Enums.PayState.未支付 || OrderModel.PayState == (int)Enums.PayState.部分支付)) ||
                  (OrderModel.Otype != (int)Enums.OType.赊销订单 && OrderModel.Otype != (int)Enums.OType.推送账单 && (OrderModel.OState == (int)Enums.OrderState.已审 || OrderModel.OState == (int)Enums.OrderState.已发货 || OrderModel.OState == (int)Enums.OrderState.已到货) && (OrderModel.PayState == (int)Enums.PayState.未支付 || OrderModel.PayState == (int)Enums.PayState.部分支付)) ||
                  (OrderModel.Otype == (int)Enums.OType.推送账单 && OrderModel.OState == (int)Enums.OrderState.已审 && (OrderModel.PayState == (int)Enums.PayState.部分支付 || OrderModel.PayState == (int)Enums.PayState.未支付))
                  ) &&
              OrderModel.OState != (int)Enums.OrderState.已作废))
        {
            if (OrderModel.Otype == (int)Enums.OType.推送账单)
            {
                ErrMessage("账单异常,不能支付", orderid.ToString());
            }
            else
            {
                ErrMessage("订单异常,不能支付", orderid.ToString());
            }
        }

        if (yfk == 1 && price > 0)
        {
            //企业钱包处理
            if (sumPrice < price)
            {
                ErrMessage("企业钱包余额不足", orderid.ToString());
            }
            if (disModel.Paypwd != Util.md5(payPas))
            {
                ErrMessage("支付密码不正确", orderid.ToString());
            }
            Hi.Model.PAY_PrePayment prepayModel = new Hi.Model.PAY_PrePayment();
            prepayModel.CompID     = disModel.CompID;
            prepayModel.DisID      = disModel.ID;
            prepayModel.OrderID    = OrderModel.ID;
            prepayModel.Start      = 2;
            prepayModel.PreType    = 5;
            prepayModel.price      = price * -1;
            prepayModel.Paytime    = DateTime.Now;
            prepayModel.CreatDate  = DateTime.Now;
            prepayModel.CrateUser  = this.UserID;
            prepayModel.AuditState = 2;
            prepayModel.IsEnabled  = 1;
            prepayModel.ts         = DateTime.Now;
            prepayModel.modifyuser = this.UserID;
            prepayModel.guid       = Common.Number_repeat(Guid.NewGuid().ToString().Replace("-", ""));
            // prepayModel.vdef1 = "订单支付";
            prepayid = new Hi.BLL.PAY_PrePayment().Add(prepayModel);
            int prepay = 0;
            int order  = 0;
            if (prepayid > 0 && payPrice == 0)//payPrice(网银支付金额)= 0 ,只用企业钱包支付,修改状态
            {
                SqlConnection con = new SqlConnection(LocalSqlServer);
                con.Open();
                SqlTransaction sqlTrans = con.BeginTransaction();
                try
                {
                    prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayid, sqlTrans);        //修改企业钱包状态
                    order  = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, OrderModel.ID, price, sqlTrans); //修改订单状态
                    if (prepay > 0 && order > 0)
                    {
                        sqlTrans.Commit();
                    }
                    else
                    {
                        sqlTrans.Rollback();
                    }
                }
                catch
                {
                    prepay = 0;
                    order  = 0;
                    sqlTrans.Rollback();
                }
                finally
                {
                    con.Close();
                }
                if (prepay > 0 && order > 0)
                {
                    try
                    {
                        if (OrderModel.Otype == (int)Enums.OType.推送账单)
                        {
                            Utils.AddSysBusinessLog(disModel.CompID, "Order", OrderModel.ID.ToString(), "账单支付", "支付:" + price.ToString("0.00") + "元(企业钱包支付)", this.UserID.ToString());
                        }
                        else
                        {
                            Utils.AddSysBusinessLog(disModel.CompID, "Order", OrderModel.ID.ToString(), "订单支付", "支付:" + price + "元(企业钱包支付)", this.UserID.ToString());
                        }
                        if (OrderModel.Otype != 9)
                        {
                            OrderInfoType.AddIntegral(this.CompID, this.DisID, "1", 1, OrderModel.ID, price, "订单支付", "", this.UserID);
                        }
                        new Common().GetWxService("2", OrderModel.ID.ToString(), "1", price);
                    }
                    catch (Exception ex)
                    {
                        ErrMessage("支付失败", orderid.ToString());
                    }

                    if (OrderModel.Otype == (int)Enums.OType.推送账单)
                    {
                        Response.Redirect("PaySuccess.aspx?type=" + Common.DesEncrypt("2", Common.EncryptKey) + "&KeyID=" + Common.DesEncrypt(OrderModel.ID.ToString(), Common.EncryptKey) + "&Pid=" + Common.DesEncrypt("0".ToString(), Common.EncryptKey) + "&PPid=" + Common.DesEncrypt(prepayid.ToString(), Common.EncryptKey) + "&IsRef=Y", false);
                    }
                    else
                    {
                        Response.Redirect("PaySuccess.aspx?type=" + Common.DesEncrypt("1", Common.EncryptKey) + "&KeyID=" + Common.DesEncrypt(OrderModel.ID.ToString(), Common.EncryptKey) + "&Pid=" + Common.DesEncrypt("0".ToString(), Common.EncryptKey) + "&PPid=" + Common.DesEncrypt(prepayid.ToString(), Common.EncryptKey) + "&IsRef=Y", false);
                    }
                }
            }
        }

        #endregion



        #region  插入支付表记录

        Hi.Model.PAY_Payment payModel = new Hi.Model.PAY_Payment();
        string orderNo = WebConfigurationManager.AppSettings["OrgCode"] + DateTime.Now.ToString("yyyyMMdd");//支付订单号前半部分

        string guid = Guid.NewGuid().ToString().Replace("-", "");
        payModel.OrderID      = OrderModel.ID; // orderid;
        payModel.DisID        = this.DisID;
        payModel.Type         = 0;             // isDBPay;
        payModel.PayUser      = disModel.DisName;
        payModel.PayPrice     = payPrice;
        payModel.IsAudit      = 2;
        payModel.guid         = Common.Number_repeat(guid);
        payModel.vdef3        = "1"; //1,订单支付,2,预付款充值、汇款
        payModel.vdef4        = orderNo;
        payModel.CreateDate   = DateTime.Now;
        payModel.CreateUserID = this.UserID;
        payModel.ts           = DateTime.Now;
        payModel.modifyuser   = this.UserID;
        payModel.PrintNum     = 1; //支付宝支付无需结算
        //判断账户类型,判断支付渠道
        payModel.Channel = "7";    //1,快捷支付,2,银联支付 ,3,网银支付,4,B2B网银支付,5,线下支付,6,支付宝支付 7,微信支付
        payModel.State   = 0;      //手续费收取方
        payModel.vdef5   = "0.00"; //支付手续费
        payid            = new Hi.BLL.PAY_Payment().Add(payModel);

        if (prepayid > 0)
        {
            Hi.Model.PAY_PrePayment prepayMent = new Hi.BLL.PAY_PrePayment().GetModel(prepayid);
            prepayMent.vdef4 = payid.ToString();//与企业钱包关联
            new Hi.BLL.PAY_PrePayment().Update(prepayMent);
        }

        Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
        regModel.OrderId    = OrderModel.ID;// orderid;
        regModel.Ordercode  = orderNo + payid.ToString();
        regModel.number     = payModel.guid;
        regModel.Price      = payPrice;
        regModel.Payuse     = "订单支付";
        regModel.PayName    = disModel.DisName;
        regModel.DisID      = OrderModel.DisID;
        regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
        regModel.Remark     = OrderModel.Remark;// orderModel.Remark;
        regModel.DisName    = new Hi.BLL.BD_Company().GetModel(disModel.CompID).CompName;
        regModel.BankID     = "支付宝支付";
        regModel.CreateUser = this.UserID;
        regModel.CreateDate = DateTime.Now;
        regModel.LogType    = 1311;
        int regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);
        if (payid <= 0 || regid <= 0)
        {
            Response.Redirect("Error.aspx?type=" + Common.DesEncrypt("3", Common.EncryptKey) + "&KeyID=" + Common.DesEncrypt(Convert.ToString(KeyID), Common.EncryptKey) + "&msg=" + Common.DesEncrypt("支付失败!", Common.EncryptKey), false);
        }

        //订单所有商品明细


        DataTable l = new Hi.BLL.DIS_OrderDetail().GetOrderDe("", " IsNUll(o.dr,0)=0 and o.OrderId=" + orderid);
        foreach (DataRow dr in l.Rows)
        {
            GoodsName += dr["GoodsName"] + ",";
        }
        GoodsName = GoodsName.Substring(0, GoodsName.Length - 1);//去掉最后一个逗号
        if (GoodsName.Length > 15)
        {
            GoodsName = GoodsName.Substring(0, 10) + "...";
        }



        #endregion


        int amount = Convert.ToInt32(payPrice * 100);//支付金额(单位:分)

        //隐藏域赋值
        this.hidguid.Value  = payModel.guid;
        this.hidprice.Value = payPrice.ToString();
        this.hidordid.Value = payModel.OrderID.ToString();
        this.hidpid.Value   = payid.ToString();
        this.hidppid.Value  = prepayid.ToString();

        // btnWxPay_Click(payModel.guid, orderid.ToString(), amount);

        Wxpay_Url wxpaymodel = new Wxpay_Url();
        wxpaymodel.Guid    = payModel.guid;
        wxpaymodel.OrderID = orderid.ToString();
        wxpaymodel.Amount  = amount;


        wxpaymodel.Hidguid  = payModel.guid;
        wxpaymodel.Hidprice = payModel.PayPrice.ToString();
        wxpaymodel.Hidordid = payModel.OrderID.ToString();
        wxpaymodel.Hidpid   = payid.ToString();
        wxpaymodel.Hidppid  = prepayid.ToString();

        return(wxpaymodel);
    }
예제 #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int orderid = 0;

        if (!IsPostBack)
        {
            try
            {
                // 1.取得参数
                if (Request.Form["hidOid"] == "")
                {
                    orderid = 0;
                }
                else
                {
                    orderid = Common.DesDecrypt(Request.Form["hidOid"], Common.EncryptKey).ToInt(0);
                    KeyID   = orderid;
                }
                if (!Common.PageDisOperable("Order", orderid, this.DisID))
                {
                    Response.Redirect("../../NoOperable.aspx", true);
                    return;
                }

                decimal txtPayOrder = Convert.ToDecimal(Request.Form["hidPayOrder"]); //本次支付总金额
                decimal price       = Convert.ToDecimal(Request.Form["hidPrice"]);    //使用企业钱包金额
                int     yfk         = Convert.ToInt32(Request.Form["hidIsPre"]);      //是否使用企业钱包  1:是  0:否
                int     isDBPay     = Convert.ToInt32(Request.Form["hidIsDBPay"]);    //是否是担保支付  1:是  0:否
                string  bankid      = Convert.ToString(Request.Form["hidBankNo"]);    //银行编号
                string  AccountType = Request.Form["hidAccountType"];                 //账户类型
                string  payPas      = Convert.ToString(Request.Form["hidPayPas"]);    //预付款密码

                Hi.Model.BD_Distributor disModel = new Hi.BLL.BD_Distributor().GetModel(this.DisID);

                Hi.Model.DIS_Order disOrderMOdel = new Hi.BLL.DIS_Order().GetModel(orderid);

                if (disModel == null)
                {
                    err = true;
                    ErrMessage("数据异常");
                    return;
                }

                decimal sumPrice = new Hi.BLL.PAY_PrePayment().sums(disModel.ID, disOrderMOdel.CompID); //剩余企业钱包
                int     disid    = this.DisID;                                                          //代理商ID
                string  password = disModel.Paypwd;

                if (yfk == 1)
                {
                    if (payPas == null || payPas.Trim().ToString() == "")
                    {
                        err = true;
                        ErrMessage("企业钱包密码不能为空");
                        return;
                    }
                    payPas = payPas.Trim().ToString();
                    if (password == Util.md5("123456"))
                    {
                        err = true;
                        ErrMessage("请先修改企业钱包支付密码");
                        return;
                    }
                    else
                    {
                        if (payPas == "")
                        {
                            //string Josn = "{\"error\":\"1\",\"msg\":\"密码不能为空!\"}";
                            err = true;
                            ErrMessage("密码不能为空");

                            return;
                        }
                    }
                }

                decimal payPrice = 0;
                if (txtPayOrder == 0)
                {
                    err = true;
                    ErrMessage("支付金额不能为0");

                    return;
                }
                if (yfk == 1 && txtPayOrder < price)
                {
                    err = true;
                    ErrMessage("使用企业钱包大于支付金额!");
                    return;
                }
                if (yfk == 1)
                {
                    payPrice = txtPayOrder - price;
                }
                else
                {
                    payPrice = txtPayOrder;
                }
                if (orderid <= 0)
                {
                    //string Josn = "{\"error\":\"1\",\"msg\":\"操作有误!\"}";
                    err = true;
                    ErrMessage("数据有误");

                    return;
                }
                Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(orderid);
                if (orderModel == null)
                {
                    err = true;
                    ErrMessage("数据有误");

                    return;
                }
                if (txtPayOrder > orderModel.AuditAmount + orderModel.OtherAmount - orderModel.PayedAmount)
                {
                    err = true;
                    ErrMessage("支付金额大于未支付金额,不能支付!");
                    return;
                }
                if (!((
                          (orderModel.Otype == (int)Enums.OType.赊销订单 && (orderModel.OState != (int)Enums.OrderState.退回 && orderModel.OState != (int)Enums.OrderState.未提交 && orderModel.OState != (int)Enums.OrderState.待审核) && (orderModel.PayState == (int)Enums.PayState.未支付 || orderModel.PayState == (int)Enums.PayState.部分支付)) ||
                          (orderModel.Otype != (int)Enums.OType.赊销订单 && orderModel.Otype != (int)Enums.OType.推送账单 && (orderModel.OState == (int)Enums.OrderState.已审 || orderModel.OState == (int)Enums.OrderState.已发货 || orderModel.OState == (int)Enums.OrderState.已到货) && (orderModel.PayState == (int)Enums.PayState.未支付 || orderModel.PayState == (int)Enums.PayState.部分支付)) ||
                          (orderModel.Otype == (int)Enums.OType.推送账单 && orderModel.OState == (int)Enums.OrderState.已审 && (orderModel.PayState == (int)Enums.PayState.部分支付 || orderModel.PayState == (int)Enums.PayState.未支付))
                          ) &&
                      orderModel.OState != (int)Enums.OrderState.已作废))
                {
                    if (orderModel.Otype == (int)Enums.OType.推送账单)
                    {
                        err = true;
                        ErrMessage("账单异常,不能支付");
                    }
                    else
                    {
                        err = true;
                        ErrMessage("订单异常,不能支付");
                    }
                    return;
                }

                int prepayid = 0;

                if (yfk == 1 && price > 0)
                {
                    //企业钱包处理
                    if (sumPrice < price)
                    {
                        err = true;
                        ErrMessage("企业钱包余额不足");

                        return;
                    }
                    if (disModel.Paypwd != Util.md5(payPas))
                    {
                        err = true;
                        ErrMessage("支付密码不正确");

                        return;
                    }
                    Hi.Model.PAY_PrePayment prepayModel = new Hi.Model.PAY_PrePayment();
                    prepayModel.CompID     = disOrderMOdel.CompID;
                    prepayModel.DisID      = disModel.ID;
                    prepayModel.OrderID    = orderid;
                    prepayModel.Start      = 2;
                    prepayModel.PreType    = 5;
                    prepayModel.price      = price * -1;
                    prepayModel.Paytime    = DateTime.Now;
                    prepayModel.CreatDate  = DateTime.Now;
                    prepayModel.CrateUser  = this.UserID;
                    prepayModel.AuditState = 2;
                    prepayModel.IsEnabled  = 1;
                    prepayModel.ts         = DateTime.Now;
                    prepayModel.modifyuser = this.UserID;
                    prepayModel.guid       = Common.Number_repeat(Guid.NewGuid().ToString().Replace("-", ""));
                    // prepayModel.vdef1 = "订单支付";
                    prepayid = new Hi.BLL.PAY_PrePayment().Add(prepayModel);
                    int prepay = 0;
                    int order  = 0;
                    if (prepayid > 0 && payPrice == 0)//payPrice(网银支付金额)= 0 ,只用企业钱包支付,修改状态
                    {
                        SqlConnection con = new SqlConnection(LocalSqlServer);
                        con.Open();
                        SqlTransaction sqlTrans = con.BeginTransaction();
                        try
                        {
                            prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayid, sqlTrans);  //修改企业钱包状态
                            order  = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderid, price, sqlTrans); //修改订单状态
                            if (prepay > 0 && order > 0)
                            {
                                sqlTrans.Commit();
                            }
                            else
                            {
                                sqlTrans.Rollback();
                            }
                        }
                        catch
                        {
                            prepay = 0;
                            order  = 0;
                            sqlTrans.Rollback();
                        }
                        finally
                        {
                            con.Close();
                        }
                        if (prepay > 0 && order > 0)
                        {
                            try
                            {
                                if (orderModel.Otype == (int)Enums.OType.推送账单)
                                {
                                    Utils.AddSysBusinessLog(disOrderMOdel.CompID, "Order", orderid.ToString(), "账单支付", "支付:" + price.ToString("0.00") + "元(企业钱包支付)", this.UserID.ToString());
                                }
                                else
                                {
                                    Utils.AddSysBusinessLog(disOrderMOdel.CompID, "Order", orderid.ToString(), "订单支付", "支付:" + price + "元(企业钱包支付)", this.UserID.ToString());
                                }
                                if (orderModel.Otype != 9)
                                {
                                    OrderInfoType.AddIntegral(disOrderMOdel.CompID, disOrderMOdel.DisID, "1", 1, orderid, price, "订单支付", "", this.UserID);
                                }
                                new Common().GetWxService("2", orderid.ToString(), "1", price);
                            }
                            catch (Exception ex) { throw ex; }

                            if (orderModel.Otype == (int)Enums.OType.推送账单)
                            {
                                err = true;//阻止进入网银支付
                                Response.Redirect("PaySuccess.aspx?type=" + Common.DesEncrypt("2", Common.EncryptKey) + "&KeyID=" + Common.DesEncrypt(orderid.ToString(), Common.EncryptKey) + "&Pid=" + Common.DesEncrypt("0".ToString(), Common.EncryptKey) + "&PPid=" + Common.DesEncrypt(prepayid.ToString(), Common.EncryptKey) + "&IsRef=Y", false);
                            }
                            else
                            {
                                err = true;//阻止进入网银支付
                                Response.Redirect("PaySuccess.aspx?type=" + Common.DesEncrypt("1", Common.EncryptKey) + "&KeyID=" + Common.DesEncrypt(orderid.ToString(), Common.EncryptKey) + "&Pid=" + Common.DesEncrypt("0".ToString(), Common.EncryptKey) + "&PPid=" + Common.DesEncrypt(prepayid.ToString(), Common.EncryptKey) + "&IsRef=Y", false);
                            }
                            return;
                        }
                        else
                        {
                            err = true;
                            ErrMessage("支付失败");
                            return;
                        }
                    }
                }

                if (payPrice <= 0)
                {
                    err = true;
                    ErrMessage("数据有误");
                    return;
                }


                #region     计算支付手续费 start
                string  sxfsq    = "-1";
                decimal sxf      = 0;
                decimal comp_sxf = 0;//收费方是厂商是,为了不改变支付金额,故声明此变量来记录,厂商手续费。
                // 获取手续费 begin
                string[] Json = Common.GetSxf(disOrderMOdel.CompID, AccountType, bankid, payPrice);

                string strMsg = Json[2].ToString();
                if (!string.IsNullOrEmpty(strMsg))
                {
                    ErrMessage(strMsg);
                    return;
                }
                else
                {
                    sxfsq    = Json[1].ToString();
                    sxf      = Convert.ToDecimal(Json[0]);
                    comp_sxf = Convert.ToDecimal(Json[3]);
                }
                // 获取手续费 end


                //支付总金额(含手续费)
                decimal UNIT = 0.01M;
                payPrice = payPrice + Common.Round(sxf, UNIT);

                #endregion  计算支付手续费 end


                int payid = 0;
                int regid = 0;
                Hi.Model.PAY_Payment payModel = new Hi.Model.PAY_Payment();
                string orderNo = WebConfigurationManager.AppSettings["OrgCode"] + DateTime.Now.ToString("yyyyMMdd");//支付订单号前半部分

                string guid = Guid.NewGuid().ToString().Replace("-", "");
                payModel.OrderID      = orderid;
                payModel.DisID        = this.DisID;
                payModel.Type         = isDBPay;
                payModel.PayUser      = disModel.DisName;
                payModel.PayPrice     = payPrice;
                payModel.IsAudit      = 2;
                payModel.guid         = Common.Number_repeat(guid);
                payModel.vdef3        = "1";
                payModel.vdef4        = orderNo;
                payModel.CreateDate   = DateTime.Now;
                payModel.CreateUserID = this.UserID;
                payModel.ts           = DateTime.Now;
                payModel.modifyuser   = this.UserID;
                //判断账户类型,判断支付渠道,然后赋值
                if (AccountType == "11")
                {
                    if (bankid == "888")
                    {
                        payModel.Channel = "2";
                    }
                    else
                    {
                        payModel.Channel = "3";
                    }
                }//信用卡支付
                else if (AccountType == "13")
                {
                    payModel.Channel = "8";
                }
                else//网银支付
                {
                    payModel.Channel = "4";
                }

                payModel.State = Convert.ToInt32(sxfsq);//手续费收取方

                if (sxfsq.Equals("2"))
                {
                    payModel.vdef5 = comp_sxf.ToString("0.00");
                }
                else
                {
                    payModel.vdef5 = sxf.ToString("0.00");//支付手续费
                }
                payid = new Hi.BLL.PAY_Payment().Add(payModel);
                if (prepayid > 0)
                {
                    Hi.Model.PAY_PrePayment prepayMent = new Hi.BLL.PAY_PrePayment().GetModel(prepayid);
                    prepayMent.vdef4 = payid.ToString();//与企业钱包关联
                    new Hi.BLL.PAY_PrePayment().Update(prepayMent);
                }

                Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
                regModel.OrderId    = orderid;
                regModel.Ordercode  = orderNo;// orderNo + payid.ToString();
                regModel.number     = payModel.guid;
                regModel.Price      = payPrice;
                regModel.Payuse     = "订单支付";
                regModel.PayName    = disModel.DisName;
                regModel.DisID      = disid;
                regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                regModel.Remark     = orderModel.Remark;
                regModel.DisName    = new Hi.BLL.BD_Company().GetModel(disOrderMOdel.CompID).CompName;
                regModel.BankID     = bankid;
                regModel.CreateUser = this.UserID;
                regModel.CreateDate = DateTime.Now;
                regModel.LogType    = 1311;
                regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);
                if (payid <= 0 || regid <= 0)
                {
                    err = true;
                    ErrMessage("数据有误");
                    return;
                }
                string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
                try
                {
                    PaymentEnvironment.Initialize(configPath);
                }
                catch (Exception ex)
                {
                    //string Josn = "{\"error\":\"1\",\"msg\":\"支付配置有误,请联系系统管理员!\"}";
                    err = true;
                    ErrMessage("支付配置有误,请联系系统管理员");

                    return;
                }

                String institutionID = WebConfigurationManager.AppSettings["PayOrgCode"]; //机构代码

                long   amount          = Convert.ToInt64(payPrice * 100);                 //支付金额(单位:分)
                long   fee             = 0;
                String usage           = "支付订单";
                String remark          = "订单支付";
                String notificationURL = "";
                //"http://www.my1818.com/Handler/ReceiveNoticePage.ashx";//Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port +

                if (WebConfigurationManager.AppSettings["PayType"] == "0")
                {
                    notificationURL = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/Handler/ReceiveNoticePage.ashx";
                }
                // notificationURL = "https://www.yibanmed.com/Handler/ReceiveNoticePage.ashx";
                else
                {
                    notificationURL = "https://www.yibanmed.com/Handler/ReceiveNoticePage.ashx";//回调页面地址
                }
                String payees = new Hi.BLL.BD_Company().GetModel(disOrderMOdel.CompID).CompName;

                //判断支付接口
                string Pay_type = WebConfigurationManager.AppSettings["PayType"];
                String bankID   = string.Empty;
                if (Pay_type == "0") //测试接口
                {
                    bankID = "700";  //bankid;//
                }
                else
                {
                    bankID = bankid;//正式接口
                }
                int accountType = Convert.ToInt32(AccountType);

                // 2.创建交易请求对象
                Tx1311Request tx1311Request = new Tx1311Request();
                tx1311Request.setInstitutionID(institutionID);     //机构号码
                tx1311Request.setOrderNo(orderNo);                 //订单号orderNo + payid.ToString()
                tx1311Request.setPaymentNo(payModel.guid);         //支付交易流水号
                tx1311Request.setAmount(amount);                   //支付金额 单位分
                tx1311Request.setFee(fee);                         //支付服务手续费 单位分
                tx1311Request.setPayerID("");                      //付款人注册ID
                tx1311Request.setPayerName("");                    //付款方名称
                tx1311Request.setUsage(usage);                     //资金用途
                tx1311Request.setRemark(remark);                   //备注
                tx1311Request.setNotificationURL(notificationURL); //机构接收支付通知的URL
                tx1311Request.addPayee("");                        //收款方名称

                if (accountType == 13)
                {
                    tx1311Request.setAccountType(11); //付款方帐号类型
                    tx1311Request.setCardType("02");  //银行卡类型(01=借记卡、02=贷记卡)
                }
                else if (accountType == 11)
                {
                    tx1311Request.setAccountType(accountType); //付款方帐号类型
                    tx1311Request.setCardType("01");           //银行卡类型(01=借记卡、02=贷记卡)
                }
                else if (accountType == 12)
                {
                    tx1311Request.setAccountType(accountType); //付款方帐号类型
                }
                tx1311Request.setBankID(bankID);               //付款银行标识


                // 3.执行报文处理
                tx1311Request.process();
                try
                {
                    Hi.Model.PAY_RegisterLog regM = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                    regM.PlanMessage = tx1311Request.getRequestPlainText();
                    new Hi.BLL.PAY_RegisterLog().Update(regM);
                }
                catch (Exception ex) { throw ex; }

                //跳转的url地址
                HttpContext.Current.Items["action"] = PaymentEnvironment.PaymentURL;
                //中金返回信息
                HttpContext.Current.Items["message"] = tx1311Request.getRequestMessage();
                //中金签名信息
                HttpContext.Current.Items["signature"] = tx1311Request.getRequestSignature();
            }
            catch (Exception ex)
            {
                err = true;
                ErrMessage(ex.Message);
                return;
            }
            finally
            {
                if (!err)
                {
                    Context.Server.Transfer("DoSubmit.aspx", false);
                }
            }
        }
    }
예제 #5
0
    /// <summary>
    /// 审核通过
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Hi.Model.DIS_OrderReturn OrderReturnModel = OrderReturnBll.GetModel(KeyID);

        string AuditUserID = string.Empty;
        string AuditDate   = string.Empty;
        string AuditRemark = string.Empty;
        int    pay         = 0;

        if (!string.IsNullOrEmpty(this.hidAuditUserID.Value))
        {
            AuditUserID = this.hidAuditUserID.Value.Trim().ToString();
        }
        //if (!string.IsNullOrEmpty(this.txtArriveDate.Value.Trim().ToString()))
        //{
        //    AuditDate = this.txtArriveDate.Value.Trim().ToString();
        //}
        if (!string.IsNullOrEmpty(this.lblArriveDate.InnerText.Trim().ToString()))
        {
            AuditDate = this.lblArriveDate.InnerText.Trim().ToString();
        }
        if (!string.IsNullOrEmpty(this.txtRemark.Value.Trim().ToString()))
        {
            AuditRemark = this.txtRemark.Value.Trim().ToString();
        }

        if (OrderReturnModel != null)
        {
            //判断退货单状态是否正确
            if (OrderReturnModel.ReturnState == (int)Enums.AuditState.提交)
            {
                Hi.Model.DIS_Order OrderModel = new Hi.BLL.DIS_Order().GetModel(OrderReturnModel.OrderID);

                if (OrderModel == null)
                {
                    JScript.AlertMsgOne(this, "订单信息有误!不能通过审核", JScript.IconOption.错误, 2500);
                    return;
                }
                int    State       = 0;
                string StateRemark = string.Empty;
                string LogRemark   = string.Empty;

                StateRemark = "退货审核通过";

                //订单支付状态
                pay       = OrderModel.PayState;
                LogRemark = "退货退款:" + OrderModel.PayedAmount.ToString("N");

                //判断订单状态是否正确
                if ((OrderModel.OState == (int)Enums.OrderState.已发货 || OrderModel.OState == (int)Enums.OrderState.已到货) && OrderModel.ReturnState == (int)Enums.ReturnState.申请退货)
                {
                    if (OrderModel.PayState == (int)Enums.PayState.已支付 || pay == (int)Enums.PayState.部分支付)
                    {
                        //订单已支付退货退款
                        //State = (int)Enums.AuditState.已审;
                        State                  = (int)Enums.AuditState.已完结;
                        OrderModel.OState      = (int)Enums.OrderState.已退货;
                        OrderModel.PayState    = (int)Enums.PayState.已退款;
                        OrderModel.ReturnState = (int)Enums.ReturnState.退货退款;
                    }
                    else
                    {
                        //订单未支付退货
                        OrderModel.OState = (int)Enums.OrderState.已退货;
                        State             = (int)Enums.AuditState.已完结;
                    }

                    #region
                    //if (OrderModel.Otype == (int)Enums.OType.赊销订单)
                    //{
                    //if (OrderModel.PayState == (int)Enums.PayState.已支付 || pay == (int)Enums.PayState.部分支付 || OrderModel.PayState == (int)Enums.PayState.已结算)
                    //{
                    //    //订单已支付退货退款
                    //    //State = (int)Enums.AuditState.已审;
                    //    State = (int)Enums.AuditState.已完结;
                    //    OrderModel.OState = (int)Enums.OrderState.已退货;
                    //    OrderModel.PayState = (int)Enums.PayState.已退款;
                    //    OrderModel.ReturnState = (int)Enums.ReturnState.退货退款;
                    //}
                    //else
                    //{
                    //    //订单未支付退货
                    //    OrderModel.OState = (int)Enums.OrderState.已退货;
                    //    State = (int)Enums.AuditState.已审;
                    //}
                    //}
                    //else
                    //{
                    //    //OrderModel.OState = (int)Enums.OrderState.退货处理;
                    //    //State = (int)Enums.AuditState.已审;
                    //    if (OrderModel.PayState == (int)Enums.PayState.已支付 || pay == (int)Enums.PayState.部分支付 || OrderModel.PayState == (int)Enums.PayState.已结算)
                    //    {
                    //        OrderModel.OState = (int)Enums.OrderState.已退货;
                    //        OrderModel.PayState = (int)Enums.PayState.已退款;
                    //        OrderModel.ReturnState = (int)Enums.ReturnState.退货退款;

                    //        State = (int)Enums.AuditState.已完结;
                    //    }
                    //    else
                    //    {
                    //        OrderModel.OState = (int)Enums.OrderState.已退货;
                    //        State = (int)Enums.AuditState.已审;
                    //    }
                    //}
                    #endregion
                    OrderModel.ts         = DateTime.Now;
                    OrderModel.modifyuser = this.UserID;

                    OrderReturnModel.AuditUserID = AuditUserID.ToInt(0);
                    OrderReturnModel.AuditDate   = AuditDate.ToDateTime();
                    OrderReturnModel.AuditRemark = AuditRemark;
                    OrderReturnModel.ReturnState = State;
                    OrderReturnModel.ts          = DateTime.Now;
                    OrderReturnModel.modifyuser  = this.UserID;


                    #region   把退款金额变为代理商的企业钱包金额
                    int           order  = 0;
                    int           prepay = 0;
                    SqlConnection con    = new SqlConnection(LocalSqlServer);
                    con.Open();
                    SqlTransaction sqlTrans = con.BeginTransaction();

                    Hi.Model.PAY_PrePayment PrepayModel = new Hi.Model.PAY_PrePayment();
                    Hi.BLL.PAY_PrePayment   PrepayBLL   = new Hi.BLL.PAY_PrePayment();
                    PrepayModel.CompID    = OrderModel.CompID;
                    PrepayModel.DisID     = OrderModel.DisID;
                    PrepayModel.OrderID   = OrderModel.ID;
                    PrepayModel.Start     = 1;
                    PrepayModel.PreType   = 4;
                    PrepayModel.price     = OrderModel.PayedAmount; //已支付金额
                    PrepayModel.Paytime   = DateTime.Now;
                    PrepayModel.CrateUser = this.UserID;
                    PrepayModel.CreatDate = DateTime.Now;
                    PrepayModel.OldId     = 0;

                    PrepayModel.AuditState = 2;
                    PrepayModel.IsEnabled  = 1;
                    PrepayModel.AuditUser  = this.UserID;
                    PrepayModel.dr         = 0;
                    PrepayModel.ts         = DateTime.Now;
                    PrepayModel.guid       = Common.Number_repeat("");

                    try
                    {
                        //order = new Hi.BLL.DIS_Order().UpdateOrderByggh(con, OrderModel, sqlTrans, KeyID, (int)Enums.AuditState.已完结);
                        order = OrderInfoType.ReturnOrderUpdate(con, sqlTrans, OrderReturnModel, OrderModel);

                        //if (OrderModel.Otype == (int)Enums.OType.赊销订单)
                        //{
                        //    //支付的订单 生成企业钱包
                        //    if (pay == (int)Enums.PayState.已支付||pay == (int)Enums.PayState.部分支付|| pay == (int)Enums.PayState.已结算)
                        //    {
                        //        prepay = new Hi.BLL.PAY_PrePayment().InsertPrepay(con, PrepayModel, sqlTrans);
                        //    }
                        //    else
                        //    {
                        //        //未支付的订单 不生成企业钱包
                        //        prepay = 1;
                        //    }
                        //}
                        //else
                        //{
                        if (pay == (int)Enums.PayState.已支付 || pay == (int)Enums.PayState.部分支付)
                        {
                            //支付的订单 生成企业钱包
                            prepay = new Hi.BLL.PAY_PrePayment().InsertPrepay(con, PrepayModel, sqlTrans);

                            //退款减积分
                            OrderInfoType.AddIntegral(CompID, OrderModel.DisID, "1", 2, OrderModel.ID, OrderModel.PayedAmount, "订单退款", "", this.UserID);
                        }
                        else
                        {
                            //未支付的订单 不生成企业钱包
                            prepay = 1;
                        }
                        //}

                        sqlTrans.Commit();
                    }
                    catch
                    {
                        order  = 0;
                        prepay = 0;
                        sqlTrans.Rollback();
                    }
                    finally
                    {
                        con.Close();
                    }
                    #endregion

                    if (prepay > 0 && order > 0)
                    {
                        if (OrderInfoType.rdoOrderAudit("订单下单数量是否取整", this.CompID) == "0")
                        {
                            //退货审核通过,返还商品库存
                            string sql = new Hi.BLL.DIS_Order().GetSqlAddInve(OrderModel.ID, null, 0);
                            new Hi.BLL.DIS_Order().UpdateOrderState(sql);
                        }

                        if (pay == (int)Enums.PayState.未支付)
                        {
                            // type : "4":订单发货通知;"3":订单状态变更通知(待发货、审批通过);"2":订单支付通知;"1":下单通知
                            new Common().GetWxService("44", OrderReturnModel.OrderID.ToString(), "0");

                            //代理商手机号
                            string Phone = Common.GetDis(OrderModel.DisID, "Phone");
                            string msg   = "您的订单:" + OrderModel.ReceiptNo + "退货申请已通过!";
                            //退款向代理商推送信息提示
                            Common.GetPhone(Phone, msg);
                        }
                        else
                        {
                            //type : "4":订单发货通知;"3":订单状态变更通知(待发货、审批通过);"2":订单支付通知;"1":下单通知
                            new Common().GetWxService("44", OrderReturnModel.OrderID.ToString(), "0");
                            new Common().GetWxService("45", OrderReturnModel.OrderID.ToString(), "0");

                            //代理商手机号
                            string Phone = Common.GetDis(OrderModel.DisID, "Phone");
                            string msg   = "您的订单:" + OrderModel.ReceiptNo + "退货金额已退回您的企业钱包账户,请查收!";
                            //退款向代理商推送信息提示
                            Common.GetPhone(Phone, msg);
                        }

                        Utils.AddSysBusinessLog(this.CompID, "Order", OrderReturnModel.OrderID.ToString(), StateRemark, LogRemark);

                        Response.Write("<script language=\"javascript\">window.parent.AuditReturn('" + Common.DesEncrypt(this.KeyID.ToString(), Common.EncryptKey) + "');</script>");
                    }
                }
                else
                {
                    JScript.AlertMsgOne(this, "订单信息有误!不能通过审核!", JScript.IconOption.错误, 2500);
                    return;
                }
            }
            else
            {
                JScript.AlertMsgOne(this, "数据状态不正确,不能进行审核!", JScript.IconOption.错误, 2500);
            }
        }
        else
        {
            JScript.AlertMsgOne(this, "数据不存在!", JScript.IconOption.错误, 2500);
        }
    }
예제 #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SortedDictionary <string, string> sPara = GetRequestPost();

        if (sPara.Count > 0)//判断是否有带返回参数
        {
            Notify aliNotify    = new Notify();
            bool   verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);

            if (verifyResult)//验证成功
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //请在这里加上商户的业务逻辑程序代码
                //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

                //商户订单号
                string out_trade_no = Request.Form["out_trade_no"];

                //支付宝交易号
                string trade_no = Request.Form["trade_no"];

                //交易状态
                string trade_status = Request.Form["trade_status"];

                //买家帐号
                string buyer_email = Request.Form["buyer_email"];

                //支付金额
                string price = Request.Form["total_fee"];

                if (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")
                {
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //如果有做过处理,不执行商户的业务程序
                    string strWhere2 = string.Empty;
                    if (out_trade_no != "")
                    {
                        strWhere2 += " number = '" + out_trade_no + "'";
                    }
                    Hi.Model.PAY_RegisterLog        regM = new Hi.Model.PAY_RegisterLog();
                    List <Hi.Model.PAY_RegisterLog> regL = new Hi.BLL.PAY_RegisterLog().GetList("", strWhere2, "");
                    if (regL == null || regL.Count <= 0)
                    {
                        //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到对应的支付记录!", false);
                        //return;
                        Console.WriteLine("未找到对应的支付记录!");
                    }
                    regM = regL[0];
                    string strWhere = string.Empty;
                    if (out_trade_no != "")
                    {
                        strWhere += " guid = '" + out_trade_no + "'";
                    }
                    strWhere += " and isnull(dr,0)=0";
                    Hi.Model.PAY_Payment        payM = new Hi.Model.PAY_Payment();
                    List <Hi.Model.PAY_Payment> payL = new Hi.BLL.PAY_Payment().GetList("", strWhere, "");
                    if (payL == null || payL.Count <= 0)
                    {
                        //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到对应的支付记录!", false);
                        // return;
                        Console.WriteLine("未找到对应的支付记录!");
                    }
                    payM = payL[0];

                    payM.PayDate = DateTime.Now;
                    payM.ts      = DateTime.Now;
                    payM.status  = trade_status == "TRADE_FINISHED" ? 80 : 90;
                    new Hi.BLL.PAY_Payment().Update(payM);
                    regM.Start = trade_status;
                    new Hi.BLL.PAY_RegisterLog().Update(regM);
                    if (payM.IsAudit == 1)
                    {
                        Console.WriteLine("该支付记录状态已经修改成功,请不要重复操作!");
                    }

                    //!!!支付成功 !!!
                    decimal prepayPrice = 0;

                    //企业钱包充值
                    Hi.Model.PAY_PrePayment prepayMnew = new Hi.Model.PAY_PrePayment();
                    string strWhere3 = string.Empty;
                    if (out_trade_no != "")
                    {
                        strWhere3 += " ID = " + payM.OrderID;
                    }
                    strWhere3 += " and isnull(dr,0)=0";
                    List <Hi.Model.PAY_PrePayment> plist = new Hi.BLL.PAY_PrePayment().GetList("", strWhere3, "");
                    if (plist.Count > 0)
                    {
                        prepayMnew = plist[0];
                    }

                    //订单
                    Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(payM.OrderID);
                    if (orderModel != null)
                    {
                        string strWhere1 = string.Empty;
                        strWhere1 += " vdef4 = '" + payM.ID + "'";
                        strWhere1 += " and isnull(dr,0)=0";
                        Hi.Model.PAY_PrePayment        prepayM = new Hi.Model.PAY_PrePayment();
                        List <Hi.Model.PAY_PrePayment> prepayL = new Hi.BLL.PAY_PrePayment().GetList("", strWhere1, "");
                        if (prepayL != null && prepayL.Count > 0)
                        {
                            prepayM     = prepayL[0];
                            prepayPrice = prepayM.price * -1;
                        }

                        int           order  = 0;
                        int           prepay = 0;
                        int           pay    = 0;
                        decimal       prices = Convert.ToDecimal(price);
                        SqlConnection con    = new SqlConnection(LocalSqlServer);
                        con.Open();
                        SqlTransaction sqlTrans = con.BeginTransaction();
                        try
                        {
                            order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, orderModel.ID, payM.PayPrice + prepayPrice - Convert.ToDecimal(payM.vdef5), sqlTrans);
                            pay   = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);


                            if (prepayPrice > 0)
                            {
                                prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                            }
                            else
                            {
                                prepay = 1;
                            }
                            sqlTrans.Commit();
                        }
                        catch
                        {
                            order  = 0;
                            prepay = 0;
                            pay    = 0;
                            sqlTrans.Rollback();
                        }
                        finally
                        {
                            con.Close();
                        }

                        if (order <= 0 || prepay <= 0 || pay <= 0)
                        {
                            Console.WriteLine("支付成功,但修改支付状态失败,请联系系统管理员,勿重复操作!");
                        }

                        try
                        {
                            //new Common().GetWxService("2", orderModel.ID.ToString(), "1");
                            if (orderModel.Otype != 9)
                            {
                                OrderInfoType.AddIntegral(orderModel.CompID, orderModel.DisID, "1", 1, orderModel.ID, (prepayPrice + prices), "订单支付", "", orderModel.CreateUserID);
                            }
                        }
                        catch { }
                        if (orderModel.Otype == (int)Enums.OType.推送账单)
                        {
                            Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "账单支付", "支付:" + (prepayPrice + prices).ToString("0.00") + "元(支付宝支付" + prices.ToString("0.00") + (prepayM.ID > 0 ? "+企业钱包支付" + prepayPrice.ToString("0.00") : "") + "【含手续费" + Convert.ToDecimal(payM.vdef5).ToString("0.00") + "元】)", payM.CreateUserID.ToString());
                        }
                        else
                        {
                            Utils.AddSysBusinessLog(orderModel.CompID, "Order", orderModel.ID.ToString(), "订单支付", "支付:" + (prepayPrice + prices).ToString("0.00") + "元(支付宝支付" + prices.ToString("0.00") + (prepayM.ID > 0 ? "+企业钱包支付" + prepayPrice.ToString("0.00") : "") + "【含手续费" + Convert.ToDecimal(payM.vdef5).ToString("0.00") + "元】)", payM.CreateUserID.ToString());
                        }

                        //微信和安卓消息推送
                        try
                        {
                            new Common().GetWxService("2", orderModel.ID.ToString(), "1", prepayPrice + prices);
                        }
                        catch { }

                        //Response.Write("success");  //请不要修改或删除
                        //打印页面
                        //Response.Write("支付成功<br />");
                        Response.Write("success");  //请不要修改或删除
                    }//钱包充值
                    else if (prepayMnew != null)
                    {
                        int           prepay = 0;
                        int           pay    = 0;
                        SqlConnection con    = new SqlConnection(LocalSqlServer);
                        con.Open();
                        SqlTransaction sqlTrans = con.BeginTransaction();
                        try
                        {
                            pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payM.ID, sqlTrans);
                            prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayMnew.ID, sqlTrans);
                            sqlTrans.Commit();
                        }
                        catch
                        {
                            pay    = 0;
                            prepay = 0;
                            sqlTrans.Rollback();
                        }
                        finally
                        {
                            con.Close();
                        }
                    }
                    else
                    {
                        //response.Redirect("../Distributor/Pay/Error.aspx?msg=未找到该支付订单!", false);
                        //return;

                        Console.WriteLine("未找到该支付记录!");
                    }
                }

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
            else//验证失败
            {
                Response.Write("fail");
            }
        }
        //else
        //{
        //    Response.Write("无通知参数");
        //    Response.Redirect("ErrorPay.aspx?type=2&OrderCode=" + Request.QueryString["out_trade_no"]);
        //}
    }