Ejemplo n.º 1
0
        /// <summary>
        /// 处理网银支付异步通知返回订单信息,执行扣量等操作,处理完毕会自动输出succflag或failflag给接口供应商平台
        /// </summary>
        /// <param name="supplierId"></param>
        /// <param name="orderId"></param>
        /// <param name="supplierOrderId"></param>
        /// <param name="status"></param>
        /// <param name="opstate"></param>
        /// <param name="msg"></param>
        /// <param name="tranAmt">结算金额</param>
        ///  <param name="suppSettleAmt">供应商给平台的费率</param>
        /// <param name="succflag"></param>
        /// <param name="failflag"></param>
        public static void SuppNotify(int supplierId, string orderId, string supplierOrderId, int status,
                                      string opstate, string msg, decimal tranAmt, decimal suppSettleAmt,
                                      string succflag, string failflag)
        {
            var execResult = new FunExecResult()
            {
                ErrCode = 0,
                ErrMsg  = ""
            };

            var orderInfo = Cache.WebCache.GetCacheService().RetrieveObject(orderId) as OrderBankInfo;

            if (orderInfo == null)
            {
                orderInfo = BLL.Order.Bank.Factory.Instance.GetModelByOrderId(orderId);
            }
            if (orderInfo != null)
            {
                bool insertToDb = orderInfo.status == 1;
                if (insertToDb)
                {
                    #region InsertToDb
                    orderInfo.status    = status;
                    orderInfo.realvalue = tranAmt;
                    orderInfo.msg       = msg;

                    execResult = InsertToDb(supplierId
                                            , orderInfo
                                            , supplierOrderId
                                            , status
                                            , opstate
                                            , msg, tranAmt, suppSettleAmt);

                    //Cache.WebCache.GetCacheService().RemoveObject(orderId);
                    #endregion
                }
                if (orderInfo.status != 1)
                {
                    APINotification.SynchronousNotifyX(orderInfo);
                }
            }

            if (execResult.ErrCode == 0)
            {
                if (!string.IsNullOrEmpty(succflag))
                {
                    System.Web.HttpContext.Current.Response.Write(succflag);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(failflag))
                {
                    System.Web.HttpContext.Current.Response.Write(failflag);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="intputUserid"></param>
        /// <param name="ischeckuserorder"></param>
        /// <param name="intputUserorder"></param>
        /// <returns></returns>
        public FunExecResult CheckAPIParms(int intputUserid
                                           , int typeid
                                           , bool ischeckuserorder
                                           , string intputUserorder)
        {
            var chkResult = new FunExecResult();

            int result = 0;

            SqlParameter[] parameters =
            {
                new SqlParameter("@intput_userid", SqlDbType.Int,                                  4)
                ,                                  new SqlParameter("@typeid",           SqlDbType.Int, 4)
                ,                                  new SqlParameter("@ischeckuserorder", SqlDbType.Bit)
                ,                                  new SqlParameter("@intput_userorder", SqlDbType.VarChar, 30)
                ,                                  new SqlParameter("@result",           SqlDbType.TinyInt)
            };
            parameters[0].Value     = intputUserid;
            parameters[1].Value     = typeid;
            parameters[2].Value     = ischeckuserorder;
            parameters[3].Value     = intputUserorder;
            parameters[4].Direction = ParameterDirection.Output;

            DataSet data = DataBase.ExecuteDataset(CommandType.StoredProcedure, "proc_orderbank_checkdata", parameters);


            result = Convert.ToInt32(parameters[4].Value);
            if (result == 0 && data != null && data.Tables.Count > 0)
            {
                var userInfo = new UserInfo();

                DataRow row = data.Tables[0].Rows[0];
                userInfo.ID     = intputUserid;
                userInfo.APIKey = row["apikey"].ToString();
                if (row["isdebug"] != DBNull.Value)
                {
                    userInfo.isdebug = Convert.ToInt32(row["isdebug"]);
                }
                if (row["manageId"] != DBNull.Value)
                {
                    userInfo.manageId = Convert.ToInt32(row["manageId"]);
                }
                if (row["RiskWarning"] != DBNull.Value)
                {
                    userInfo.RiskWarning = Convert.ToByte(row["RiskWarning"]);
                }

                chkResult.Obj = userInfo;
            }
            chkResult.ErrCode = result;

            return(chkResult);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理网银支付同步返回订单信息,执行扣量等操作,并跳转到支付完成页面
        /// (与SuppNotify相比没有给供应商接口返回的成功或失败信息输出,而是跳转到支付完成页面)
        /// </summary>
        /// <param name="supplierId"></param>
        /// <param name="orderId">系统内部订单号</param>
        /// <param name="supplierOrderId">接口订单号</param>
        /// <param name="status">状态</param>
        /// <param name="opstate">返回码</param>
        /// <param name="msg">返回信息</param>
        /// <param name="tranAmt">消费金额</param>
        /// <param name="suppSettleAmt">供应商给平台的费率</param>
        public static void SuppPageReturn(int supplierId, string orderId, string supplierOrderId, int status,
                                          string opstate, string msg, decimal tranAmt, decimal suppSettleAmt)
        {
            bool insertToDb = false;

            var orderInfo = Cache.WebCache.GetCacheService().RetrieveObject(orderId) as OrderBankInfo;

            if (orderInfo == null)
            {
                orderInfo = BLL.Order.Bank.Factory.Instance.GetModelByOrderId(orderId);
            }

            if (orderInfo != null)
            {
                insertToDb = orderInfo.status == 1;

                var execResult = new FunExecResult();
                if (insertToDb)
                {
                    #region InsertToDb
                    orderInfo.status    = status;
                    orderInfo.realvalue = tranAmt;
                    orderInfo.msg       = msg;
                    execResult          = InsertToDb(supplierId
                                                     , orderInfo
                                                     , supplierOrderId
                                                     , status
                                                     , opstate
                                                     , msg, tranAmt, suppSettleAmt);
                    #endregion
                }

                if (execResult.ErrCode == 0)
                {
                    Utility.ReturnToMerchant(orderInfo);
                }
                else
                {
                    System.Web.HttpContext.Current.Response.Write("system error");
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="supplierId">接口供应商ID</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="supplierOrderId"></param>
        /// <param name="status"></param>
        /// <param name="opstate">状态码</param>
        /// <param name="msg">返回信息</param>
        /// <param name="tranAmt">结算金额</param>
        /// <param name="suppSettleAmt">供应商给平台的结算价</param>
        /// <returns></returns>
        public static FunExecResult InsertToDb(int supplierId
                                               , OrderBankInfo orderInfo
                                               , string supplierOrderId
                                               , int status
                                               , string opstate
                                               , string msg
                                               , decimal tranAmt
                                               , decimal suppSettleAmt)
        {
            var result = new FunExecResult()
            {
                ErrCode = 0,
                ErrMsg  = ""
            };

            string cacheKey = "OrderBankComplete" + orderInfo.orderid + orderInfo.supplierId.ToString(CultureInfo.InvariantCulture);

            object flag = Cache.WebCache.GetCacheService().RetrieveObject(cacheKey);

            if (flag != null)
            {
                return(result);
            }

            try
            {
                orderInfo.supplierId = supplierId;
                orderInfo.status     = status;
                orderInfo.deduct     = 0;

                #region 扣量
                if (BLL.Sys.TransactionSettings.OpenDeduct && status == 2)
                {
                    Model.User.UserInfo userInfo = BLL.User.Factory.GetCacheUserBaseInfo(orderInfo.userid);
                    if (userInfo != null)
                    {
                        //0x3e8 1000 扣率 扣率 = 被扣单的机率是多少
                        if (new Random(Guid.NewGuid().GetHashCode()).Next(1, 1000) <= userInfo.CPSDrate)
                        {
                            orderInfo.deduct = 1;
                        }
                    }
                }
                #endregion

                orderInfo.realvalue    = tranAmt;
                orderInfo.supplierId   = supplierId;
                orderInfo.completetime = DateTime.Now;

                orderInfo.payRate      = 0M;
                orderInfo.payAmt       = 0M;
                orderInfo.promRate     = 0M;
                orderInfo.promAmt      = 0M;
                orderInfo.supplierRate = 0M;
                orderInfo.supplierAmt  = 0M;
                orderInfo.profits      = 0M;

                if (status == 2)
                {
                    if (orderInfo.deduct == 0)
                    {
                        #region 计算费率
                        if (orderInfo.payRate <= 0M)
                        {
                            orderInfo.payRate = BLL.Finance.PayRate.Instance.GetUserPayRate(orderInfo.userid,
                                                                                            orderInfo.typeId);
                        }
                        orderInfo.payAmt = orderInfo.payRate * tranAmt;


                        if (orderInfo.agentId > 0)
                        {
                            //代理费率
                            orderInfo.promRate = BLL.Finance.PayRate.Instance.GetUserPayRate(orderInfo.agentId,
                                                                                             orderInfo.typeId);
                            //代理金额
                            orderInfo.promAmt = (orderInfo.promRate - orderInfo.payRate) * tranAmt;

                            if (orderInfo.promAmt < 0)
                            {
                                orderInfo.promAmt = 0;
                            }
                        }
                        #endregion
                    }
                    if (orderInfo.supplierRate <= 0M)
                    {
                        #region 计算平台费率
                        var chanelInfo = BLL.Channel.Channel.GetModel(orderInfo.paymodeId, orderInfo.userid, false);
                        if (chanelInfo != null)
                        {
                            orderInfo.supplierRate = chanelInfo.supprate;
                        }
                        #endregion
                    }

                    orderInfo.supplierAmt = suppSettleAmt;
                    if (suppSettleAmt > 0 && tranAmt > 0)
                    {
                        orderInfo.supplierRate = suppSettleAmt / tranAmt;
                    }

                    //利润
                    orderInfo.profits = orderInfo.supplierAmt - orderInfo.payAmt - orderInfo.promAmt;
                }

                orderInfo.opstate = opstate;
                orderInfo.msg     = msg;

                orderInfo.supplierOrder = "";
                if (!string.IsNullOrEmpty(supplierOrderId))
                {
                    orderInfo.supplierOrder = supplierOrderId;
                }

                BLLBank.Complete(orderInfo);

                result.ErrCode = 0;
                result.ErrMsg  = "success";

                Cache.WebCache.GetCacheService().AddObject(cacheKey, status, 5);
            }
            catch (System.Threading.ThreadAbortException ex)
            {
                result.ErrCode = 98;
                result.ErrMsg  = ex.Message;
                //
            }
            catch (Exception ex)
            {
                result.ErrCode = 99;
                result.ErrMsg  = ex.Message;
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                string orderId = this.txtOrderId.Text.Trim();
                if (string.IsNullOrEmpty(orderId))
                {
                    ShowMessageBox("请输入订单号");
                    return;
                }

                if (string.IsNullOrEmpty(ddlSupp.SelectedValue))
                {
                    ShowMessageBox("请选择接口商");
                    return;
                }

                string  orderAmt = this.txtOrderAmt.Text.Trim();
                decimal amt      = 0M;
                if (string.IsNullOrEmpty(orderAmt))
                {
                    ShowMessageBox("请输入订单金额");
                    return;
                }

                if (!decimal.TryParse(orderAmt, out amt))
                {
                    ShowMessageBox("订单金额不能为空");
                    return;
                }
                if (amt <= 0M)
                {
                    ShowMessageBox("金额不能为0");
                    return;
                }

                OrderBankInfo orderBank = viviapi.BLL.Order.Bank.Factory.Instance.GetModelByOrderId(orderId);
                if (orderBank == null)
                {
                    ShowMessageBox("不存在此订单");
                    return;
                }

                if (orderBank.status != 1)
                {
                    ShowMessageBox("订单状态不正确");
                    return;
                }

                string supp = this.ddlSupp.SelectedValue;

                if (orderBank.status == 1)
                {
                    FunExecResult result = viviapi.ETAPI.Common.OrderBankUtils.InsertToDb(int.Parse(supp)
                                                                                          , orderBank
                                                                                          , "Sys" + DateTime.Now.Ticks.ToString()
                                                                                          , 2
                                                                                          , "0"
                                                                                          , "手动补单"
                                                                                          , amt, 0M);

                    if (result.ErrCode == 0)
                    {
                        if (orderBank.status != 1)
                        {
                            APINotification.SynchronousNotifyX(orderBank);
                        }

                        ShowMessageBox("操作成功");
                    }
                    else
                    {
                        ShowMessageBox("操作失败");
                    }
                }
                else
                {
                    ShowMessageBox("订单状态不正确");
                }
            }
        }