예제 #1
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;//启用当前按钮
        }