Ejemplo n.º 1
0
        /// <summary>
        /// 根据用户ID获取所有推荐商品,并根据其购物车组装对应的购买信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public string GetRecommentProductListAndCarInfor(string userid)
        {
            MPageListResult <Mproduct> pageListResult = new MPageListResult <Mproduct>();

            // 所有推荐商品
            if (CacheData.allRecommendProList != null &&
                CacheData.allRecommendProList.Count > 0)
            {
                pageListResult.dataList =
                    JsonHelper.ParseFormJson <List <Mproduct> >(
                        JsonHelper.GetJson <List <Mproduct> >(CacheData.allRecommendProList));


                List <MshoppingCart> listShoppingCart = null;

                if (!string.IsNullOrEmpty(userid))
                {
                    // 获取用户的所有购物车详情
                    listShoppingCart = new ShoppingCartBus().GetAllShoppingCartListBySserId(userid);
                }

                //
                MshoppingCart thisMshoppingCart = null;
                if (pageListResult.dataList != null && pageListResult.dataList.Count > 0)
                {
                    foreach (var item in pageListResult.dataList)
                    {
                        thisMshoppingCart = listShoppingCart == null ? null : listShoppingCart.Find(x => x.productId == item.productid);
                        if (thisMshoppingCart == null || string.IsNullOrEmpty(thisMshoppingCart.productId))
                        {
                            item.hassellnum = 0;
                        }
                        else
                        {
                            item.hassellnum = thisMshoppingCart.buyNum;
                        }
                    }
                }
            }

            return(JsonHelper.GetJson <MPageListResult <Mproduct> >(pageListResult));
        }
Ejemplo n.º 2
0
        public string AddOrderByShoppingCart(string userId, string deliveryTime,
                                             string mailAddress,
                                             string deliveryName,
                                             string deliveryTell,
                                             string hasSelProId)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    mwxResult.errmsg = "请先登录!";
                    return(JsonHelper.GetJson <MwxResult>(mwxResult));
                }

                if (string.IsNullOrEmpty(hasSelProId))
                {
                    mwxResult.errmsg = "请选择需要购买的产品!";
                    return(JsonHelper.GetJson <MwxResult>(mwxResult));
                }

                ///// 获取该用户的购物车全部商品
                List <MshoppingCart> mshoppingCartsList = new ShoppingCartBus().GetAllShoppingCartListBySserId(userId);
                string[]             hasSel             = hasSelProId.Split(',');

                if (hasSel == null || hasSel.Length < 1 || mshoppingCartsList == null || mshoppingCartsList.Count <= 0)
                {
                    mwxResult.errmsg = "请选择需要购买的产品!";
                    return(JsonHelper.GetJson <MwxResult>(mwxResult));
                }
                else
                {
                    ///// 构建订单列表
                    List <Morder> modelList = new List <Morder>();
                    decimal       freight   = 0;
                    decimal       totalF    = 0;
                    foreach (var item in mshoppingCartsList)
                    {
                        if (!hasSel.Contains(item.productId))
                        {
                            continue;
                        }
                        totalF = totalF + item.sellPrice * item.buyNum;
                        modelList.Add(new Morder()
                        {
                            buyNum              = item.buyNum,
                            mailAddress         = mailAddress + "-" + deliveryName + "-" + deliveryTell,
                            requireDeliveryTime = deliveryTime,
                            deliveryTime        = System.DateTime.MinValue,
                            receiptTime         = System.DateTime.MinValue,

                            userId        = item.userId,
                            userName      = item.userName,
                            productId     = item.productId,
                            productname   = item.productname,
                            productformat = item.productformat,
                            origPrice     = item.origPrice,
                            sellPrice     = item.sellPrice,
                            totalPrice    = item.sellPrice * item.buyNum,
                            // freight = item.sellPrice,

                            shoppingCartId = item.shoppingCartId
                        });
                    }

                    // 小于20需要1元钱运费
                    if (totalF < 20)
                    {
                        foreach (var item in modelList)
                        {
                            item.freight = 0M;
                        }
                    }

                    mwxResult = this.AddOrder(modelList);
                    if (mwxResult.errcode == 0)
                    {
                        try
                        {
                            NewOrderNum.TotalNum = NewOrderNum.TotalNum + 1;
                        }
                        catch (Exception)
                        {
                        }
                    }
                    return(JsonHelper.GetJson <MwxResult>(mwxResult));
                }
            }
            catch (Exception)
            {
                mwxResult.errmsg = "下单失败!";
                return(JsonHelper.GetJson <MwxResult>(mwxResult));
            }
        }