Exemple #1
0
        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            #region 获取商品规格信息,构造购物车信息
            //实例化购物车
            ShoppingCartInfo shoppingCartInfo = new ShoppingCartInfo();

            //实例化SKU信息
            SkuItemInfo skuItemInfo = new SkuItemInfo();

            List <SkuInfo> skuInfoList           = new List <SkuInfo>();
            List <ShoppingCartItemInfo> itemInfo = new List <ShoppingCartItemInfo>();

            //区县Id
            int regionId = 0;
            int.TryParse(txtRegionId.Text, out regionId);
            if (regionId == 0 && dropRegions.GetSelectedRegionId() != null && this.dropRegions.GetSelectedRegionId().Value > 0)
            {
                regionId = this.dropRegions.GetSelectedRegionId().Value;
            }

            string skuList = !string.IsNullOrWhiteSpace(hiddenSkus.Value) ? hiddenSkus.Value : "";

            if (!string.IsNullOrEmpty(skuList))
            {
                skuItemInfo.skuInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <SkuInfo[]>(skuList);
            }

            if (skuItemInfo != null && skuItemInfo.skuInfo != null && skuItemInfo.skuInfo.Count() > 0)
            {
                skuInfoList = skuItemInfo.skuInfo.OrderByDescending(a => a.SkuId).ToList();
            }
            string skuIdStr = "";

            if (skuInfoList.Count > 0)
            {
                skuInfoList.ForEach(a => { skuIdStr += "'" + a.SkuId + "'" + ","; });
            }

            if (!string.IsNullOrEmpty(skuIdStr) && skuIdStr.Length > 0)
            {
                skuIdStr = skuIdStr.Substring(0, skuIdStr.Length - 1);
                skuIdStr = "(" + skuIdStr + ")";

                itemInfo = ShoppingProcessor.GetSkuList(skuIdStr).ToList();
            }

            if (itemInfo.Count > 0)
            {
                //循环处理
                itemInfo.ForEach(a =>
                {
                    skuInfoList.ForEach(b =>
                    {
                        if (b.SkuId == a.SkuId)
                        {
                            a.Quantity      = b.BuyQty;
                            a.ShippQuantity = b.BuyQty;
                        }
                    });
                });
            }
            #endregion

            //收货地址ID
            int shippingId = 0;
            int.TryParse(txtShippingId.Text, out shippingId);
            //身份证号码
            string identityCard = txtIdentityCard.Text.Trim();
            //用户ID
            int userId = 0;
            int.TryParse(txtUserId.Text, out userId);
            //手机号码
            string cellPhone = txtCellPhone.Text.Trim();
            //收货人姓名
            string shipTo = txtShipTo.Text.Trim();
            //地址
            string address     = txtDetailsAddress.Text.Trim();
            string addressproc = "";
            if (!string.IsNullOrEmpty(dropRegions.SelectedRegions))
            {
                addressproc = (dropRegions.SelectedRegions).Replace(",", "") + address;
            }
            //邮政编码
            string zipcode = txtZipcode.Text.Trim();
            //电话号码
            string telPhone = txtTelPhone.Text.Trim();
            //用户名
            string username = txtUserName.Text.Trim();

            #region 新增或修改收货地址信息
            ShippingAddressInfo shippingAddress = new ShippingAddressInfo()
            {
                ShipTo       = shipTo,
                Address      = addressproc,
                Zipcode      = zipcode,
                TelPhone     = telPhone,
                CellPhone    = cellPhone,
                IdentityCard = identityCard,
                IsDefault    = true,
                RegionId     = regionId,
                UserId       = userId,
                ShippingId   = shippingId
            };

            //如果没有选择收获地址,那么新增一个用户,手机号作为用户名,密码为手机号
            int newUserId = 0;
            if (userId == 0)
            {
                Member member = new Member(UserRole.Member);
                member.GradeId             = MemberProcessor.GetDefaultMemberGrade();
                member.SessionId           = Globals.GetGenerateId();
                member.Username            = cellPhone;
                member.Email               = "";// cellPhone + "@mail.haimylife.com";
                member.Password            = cellPhone;
                member.PasswordFormat      = MembershipPasswordFormat.Hashed;
                member.TradePasswordFormat = MembershipPasswordFormat.Hashed;
                member.TradePassword       = cellPhone;
                member.IsApproved          = true;
                member.RealName            = string.Empty;
                member.Address             = string.Empty;
                CreateUserStatus createUserStatus = MemberProcessor.CreateMember(member);
                if (createUserStatus == CreateUserStatus.DuplicateUsername || createUserStatus == CreateUserStatus.DisallowedUsername)
                {
                    ErrorLog.Write("用户名重复,用户名为:" + member.Username);
                }
                if (createUserStatus == CreateUserStatus.DuplicateEmailAddress)
                {
                    ErrorLog.Write("邮件名重复,邮箱为:" + member.Email);
                }
                if (createUserStatus == CreateUserStatus.Created)
                {
                    newUserId = member.UserId;
                    userId    = member.UserId;
                }
            }

            int newShippingId = 0;

            //新增或修改收货地址信息
            int addressResult = MemberProcessor.AddOrUpdateShippingAddress(shippingAddress, newUserId, out newShippingId);
            if (addressResult > 0)
            {
                ErrorLog.Write("新增或修改收货地址信息成功,收获地址Id[newShippingId]" + newShippingId);
            }

            #endregion


            itemInfo.ForEach(a =>
            {
                //门店Id为当前登录用户的Id
                a.StoreId = HiContext.Current.User.UserId;
                a.UserId  = userId;
                shoppingCartInfo.LineItems.Add(a);
            });

            //获取订单信息
            OrderInfo orderInfo = ShoppingProcessor.ConvertShoppingCartToOrder(shoppingCartInfo, false, false, false, userId);
            if (orderInfo != null)
            {
                orderInfo.OrderId   = this.GenerateOrderId();
                orderInfo.OrderDate = System.DateTime.Now;
                orderInfo.UserId    = userId;

                if (!string.IsNullOrEmpty(username))
                {
                    orderInfo.Username = username;
                }
                else
                {
                    orderInfo.Username = cellPhone;
                }
                orderInfo.EmailAddress = "";
                orderInfo.RealName     = "";
                orderInfo.QQ           = "";
                orderInfo.Remark       = txtBak.Text.Trim();
                //站点默认为深圳
                orderInfo.SiteId       = 0;
                orderInfo.IdentityCard = identityCard;
                orderInfo.OrderStatus  = OrderStatus.WaitBuyerPay;
                orderInfo.RefundStatus = RefundStatus.None;
                orderInfo.ShipToDate   = DateTime.Now.ToString();
                //门店Id
                int userStoreId = ManagerHelper.GetStoreIdByUserId(HiContext.Current.User.UserId);
                orderInfo.StoreId = userStoreId;

                if (!string.IsNullOrEmpty(txtDeductible.Text.Trim()))
                {
                    orderInfo.Deductible = Decimal.Parse(txtDeductible.Text.Trim());
                }


                if (shippingAddress != null)
                {
                    #region 验证每人每日最多消费1000元,1000元以上为单件商品
                    int mayCount = 0;
                    foreach (ShoppingCartItemInfo item in shoppingCartInfo.LineItems)
                    {
                        mayCount += item.Quantity;
                        //#region 验证库存
                        int stock = ShoppingProcessor.GetProductStock(item.SkuId);
                        if (stock <= 0 || stock < item.Quantity)
                        {
                            this.ShowMsg("商品库存不足!商品名称为:" + item.Name, false);
                            return;
                        }
                    }
                    #endregion

                    #region 验证是否符合清关条件
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < shoppingCartInfo.LineItems.Count; i++)
                    {
                        if (i == (shoppingCartInfo.LineItems.Count - 1))
                        {
                            sb.Append(shoppingCartInfo.LineItems[i].ProductId);
                        }
                        else
                        {
                            sb.AppendFormat("{0},", shoppingCartInfo.LineItems[i].ProductId);
                        }
                    }
                    bool b = ShoppingProcessor.CheckIsCustomsClearance(sb.ToString());
                    if (b)
                    {
                        orderInfo.IsCustomsClearance = 1;
                        if (string.IsNullOrEmpty(identityCard))
                        {
                            Member memberNew = Users.GetUser(HiContext.Current.User.UserId, false) as Member;
                            identityCard = memberNew.IdentityCard;
                        }
                        if (string.IsNullOrEmpty(identityCard))
                        {
                            this.ShowMsg("有需要清关的商品,身份证号码不能为空,请到个人资料里面填写身份信息!", false);
                            return;
                        }
                    }
                    else
                    {
                        orderInfo.IsCustomsClearance = 0;
                    }
                    #endregion

                    orderInfo.ShippingRegion = RegionHelper.GetFullRegion(regionId, ",");
                    orderInfo.RegionId       = regionId;
                    orderInfo.Address        = address;
                    orderInfo.ZipCode        = zipcode;
                    orderInfo.ShipTo         = shipTo;
                    orderInfo.TelPhone       = telPhone;
                    orderInfo.CellPhone      = cellPhone;

                    orderInfo.ShippingId = shippingId <= 0 ? newShippingId : shippingId;
                }

                //配送方式
                orderInfo.ShippingModeId = ddlshippingMode.SelectedValue > 0 ? (int)ddlshippingMode.SelectedValue : 0;
                orderInfo.ModeName       = !string.IsNullOrEmpty(ddlshippingMode.SelectedItem.Text) ? ddlshippingMode.SelectedItem.Text : "";
                decimal tax     = 0m;
                decimal freight = 0m;

                Dictionary <int, decimal> dictShippingMode = new Dictionary <int, decimal>();
                if (shoppingCartInfo.LineItems.Count != shoppingCartInfo.LineItems.Count((ShoppingCartItemInfo a) => a.IsfreeShipping) && !shoppingCartInfo.IsFreightFree)
                {
                    foreach (ShoppingCartItemInfo item in shoppingCartInfo.LineItems)
                    {
                        tax += item.AdjustedPrice * item.TaxRate * item.Quantity;
                        if ((!item.IsfreeShipping))
                        {
                            if (item.TemplateId > 0)
                            {
                                if (dictShippingMode.ContainsKey(item.TemplateId))
                                {
                                    dictShippingMode[item.TemplateId] += item.Weight * item.Quantity;
                                }
                                else
                                {
                                    dictShippingMode.Add(item.TemplateId, item.Weight * item.Quantity);
                                }
                            }
                        }
                    }
                    foreach (var item in dictShippingMode)
                    {
                        ShippingModeInfo shippingMode = ShoppingProcessor.GetShippingMode(item.Key);
                        freight += ShoppingProcessor.CalcFreight(shippingAddress.RegionId, item.Value, shippingMode);
                    }
                    //运费需要减去优惠
                    orderInfo.Freight     = freight;
                    orderInfo.Tax         = tax <= 50 ? 0 : tax;
                    orderInfo.OriginalTax = tax;
                }
                else
                {
                    orderInfo.Freight = 0m;
                }
                orderInfo.AdjustedFreight = orderInfo.Freight;

                int num = ddlpayment.SelectedValue > 0 ? (int)ddlpayment.SelectedValue:0;
                orderInfo.PaymentTypeId = num;
                if (num == 16)
                {
                    orderInfo.PaymentType = "线下支付";
                    orderInfo.Gateway     = "Ecdev.plugins.payment.bankrequest";
                }
                else
                {
                    PaymentModeInfo paymentMode = ShoppingProcessor.GetPaymentMode(num);
                    if (paymentMode != null)
                    {
                        orderInfo.PaymentTypeId = paymentMode.ModeId;
                        orderInfo.PaymentType   = paymentMode.Name;
                        orderInfo.Gateway       = paymentMode.Gateway;
                    }
                }

                orderInfo.OrderSource = OrderSource.storeAdd;

                try
                {
                    orderInfo.OrderType = (int)OrderType.Normal;

                    if (ShoppingProcessor.CreateOrder(orderInfo, true, true))
                    {
                        Reset();
                        //this.ShowMsg("添加门店订单成功", true);
                        string url = Globals.GetAdminAbsolutePath("/sales/StoreManageOrder.aspx");
                        //清除前端的cookie
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ClearsCookie();alert('添加门店订单成功');window.location.href='" + url + "';</script>");
                        //base.Response.Redirect(Globals.GetAdminAbsolutePath("'/sales/StoreManageOrder.aspx'"), true);
                    }
                    else
                    {
                        this.ShowMsg("添加门店订单失败!", false);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ErrorLog.Write("后台成功添加门店订单错误:", Newtonsoft.Json.JsonConvert.SerializeObject(orderInfo), ex);
                }
            }
        }
        protected override void AttachChildControls()
        {
            this.litShipTo            = (System.Web.UI.WebControls.Literal) this.FindControl("litShipTo");
            this.litCellPhone         = (System.Web.UI.WebControls.Literal) this.FindControl("litCellPhone");
            this.litAddress           = (System.Web.UI.WebControls.Literal) this.FindControl("litAddress");
            this.rptCartProducts      = (WapTemplatedRepeater)this.FindControl("rptCartProducts");
            this.dropCoupon           = (WAP_CouponSelect)this.FindControl("dropCoupon");
            this.litOrderTotal        = (System.Web.UI.WebControls.Literal) this.FindControl("litOrderTotal");
            this.litPromotionPrice    = (System.Web.UI.WebControls.Literal) this.FindControl("litPromotionPrice");
            this.groupbuyHiddenBox    = (System.Web.UI.HtmlControls.HtmlInputControl) this.FindControl("groupbuyHiddenBox");
            this.selectShipTo         = (System.Web.UI.HtmlControls.HtmlInputHidden) this.FindControl("selectShipTo");
            this.regionId             = (System.Web.UI.HtmlControls.HtmlInputHidden) this.FindControl("regionId");
            this.litProductTotalPrice = (System.Web.UI.WebControls.Literal) this.FindControl("litProductTotalPrice");
            this.rptPromotions        = (WapTemplatedRepeater)this.FindControl("rptPromotions");
            this.litTotalTax          = (System.Web.UI.WebControls.Literal) this.FindControl("litTotalTax");
            this.litToalFreight       = (System.Web.UI.WebControls.Literal) this.FindControl("litToalFreight");
            this.litTotalQuantity     = (System.Web.UI.WebControls.Literal) this.FindControl("litTotalQuantity");
            this.isCustomsClearance   = (System.Web.UI.HtmlControls.HtmlInputHidden) this.FindControl("isCustomsClearance");
            //this.txtmemberIdentityCard = (System.Web.UI.HtmlControls.HtmlInputText)this.FindControl("txtmemberIdentityCard");
            //this.txtRealName = (System.Web.UI.HtmlControls.HtmlInputText)this.FindControl("txtRealName");
            this.htmlIsCanMergeOrder = (System.Web.UI.HtmlControls.HtmlInputHidden) this.FindControl("htmlIsCanMergeOrder");
            this.txtVoucherCode      = (HtmlInputText)this.FindControl("txtVoucherCode");
            this.txtVoucherPwd       = (HtmlInputText)this.FindControl("txtVoucherPwd");
            this.dropVoucher         = (WAP_VoucherSelect)this.FindControl("dropVoucher"); // 现金券列表
            this.litIdentityCard     = (System.Web.UI.WebControls.Literal) this.FindControl("litIdentityCard");
            this.litPoint            = (System.Web.UI.WebControls.Literal) this.FindControl("litPoint");
            System.Collections.Generic.IList <ShippingAddressInfo> shippingAddresses = MemberProcessor.GetShippingAddresses();
            ShippingAddressInfo shippingAddressInfo = shippingAddresses.FirstOrDefault((ShippingAddressInfo item) => item.IsDefault);

            if (shippingAddressInfo == null)
            {
                shippingAddressInfo = ((shippingAddresses.Count > 0) ? shippingAddresses[0] : null);
            }
            if (shippingAddressInfo != null)
            {
                this.litShipTo.Text       = shippingAddressInfo.ShipTo;
                this.litCellPhone.Text    = shippingAddressInfo.CellPhone;
                this.litAddress.Text      = RegionHelper.GetFullRegion(shippingAddressInfo.RegionId, "  ") + shippingAddressInfo.Address;
                this.litIdentityCard.Text = shippingAddressInfo.IdentityCard;
                this.selectShipTo.SetWhenIsNotNull(shippingAddressInfo.ShippingId.ToString());
                this.regionId.SetWhenIsNotNull(shippingAddressInfo.RegionId.ToString());
            }
            if (shippingAddresses == null || shippingAddresses.Count == 0)
            {
                this.Page.Response.Redirect(Globals.ApplicationPath + "/Wapshop/AddShippingAddress.aspx?returnUrl=" + Globals.UrlEncode(System.Web.HttpContext.Current.Request.Url.ToString()));
                return;
            }
            ShoppingCartInfo shoppingCartInfo;

            if (int.TryParse(this.Page.Request.QueryString["buyAmount"], out this.buyAmount) && !string.IsNullOrEmpty(this.Page.Request.QueryString["productSku"]) && !string.IsNullOrEmpty(this.Page.Request.QueryString["from"]) && (this.Page.Request.QueryString["from"] == "signBuy" || this.Page.Request.QueryString["from"] == "groupBuy"))
            {
                this.productSku = this.Page.Request.QueryString["productSku"];
                int storeId = 0;
                int.TryParse(this.Page.Request.QueryString["storeId"], out storeId);
                if (int.TryParse(this.Page.Request.QueryString["groupbuyId"], out this.groupBuyId))
                {
                    this.groupbuyHiddenBox.SetWhenIsNotNull(this.groupBuyId.ToString());
                    shoppingCartInfo = ShoppingCartProcessor.GetGroupBuyShoppingCart(this.productSku, this.buyAmount, storeId);
                }
                else
                {
                    shoppingCartInfo = ShoppingCartProcessor.GetShoppingCart(this.productSku, this.buyAmount, storeId);
                }
            }
            else
            {
                if (int.TryParse(this.Page.Request.QueryString["buyAmount"], out this.buyAmount) && !string.IsNullOrEmpty(this.Page.Request.QueryString["productSku"]) && !string.IsNullOrEmpty(this.Page.Request.QueryString["from"]) && this.Page.Request.QueryString["from"] == "countDown")
                {
                    this.productSku = this.Page.Request.QueryString["productSku"];
                    int storeId = 0;
                    int.TryParse(this.Page.Request.QueryString["storeId"], out storeId);
                    if (int.TryParse(this.Page.Request.QueryString["countDownId"], out this.countDownId))
                    {
                        this.groupbuyHiddenBox.SetWhenIsNotNull(this.countDownId.ToString());
                        shoppingCartInfo = ShoppingCartProcessor.GetCountDownShoppingCart(this.productSku, this.buyAmount, storeId);
                    }
                    else
                    {
                        shoppingCartInfo = ShoppingCartProcessor.GetShoppingCart(this.productSku, this.buyAmount, storeId);
                    }
                }
                else
                {
                    //shoppingCartInfo = ShoppingCartProcessor.GetShoppingCart();
                    HttpCookie cookieSkuIds = this.Page.Request.Cookies["UserSession-SkuIds"];
                    if (cookieSkuIds != null && !string.IsNullOrEmpty(cookieSkuIds.Value))
                    {
                        shoppingCartInfo = ShoppingCartProcessor.GetPartShoppingCartInfo(Globals.UrlDecode(cookieSkuIds.Value));//获取用户选择的商品
                    }
                    else
                    {
                        shoppingCartInfo = ShoppingCartProcessor.GetShoppingCart();
                    }
                    if (shoppingCartInfo != null && shoppingCartInfo.GetQuantity() == 0)
                    {
                        //this.buytype = "0";
                    }
                }
            }
            if (shoppingCartInfo != null)
            {
                this.rptCartProducts.DataSource = shoppingCartInfo.LineItems;
                this.rptCartProducts.DataBind();



                #region  获取优惠券筛选条件
                string bindId     = "";
                string categoryId = "";

                List <int> bindIdList     = new List <int>();
                List <int> categoryIdList = new List <int>();

                if (shoppingCartInfo.LineItems != null && shoppingCartInfo.LineItems.Count > 0)
                {
                    shoppingCartInfo.LineItems.ToList().ForEach(t =>
                    {
                        //单品券
                        if (t.ProductId > 0)
                        {
                            bindIdList.Add(t.ProductId);
                        }
                        //商品分类
                        if (t.CategoryId > 0)
                        {
                            categoryIdList.Add(t.CategoryId);
                        }
                        //品牌
                        if (t.BrandId > 0)
                        {
                            bindIdList.Add(t.BrandId);
                        }
                        //供货商
                        if (t.SupplierId > 0)
                        {
                            bindIdList.Add(t.SupplierId);
                        }
                    });
                }

                if (bindIdList != null && bindIdList.Count > 0)
                {
                    bindId = string.Join(",", bindIdList.Distinct().ToArray());
                }
                if (categoryIdList != null && categoryIdList.Count > 0)
                {
                    categoryId = string.Join(",", categoryIdList.Distinct().ToArray());
                }


                #endregion


                decimal totalAmount = shoppingCartInfo.GetNewTotal();
                this.dropVoucher.CartTotal = totalAmount;
                this.dropCoupon.CartTotal  = totalAmount;
                this.dropCoupon.BindId     = bindId;
                this.dropCoupon.CategoryId = categoryId;
                this.litPoint.Text         = shoppingCartInfo.GetPoint().ToString();

                System.Collections.Generic.List <System.Collections.Generic.KeyValuePair <string, string> > list = new System.Collections.Generic.List <System.Collections.Generic.KeyValuePair <string, string> >();
                if (shoppingCartInfo.IsReduced)
                {
                    list.Add(new System.Collections.Generic.KeyValuePair <string, string>(PromotionHelper.GetShortName(PromoteType.Reduced), shoppingCartInfo.ReducedPromotionName + string.Format(" 优惠:{0}", shoppingCartInfo.ReducedPromotionAmount.ToString("F2"))));
                }
                if (shoppingCartInfo.IsFreightFree)
                {
                    list.Add(new System.Collections.Generic.KeyValuePair <string, string>(PromotionHelper.GetShortName(PromoteType.FullAmountSentFreight), string.Format("{0}", shoppingCartInfo.FreightFreePromotionName)));
                }
                if (shoppingCartInfo.IsSendTimesPoint)
                {
                    list.Add(new System.Collections.Generic.KeyValuePair <string, string>(PromotionHelper.GetShortName(PromoteType.FullAmountSentTimesPoint), string.Format("{0}:送{1}倍", shoppingCartInfo.SentTimesPointPromotionName, shoppingCartInfo.TimesPoint.ToString("F2"))));
                }
                if (this.groupBuyId == 0)
                {
                    this.rptPromotions.DataSource = list;
                    this.rptPromotions.DataBind();
                }
                Member currentUser = HiContext.Current.User as Member;
                //this.txtmemberIdentityCard.Value = shippingAddressInfo.IdentityCard;
                //this.txtRealName.Value = shippingAddressInfo.ShipTo;
                #region 是否存在清关商品标识
                bool          isOneTemplateId = true;
                int           templateId      = 0;
                StringBuilder stringBuilder   = new StringBuilder();
                for (int i = 0; i < shoppingCartInfo.LineItems.Count; i++)
                {
                    if (i == (shoppingCartInfo.LineItems.Count - 1))
                    {
                        stringBuilder.Append(shoppingCartInfo.LineItems[i].ProductId);
                    }
                    else
                    {
                        stringBuilder.AppendFormat("{0},", shoppingCartInfo.LineItems[i].ProductId);
                    }
                    if (i == 0)
                    {
                        templateId = shoppingCartInfo.LineItems[i].TemplateId;
                    }
                    else
                    {
                        if (templateId != shoppingCartInfo.LineItems[i].TemplateId)
                        {
                            isOneTemplateId = false;
                        }
                    }
                }
                bool b = ShoppingProcessor.CheckIsCustomsClearance(stringBuilder.ToString());
                if (b)
                {
                    this.isCustomsClearance.Value = "1";//表示存在需要清关的商品
                }
                else
                {
                    this.isCustomsClearance.Value = "0";
                }
                #endregion

                decimal tax           = 0m;//输出税费+运费
                decimal freight       = 0m;
                bool    flag          = groupBuyId > 0;
                int     totalQuantity = 0;
                //Dictionary<int, decimal> dictShippingMode = new Dictionary<int, decimal>();
                foreach (ShoppingCartItemInfo item in shoppingCartInfo.LineItems)
                {
                    totalQuantity += item.Quantity;
                    tax           += item.AdjustedPrice * item.TaxRate * item.Quantity;
                    #region 弃用代码
                    //if ((!shoppingCartInfo.IsFreightFree ||!item.IsfreeShipping|| flag))
                    //{
                    //    if (item.TemplateId > 0)
                    //    {
                    //        if (dictShippingMode.ContainsKey(item.TemplateId))
                    //        {
                    //            dictShippingMode[item.TemplateId] += item.Weight * item.Quantity;
                    //        }
                    //        else
                    //        {
                    //            dictShippingMode.Add(item.TemplateId, item.Weight * item.Quantity);
                    //        }
                    //    }
                    //}
                }
                //foreach (var item in dictShippingMode)//模拟分单,计算运费
                //{
                //    ShippingModeInfo shippingMode = ShoppingProcessor.GetShippingMode(item.Key);
                //    freight += ShoppingProcessor.CalcFreight(shippingAddressInfo.RegionId, item.Value, shippingMode);
                //}
                #endregion
                freight = ShoppingCartProcessor.GetFreight(shoppingCartInfo, shippingAddressInfo.RegionId, false); //ShoppingProcessor.CalcShoppingCartFreight(shoppingCartInfo, shippingAddressInfo.RegionId);
                #region 判断是否符合单条件
                this.htmlIsCanMergeOrder.Value = "0";
                if (templateId != 0 && isOneTemplateId && tax <= 50)
                {
                    bool IsCanMergeOrder = ShoppingProcessor.CheckIsCanMergeOrder(templateId, tax, currentUser.UserId);
                    this.htmlIsCanMergeOrder.Value = IsCanMergeOrder ? "1" : "0";
                }
                #endregion

                //this.litTotalTax.Text =(tax<50?"0.00":tax.ToString("F2"));
                decimal totaltax = shoppingCartInfo.GetNewTotalTax();
                this.litTotalTax.Text          = (totaltax < 50 ? "0.00" : totaltax.ToString("F2"));
                this.litToalFreight.Text       = freight == 0 ? "0.00" : freight.ToString("F2");
                this.litProductTotalPrice.Text = shoppingCartInfo.GetTotal().ToString("F2");

                //tax=tax<50?0:tax;
                totaltax = totaltax < 50 ? 0 : totaltax;

                this.litOrderTotal.Text = (shoppingCartInfo.GetNewTotal() + totaltax + freight).ToString("F2");//总额=商品调整后价格+运费+税费 -活动优惠

                //活动优惠
                this.litPromotionPrice.Text = shoppingCartInfo.GetActivityPrice().ToString("F2");
                this.litTotalQuantity.Text  = totalQuantity.ToString();
            }

            else
            {
                this.Page.Response.Redirect("ShoppingCart.aspx");
            }
            PageTitle.AddSiteNameTitle("订单确认");

            WAPHeadName.AddHeadName("确认订单");
        }
Exemple #3
0
        protected override void AttachChildControls()
        {
            Member member = HiContext.Current.User as Member;

            if (member == null)
            {
                SiteSettings masterSettings = SettingsManager.GetMasterSettings(true);
                this.WriteError("跳转到通用登陆接口", "");
                if (!string.IsNullOrEmpty(masterSettings.WeixinLoginUrl))
                {
                    this.Page.Response.Redirect(masterSettings.WeixinLoginUrl);
                    return;
                }
                this.Page.Response.Redirect("Login.aspx?returnUrl=" + Globals.UrlEncode(HttpContext.Current.Request.Url.ToString()));
                return;
            }
            bool rest = MemberProcessor.CheckUserIsVerify(member.UserId);

            if (!rest)
            {
                this.Page.Response.Redirect("IdentityVerifi.aspx?type=submit&buyAmount=" + this.Page.Request.QueryString["buyAmount"] + "&productSku=" + this.Page.Request.QueryString["productSku"] + "&from=" + this.Page.Request.QueryString["from"]);
                return;
            }


            PageTitle.AddSiteNameTitle("订单确认");
            this.litShipTo                      = (System.Web.UI.WebControls.Literal) this.FindControl("litShipTo");
            this.litCellPhone                   = (System.Web.UI.WebControls.Literal) this.FindControl("litCellPhone");
            this.litAddress                     = (System.Web.UI.WebControls.Literal) this.FindControl("litAddress");
            this.rptCartProducts                = (VshopTemplatedRepeater)this.FindControl("rptCartProducts");
            this.dropCoupon                     = (Common_CouponSelect)this.FindControl("dropCoupon");
            this.litOrderTotal                  = (System.Web.UI.WebControls.Literal) this.FindControl("litOrderTotal");
            this.litPromotionPrice              = (System.Web.UI.WebControls.Literal) this.FindControl("litPromotionPrice");
            this.groupbuyHiddenBox              = (System.Web.UI.HtmlControls.HtmlInputControl) this.FindControl("groupbuyHiddenBox");
            this.rptAddress                     = (VshopTemplatedRepeater)this.FindControl("rptAddress");
            this.selectShipTo                   = (System.Web.UI.HtmlControls.HtmlInputHidden) this.FindControl("selectShipTo");
            this.regionId                       = (System.Web.UI.HtmlControls.HtmlInputHidden) this.FindControl("regionId");
            this.litProductTotalPrice           = (System.Web.UI.WebControls.Literal) this.FindControl("litProductTotalPrice");
            this.rptPromotions                  = (VshopTemplatedRepeater)this.FindControl("rptPromotions");
            this.litTotalTax                    = (System.Web.UI.WebControls.Literal) this.FindControl("litTotalTax");
            this.litToalFreight                 = (System.Web.UI.WebControls.Literal) this.FindControl("litToalFreight");
            this.litTotalQuantity               = (System.Web.UI.WebControls.Literal) this.FindControl("litTotalQuantity");
            this.isCustomsClearance             = (System.Web.UI.HtmlControls.HtmlInputHidden) this.FindControl("isCustomsClearance");
            this.txtmemberIdentityCard          = (System.Web.UI.HtmlControls.HtmlInputText) this.FindControl("txtmemberIdentityCard");
            this.txtRealName                    = (System.Web.UI.HtmlControls.HtmlInputText) this.FindControl("txtRealName");
            this.htmlIsCanMergeOrder            = (System.Web.UI.HtmlControls.HtmlInputHidden) this.FindControl("htmlIsCanMergeOrder");
            this.txtVoucherCode                 = (HtmlInputText)this.FindControl("txtVoucherCode");
            this.txtVoucherPwd                  = (HtmlInputText)this.FindControl("txtVoucherPwd");
            this.dropVoucher                    = (Common_VoucherSelect)this.FindControl("dropVoucher"); // 现金券列表
            this.litAddressNotExits             = (System.Web.UI.WebControls.Literal) this.FindControl("litAddressNotExits");
            this.rptCartProducts.ItemDataBound += rptCartProducts_ItemDataBound;

            System.Collections.Generic.IList <ShippingAddressInfo> shippingAddresses = MemberProcessor.GetShippingAddresses();
            this.rptAddress.DataSource =
                from item in shippingAddresses
                orderby item.IsDefault
                select item;

            this.rptAddress.DataBind();
            ShippingAddressInfo shippingAddressInfo = shippingAddresses.FirstOrDefault((ShippingAddressInfo item) => item.IsDefault);

            if (shippingAddressInfo == null)
            {
                shippingAddressInfo = ((shippingAddresses.Count > 0) ? shippingAddresses[0] : null);
            }
            if (shippingAddressInfo != null)
            {
                this.litShipTo.Text    = shippingAddressInfo.ShipTo + "(收)";
                this.litCellPhone.Text = shippingAddressInfo.CellPhone;
                this.litAddress.Text   = RegionHelper.GetFullRegion(shippingAddressInfo.RegionId, "") + "  " + shippingAddressInfo.Address;
                this.selectShipTo.SetWhenIsNotNull(shippingAddressInfo.ShippingId.ToString());
                this.regionId.SetWhenIsNotNull(shippingAddressInfo.RegionId.ToString());
                this.txtRealName.Value = shippingAddressInfo.ShipTo;

                DataTable dt = SitesManagementHelper.GetMySubMemberByUserId(HiContext.Current.User.UserId);
                if (dt != null && dt.Rows.Count > 0)
                {
                    this.txtmemberIdentityCard.Value = dt.Rows[0]["IdentityCard"].ToString();
                    this.txtRealName.Value           = dt.Rows[0]["RealName"].ToString();
                }

                this.litAddressNotExits.Text = "<div class=\"addr-con\" id=\"addr-con\"><a href=\"/vshop/ShippingAddresses.aspx?returnUrl=" + HttpContext.Current.Request.Url.AbsoluteUri + "\" id=\"addressurl\"><p><label id=\"lbAddress\">" + RegionHelper.GetFullRegion(shippingAddressInfo.RegionId, "") + "  " + shippingAddressInfo.Address + "</label></p>" +
                                               "<div class=\"rec-info fix\"> <label id=\"lbShipTo\">" + shippingAddressInfo.ShipTo + "(收)" + "</label><span class=\"ml10\"><label id=\"lbCellPhone\">" + shippingAddressInfo.CellPhone + "</label></span></div></a></div>";
            }
            else
            {
                this.litAddressNotExits.Text = "<div class=\"no-addr\" id=\"no-addr\"> <span class=\"n-tip\">亲,您当前没有收货地址哦!</span> <a class=\"add-addr-btn\" href=\"/vshop/AddShippingAddress.aspx\">添加新地址</a> </div>";
            }
            //if (shippingAddresses == null || shippingAddresses.Count == 0)
            //{
            //    this.Page.Response.Redirect(Globals.ApplicationPath + "/Vshop/AddShippingAddress.aspx?returnUrl=" + Globals.UrlEncode(System.Web.HttpContext.Current.Request.Url.ToString()));
            //    return;
            //}

            if (int.TryParse(this.Page.Request.QueryString["buyAmount"], out this.buyAmount) && !string.IsNullOrEmpty(this.Page.Request.QueryString["productSku"]) && !string.IsNullOrEmpty(this.Page.Request.QueryString["from"]) && (this.Page.Request.QueryString["from"] == "signBuy" || this.Page.Request.QueryString["from"] == "groupBuy"))
            {
                this.productSku = this.Page.Request.QueryString["productSku"];
                int storeId = 0;
                int.TryParse(this.Page.Request.QueryString["storeId"], out storeId);
                if (int.TryParse(this.Page.Request.QueryString["groupbuyId"], out this.groupBuyId))
                {
                    this.groupbuyHiddenBox.SetWhenIsNotNull(this.groupBuyId.ToString());
                    shoppingCartInfo = ShoppingCartProcessor.GetGroupBuyShoppingCart(this.productSku, this.buyAmount, storeId);
                }
                else
                {
                    shoppingCartInfo = ShoppingCartProcessor.GetShoppingCart(this.productSku, this.buyAmount, storeId);
                }
            }
            else
            {
                if (int.TryParse(this.Page.Request.QueryString["buyAmount"], out this.buyAmount) && !string.IsNullOrEmpty(this.Page.Request.QueryString["productSku"]) && !string.IsNullOrEmpty(this.Page.Request.QueryString["from"]) && this.Page.Request.QueryString["from"] == "countDown")
                {
                    this.productSku = this.Page.Request.QueryString["productSku"];
                    int storeId = 0;
                    int.TryParse(this.Page.Request.QueryString["storeId"], out storeId);
                    if (int.TryParse(this.Page.Request.QueryString["countDownId"], out this.countDownId))
                    {
                        this.groupbuyHiddenBox.SetWhenIsNotNull(this.countDownId.ToString());
                        shoppingCartInfo = ShoppingCartProcessor.GetCountDownShoppingCart(this.productSku, this.buyAmount, storeId);
                    }
                    else
                    {
                        shoppingCartInfo = ShoppingCartProcessor.GetShoppingCart(this.productSku, this.buyAmount, storeId);
                    }
                }
                else
                {
                    //shoppingCartInfo = ShoppingCartProcessor.GetShoppingCart();
                    HttpCookie cookieSkuIds = this.Page.Request.Cookies["UserSession-SkuIds"];
                    if (cookieSkuIds != null && !string.IsNullOrEmpty(cookieSkuIds.Value))
                    {
                        shoppingCartInfo = ShoppingCartProcessor.GetPartShoppingCartInfo(Globals.UrlDecode(cookieSkuIds.Value));//获取未用户选择的商品
                    }
                    else
                    {
                        shoppingCartInfo = ShoppingCartProcessor.GetShoppingCart();
                    }
                    if (shoppingCartInfo != null && shoppingCartInfo.GetQuantity() == 0)
                    {
                        //this.buytype = "0";
                    }
                }
            }
            if (shoppingCartInfo != null)
            {
                this.rptCartProducts.DataSource = shoppingCartInfo.LineItems;
                this.rptCartProducts.DataBind();
                decimal totalAmount = shoppingCartInfo.GetNewTotal(); //shoppingCartInfo.GetTotal();
                this.dropCoupon.CartTotal  = totalAmount;
                this.dropVoucher.CartTotal = totalAmount;

                System.Collections.Generic.List <System.Collections.Generic.KeyValuePair <string, string> > list = new System.Collections.Generic.List <System.Collections.Generic.KeyValuePair <string, string> >();
                if (shoppingCartInfo.IsReduced)
                {
                    list.Add(new System.Collections.Generic.KeyValuePair <string, string>(PromotionHelper.GetShortName(PromoteType.Reduced), shoppingCartInfo.ReducedPromotionName + string.Format(" 优惠:{0}", shoppingCartInfo.ReducedPromotionAmount.ToString("F2"))));
                }
                if (shoppingCartInfo.IsFreightFree)
                {
                    list.Add(new System.Collections.Generic.KeyValuePair <string, string>(PromotionHelper.GetShortName(PromoteType.FullAmountSentFreight), string.Format("{0}", shoppingCartInfo.FreightFreePromotionName)));
                }
                if (shoppingCartInfo.IsSendTimesPoint)
                {
                    list.Add(new System.Collections.Generic.KeyValuePair <string, string>(PromotionHelper.GetShortName(PromoteType.FullAmountSentTimesPoint), string.Format("{0}:送{1}倍", shoppingCartInfo.SentTimesPointPromotionName, shoppingCartInfo.TimesPoint.ToString("F2"))));
                }
                if (this.groupBuyId == 0)
                {
                    this.rptPromotions.DataSource = list;
                    this.rptPromotions.DataBind();
                }
                Member currentUser = HiContext.Current.User as Member;
                #region 是否存在清关商品标识
                bool          isOneTemplateId = true;
                int           templateId      = 0;
                StringBuilder stringBuilder   = new StringBuilder();
                for (int i = 0; i < shoppingCartInfo.LineItems.Count; i++)
                {
                    if (i == (shoppingCartInfo.LineItems.Count - 1))
                    {
                        stringBuilder.Append(shoppingCartInfo.LineItems[i].ProductId);
                    }
                    else
                    {
                        stringBuilder.AppendFormat("{0},", shoppingCartInfo.LineItems[i].ProductId);
                    }
                    if (i == 0)
                    {
                        templateId = shoppingCartInfo.LineItems[i].TemplateId;
                    }
                    else
                    {
                        if (templateId != shoppingCartInfo.LineItems[i].TemplateId)
                        {
                            isOneTemplateId = false;
                        }
                    }
                }
                bool b = ShoppingProcessor.CheckIsCustomsClearance(stringBuilder.ToString());
                if (b)
                {
                    this.isCustomsClearance.Value = "1";//表示存在需要清关的商品
                }
                else
                {
                    this.isCustomsClearance.Value = "0";
                }
                #endregion

                decimal tax           = 0m;//输出税费+运费
                decimal freight       = 0m;
                bool    flag          = groupBuyId > 0;
                int     totalQuantity = 0;
                //Dictionary<int, decimal> dictShippingMode = new Dictionary<int, decimal>();
                foreach (ShoppingCartItemInfo item in shoppingCartInfo.LineItems)
                {
                    totalQuantity += item.Quantity;
                    tax           += item.AdjustedPrice * item.TaxRate * item.Quantity;
                    #region 弃用代码
                    //if ((!shoppingCartInfo.IsFreightFree ||!item.IsfreeShipping|| flag))
                    //{
                    //    if (item.TemplateId > 0)
                    //    {
                    //        if (dictShippingMode.ContainsKey(item.TemplateId))
                    //        {
                    //            dictShippingMode[item.TemplateId] += item.Weight * item.Quantity;
                    //        }
                    //        else
                    //        {
                    //            dictShippingMode.Add(item.TemplateId, item.Weight * item.Quantity);
                    //        }
                    //    }
                    //}
                }
                //foreach (var item in dictShippingMode)//模拟分单,计算运费
                //{
                //    ShippingModeInfo shippingMode = ShoppingProcessor.GetShippingMode(item.Key);
                //    freight += ShoppingProcessor.CalcFreight(shippingAddressInfo.RegionId, item.Value, shippingMode);
                //}
                #endregion
                if (shippingAddressInfo != null)
                {
                    freight = ShoppingCartProcessor.GetFreight(shoppingCartInfo, shippingAddressInfo.RegionId, false); //ShoppingProcessor.CalcShoppingCartFreight(shoppingCartInfo, shippingAddressInfo.RegionId);
                }
                #region 判断是否符合单条件
                this.htmlIsCanMergeOrder.Value = "0";
                if (templateId != 0 && isOneTemplateId && tax <= 50)
                {
                    bool IsCanMergeOrder = ShoppingProcessor.CheckIsCanMergeOrder(templateId, tax, currentUser == null ? 0 : currentUser.UserId);
                    this.htmlIsCanMergeOrder.Value = IsCanMergeOrder ? "1" : "0";
                }
                #endregion

                //this.litTotalTax.Text =(tax<50?"0.00":tax.ToString("F2"));
                decimal totaltax = shoppingCartInfo.GetNewTotalTax();
                this.litTotalTax.Text = totaltax.ToString("F2");


                string strToalFreight = freight == 0 ? "0.00" : freight.ToString("F2");

                if (shoppingCartInfo.LineItems.Count != shoppingCartInfo.LineItems.Count((ShoppingCartItemInfo a) => a.IsfreeShipping) && !shoppingCartInfo.IsFreightFree)
                {
                    this.litToalFreight.Text = "<span id='showfreight'>" + strToalFreight + "</span>";
                    totaltax = totaltax < 50 ? 0 : totaltax;

                    this.litOrderTotal.Text = (shoppingCartInfo.GetNewTotal() + totaltax + freight).ToString("F2");//总额=商品调整后价格+运费+税费 -活动优惠
                }

                else
                {
                    this.litToalFreight.Text = "<span id='showfreight' style='text-decoration: line-through;'>" + strToalFreight + "</span>";

                    totaltax = totaltax < 50 ? 0 : totaltax;

                    this.litOrderTotal.Text = (shoppingCartInfo.GetNewTotal() + totaltax).ToString("F2");//总额=商品调整后价格+运费+税费 -活动优惠
                }

                this.litProductTotalPrice.Text = shoppingCartInfo.GetTotal().ToString("F2");

                //tax=tax<50?0:tax;
                //totaltax = totaltax < 50 ? 0 : totaltax;

                //this.litOrderTotal.Text = (shoppingCartInfo.GetNewTotal() + totaltax + freight).ToString("F2");//总额=商品调整后价格+运费+税费 -活动优惠

                //活动优惠
                this.litPromotionPrice.Text = shoppingCartInfo.GetActivityPrice().ToString("F2");
                this.litTotalQuantity.Text  = totalQuantity.ToString();
            }
        }