Ejemplo n.º 1
0
        private int SyncShop(Model.TD_Order_WeiXinPay model, string orderID)
        {
            Model.TD_Shop_Order order = shopOrderBLL.GetModel(orderID);
            if (order == null)
            {
                return(0);
            }
            if (order.IsPay == "1")
            {
                return(0);
            }
            DateTime now = DateTime.Now;

            order.PayTime = now;
            order.IsPay   = "1";

            IList <Model.TD_Shop_OrderGoods> orderGoodsList = orderGoodsBLL.GetListByOrderID(orderID);
            string tranID = MySqlHelperUtil.BeginTran();

            try
            {
                decimal result = dal.Sync(model, tranID);
                if (result == 0)
                {
                    MySqlHelperUtil.RollbackTran(tranID);
                    return(0);
                }
                result = goodsBLL.PayOrder(orderID, orderGoodsList, tranID);
                if (result == 0)
                {
                    //商品中不存在  去sell中找
                    result = sellGoods.PayOrderNoFrozen(orderID, orderGoodsList, tranID);
                    if (result == 0)
                    {
                        MySqlHelperUtil.RollbackTran(tranID);
                        return(0);
                    }
                }
                result = shopOrderBLL.PayOrder(order, tranID);
                if (result == 0)
                {
                    MySqlHelperUtil.RollbackTran(tranID);
                    return(0);
                }
                MySqlHelperUtil.CommitTran(tranID);
                return(1);
            }
            catch
            {
                MySqlHelperUtil.RollbackTran(tranID);
                return(0);
            }
        }
Ejemplo n.º 2
0
        public int Sync(Model.TD_Order_WeiXinPay model, string tranID)
        {
            string sql = "UPDATE TD_Order_WeiXinPay SET Status=@Status,OrderFee=@OrderFee,CashFee=@CashFee,CallBackTime=@CallBackTime WHERE OrderID=@OrderID and NonceStr=@NonceStr and Status=0";

            MySqlParameter[] parameters =
            {
                new MySqlParameter("@Status",       model.Status),
                new MySqlParameter("@OrderFee",     model.OrderFee),
                new MySqlParameter("@CashFee",      model.CashFee),
                new MySqlParameter("@CallBackTime", model.CallBackTime),
                new MySqlParameter("@OrderID",      model.OrderID),
                new MySqlParameter("@NonceStr",     model.NonceStr)
            };
            return(MySqlHelperUtil.ExecuteNonQuery(tranID, sql, parameters));
        }
Ejemplo n.º 3
0
        public int Sync(Model.TD_Order_WeiXinPay model, string orderID)
        {
            int    result = 0;
            string prefix = model.OrderID.Substring(0, 2);

            switch (prefix)
            {
            case Constants.PayCode.Donation:
                result = SyncDonation(model, orderID);
                break;

            case Constants.PayCode.Shop:
                result = SyncShop(model, orderID);
                break;
            }
            return(result);
        }
Ejemplo n.º 4
0
        public int SyncDonation(Model.TD_Order_WeiXinPay model, string orderID)
        {
            Model.TD_Donation_Order order = donationOrderBLL.GetModel(orderID);
            if (order == null)
            {
                return(0);
            }
            if (order.IsPay == "1")
            {
                return(0);
            }
            DateTime now = DateTime.Now;

            order.PayTime = now;
            order.IsPay   = "1";

            string tranID = MySqlHelperUtil.BeginTran();

            try
            {
                decimal result = dal.Sync(model, tranID);
                if (result == 0)
                {
                    MySqlHelperUtil.RollbackTran(tranID);
                    return(0);
                }
                result = donationOrderBLL.PayOrder(order, tranID);
                if (result == 0)
                {
                    MySqlHelperUtil.RollbackTran(tranID);
                    return(0);
                }
                MySqlHelperUtil.CommitTran(tranID);
                return(1);
            }
            catch
            {
                MySqlHelperUtil.RollbackTran(tranID);
                return(0);
            }
        }
Ejemplo n.º 5
0
        public ActionResult PayForShop(string orderid, string url)
        {
            var member = MemberData.GetMember();
            var now    = DateTime.Now;

            if (string.IsNullOrEmpty(orderid))
            {
                return(GotoErrorResult("未找到该订单"));
            }
            Model.TD_Shop_Order model = shopOrderBLL.GetModel(orderid);
            if (model == null)
            {
                return(GotoErrorResult("未找到该订单"));
            }
            if (model.Status == (int)Constants.OrderStatus.Cancel)
            {
                return(GotoErrorResult("订单已取消"));
            }
            if (model.IsPay == "0")
            {
                bool exists = weiXinPayBLL.OrderIsPay(model.OrderID, 1);
                if (exists)
                {
                    return(GotoErrorResult("订单已微信支付,请联系平台"));
                }
                string     ip   = Request.UserHostAddress;
                WeiXinPort port = new WeiXinPort();
                try
                {
                    port.InitSignature(HttpContext.Request.Url.AbsoluteUri);
                    string domain = Request.Url.Scheme + "://" + Request.Url.Authority;
                    port.InitPaySignature(model.OrderID.ToString(), model.RealPrice.Value, member.OpenID, domain, ip);
                    if (!string.IsNullOrEmpty(port.ErrorMessage))
                    {
                        return(GotoErrorResult(port.ErrorMessage));
                    }
                    Model.TD_Order_WeiXinPay weiXinPay = new Model.TD_Order_WeiXinPay();
                    weiXinPay.OrderID   = model.OrderID.ToString();
                    weiXinPay.Timestamp = port.Timestamp;
                    weiXinPay.NonceStr  = port.NonceStr;
                    weiXinPay.Package   = port.Package;
                    weiXinPay.Status    = 0;
                    weiXinPay.PayTime   = now;
                    weiXinPayBLL.Add(weiXinPay);
                    ViewBag.ThirdPortConfig = new ThirdSharedInfo()
                    {
                        AppID        = port.AppID,
                        NonceStr     = port.NonceStr,
                        Timestamp    = port.Timestamp,
                        Package      = port.Package,
                        SignType     = port.SignType,
                        Signature    = port.Signature,
                        PaySignature = port.PaySignature
                    };
                }
                catch
                { }
                ViewBag.BackURL = HttpUtility.UrlEncode(url);
                return(View(model));
            }
            else
            {
                return(GotoErrorResult("订单状态有误"));
            }
        }
Ejemplo n.º 6
0
 public ActionResult Monitor()
 {
     if (Request.InputStream.Length > 0)
     {
         string xml = string.Empty;
         using (StreamReader reader = new StreamReader(Request.InputStream))
         {
             xml = reader.ReadToEnd();
         }
         WeiXinPayRequestXML request = XmlOperator.Derialize <WeiXinPayRequestXML>(xml);
         if (request.result_code.ToUpper() != "SUCCESS")
         {
             return(Content(""));
         }
         int    splitIndex = request.out_trade_no.IndexOf("_");
         string orderID    = request.out_trade_no;
         if (splitIndex > 0)
         {
             orderID = request.out_trade_no.Substring(0, splitIndex);
         }
         string where = string.Format("OrderID='{0}'", orderID);
         IList <Model.TD_Order_WeiXinPay> payList = weiXinPayBLL.GetList(where, "PayTime desc", null);
         int count = payList.Count((model) => { return(model.Status == 1); });
         if (count > 0)
         {
             return(PayOK());
         }
         var config = WeiXinConfig.GetConfig();
         count = payList.Count((model) => {
             if (model.OrderID == orderID &&
                 model.NonceStr == request.nonce_str &&
                 config.AppID == request.appid &&
                 config.ShopID == request.mch_id)
             {
                 return(true);
             }
             return(false);
         });
         if (count > 0)
         {
             Model.TD_Order_WeiXinPay pay = new Model.TD_Order_WeiXinPay();
             pay.OrderID       = orderID;
             pay.NonceStr      = request.nonce_str;
             pay.WeiXinOrderID = request.transaction_id;
             pay.OrderFee      = request.total_fee;
             pay.CashFee       = request.cash_fee;
             pay.Status        = 1;
             pay.CallBackTime  = DateTime.ParseExact(request.time_end, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
             int result = weiXinPayBLL.Sync(pay, orderID);
             if (result > 0)
             {
                 return(PayOK());
             }
             else
             {
                 return(PayFail());
             }
         }
         else
         {
             return(PayFail());
         }
     }
     return(Content(""));
 }