示例#1
0
    public void Tx1372()
    {
        LogManager.LogFielPrefix = "tx1372";
        LogManager.LogPath       = "D:/Tx1372Order_log/";
        LogManager.WriteLog(LogFile.Trace.ToString(), DateTime.Now + "进入Tx372程序\r");
        string    LocalSqlServer = SqlHelper.LocalSqlServer;
        DataTable dt             = new Hi.BLL.PAY_PrePayment().GetDate("guid,id,OrderID", "pay_payment", "  verifystatus=40 and status =10 and IsAudit =2 ");

        foreach (DataRow dr in dt.Rows)
        {
            string number    = Convert.ToString(dr["guid"]);   //支付交易流水号
            int    paymentid = Convert.ToInt32(dr["id"]);      //支付表id
            int    Orderid   = Convert.ToInt32(dr["OrderID"]); //支付表关联ID

            string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
            PaymentEnvironment.Initialize(configPath);
            string institutionID = WebConfigurationManager.AppSettings["PayOrgCode"];//机构号码

            Tx1372Request tx1372 = new Tx1372Request();
            tx1372.setInstitutionID(institutionID);
            tx1372.setPaymentNo(number);
            tx1372.process();
            TxMessenger    txMessenger    = new TxMessenger();
            String[]       respMsg        = txMessenger.send(tx1372.getRequestMessage(), tx1372.getRequestSignature());
            Tx1372Response tx1372Response = new Tx1372Response(respMsg[0], respMsg[1]);
            //接口调用成功
            if ("2000".Equals(tx1372Response.getCode()))
            {
                LogManager.WriteLog(LogFile.Trace.ToString(), "流水号:" + number + "    状态:" + tx1372Response.getStatus() + "\r");
                //支付成功
                if (20 == tx1372Response.getStatus())
                {
                    //支付成功,修改状态
                    //企业钱包修改状态
                    int           order  = 0;
                    int           pay    = 0;
                    int           prepay = 0;
                    SqlConnection con    = new SqlConnection(LocalSqlServer);
                    con.Open();
                    SqlTransaction sqlTrans = con.BeginTransaction();
                    try
                    {
                        Hi.Model.PAY_Payment    paymentmodel    = new Hi.BLL.PAY_Payment().GetModel(paymentid);
                        Hi.Model.DIS_Order      ordermodel      = new Hi.BLL.DIS_Order().GetModel(Orderid);
                        Hi.Model.PAY_PrePayment prepaymentmodel = new Hi.BLL.PAY_PrePayment().GetModel(Orderid);
                        if (ordermodel != null)                                                                                                                                                       //订单支付
                        {
                            order = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, Orderid, paymentmodel.PayPrice - Convert.ToDecimal(paymentmodel.vdef5 == "" ? "0" : paymentmodel.vdef5), sqlTrans); //修改订单状态
                            pay   = new Hi.BLL.PAY_Payment().updatePayState(con, paymentid, sqlTrans);                                                                                                //修改支付表状态

                            if (order > 0 && pay > 0)
                            {
                                sqlTrans.Commit();
                            }
                            else
                            {
                                sqlTrans.Rollback();
                            }
                        }
                        else if (prepaymentmodel != null)//预付款充值
                        {
                            pay    = new Hi.BLL.PAY_Payment().updatePayState(con, paymentid, sqlTrans);
                            prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepaymentmodel.ID, sqlTrans);
                            if (pay > 0 && prepay > 0)
                            {
                                sqlTrans.Commit();
                            }
                            else
                            {
                                sqlTrans.Rollback();
                            }
                        }
                    }
                    catch
                    {
                        order = 0;
                        pay   = 0;
                        sqlTrans.Rollback();
                    }
                    finally
                    {
                        con.Close();
                    }
                }
                else if (30 == tx1372Response.getStatus())//支付失败
                {
                    Hi.Model.PAY_Payment payment = new Hi.BLL.PAY_Payment().GetModel(paymentid);
                    payment.status = 30;//支付失败
                    new Hi.BLL.PAY_Payment().Update(payment);

                    LogManager.WriteLog(LogFile.Trace.ToString(), "失败:" + tx1372Response.getStatus() + "\r");
                }
            }
        }
    }
示例#2
0
    /// <summary>
    /// 申请退款
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //protected void btnRefund_Click(object sender, EventArgs e)
    //{
    //    Hi.Model.DIS_Order OrderModel = OrderBll.GetModel(KeyID);

    //    if (OrderModel != null)
    //    {
    //        if ((OrderModel.OState == (int)Enums.OrderState.已审) && OrderModel.PayState == (int)Enums.PayState.已支付)
    //        {
    //            string sql = " update [DIS_Order] set [PayState]=" + (int)Enums.PayState.申请退款 + ",[ReturnState]=" + (int)Enums.ReturnState.申请退款 + " where ID=" + KeyID;

    //            if (OrderBll.UpdateOrderState(sql))
    //            {
    //                Utils.AddSysBusinessLog(this.CompID, "Order", KeyID.ToString(), "申请退款", "");
    //                //Bind();
    //                Response.Redirect("OrderInfo.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey));
    //            }
    //        }
    //        else
    //        {
    //            JScript.ShowAlert(this, "数据状态不正确,不能取消!");
    //        }
    //    }
    //}

    /// <summary>
    /// 支付查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPayInfo_Click(object sender, EventArgs e)
    {
        Hi.Model.DIS_Order      orderM  = OrderBll.GetModel(KeyID);
        Hi.Model.PAY_PrePayment prepayM = new Hi.Model.PAY_PrePayment();
        if (orderM.PayState == (int)Enums.PayState.已支付)
        {
            //支付已成功
            JScript.AlertMsgOne(this, "支付已成功!", JScript.IconOption.笑脸);
            return;
        }
        else
        {
            //支付未成功
            string strWhere5 = string.Empty;
            if (KeyID > 0)
            {
                strWhere5 += " OrderID = " + KeyID;
            }
            strWhere5 += " and isnull(dr,0)=0";
            List <Hi.Model.PAY_PrePayment> prepayL = new Hi.BLL.PAY_PrePayment().GetList("", strWhere5, "");
            if (prepayL.Count > 0 && orderM.AuditAmount == prepayL[0].price * -1)
            {
                //只用企业钱包支付,但是修改状态时出错
                SqlConnection con = new SqlConnection(LocalSqlServer);
                con.Open();
                SqlTransaction sqlTrans = con.BeginTransaction();
                int            order    = 0;
                int            prepay   = 0;
                try
                {
                    order  = new Hi.BLL.DIS_Order().UpdateOrderPstate(con, KeyID, prepayL[0].price * -1, sqlTrans);
                    prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayL[0].ID, sqlTrans);
                    sqlTrans.Commit();
                }
                catch
                {
                    order  = 0;
                    prepay = 0;
                    sqlTrans.Rollback();
                }
                finally
                {
                    con.Close();
                }
                if (order > 0 && prepay > 0)
                {
                    JScript.AlertMsgOne(this, "支付已成功!", JScript.IconOption.笑脸);
                    return;
                }
                else
                {
                    JScript.AlertMsgOne(this, "支付处理中!", JScript.IconOption.哭脸);
                    return;
                }
            }

            string strWhere = string.Empty;
            if (KeyID > 0)
            {
                strWhere += " OrderID = " + KeyID;
            }
            strWhere += " and vdef3 = '1' and verifystatus = '40' and status = '20' and isnull(dr,0)=0";
            List <Hi.Model.PAY_Payment> payL = new Hi.BLL.PAY_Payment().GetList("", strWhere, "");
            if (payL.Count > 0)
            {
                //使用快捷支付成功,但是修改状态失败
                if (orderM.AuditAmount > payL[0].PayPrice)
                {
                    //是否使用企业钱包
                    string strWhere1 = string.Empty;
                    if (KeyID != 0)
                    {
                        strWhere1 += " OrderID = " + KeyID;
                    }
                    strWhere += " and isnull(dr,0)=0";
                    prepayM   = new Hi.BLL.PAY_PrePayment().GetList("", strWhere1, "")[0];
                }
                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, orderM.ID, payL[0].PayPrice + (prepayM.price * -1), sqlTrans);

                    if (orderM.AuditAmount == payL[0].PayPrice)
                    {
                        prepay = 1;
                        pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payL[0].ID, sqlTrans);
                    }
                    else if (orderM.AuditAmount > payL[0].PayPrice)
                    {
                        prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                        pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payL[0].ID, sqlTrans);
                    }
                    else
                    {
                        order  = 0;
                        prepay = 0;
                        pay    = 0;
                        sqlTrans.Rollback();
                    }

                    sqlTrans.Commit();
                }
                catch
                {
                    order  = 0;
                    prepay = 0;
                    pay    = 0;
                    sqlTrans.Rollback();
                }
                finally
                {
                    con.Close();
                }
                if (order > 0 && prepay > 0 && pay > 0)
                {
                    JScript.AlertMsgOne(this, "支付成功!", JScript.IconOption.笑脸);
                    //Bind();
                    Response.Redirect("neworder/orderdetail.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey));
                    return;
                }
                else
                {
                    JScript.AlertMsgOne(this, "支付处理中!", JScript.IconOption.哭脸);
                    return;
                }
            }
            else
            {
                //使用快捷支付未成功
                string strWhere2 = string.Empty;
                if (KeyID > 0)
                {
                    strWhere2 += " OrderID = " + KeyID;
                }
                strWhere2 += " and vdef3 = '1' and verifystatus = '40' and status = '10' and isnull(dr,0)=0";
                List <Hi.Model.PAY_Payment> payList = new Hi.BLL.PAY_Payment().GetList("", strWhere2, "ID desc");

                if (payList.Count > 0)
                {
                    //使用快捷支付,处理中
                    int regid = 0;
                    try
                    {
                        Hi.Model.PAY_RegisterLog regModel = new Hi.Model.PAY_RegisterLog();
                        regModel.OrderId    = KeyID;
                        regModel.Ordercode  = orderM.ReceiptNo;
                        regModel.number     = payList[0].guid;
                        regModel.Price      = payList[0].PayPrice;
                        regModel.Payuse     = "订单支付查询";
                        regModel.PayName    = new Hi.BLL.BD_Distributor().GetModel(orderM.DisID).DisName;
                        regModel.DisID      = orderM.DisID;
                        regModel.PayTime    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        regModel.Remark     = orderM.Remark;
                        regModel.DisName    = new Hi.BLL.BD_Company().GetModel(orderM.CompID).CompName;
                        regModel.CreateUser = this.UserID;
                        regModel.CreateDate = DateTime.Now;
                        regModel.LogType    = 1372;
                        regid = new Hi.BLL.PAY_RegisterLog().Add(regModel);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    if (regid > 0)
                    {
                        if (orderM.AuditAmount > payList[0].PayPrice)
                        {
                            //是否使用企业钱包
                            string strWhere3 = string.Empty;
                            if (KeyID != 0)
                            {
                                strWhere3 += " OrderID = " + KeyID;
                            }
                            strWhere3 += " and isnull(dr,0)=0";
                            prepayM    = new Hi.BLL.PAY_PrePayment().GetList("", strWhere3, "")[0];
                        }

                        //调用快捷支付查询接口
                        string configPath = WebConfigurationManager.AppSettings["payment.config.path"];
                        PaymentEnvironment.Initialize(configPath);

                        Tx1372Request tx1372Request = new Tx1372Request();
                        tx1372Request.setInstitutionID("001520");
                        tx1372Request.setPaymentNo(payList[0].guid);
                        tx1372Request.process();

                        TxMessenger txMessenger = new TxMessenger();
                        String[]    respMsg     = txMessenger.send(tx1372Request.getRequestMessage(), tx1372Request.getRequestSignature());

                        Tx1372Response tx1372Response = new Tx1372Response(respMsg[0], respMsg[1]);

                        try
                        {
                            Hi.Model.PAY_RegisterLog regModel = new Hi.BLL.PAY_RegisterLog().GetModel(regid);
                            regModel.Start         = tx1372Response.getCode();
                            regModel.ResultMessage = tx1372Response.getMessage();
                            new Hi.BLL.PAY_RegisterLog().Update(regModel);
                            Hi.Model.PAY_Payment payM = new Hi.BLL.PAY_Payment().GetModel(payList[0].ID);
                            payM.status = tx1372Response.getStatus();
                            new Hi.BLL.PAY_Payment().Update(payM);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        if ("2000".Equals(tx1372Response.getCode()))
                        {
                            int Status = tx1372Response.getStatus();
                            if (Status == 10)
                            {
                                JScript.AlertMsgOne(this, "支付处理中!", JScript.IconOption.哭脸);
                                return;
                            }
                            else if (Status == 20)
                            {
                                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, KeyID, payList[0].PayPrice + prepayM.price * -1, sqlTrans);

                                    if (orderM.AuditAmount == payList[0].PayPrice)
                                    {
                                        prepay = 1;
                                        pay    = 1;
                                    }
                                    else if (orderM.AuditAmount > payList[0].PayPrice)
                                    {
                                        prepay = new Hi.BLL.PAY_PrePayment().updatePrepayState(con, prepayM.ID, sqlTrans);
                                        pay    = new Hi.BLL.PAY_Payment().updatePayState(con, payList[0].ID, sqlTrans);
                                    }
                                    else
                                    {
                                        sqlTrans.Rollback();
                                    }

                                    sqlTrans.Commit();
                                }
                                catch (Exception ex)
                                {
                                    order  = 0;
                                    prepay = 0;
                                    pay    = 0;
                                    sqlTrans.Rollback();
                                }
                                finally
                                {
                                    con.Close();
                                }

                                if (order > 0 && prepay > 0 && pay > 0)
                                {
                                    JScript.AlertMsgOne(this, "支付成功!", JScript.IconOption.笑脸);
                                    //Bind();
                                    Response.Redirect("neworder/orderdetail.aspx?KeyID=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey));
                                    return;
                                }
                                else
                                {
                                    JScript.AlertMsgOne(this, "系统繁忙,请稍后!", JScript.IconOption.错误);
                                    return;
                                }
                            }
                            else if (Status == 30)
                            {
                                bool f = false;
                                try
                                {
                                    Hi.Model.PAY_PrePayment prepayModel = new Hi.BLL.PAY_PrePayment().GetModel(prepayL[0].ID);
                                    prepayModel.Start = Convert.ToInt32(Enums.PrePayMentState.失败);
                                    f = new Hi.BLL.PAY_PrePayment().Update(prepayModel);
                                    Hi.Model.DIS_Order orderModel = new Hi.BLL.DIS_Order().GetModel(KeyID);
                                    orderModel.PayState = Convert.ToInt32(Enums.PayState.未支付);
                                    f = new Hi.BLL.DIS_Order().Update(orderModel);
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                                if (f)
                                {
                                    JScript.AlertMsgOne(this, "支付失败!", JScript.IconOption.错误);
                                    Bind();
                                    return;
                                }
                                else
                                {
                                    JScript.AlertMsgOne(this, "系统繁忙,请稍后!", JScript.IconOption.错误);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
    }