Пример #1
0
        public JsonResult GetProductPromote(int productID)
        {
            try
            {
                Response.Cache.SetOmitVaryStar(true);
                //if (this.GetUserID() != 0)
                //{
                //    var userBrowseHistoryService = new UserBrowseHistoryService();
                //    var userBrowseHistory = new User_BrowseHistory { UserID = this.GetUserID(), ProductID = productID };
                //    userBrowseHistoryService.Add(userBrowseHistory);
                //}

                Product_Cache promote = new OrderBillServices().QueryCartProduct(productID);
                return this.Json(promote, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// 获取订单结算信息
        /// </summary>
        /// <param name="productDictionary"></param>
        /// <returns></returns>
        private Order_Bill GetOrderBill(Dictionary<int, int> productDictionary)
        {
            Order_Bill orderBill = null;
            try
            {
                orderBill = new OrderBillServices().QueryOrderBill(productDictionary, this.GetUserID());
            }
            catch (Exception exception)
            {
                LogUtils.Log("获取订单促销信息失败,出错原因:" + exception.Message + ";错误堆栈:" + exception.StackTrace, "OrderInfo", Category.Warn);
            }

            if (orderBill == null || orderBill.Products == null || orderBill.Products.Count < 1)
            {
                LogUtils.Log("没有获取订单促销信息", "OrderInfo", Category.Warn);
            }
            return orderBill ?? new Order_Bill();
        }
Пример #3
0
        public JsonResult GetProductListInfo(List<int> id)
        {
            Response.Cache.SetOmitVaryStar(true);
            if (id == null) return null;

            try
            {
                var list = new OrderBillServices().QueryCartProduct(id.ToArray());
                var query = from p in list
                            select new
                            {
                                ID = p.ProductID,
                                S = p.SoldOfReality + p.SoldOfVirtual,
                                P = p.PromotePrice,
                                C = p.CommentNumber,
                                A = p.Advertisement
                            };
                return this.Json(query);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
Пример #4
0
        private Order_Bill GetCartProductBill()
        {
            int count = 0;
            var userCart = this.GetUserCart();

            var productDictionary = new Dictionary<int, int>();

            List<Cart_Product> specialPromoteProducts = new List<Cart_Product>();

            if (userCart != null && userCart.ProductItems != null)
            {
                foreach (var productItem in userCart.ProductItems)
                {
                    int quantity = 0;
                    if (this.CheckSpecialPromote(productItem.ProductID, ref quantity) != null) //参加全场特殊活动
                    {
                        if (quantity > 0)
                        {
                            specialPromoteProducts.Add(
                            new Cart_Product { GoujiuPrice = 0, ProductName = "[赠品]" + productItem.ProductName, ProductID = productItem.ProductID, PromotePrice = 0, Quantity = quantity });
                        }

                        continue;
                    }

                    //只需要加入数量大于0的商品
                    if (productItem.Quantity > 0)
                    {
                        productDictionary.Add(productItem.ProductID, productItem.Quantity);
                        count += productItem.Quantity;
                    }
                }
            }

            var orderBill = new OrderBillServices().QueryOrderBill(productDictionary, this.UserSession.UserID);

            orderBill.Products.AddRange(specialPromoteProducts);

            orderBill.ProductCount = count;
            return orderBill;
        }
Пример #5
0
        /// <summary>
        /// 检查库存、限购信息并设置购买数量
        /// </summary>
        /// <param name="product"></param>
        /// <param name="updateQuantity"></param>
        /// <returns></returns>
        private AjaxResponse SetUpdateQuantity(ProductSearchResult product, ref int updateQuantity)
        {
            AjaxResponse ajaxResponse = null;

            ajaxResponse = CheckSpecialPromote(product.ID, ref updateQuantity);

            //此商品参加了特殊全局促销活动
            if (ajaxResponse != null)
            {
                return ajaxResponse;
            }

            var billProduct = new OrderBillServices().QueryCartProduct(product.ID, updateQuantity, this.UserSession.UserID);

            //不允许购买情况
            if (billProduct.DenyFlag > 0)
            {
                switch (billProduct.DenyFlag)
                {
                    case 1:
                        ajaxResponse = new AjaxResponse(
                            11,
                            "对不起,此商品只允许新会员购买!");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 2:
                        ajaxResponse = new AjaxResponse(
                            12,
                            "对不起,此商品只允许老会员购买!");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 3:
                        ajaxResponse = new AjaxResponse(
                            13,
                            "对不起,此商品只允许通过手机验证会员购买。");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 4:
                        ajaxResponse = new AjaxResponse(
                            14,
                            "对不起,此商品只允许通过邮箱验证会员购买。");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 5:
                        ajaxResponse = new AjaxResponse(
                            15,
                            "对不起,此商品仅限新会员购买,请先注册或登录。");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 6:
                        ajaxResponse = new AjaxResponse(
                            16,
                            "对不起,您已参加过此活动。");
                        updateQuantity = 0;
                        return ajaxResponse;
                    default:
                        ajaxResponse = new AjaxResponse(
                            0,
                            "对不起,您不满足此商品的购买条件。");
                        updateQuantity = 0;
                        return ajaxResponse;
                }
            }

            var promnoteItems = billProduct.PromoteTypes.Split(',');

            //验证多选一互斥促销
            if (promnoteItems.Contains("4")&&!string.IsNullOrWhiteSpace(billProduct.Exclude))
            {
                var userCart = MongoDBHelper.GetModel<UserCartModel>(u => u.VisitorKey == this.UserSession.VisitorKey);
                if (userCart != null && userCart.ProductItems.Count > 0)
                {
                    var excludes = billProduct.Exclude.Split(',');
                    if (excludes.Length > 0)
                    {
                        foreach (var item in userCart.ProductItems)
                        {
                            if (item.ProductID != billProduct.ProductID && excludes.Contains(item.ProductID.ToString()))
                            {
                                ajaxResponse = new AjaxResponse(
                                    0,
                                    string.Format("对不起,【{0}】与【{1}】不能同时购买。", item.ProductName, billProduct.ProductName));
                                updateQuantity = 0;
                                return ajaxResponse;
                            }
                        }
                    }
                }
            }

            var islimited = promnoteItems.Contains("1"); // 是否参加限时抢购
            if (islimited)
            {
                if (product.InventoryNumber <= 0)
                {
                    ajaxResponse = new AjaxResponse(
                        0,
                        "对不起,商品已售完!",
                        new { quantity = updateQuantity, totalDiscount = billProduct.FavorablePrice });
                    updateQuantity = 0;
                }
                else if (billProduct.PromoteResidueQuantity <= 0)
                {
                    ajaxResponse = new AjaxResponse(
                        0,
                        "对不起,活动商品库存不足!",
                        new { quantity = updateQuantity, totalDiscount = billProduct.FavorablePrice });
                    updateQuantity = 0;
                }
                else
                {
                    // 检查此商品是否限购件数(不限购)
                    if (billProduct.LimitedBuyQuantity <= 0)
                    {
                        if (billProduct.PromoteResidueQuantity < updateQuantity)
                        {
                            // 购物车数量必须小于活动库存
                            ajaxResponse = new AjaxResponse(
                                0,
                                "对不起,此商品库存不足!你最多可购买" + billProduct.PromoteResidueQuantity + "件",
                                new { quantity = updateQuantity, totalDiscount = billProduct.FavorablePrice });
                            updateQuantity = billProduct.PromoteResidueQuantity;
                        }
                    }
                    else
                    {
                        // 每人限购
                        if (billProduct.MaxBuyQuantity < updateQuantity)
                        {

                            ajaxResponse = new AjaxResponse(
                                0,
                                string.Format("对不起,此商品每人限购{0}件", billProduct.LimitedBuyQuantity),
                                new { quantity = updateQuantity, totalDiscount = billProduct.FavorablePrice });
                            updateQuantity = billProduct.MaxBuyQuantity;
                        }
                    }
                }
            }
            else if (product.InventoryNumber < updateQuantity) // 检查库存
            {
                if (product.InventoryNumber > 0)
                {
                    ajaxResponse = new AjaxResponse(
                        0,
                        "对不起,此商品的库存不足,您最多可购买" + product.InventoryNumber + "件",
                        new { quantity = product.InventoryNumber, totalDiscount = billProduct.FavorablePrice });
                    //cart.ProductItems.Add(this.ConvertToCartProduct(product, product.InventoryNumber)); //库存不够,则设置库存值
                    updateQuantity = product.InventoryNumber;
                }
                else
                {
                    ajaxResponse = new AjaxResponse(
                        0,
                        "对不起,此商品已售完",
                        new { quantity = product.InventoryNumber, totalDiscount = billProduct.FavorablePrice });
                    //cart.ProductItems.Add(this.ConvertToCartProduct(product, product.InventoryNumber)); //库存不够,则设置库存值
                    updateQuantity = 0;
                }
            }

            return ajaxResponse;
        }
Пример #6
0
        public string GetHtmlByTemplete(string htmlTemplete, ProductSearchResult product)
        {
            var properties = TypeDescriptor.GetProperties(product);

            if (htmlTemplete.Contains("$Path$"))
            {
                htmlTemplete = htmlTemplete.Replace("$Path$", Utils.GetProductImage(product.Path));
            }

            if (htmlTemplete.Contains("$ThumbnailPath$"))
            {
                htmlTemplete = htmlTemplete.Replace("$ThumbnailPath$", Utils.GetProductImage(product.Path, "1"));
            }

            if (htmlTemplete.Contains("$ThumbnailPath2$"))
            {
                htmlTemplete = htmlTemplete.Replace("$ThumbnailPath2$", Utils.GetProductImage(product.Path, "2"));
            }

            if (htmlTemplete.Contains("$Sold$"))
            {
                htmlTemplete = htmlTemplete.Replace("$Sold$", Utils.ToString(product.SoldOfReality + product.SoldOfVirtual));
            }

            var cart = new OrderBillServices().QueryCartProduct(product.ID);
            if (cart != null)
            {
                htmlTemplete = htmlTemplete.Replace("$GoujiuPrice$", Utils.ToString(cart.PromotePrice));
            }

            foreach (PropertyDescriptor propertyDescriptror in properties)
            {
                htmlTemplete = htmlTemplete.Replace("$" + propertyDescriptror.Name + "$", Utils.ToString(propertyDescriptror.GetValue(product)));
            }
            return htmlTemplete;
        }
Пример #7
0
        public JsonResult GetCarProductInfo()
        {
            var cartModel = this.GetUserCart();

            var productDictionary = new Dictionary<int, int>();
            foreach (var items in cartModel.ProductItems)
            {
                productDictionary.Add(items.ProductID, items.Quantity);
            }

            var cart = new OrderBillServices();
            var orderBill = cart.QueryOrderBill(productDictionary, this.GetUserID());
            return this.Json(orderBill);
        }
Пример #8
0
        public string GetHtml(string htmlTemplete, int count, ProductType productType, string brandCategory)
        {
            if (count == 0)
            {
                return "";
            }
            if (htmlTemplete == null || htmlTemplete == "")
            {
                return "";
            }

            List<int> list = GetProductSearchResult(count, productType, brandCategory, "");
            if (list == null || list.Count == 0) return "";

            StringBuilder sb = new StringBuilder();
            var cartParductList = new OrderBillServices().QueryCartProduct(list.ToArray());
            foreach (var cartProduct in cartParductList)
            {
                sb.Append(GetHtmlByTemplete(htmlTemplete, cartProduct));
            }
            return sb.ToString();
        }
Пример #9
0
        public string GetHtml(string htmlTemplete, int count, ProductType productType, NameValueCollection nv)
        {
            if (htmlTemplete == null || htmlTemplete == "") return "";

            List<int> list = GetProductSearchResultList(nv);
            if (list == null || list.Count == 0) return "";

            StringBuilder sb = new StringBuilder();
            var cartParductList = new OrderBillServices().QueryCartProduct(list.ToArray());
            foreach (var cartProduct in cartParductList)
            {
                sb.Append(GetHtmlByTemplete(htmlTemplete, cartProduct));
            }
            return sb.ToString();
        }
Пример #10
0
        public string GetGroupListHtml(int count, string condition, NameValueCollection nv)
        {
            List<Advertise_Config> list = GetAdvertiseResult(count, condition, AdvertiseSource.Product);
            if (list == null || list.Count == 0) return "";

            List<ProductSearchResult> products = new List<ProductSearchResult>();
            foreach (Advertise_Config adv in list)
            {
                if (adv.IndexID > 0)
                {
                    List<ProductSearchResult> product = new ProductService().Query(ProductType.Rand, count, "id =" + adv.IndexID.ToString());
                    if (product == null || product.Count == 0) continue;
                    product[0].ThumbnailPath = string.IsNullOrEmpty(adv.ImagePath) ? Utils.GetProductImage(product[0].Path, "3") : adv.ImagePath;
                    var cart = new OrderBillServices().QueryCartProduct(product[0].ID);
                    if (cart != null)
                    {
                        product[0].GoujiuPrice = cart.PromotePrice;
                    }
                    products.Add(product[0]);
                }
            }
            string sort = Utils.ToString(nv["sort"], "0");
            string desc = Utils.ToString(nv["desc"], "0");

            var query = new List<ProductSearchResult>();
            switch (sort)
            {
                case "0": //销量
                    if (desc == "1")
                    {
                        query = (from p in products orderby p.SoldOfReality + p.SoldOfVirtual descending select p).ToList<ProductSearchResult>();
                    }
                    else
                    {
                        query = (from p in products orderby p.SoldOfReality + p.SoldOfVirtual select p).ToList<ProductSearchResult>();
                    }
                    break;
                case "1": //价格
                    if (desc == "1")
                    {
                        query = (from p in products orderby p.GoujiuPrice descending select p).ToList<ProductSearchResult>();
                    }
                    else
                    {
                        query = (from p in products orderby p.GoujiuPrice select p).ToList<ProductSearchResult>();
                    }
                    break;
                case "2": //人气
                    if (desc == "1")
                    {
                        query = (from p in products orderby p.PageView descending select p).ToList<ProductSearchResult>();
                    }
                    else
                    {
                        query = (from p in products orderby p.PageView select p).ToList<ProductSearchResult>();
                    }
                    break;
            }

            int i = 1;
            StringBuilder sb = new StringBuilder();
            foreach (ProductSearchResult product in query)
            {
                if (i % 3 == 0)
                {
                    sb.Append(GetGroupItemHtml(product, true));
                }
                else
                {
                    sb.Append(GetGroupItemHtml(product, false));
                }
                i++;
            }
            return sb.ToString();
        }
Пример #11
0
        public string GetAdvertiseHtmlByTemplete(string htmlTemplete, Advertise_Config adv, string imgsize)
        {
            var obj = new object();
            adv.ImagePath = Utils.GetAdvertiseImage(adv.ImagePath);
            switch (adv.Source)
            {
                case "1": // 产品
                    if (adv.IndexID > 0)
                    {
                        var cart = new OrderBillServices().QueryCartProduct(adv.IndexID);
                        if (cart == null)
                        {
                            obj = adv;
                        }
                        else
                        {
                            adv.ImagePath = string.IsNullOrEmpty(adv.ImagePath) ? Utils.GetProductImage(cart.Path, imgsize) : adv.ImagePath;
                            htmlTemplete = htmlTemplete.Replace("$Name$", Utils.ToString(cart.ProductName));
                            htmlTemplete = htmlTemplete.Replace("$Sold$", Utils.ToString(cart.SoldOfReality + cart.SoldOfVirtual));
                            htmlTemplete = htmlTemplete.Replace("$GoujiuPrice$", Utils.ToString(cart.PromotePrice));
                            obj = cart;
                        }
                    }
                    else
                    {
                        obj = adv;
                    }

                    break;
                case "2": // LP
                    if (adv.IndexID > 0)
                    {
                        Promote_LandingPage lp = new PromoteLandingPageService().Query(adv.IndexID);
                        if (lp == null)
                        {
                            obj = adv;
                        }
                        else
                        {
                            lp.Name = adv.Name;
                            obj = lp;
                        }
                    }
                    else
                    {
                        obj = adv;
                    }

                    break;
                case "3": // 其他
                    obj = adv;
                    break;
                default: // 默认
                    obj = adv;
                    break;
            }

            if (htmlTemplete.Contains("$Description$"))
            {
                htmlTemplete = htmlTemplete.Replace("$Description$", Utils.ToString(adv.Description));
            }

            if (htmlTemplete.Contains("$ImagePath$"))
            {
                htmlTemplete = htmlTemplete.Replace("$ImagePath$", Utils.ToString(adv.ImagePath));
            }

            if (htmlTemplete.Contains("$BackgroundColor$"))
            {
                htmlTemplete = htmlTemplete.Replace("$BackgroundColor$", Utils.ToString(adv.BackgroundColor));
            }

            if (htmlTemplete.Contains("$URL$"))
            {
                htmlTemplete = htmlTemplete.Replace("$URL$", Utils.ToString(adv.URL));
            }

            if (htmlTemplete.Contains("$IndexID$"))
            {
                htmlTemplete = htmlTemplete.Replace("$IndexID$", Utils.ToString(adv.IndexID));
            }

            var properties = TypeDescriptor.GetProperties(obj);
            foreach (PropertyDescriptor propertyDescriptror in properties)
            {
                htmlTemplete = htmlTemplete.Replace("$" + propertyDescriptror.Name + "$", Utils.ToString(propertyDescriptror.GetValue(obj)));
            }
            return htmlTemplete;
        }
Пример #12
0
        public ActionResult TuanItem(int id)
        {
            Response.Cache.SetOmitVaryStar(true);
            ProductSearchResult result = new ProductService().QueryByID(id);

            if (result == null)
            {
                Response.StatusCode = 404;
                return this.Content(Utils.ReadFile("Error/404.htm"));
            }

            result.Introduce = Utils.AppendLazy(result.Introduce);
            result.Introduce = Utils.AppendLazy(result.Introduce, "input");
            ViewBag.ID = id;

            var cart = new OrderBillServices().QueryCartProduct(result.ID);
            if (cart != null)
            {
                result.GoujiuPrice = cart.PromotePrice;
            }

            result.ThumbnailPath = Utils.GetProductImage(result.Path, "2");

            return this.View(result);
        }
Пример #13
0
        /// <summary>
        /// 刷新指定商品的缓存.
        /// </summary>
        /// <param name="productID">
        /// 商品编号.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public JsonResult RefreshProductByID(int productID)
        {
            try
            {
                var products = Refresh.GetCache<Product_Cache>(CacheType.Product, true);
                if (products != null)
                {
                    var cartProdcut = products.Find(p => p.ProductID == productID);
                    products.Remove(cartProdcut);
                    cartProdcut = new OrderBillServices().QueryCartProductFromDB(productID);
                    products.Add(cartProdcut);
                    Refresh.WriteCache(products);
                }
                else
                {
                    Refresh.Product();
                }

                return this.Json(new AjaxResponse(1, "刷新成功!"));
            }
            catch (Exception exception)
            {
                return this.Json(new AjaxResponse(0, exception.Message));
            }
        }
Пример #14
0
        public string GetTuanSilderColumnHtml(ProductSearchResult product)
        {
            var cart = new OrderBillServices().QueryCartProduct(product.ID);
            if (cart != null)
            {
                product.GoujiuPrice= cart.PromotePrice;
            }
            double marketprice = product.MarketPrice == null ? 0 : product.MarketPrice;
            double goujiuprice = product.GoujiuPrice == null ? 0 : product.GoujiuPrice;
            string discount = marketprice == 0 ? "" : (Math.Round(goujiuprice / marketprice, 2) * 10).ToString();
            long time = GetTime();

            System.Diagnostics.Trace.WriteLine(time.ToString());

            return "<div class=\"silder_column_image\" style=\"background-image:url(" + Utils.ToString(product.ThumbnailPath) + ");\" ></div>" +
            "<ul class=\"silder_column_intro\">" +
            "    <li class=\"silder_column_name\"><i class=\"image_group\"></i><span>" + Utils.ToString(product.Name) + "</span></li>" +
            "    <li class=\"silder_column_desc\">" + Utils.ToString(product.Advertisement, "没有任何描述信息,请添加描述信息") + "</li>" +
            "    <li class=\"silder_column_price\">" +
            "        <div class=\"goujiu_price\">&#65509;<span>" + Utils.ToString(product.GoujiuPrice) + "</span></div>" +
            "        <div class=\"goujiu_discount\">" +
            "            <div class=\"discount\"><span>" + discount + "</span>折</div>" +
            "            <div class=\"market_price\">&#65509;<span>" + Utils.ToString(product.MarketPrice) + "</span></div>" +
            "        </div>" +
            "        <div class=\"split\"></div>" +
            "        <a href=\"###\" class=\"image_group buy\"></a>" +
            "        <div class=\"clear\"></div>" +
            "    </li>" +
            "    <li class=\"silder_column_time\"><i class=\"image_group\"></i>" +
            "        <div class=\"time\" time=\"" + time.ToString() + "\"></div>" +
            "        <div class=\"clear\"></div>" +
            "    </li>" +
            "    <li class=\"silder_column_other\"><i class=\"image_group\"></i>" +
            "        <div class=\"attention\">共有<span class=\"attention_count\">" + Utils.ToString(product.PageView) + "</span>人关注</div>" +
            "        <div class=\"buyer\"><span class=\"buyer_count\">" + Utils.ToString(product.SoldOfVirtual) + "</span>人购买</div>" +
            "        <div class=\"clear\"></div>" +
            "    </li>" +
            "</ul>" +
            "<div class=\"clear\"></div>";
        }