private void ProcessOrderAdd(HttpContext context)
        {
            OrderInfo orderInfo = new OrderInfo();

            try
            {
                string text = context.Request.Form["TaobaoOrderId"];
                if (string.IsNullOrEmpty(text) || ShoppingProcessor.IsExistOuterOrder("tb_" + text))
                {
                    context.Response.Write("0");
                }
                else
                {
                    orderInfo.OrderId      = this.GenerateOrderId();
                    orderInfo.OuterOrderId = "tb_" + context.Request.Form["TaobaoOrderId"];
                    orderInfo.Remark       = context.Request.Form["BuyerMemo"] + context.Request.Form["BuyerMessage"];
                    string text2 = context.Request.Form["SellerFlag"];
                    if (!string.IsNullOrEmpty(text2) && text2 != "0")
                    {
                        orderInfo.ManagerMark = (OrderMark)int.Parse(text2);
                    }
                    orderInfo.ManagerRemark = context.Request.Form["SellerMemo"];
                    orderInfo.OrderDate     = DateTime.Parse(context.Request.Form["OrderDate"]);
                    orderInfo.PayDate       = DateTime.Parse(context.Request.Form["PayDate"]);
                    orderInfo.UserId        = 1100;
                    OrderInfo orderInfo2 = orderInfo;
                    OrderInfo orderInfo3 = orderInfo;
                    string    text5      = orderInfo2.RealName = (orderInfo3.Username = context.Request.Form["Username"]);
                    orderInfo.EmailAddress   = context.Request.Form["EmailAddress"];
                    orderInfo.ShipTo         = context.Request.Form["ShipTo"];
                    orderInfo.ShippingRegion = context.Request.Form["ReceiverState"] + context.Request.Form["ReceiverCity"] + context.Request.Form["ReceiverDistrict"];
                    orderInfo.RegionId       = RegionHelper.GetRegionId(context.Request.Form["ReceiverDistrict"], context.Request.Form["ReceiverCity"], context.Request.Form["ReceiverState"]);
                    orderInfo.FullRegionPath = RegionHelper.GetFullPath(orderInfo.RegionId, true);
                    orderInfo.Address        = context.Request.Form["ReceiverAddress"];
                    orderInfo.TelPhone       = context.Request.Form["TelPhone"];
                    orderInfo.CellPhone      = context.Request.Form["CellPhone"];
                    OrderInfo orderInfo4 = orderInfo;
                    OrderInfo orderInfo5 = orderInfo;
                    int       num3       = orderInfo4.RealShippingModeId = (orderInfo5.ShippingModeId = 0);
                    OrderInfo orderInfo6 = orderInfo;
                    OrderInfo orderInfo7 = orderInfo;
                    text5 = (orderInfo6.RealModeName = (orderInfo7.ModeName = context.Request.Form["ModeName"]));
                    orderInfo.PaymentType      = "支付宝担宝交易";
                    orderInfo.Gateway          = "hishop.plugins.payment.alipayassure.assurerequest";
                    orderInfo.AdjustedDiscount = decimal.Zero;
                    string text8 = context.Request.Form["Products"];
                    if (string.IsNullOrEmpty(text8))
                    {
                        context.Response.Write("-1");
                    }
                    else
                    {
                        string[] array = text8.Split('|');
                        if (array.Length == 0)
                        {
                            context.Response.Write("-2");
                        }
                        else
                        {
                            string[] array2 = array;
                            decimal  num9;
                            foreach (string text9 in array2)
                            {
                                string[]     array3       = text9.Split(',');
                                LineItemInfo lineItemInfo = new LineItemInfo();
                                int          productId    = 0;
                                int.TryParse(array3[1], out productId);
                                int num4 = 1;
                                int.TryParse(array3[3], out num4);
                                lineItemInfo.SkuId     = array3[0];
                                lineItemInfo.ProductId = productId;
                                lineItemInfo.SKU       = array3[2];
                                LineItemInfo lineItemInfo2 = lineItemInfo;
                                LineItemInfo lineItemInfo3 = lineItemInfo;
                                num3 = (lineItemInfo2.Quantity = (lineItemInfo3.ShipmentQuantity = num4));
                                LineItemInfo lineItemInfo4 = lineItemInfo;
                                LineItemInfo lineItemInfo5 = lineItemInfo;
                                num9 = (lineItemInfo4.ItemCostPrice = (lineItemInfo5.ItemAdjustedPrice = decimal.Parse(array3[4])));
                                lineItemInfo.ItemListPrice   = decimal.Parse(array3[5]);
                                lineItemInfo.ItemDescription = HttpUtility.UrlDecode(array3[6]);
                                lineItemInfo.ThumbnailsUrl   = array3[7];
                                lineItemInfo.ItemWeight      = decimal.Zero;
                                lineItemInfo.SKUContent      = array3[8];
                                lineItemInfo.PromotionId     = 0;
                                lineItemInfo.PromotionName   = "";
                                orderInfo.ParentOrderId      = "0";
                                orderInfo.LineItems.Add(lineItemInfo.SkuId, lineItemInfo);
                            }
                            OrderInfo orderInfo8 = orderInfo;
                            OrderInfo orderInfo9 = orderInfo;
                            num9 = (orderInfo8.AdjustedFreight = (orderInfo9.Freight = decimal.Parse(context.Request.Form["PostFee"])));
                            orderInfo.OrderStatus = OrderStatus.BuyerAlreadyPaid;
                            orderInfo.OrderSource = OrderSource.Taobao;
                            if (ShoppingProcessor.CreatOrder(orderInfo))
                            {
                                context.Response.Write("1");
                            }
                            else
                            {
                                context.Response.Write("0");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NameValueCollection nameValueCollection = new NameValueCollection
                {
                    HttpContext.Current.Request.Form,
                    HttpContext.Current.Request.QueryString
                };
                nameValueCollection.Add("ErrorMessage", ex.Message);
                nameValueCollection.Add("StackTrace", ex.StackTrace);
                if (ex.InnerException != null)
                {
                    nameValueCollection.Add("InnerException", ex.InnerException.ToString());
                }
                if (ex.GetBaseException() != null)
                {
                    nameValueCollection.Add("BaseException", ex.GetBaseException().Message);
                }
                if (ex.TargetSite != (MethodBase)null)
                {
                    nameValueCollection.Add("TargetSite", ex.TargetSite.ToString());
                }
                nameValueCollection.Add("ExSource", ex.Source);
                Globals.AppendLog(nameValueCollection, "", "", HttpContext.Current.Request.Url.ToString(), "TaobaoOrder");
            }
        }
Esempio n. 2
0
        public void btnCreateOrder_Click(object sender, EventArgs e)
        {
            if (ValidateCreateOrder())
            {
                OrderInfo orderInfo = GetOrderInfo(shoppingCart);

                if (shoppingCart.Quantity > 1)
                {
                    isSignBuy = false;
                }

                if (orderInfo == null)
                {
                    ShowMessage("购物车中已经没有任何商品", false);
                }
                else if (!HiContext.Current.User.IsAnonymous && (shoppingCart.GetTotalNeedPoint() > ((Member)HiContext.Current.User).Points))
                {
                    ShowMessage("您当前的积分不够兑换所需积分!", false);
                }
                else if (isCountDown && (ProductBrowser.GetCountDownInfo(shoppingCart.LineItems[productSku].ProductId).EndDate < DateTime.Now))
                {
                    ShowMessage("此订单为抢购订单,但抢购时间已到!", false);
                }
                else
                {
                    try
                    {
                        if (ShoppingProcessor.CreatOrder(orderInfo))
                        {
                            Messenger.OrderCreated(orderInfo, HiContext.Current.User);
                            orderInfo.OnCreated();
                            if (shoppingCart.GetTotalNeedPoint() > 0)
                            {
                                ShoppingProcessor.CutNeedPoint(shoppingCart.GetTotalNeedPoint());
                            }
                            if ((!isCountDown && !isGroupBuy) && !isSignBuy)
                            {
                                ShoppingCartProcessor.ClearShoppingCart();
                            }
                            if (!HiContext.Current.User.IsAnonymous && (PersonalHelper.GetShippingAddressCount(HiContext.Current.User.UserId) == 0))
                            {
                                ShippingAddressInfo shippingAddress = new ShippingAddressInfo();
                                shippingAddress.UserId    = HiContext.Current.User.UserId;
                                shippingAddress.ShipTo    = Globals.HtmlEncode(txtShipTo.Text);
                                shippingAddress.RegionId  = dropRegions.GetSelectedRegionId().Value;
                                shippingAddress.Address   = Globals.HtmlEncode(txtAddress.Text);
                                shippingAddress.Zipcode   = txtZipcode.Text;
                                shippingAddress.CellPhone = txtCellPhone.Text;
                                shippingAddress.TelPhone  = txtTelPhone.Text;
                                PersonalHelper.CreateShippingAddress(shippingAddress);
                            }
                            Page.Response.Redirect(Globals.GetSiteUrls().UrlData.FormatUrl("FinishOrder", new object[] { orderInfo.OrderId }));
                        }
                    }
                    catch (Exception exception)
                    {
                        ShowMessage(exception.ToString(), false);
                    }
                }
            }
        }
Esempio n. 3
0
        private void Down(HttpContext context)
        {
            string parameter = base.GetParameter(context, "ids", true);

            if (context.Session["jdOrder"] != null && !string.IsNullOrEmpty(parameter))
            {
                string text = "";
                text = parameter;
                string[] idArray = text.Split(',');
                PageModel <JDOrderModel> pageModel = (PageModel <JDOrderModel>)context.Session["jdOrder"];
                int i;
                for (i = 0; i < idArray.Length; i++)
                {
                    JDOrderModel jDOrderModel = ((List <JDOrderModel>) pageModel.Models).Find(delegate(JDOrderModel jdOrder)
                    {
                        if (jdOrder.OrderId.Equals(idArray[i]))
                        {
                            return(true);
                        }
                        return(false);
                    });
                    if (jDOrderModel != null)
                    {
                        OrderInfo orderInfo = new OrderInfo();
                        try
                        {
                            if (!ShoppingProcessor.IsExistOuterOrder("jd_" + jDOrderModel.OrderId))
                            {
                                orderInfo.OrderId       = this.GenerateOrderId();
                                orderInfo.OuterOrderId  = "jd_" + jDOrderModel.OrderId;
                                orderInfo.Remark        = jDOrderModel.OrderReMark;
                                orderInfo.ManagerRemark = jDOrderModel.OrderManagerReMark;
                                orderInfo.OrderDate     = DateTime.Parse(jDOrderModel.CreatedAt);
                                orderInfo.PayDate       = DateTime.Parse(jDOrderModel.ModifyAt);
                                orderInfo.UserId        = 1100;
                                OrderInfo orderInfo2 = orderInfo;
                                OrderInfo orderInfo3 = orderInfo;
                                string    text3      = orderInfo2.RealName = (orderInfo3.Username = jDOrderModel.Consignee.FullName);
                                orderInfo.EmailAddress   = "";
                                orderInfo.ShipTo         = jDOrderModel.Consignee.FullName;
                                orderInfo.ShippingRegion = jDOrderModel.Consignee.Province + jDOrderModel.Consignee.City + jDOrderModel.Consignee.County;
                                orderInfo.RegionId       = RegionHelper.GetRegionId(jDOrderModel.Consignee.County, jDOrderModel.Consignee.City, jDOrderModel.Consignee.Province);
                                orderInfo.FullRegionPath = RegionHelper.GetFullPath(orderInfo.RegionId, true);
                                orderInfo.Address        = jDOrderModel.Consignee.FullAddress;
                                orderInfo.TelPhone       = jDOrderModel.Consignee.Telephone;
                                orderInfo.CellPhone      = jDOrderModel.Consignee.Mobile;
                                orderInfo.ZipCode        = "";
                                OrderInfo orderInfo4 = orderInfo;
                                OrderInfo orderInfo5 = orderInfo;
                                int       num3       = orderInfo4.RealShippingModeId = (orderInfo5.ShippingModeId = 0);
                                OrderInfo orderInfo6 = orderInfo;
                                OrderInfo orderInfo7 = orderInfo;
                                text3 = (orderInfo6.RealModeName = (orderInfo7.ModeName = ""));
                                orderInfo.PaymentType      = jDOrderModel.PayType;
                                orderInfo.Gateway          = "";
                                orderInfo.AdjustedDiscount = decimal.Zero;
                                if (jDOrderModel.Products.Count > 0)
                                {
                                    decimal num8;
                                    foreach (JDOrderItemModel product in jDOrderModel.Products)
                                    {
                                        LineItemInfo lineItemInfo = new LineItemInfo();
                                        lineItemInfo.SkuId     = product.SkuId;
                                        lineItemInfo.ProductId = Convert.ToInt32(product.ProductId);
                                        lineItemInfo.SKU       = "";
                                        LineItemInfo lineItemInfo2 = lineItemInfo;
                                        LineItemInfo lineItemInfo3 = lineItemInfo;
                                        num3 = (lineItemInfo2.Quantity = (lineItemInfo3.ShipmentQuantity = Convert.ToInt32(product.Total)));
                                        LineItemInfo lineItemInfo4 = lineItemInfo;
                                        LineItemInfo lineItemInfo5 = lineItemInfo;
                                        num8 = (lineItemInfo4.ItemCostPrice = (lineItemInfo5.ItemAdjustedPrice = decimal.Parse(product.Price)));
                                        lineItemInfo.ItemListPrice   = decimal.Parse(product.Price);
                                        lineItemInfo.ItemDescription = "";
                                        lineItemInfo.ThumbnailsUrl   = "";
                                        lineItemInfo.ItemWeight      = decimal.Zero;
                                        lineItemInfo.SKUContent      = product.SkuName;
                                        lineItemInfo.PromotionId     = 0;
                                        lineItemInfo.PromotionName   = "";
                                        orderInfo.LineItems.Add(lineItemInfo.SkuId, lineItemInfo);
                                    }
                                    OrderInfo orderInfo8 = orderInfo;
                                    OrderInfo orderInfo9 = orderInfo;
                                    num8 = (orderInfo8.AdjustedFreight = (orderInfo9.Freight = decimal.Parse(jDOrderModel.Freight)));
                                    orderInfo.OrderStatus = OrderStatus.BuyerAlreadyPaid;
                                    orderInfo.OrderSource = OrderSource.JD;
                                    if (ShoppingProcessor.CreatOrder(orderInfo))
                                    {
                                        jDOrderModel.IsExsit = true;
                                        jDOrderModel.Status  = "已下载";
                                    }
                                    else
                                    {
                                        jDOrderModel.Status = "下载失败";
                                    }
                                    continue;
                                }
                                goto end_IL_00c4;
                            }
                            return;

                            end_IL_00c4 :;
                        }
                        catch (Exception ex)
                        {
                            NameValueCollection param = new NameValueCollection
                            {
                                HttpContext.Current.Request.Form,
                                HttpContext.Current.Request.QueryString
                            };
                            Globals.WriteExceptionLog_Page(ex, param, "JDOrder");
                            continue;
                        }
                        break;
                    }
                }
                base.ReturnSuccessResult(context, "操作完成", 0, true);
                return;
            }
            throw new HidistroAshxException("无数据");
        }
Esempio n. 4
0
        /// <summary>
        /// 提交到订货列表按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBuy_Click(object sender, System.EventArgs e)
        {
            this.btnBuy.Enabled = false;                                    //禁用当前按钮
            ManagerInfo currentManager = ManagerHelper.GetCurrentManager(); //当前登录用户信息

            if (currentManager != null /*&& currentManager.ClientUserId > 0*/)
            {
                string strSkuIds     = string.Empty; //存储所有订购商品的SkuId,用于操作后清除待选列表Erp_AgentProduct表数据
                int    shipaddressId = 0;            //送货地址Id
                int    givemodeId    = 0;            //配送方式Id
                int    paymodeId     = 0;            //支付方式Id

                ShoppingCartInfo shoppingCart = null;

                OrderInfo  orderInfo     = new OrderInfo();
                MemberInfo currentMember = MemberHelper.GetMember(currentManager.ClientUserId);
                foreach (System.Web.UI.WebControls.GridViewRow row in this.grdProducts.Rows)
                {
                    //decimal total = 0;
                    decimal price     = 0;                                                                                                 //单价
                    int     resultNum = 0;                                                                                                 //数量

                    System.Web.UI.WebControls.HiddenField txtboxvalue = (System.Web.UI.WebControls.HiddenField)row.FindControl("hiValue"); //得到SkuId
                    //System.Web.UI.WebControls.HiddenField txtboxproduct = (System.Web.UI.WebControls.HiddenField)row.FindControl("hiProductId");//得到ProductId
                    System.Web.UI.WebControls.Literal litSalePrice = (System.Web.UI.WebControls.Literal)row.FindControl("litSalePrice");

                    if (int.TryParse(txtboxvalue.Value.Trim(), out resultNum) && decimal.TryParse(litSalePrice.Text, out price))
                    {
                        string skuId = this.grdProducts.DataKeys[row.RowIndex].Value.ToString();
                        strSkuIds += "'" + skuId + "',";//累加SkuId值并用'',''分割
                        if (!string.IsNullOrEmpty(skuId))
                        {
                            //首先将商品插入购物车
                            //后台订单的购物车处理
                            int pcUserid = 0;
                            if (Hidistro.ControlPanel.Config.CustomConfigHelper.Instance.RegionalFunction && ManagerHelper.GetCurrentManager() != null)
                            {
                                int categoryId = CategoryBrowser.GetCategoryIdBySkuId(skuId);
                                pcUserid = currentManager.UserId;
                                ShoppingCartProcessor.AddLineItemPC(skuId, resultNum, categoryId, pcUserid);
                            }


                            //total += price * resultNum;//计算合计
                            //生成订单项

                            //shoppingCart = ShoppingCartProcessor.GetGroupBuyShoppingCart(currentMember, price, skuId, resultNum);
                            shoppingCart = ShoppingCartProcessor.GetShoppingCart(currentManager.UserId);
                            if (shoppingCart != null && shoppingCart.LineItems != null && shoppingCart.LineItems.Count > 0)
                            {
                                foreach (ShoppingCartItemInfo info2 in shoppingCart.LineItems)
                                {
                                    LineItemInfo info3 = new LineItemInfo
                                    {
                                        SkuId             = info2.SkuId,
                                        ProductId         = info2.ProductId,
                                        SKU               = info2.SKU,
                                        Quantity          = info2.Quantity,
                                        ShipmentQuantity  = info2.ShippQuantity,
                                        ItemCostPrice     = new SkuDao().GetSkuItem(info2.SkuId).CostPrice,
                                        ItemListPrice     = info2.MemberPrice,
                                        ItemAdjustedPrice = info2.AdjustedPrice,
                                        ItemDescription   = info2.Name,
                                        ThumbnailsUrl     = info2.ThumbnailUrl40,
                                        ItemWeight        = info2.Weight,
                                        SKUContent        = info2.SkuContent,
                                        PromotionId       = info2.PromotionId,
                                        PromotionName     = info2.PromotionName,
                                        MainCategoryPath  = info2.MainCategoryPath
                                    };
                                    orderInfo.LineItems.Add(info3.SkuId, info3);
                                }
                            }
                            else
                            {
                                this.ShowMsg("订单生成失败。", true);
                                this.btnBuy.Enabled = true;//启用当前按钮
                                return;
                            }
                        }
                    }
                }
                //一个商品数量都没输入,则退出
                if (string.IsNullOrEmpty(strSkuIds))
                {
                    this.ShowMsg("请输入商品数量。", true);
                    this.btnBuy.Enabled = true;//启用当前按钮
                    return;
                }

                //送货地址
                if (int.TryParse(this.userAddress.SelectedValue, out shipaddressId))
                {
                    ShippingAddressInfo shippingAddress = MemberProcessor.GetShippingAddress(shipaddressId, Convert.ToInt32("99999" + currentManager.UserId.ToString()));//(shipaddressId, currentMember.UserId);
                    if (shippingAddress != null)
                    {
                        //this.userAddress.SelectedItem.Text
                        orderInfo.ShippingRegion = RegionHelper.GetFullRegion(shippingAddress.RegionId, ",");
                        orderInfo.RegionId       = shippingAddress.RegionId;
                        orderInfo.Address        = shippingAddress.Address;
                        orderInfo.ZipCode        = shippingAddress.Zipcode;
                        orderInfo.ShipTo         = shippingAddress.ShipTo;
                        orderInfo.TelPhone       = shippingAddress.TelPhone;
                        orderInfo.CellPhone      = shippingAddress.CellPhone;
                        MemberProcessor.SetDefaultShippingAddress(shipaddressId, Convert.ToInt32("99999" + currentManager.UserId.ToString()));
                    }
                }
                //配送方式
                if (int.TryParse(this.userGiveMode.SelectedValue, out givemodeId))
                {
                    ShippingModeInfo shippingMode = ShoppingProcessor.GetShippingMode(givemodeId, true);
                    if (shippingMode != null)
                    {
                        orderInfo.ShippingModeId = shippingMode.ModeId;
                        orderInfo.ModeName       = shippingMode.Name;
                        if (shoppingCart.LineItems.Count != shoppingCart.LineItems.Count((ShoppingCartItemInfo a) => a.IsfreeShipping))
                        {
                            orderInfo.AdjustedFreight = (orderInfo.Freight = ShoppingProcessor.CalcFreight(orderInfo.RegionId, shoppingCart.Weight, shippingMode));
                        }
                        else
                        {
                            orderInfo.AdjustedFreight = (orderInfo.Freight = 0m);
                        }
                    }
                }
                //支付方式
                if (int.TryParse(this.userPayMode.SelectedValue, out paymodeId))
                {
                    orderInfo.PaymentTypeId = paymodeId;
                    switch (paymodeId)
                    {
                    //case -1:
                    //case 0:
                    //    {
                    //        orderInfo.PaymentType = "货到付款";
                    //        orderInfo.Gateway = "hishop.plugins.payment.podrequest";
                    //        break;
                    //    }
                    //case 88:
                    //    {
                    //        orderInfo.PaymentType = "微信支付";
                    //        orderInfo.Gateway = "hishop.plugins.payment.weixinrequest";
                    //        break;
                    //    }
                    case 99:
                    {
                        orderInfo.PaymentType = "线下付款";
                        orderInfo.Gateway     = "hishop.plugins.payment.offlinerequest";
                        break;
                    }

                    default:
                    {
                        PaymentModeInfo paymentMode = ShoppingProcessor.GetPaymentMode(paymodeId);
                        if (paymentMode != null)
                        {
                            orderInfo.PaymentTypeId = paymentMode.ModeId;
                            orderInfo.PaymentType   = paymentMode.Name;
                            orderInfo.Gateway       = paymentMode.Gateway;
                        }
                        break;
                    }
                    }
                }
                orderInfo.OrderId   = this.GenerateOrderId(currentManager.UserId); //生成ID
                orderInfo.OrderDate = System.DateTime.Now;                         //当前时间
                //基本信息
                orderInfo.OrderStatus    = OrderStatus.WaitBuyerPay;
                orderInfo.RefundStatus   = RefundStatus.None;
                orderInfo.ShipToDate     = "时间不限";
                orderInfo.ReferralUserId = 0;//订单的所属分销ID,没有就设置为0

                //代理商用户相关信息
                orderInfo.UserId       = Convert.ToInt32("99999" + currentManager.UserId.ToString()); //currentMember.UserId;
                orderInfo.Username     = currentManager.UserName;                                     //currentMember.UserName;
                orderInfo.EmailAddress = currentManager.Email;                                        //currentMember.Email;

                //orderInfo.RealName = currentMember.RealName;
                orderInfo.RealName = currentManager.AgentName;//存储用户后台昵称

                //orderInfo.QQ = currentMember.QQ;
                orderInfo.Remark      = this.txtOrderRemark.Text; //得到前端TextBox值
                orderInfo.OrderSource = 1;                        //来源代理商采购
                this.SetOrderItemStatus(orderInfo);



                if (ShoppingProcessor.CreatOrder(orderInfo))
                {
                    ShoppingCartProcessor.ClearShoppingCartPC();
                    //订单生成成功后清空
                    strSkuIds = strSkuIds.TrimEnd(',');
                    //清除已经订购的商品在订购列表中
                    ProductBrowser.DeleteAgentProduct(strSkuIds, currentManager.UserId);

                    this.ShowMsg("订单生成成功,请尽快完成支付。", true);
                }
                else
                {
                    this.ShowMsg("订单生成失败。", true);
                }

                //HiCache.Remove("DataCache-Categories");//刷前台缓存
                this.BindProducts();
            }
            else
            {
                this.ShowMsg("当前登录用户不是前端用户升级而来,无法进行生成订单操作。", true);
            }
            this.btnBuy.Enabled = true;//启用当前按钮
        }
Esempio n. 5
0
 public void btnCreateOrder_Click(object sender, System.EventArgs e)
 {
     if (this.ValidateCreateOrder())
     {
         OrderInfo orderInfo = this.GetOrderInfo(this.shoppingCart);
         if (this.shoppingCart.GetQuantity() > 1)
         {
             this.isSignBuy = false;
         }
         if (orderInfo == null)
         {
             this.ShowMessage("购物车中已经没有任何商品", false);
         }
         else
         {
             if (orderInfo.GetTotal() < 0m)
             {
                 this.ShowMessage("订单金额不能为负", false);
             }
             else
             {
                 if (!Hidistro.Membership.Context.HiContext.Current.User.IsAnonymous)
                 {
                     int totalNeedPoint = this.shoppingCart.GetTotalNeedPoint();
                     int points         = ((Hidistro.Membership.Context.Member)Hidistro.Membership.Context.HiContext.Current.User).Points;
                     if (points >= 0 && totalNeedPoint > points)
                     {
                         this.ShowMessage("您当前的积分不够兑换所需积分!", false);
                         return;
                     }
                 }
                 if (this.isCountDown)
                 {
                     CountDownInfo countDownInfo = ProductBrowser.GetCountDownInfo(this.shoppingCart.LineItems[this.productSku].ProductId);
                     if (countDownInfo.EndDate < System.DateTime.Now)
                     {
                         this.ShowMessage("此订单为抢购订单,但抢购时间已到!", false);
                         return;
                     }
                     if (this.shoppingCart.LineItems[this.productSku].Quantity > countDownInfo.MaxCount)
                     {
                         this.ShowMessage("你购买的数量超过限购数量:" + countDownInfo.MaxCount.ToString(), false);
                         return;
                     }
                     int num = ShoppingProcessor.CountDownOrderCount(this.shoppingCart.LineItems[this.productSku].ProductId);
                     if (num + this.shoppingCart.LineItems[this.productSku].Quantity > countDownInfo.MaxCount)
                     {
                         this.ShowMessage(string.Format("你已经抢购过该商品{0}件,每个用户只允许抢购{1}件,如果你有未付款的抢购单,请及时支付!", num, countDownInfo.MaxCount), false);
                         return;
                     }
                 }
                 try
                 {
                     if (ShoppingProcessor.CreatOrder(orderInfo))
                     {
                         Messenger.OrderCreated(orderInfo, Hidistro.Membership.Context.HiContext.Current.User);
                         orderInfo.OnCreated();
                         if (this.shoppingCart.GetTotalNeedPoint() > 0)
                         {
                             ShoppingProcessor.CutNeedPoint(this.shoppingCart.GetTotalNeedPoint(), orderInfo.OrderId);
                         }
                         if (!this.isCountDown && !this.isGroupBuy && !this.isSignBuy && !this.isBundling)
                         {
                             ShoppingCartProcessor.ClearShoppingCart();
                         }
                         if (!Hidistro.Membership.Context.HiContext.Current.User.IsAnonymous && PersonalHelper.GetShippingAddressCount(Hidistro.Membership.Context.HiContext.Current.User.UserId) == 0)
                         {
                             PersonalHelper.CreateShippingAddress(new ShippingAddressInfo
                             {
                                 UserId    = Hidistro.Membership.Context.HiContext.Current.User.UserId,
                                 ShipTo    = Globals.HtmlEncode(this.txtShipTo.Text),
                                 RegionId  = this.dropRegions.GetSelectedRegionId().Value,
                                 Address   = Globals.HtmlEncode(this.txtAddress.Text),
                                 Zipcode   = this.txtZipcode.Text,
                                 CellPhone = this.txtCellPhone.Text,
                                 TelPhone  = this.txtTelPhone.Text
                             });
                         }
                         this.Page.Response.Redirect(Globals.GetSiteUrls().UrlData.FormatUrl("FinishOrder", new object[]
                         {
                             orderInfo.OrderId
                         }));
                     }
                 }
                 catch (System.Exception ex)
                 {
                     this.ShowMessage(ex.ToString(), false);
                 }
             }
         }
     }
 }