Beispiel #1
0
        private void ProcessPurchaseOrderAdd(HttpContext context)
        {
            PurchaseOrderInfo purchaseOrderInfo = new PurchaseOrderInfo();
            decimal           totalWeight       = 0M;

            if (string.IsNullOrEmpty(context.Request["Products"]))
            {
                context.Response.Write("{\"PurchaseOrderAddResponse\":\"-1\"}");
            }
            else
            {
                int distributorId = int.Parse(context.Request["distributorUserId"]);
                foreach (string str in context.Request["Products"].Split(new char[] { ';' }))
                {
                    string[]  strArray2 = str.Split(new char[] { ',' });
                    DataTable table     = SubSiteProducthelper.GetSkuContent(long.Parse(strArray2[0]), strArray2[1], distributorId);
                    if ((table != null) && (table.Rows.Count > 0))
                    {
                        PurchaseOrderItemInfo item = new PurchaseOrderItemInfo();
                        foreach (DataRow row in table.Rows)
                        {
                            if (!string.IsNullOrEmpty(row["AttributeName"].ToString()) && !string.IsNullOrEmpty(row["ValueStr"].ToString()))
                            {
                                object sKUContent = item.SKUContent;
                                item.SKUContent = string.Concat(new object[] { sKUContent, row["AttributeName"], ":", row["ValueStr"], "; " });
                            }
                        }
                        item.PurchaseOrderId = purchaseOrderInfo.PurchaseOrderId;
                        item.SkuId           = (string)table.Rows[0]["SkuId"];
                        item.ProductId       = (int)table.Rows[0]["ProductId"];
                        if (table.Rows[0]["SKU"] != DBNull.Value)
                        {
                            item.SKU = (string)table.Rows[0]["SKU"];
                        }
                        if (table.Rows[0]["Weight"] != DBNull.Value)
                        {
                            item.ItemWeight = (decimal)table.Rows[0]["Weight"];
                        }
                        item.ItemPurchasePrice = (decimal)table.Rows[0]["PurchasePrice"];
                        item.Quantity          = int.Parse(strArray2[2]);
                        item.ItemListPrice     = (decimal)table.Rows[0]["SalePrice"];
                        if (table.Rows[0]["CostPrice"] != DBNull.Value)
                        {
                            item.ItemCostPrice = (decimal)table.Rows[0]["CostPrice"];
                        }
                        item.ItemDescription         = (string)table.Rows[0]["ProductName"];
                        item.ItemHomeSiteDescription = (string)table.Rows[0]["ProductName"];
                        if (table.Rows[0]["ThumbnailUrl40"] != DBNull.Value)
                        {
                            item.ThumbnailsUrl = (string)table.Rows[0]["ThumbnailUrl40"];
                        }
                        totalWeight += item.ItemWeight * item.Quantity;
                        purchaseOrderInfo.PurchaseOrderItems.Add(item);
                    }
                }
                if (purchaseOrderInfo.PurchaseOrderItems.Count <= 0)
                {
                    context.Response.Write("{\"PurchaseOrderAddResponse\":\"-3\"}");
                }
                else
                {
                    purchaseOrderInfo.Weight          = totalWeight;
                    purchaseOrderInfo.TaobaoOrderId   = context.Request["TaobaoOrderId"];
                    purchaseOrderInfo.PurchaseOrderId = "MPO" + purchaseOrderInfo.TaobaoOrderId;
                    purchaseOrderInfo.ShipTo          = context.Request["ShipTo"];
                    string province = context.Request["ReceiverState"];
                    string city     = context.Request["ReceiverCity"];
                    string county   = context.Request["ReceiverDistrict"];
                    purchaseOrderInfo.ShippingRegion = province + city + county;
                    purchaseOrderInfo.RegionId       = RegionHelper.GetRegionId(county, city, province);
                    purchaseOrderInfo.Address        = context.Request["Address"];
                    purchaseOrderInfo.TelPhone       = context.Request["TelPhone"];
                    purchaseOrderInfo.CellPhone      = context.Request["CellPhone"];
                    purchaseOrderInfo.ZipCode        = context.Request["ZipCode"];
                    purchaseOrderInfo.OrderTotal     = decimal.Parse(context.Request["OrderTotal"]);
                    ShippingModeInfo shippingMode = ShoppingProcessor.GetShippingMode(HiContext.Current.SiteSettings.TaobaoShippingType, true);
                    if (shippingMode != null)
                    {
                        purchaseOrderInfo.ModeName        = shippingMode.Name;
                        purchaseOrderInfo.AdjustedFreight = purchaseOrderInfo.Freight = ShoppingProcessor.CalcFreight(purchaseOrderInfo.RegionId, totalWeight, shippingMode);
                    }
                    purchaseOrderInfo.PurchaseStatus = OrderStatus.WaitBuyerPay;
                    purchaseOrderInfo.RefundStatus   = RefundStatus.None;
                    Distributor user = Users.GetUser(distributorId) as Distributor;
                    if (user != null)
                    {
                        purchaseOrderInfo.DistributorId       = user.UserId;
                        purchaseOrderInfo.Distributorname     = user.Username;
                        purchaseOrderInfo.DistributorEmail    = user.Email;
                        purchaseOrderInfo.DistributorRealName = user.RealName;
                        purchaseOrderInfo.DistributorQQ       = user.QQ;
                        purchaseOrderInfo.DistributorWangwang = user.Wangwang;
                        purchaseOrderInfo.DistributorMSN      = user.MSN;
                    }
                    if (!SubsiteSalesHelper.CreatePurchaseOrder(purchaseOrderInfo))
                    {
                        context.Response.Write("{\"PurchaseOrderAddResponse\":\"0\"}");
                    }
                    else
                    {
                        context.Response.Write("{\"PurchaseOrderAddResponse\":\"1\"}");
                    }
                }
            }
        }
Beispiel #2
0
        private void ProcessPurchaseOrderAdd(System.Web.HttpContext context)
        {
            PurchaseOrderInfo purchaseOrderInfo = new PurchaseOrderInfo();
            decimal           num = 0m;

            if (string.IsNullOrEmpty(context.Request["Products"]))
            {
                context.Response.Write("{\"PurchaseOrderAddResponse\":\"-1\"}");
                return;
            }
            int num2 = int.Parse(context.Request["distributorUserId"]);

            string[] array = context.Request["Products"].Split(new char[]
            {
                ';'
            });
            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string   text   = array2[i];
                string[] array3 = text.Split(new char[]
                {
                    ','
                });
                System.Data.DataTable skuContent = SubSiteProducthelper.GetSkuContent(long.Parse(array3[0]), array3[1], num2);
                if (skuContent != null && skuContent.Rows.Count > 0)
                {
                    PurchaseOrderItemInfo purchaseOrderItemInfo = new PurchaseOrderItemInfo();
                    foreach (System.Data.DataRow dataRow in skuContent.Rows)
                    {
                        if (!string.IsNullOrEmpty(dataRow["AttributeName"].ToString()) && !string.IsNullOrEmpty(dataRow["ValueStr"].ToString()))
                        {
                            PurchaseOrderItemInfo expr_124 = purchaseOrderItemInfo;
                            object sKUContent = expr_124.SKUContent;
                            expr_124.SKUContent = string.Concat(new object[]
                            {
                                sKUContent,
                                dataRow["AttributeName"],
                                ":",
                                dataRow["ValueStr"],
                                "; "
                            });
                        }
                    }
                    purchaseOrderItemInfo.PurchaseOrderId = purchaseOrderInfo.PurchaseOrderId;
                    purchaseOrderItemInfo.SkuId           = (string)skuContent.Rows[0]["SkuId"];
                    purchaseOrderItemInfo.ProductId       = (int)skuContent.Rows[0]["ProductId"];
                    if (skuContent.Rows[0]["SKU"] != System.DBNull.Value)
                    {
                        purchaseOrderItemInfo.SKU = (string)skuContent.Rows[0]["SKU"];
                    }
                    if (skuContent.Rows[0]["Weight"] != System.DBNull.Value)
                    {
                        purchaseOrderItemInfo.ItemWeight = (decimal)skuContent.Rows[0]["Weight"];
                    }
                    purchaseOrderItemInfo.ItemPurchasePrice = (decimal)skuContent.Rows[0]["PurchasePrice"];
                    purchaseOrderItemInfo.Quantity          = int.Parse(array3[2]);
                    purchaseOrderItemInfo.ItemListPrice     = (decimal)skuContent.Rows[0]["SalePrice"];
                    if (skuContent.Rows[0]["CostPrice"] != System.DBNull.Value)
                    {
                        purchaseOrderItemInfo.ItemCostPrice = (decimal)skuContent.Rows[0]["CostPrice"];
                    }
                    purchaseOrderItemInfo.ItemDescription         = (string)skuContent.Rows[0]["ProductName"];
                    purchaseOrderItemInfo.ItemHomeSiteDescription = (string)skuContent.Rows[0]["ProductName"];
                    if (skuContent.Rows[0]["ThumbnailUrl40"] != System.DBNull.Value)
                    {
                        purchaseOrderItemInfo.ThumbnailsUrl = (string)skuContent.Rows[0]["ThumbnailUrl40"];
                    }
                    num += purchaseOrderItemInfo.ItemWeight * purchaseOrderItemInfo.Quantity;
                    purchaseOrderInfo.PurchaseOrderItems.Add(purchaseOrderItemInfo);
                }
            }
            if (purchaseOrderInfo.PurchaseOrderItems.Count <= 0)
            {
                context.Response.Write("{\"PurchaseOrderAddResponse\":\"-3\"}");
                return;
            }
            purchaseOrderInfo.Weight          = num;
            purchaseOrderInfo.TaobaoOrderId   = context.Request["TaobaoOrderId"];
            purchaseOrderInfo.PurchaseOrderId = "MPO" + purchaseOrderInfo.TaobaoOrderId;
            purchaseOrderInfo.ShipTo          = context.Request["ShipTo"];
            string text2 = context.Request["ReceiverState"];
            string text3 = context.Request["ReceiverCity"];
            string text4 = context.Request["ReceiverDistrict"];

            purchaseOrderInfo.ShippingRegion = text2 + text3 + text4;
            purchaseOrderInfo.RegionId       = RegionHelper.GetRegionId(text4, text3, text2);
            purchaseOrderInfo.Address        = context.Request["Address"];
            purchaseOrderInfo.TelPhone       = context.Request["TelPhone"];
            purchaseOrderInfo.CellPhone      = context.Request["CellPhone"];
            purchaseOrderInfo.ZipCode        = context.Request["ZipCode"];
            purchaseOrderInfo.OrderTotal     = decimal.Parse(context.Request["OrderTotal"]);
            ShippingModeInfo shippingMode = ShoppingProcessor.GetShippingMode(Hidistro.Membership.Context.HiContext.Current.SiteSettings.TaobaoShippingType, true);

            if (shippingMode != null)
            {
                purchaseOrderInfo.ModeName        = shippingMode.Name;
                purchaseOrderInfo.AdjustedFreight = (purchaseOrderInfo.Freight = ShoppingProcessor.CalcFreight(purchaseOrderInfo.RegionId, num, shippingMode));
            }
            purchaseOrderInfo.PurchaseStatus = OrderStatus.WaitBuyerPay;
            purchaseOrderInfo.RefundStatus   = RefundStatus.None;
            Hidistro.Membership.Context.Distributor distributor = Hidistro.Membership.Context.Users.GetUser(num2) as Hidistro.Membership.Context.Distributor;
            if (distributor != null)
            {
                purchaseOrderInfo.DistributorId       = distributor.UserId;
                purchaseOrderInfo.Distributorname     = distributor.Username;
                purchaseOrderInfo.DistributorEmail    = distributor.Email;
                purchaseOrderInfo.DistributorRealName = distributor.RealName;
                purchaseOrderInfo.DistributorQQ       = distributor.QQ;
                purchaseOrderInfo.DistributorWangwang = distributor.Wangwang;
                purchaseOrderInfo.DistributorMSN      = distributor.MSN;
            }
            if (!SubsiteSalesHelper.CreatePurchaseOrder(purchaseOrderInfo))
            {
                context.Response.Write("{\"PurchaseOrderAddResponse\":\"0\"}");
                return;
            }
            context.Response.Write("{\"PurchaseOrderAddResponse\":\"1\"}");
        }
        private PurchaseOrderInfo GetPurchaseOrder(Trade trade)
        {
            PurchaseOrderInfo info = new PurchaseOrderInfo();

            info.PurchaseOrderId    = "MPO" + trade.Tid.ToString();
            info.TaobaoOrderId      = trade.Tid.ToString();
            info.ShipTo             = trade.ReceiverName;
            info.ShippingRegion     = trade.ReceiverState + trade.ReceiverCity + trade.ReceiverDistrict;
            info.RegionId           = RegionHelper.GetRegionIdByName(trade.ReceiverState, trade.ReceiverCity, trade.ReceiverDistrict);
            info.Address            = trade.ReceiverAddress;
            info.TelPhone           = trade.ReceiverPhone;
            info.ZipCode            = trade.ReceiverZip;
            info.CellPhone          = trade.ReceiverMobile;
            info.ShippingModeId     = shippingMode.ModeId;
            info.ModeName           = shippingMode.Name;
            info.RealShippingModeId = shippingMode.ModeId;
            info.RealModeName       = shippingMode.Name;
            info.AdjustedDiscount   = 0M;
            info.OrderTotal         = decimal.Parse(trade.Payment);
            int totalWeight = 0;

            foreach (Order order in trade.Orders)
            {
                DataTable skuContent = SubSiteProducthelper.GetSkuContent(order.NumIid, order.OuterSkuId);

                if ((skuContent != null) && (skuContent.Rows.Count > 0))
                {
                    PurchaseOrderItemInfo item = new PurchaseOrderItemInfo();

                    foreach (DataRow row in skuContent.Rows)
                    {
                        if (!(string.IsNullOrEmpty(row["AttributeName"].ToString()) || string.IsNullOrEmpty(row["ValueStr"].ToString())))
                        {
                            object sKUContent = item.SKUContent;
                            item.SKUContent = string.Concat(new object[] { sKUContent, row["AttributeName"], ":", row["ValueStr"], "; " });
                        }
                    }
                    item.PurchaseOrderId = info.PurchaseOrderId;
                    item.SkuId           = (string)skuContent.Rows[0]["SkuId"];
                    item.ProductId       = (int)skuContent.Rows[0]["ProductId"];
                    if (skuContent.Rows[0]["SKU"] != DBNull.Value)
                    {
                        item.SKU = (string)skuContent.Rows[0]["SKU"];
                    }
                    if (skuContent.Rows[0]["Weight"] != DBNull.Value)
                    {
                        item.ItemWeight = (int)skuContent.Rows[0]["Weight"];
                    }
                    item.ItemPurchasePrice = (decimal)skuContent.Rows[0]["PurchasePrice"];
                    item.Quantity          = int.Parse(order.Num.ToString());
                    item.ItemListPrice     = (decimal)skuContent.Rows[0]["SalePrice"];
                    if (skuContent.Rows[0]["CostPrice"] != DBNull.Value)
                    {
                        item.ItemCostPrice = (decimal)skuContent.Rows[0]["CostPrice"];
                    }
                    item.ItemDescription         = (string)skuContent.Rows[0]["ProductName"];
                    item.ItemHomeSiteDescription = (string)skuContent.Rows[0]["ProductName"];
                    if (skuContent.Rows[0]["ThumbnailUrl40"] != DBNull.Value)
                    {
                        item.ThumbnailsUrl = (string)skuContent.Rows[0]["ThumbnailUrl40"];
                    }
                    totalWeight += item.ItemWeight * item.Quantity;
                    info.PurchaseOrderItems.Add(item);
                }
            }
            if (info.PurchaseOrderItems.Count <= 0)
            {
                return(null);
            }
            info.Weight              = totalWeight;
            info.AdjustedFreight     = SubsiteSalesHelper.CalcFreight(info.RegionId, totalWeight, shippingMode);
            info.Freight             = info.AdjustedFreight;
            info.PurchaseStatus      = OrderStatus.WaitBuyerPay;
            info.RefundStatus        = RefundStatus.None;
            info.DistributorId       = distributor.UserId;
            info.Distributorname     = distributor.Username;
            info.DistributorEmail    = distributor.Email;
            info.DistributorRealName = distributor.RealName;
            info.DistributorQQ       = distributor.QQ;
            info.DistributorWangwang = distributor.Wangwang;
            info.DistributorMSN      = distributor.MSN;
            return(info);
        }