Esempio n. 1
0
        /// <summary>
        /// 购买页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Buy(int addressId = 0)
        {
            var token = Member.Token;

            var carts = YunClient.Instance.Execute(new GetShoppingCartsRequest(), token).Items;

            if (carts != null && carts.Any())
            {
                //代金券信息
                ViewData["cashCoupons"] =
                    YunClient.Instance.Execute(
                        new GetMyCashCouponsRequest
                {
                    HasExpired    = false,
                    HasUsed       = false,
                    TradePrice    = carts.Sum(e => e.Quantity * e.ItemInfo.Price.TryTo(0.0)),
                    ItemPriceJson =
                        carts.Select(
                            e =>
                            new GetMyCashCouponItemPriceJson
                    {
                        item_id          = e.ItemInfo.ItemId,
                        item_total_price = e.Quantity * e.ItemInfo.Price.TryTo(0.0)
                    }).ToList()
                }, token)
                    .CashCoupons;
            }


            //默认收货地址

            var address = addressId > 0
                ? YunClient.Instance.Execute(new GetAddressRequest {
                Id = addressId
            }, token).Result
                : YunClient.Instance.Execute(new GetDefaultAddressRequest(), token).Result;

            ViewData["defaultAddress"] = address;
            ViewData["ExpressPrice"]   = "0.00";

            if (carts != null && carts.Any())
            {
                var template = YunClient.Instance.Execute(new GetTheMostExpensiveTemplateRequest
                {
                    ItemIds = string.Join(",", carts.Select(e => e.ItemInfo.ItemId))
                }).Result;

                if (address != null)
                {
                    ViewData["ExpressPrice"] = SystemCity.GetExpressPrice(4, (int)carts.Sum(e => e.Quantity),
                                                                          string.Format("{0}{1}{2}{3}", address.Province, address.City, address.Area, address.Street),
                                                                          carts.Sum(e => e.Quantity * e.ItemInfo.Price.TryTo(0.0)),
                                                                          carts.Sum(e => e.Quantity * e.ItemInfo.Weight),
                                                                          carts.Sum(e => e.Quantity * e.ItemInfo.Volume), template).ToString("f2");
                }
            }

            //购物车内商品信息
            return(View(carts));
        }
Esempio n. 2
0
        public ActionResult GetExpressPrice(int addressId)
        {
            var token = Member.Token;

            var carts = YunClient.Instance.Execute(new GetShoppingCartsRequest(), token).Items;

            //如果购物车内没有商品,则直接返回0
            if (carts == null || !carts.Any())
            {
                return(Content("0"));
            }

            var template = YunClient.Instance.Execute(new GetTheMostExpensiveTemplateRequest
            {
                ItemIds = string.Join(",", carts.Select(e => e.ItemInfo.ItemId))
            }).Result;

            if (template == null)
            {
                return(Content("0"));
            }

            //默认收货地址
            var address = addressId > 0
                ? YunClient.Instance.Execute(new GetAddressRequest {
                Id = addressId
            }, token).Result
                : YunClient.Instance.Execute(new GetDefaultAddressRequest(), token).Result;

            if (address != null)
            {
                var price = SystemCity.GetExpressPrice(4, (int)carts.Sum(e => e.Quantity),
                                                       address.Province + address.City + address.Area,
                                                       carts.Sum(e => e.Quantity * e.ItemInfo.Price.TryTo(0.0)), carts.Sum(e => e.Quantity * e.ItemInfo.Weight),
                                                       carts.Sum(e => e.Quantity * e.ItemInfo.Volume), template);

                return(Content(price.ToString("f2")));
            }

            return(Content("0.00"));
        }