Ejemplo n.º 1
0
 /// <summary>
 /// 购物车商品条目数
 /// </summary>
 /// <param name="entId">企业</param>
 /// <param name="userId">用户</param>
 /// <param name="ywyId">业务员</param>
 /// <returns></returns>
 public ActionResult NumberOfItems(string entId, string userId, string ywyId = "")
 {
     try
     {
         if (string.IsNullOrEmpty(userId))
         {
             return(Json(new { success = false, message = "用户未登录,请先登录" }));
         }
         ///获取用户信息
         UserInfoDal     dal  = new UserInfoDal();
         List <UserInfo> user = dal.GetUserInfo(userId, entId);
         if (user.Count <= 0)
         {
             return(Json(new { success = false, message = "用户未登录,请重新登录" }));
         }
         ///获取购物车信息
         CartDal cdal = new CartDal();
         int     num  = cdal.GetCartCount(entId, userId, ywyId);
         return(Json(new { success = true, message = "购物车商品条目数获取成功", num }));
     }
     catch (Exception ex)
     {
         LogQueue.Write(LogType.Error, "Cart/NumberOfItems", ex.Message.ToString());
         return(Json(new { success = false, message = ex.Message.ToString() }));
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取购物车金额
 /// </summary>
 /// <param name="entId">企业Id</param>
 /// <param name="userId">用户id</param>
 /// <param name="goodsList">选中的商品id</param>
 /// <returns></returns>
 public JsonResult CartAmount(string entId, string userId, string goodsList, string ywyId = "")
 {
     try
     {
         if (string.IsNullOrEmpty(userId))
         {
             return(Json(new { success = false, message = "用户未登录,请先登录" }));
         }
         ///获取用户信息
         UserInfoDal     dal  = new UserInfoDal();
         List <UserInfo> user = dal.GetUserInfo(userId, entId);
         if (user.Count <= 0)
         {
             return(Json(new { success = false, message = "E002" }));
         }
         ///获取购物车信息
         CartDal         cdal = new CartDal();
         List <CartList> list = cdal.GetCartAmount(user[0].EntId, userId, goodsList, user[0].Pricelevel, user[0].KhType, ywyId);
         return(Json(new { success = true, list = list }));
     }
     catch (Exception ex)
     {
         LogQueue.Write(LogType.Error, "Cart/CartAmount", ex.Message.ToString());
         return(Json(new { success = false, message = ex.Message.ToString() }));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 再次购买
 /// </summary>
 /// <param name="userId">用户Id</param>
 /// <param name="entId">机构Id</param>
 /// <param name="billNo">订单序号</param>
 /// <returns></returns>
 public JsonResult OnceAgain(string userId, string entId, int billNo, string cartType, string bs = "XQ", string loginId = "")
 {
     try
     {
         if (string.IsNullOrEmpty(userId))
         {
             LogQueue.Write(LogType.Error, "Cart/OnceAgain", $"userId:{userId},entId:{entId},billNo:{billNo}");
             return(Json(new{ success = false, message = "用户未登录,请先登录!" }));
         }
         ///获取用户信息
         UserInfoDal     udal = new UserInfoDal();
         List <UserInfo> user = udal.GetUserInfo(userId, entId);
         string          jgjb = "", khType = "";
         if (user.Count > 0)
         {
             jgjb   = user[0].Pricelevel;
             khType = user[0].KhType;
         }
         CartDal dal    = new CartDal();
         string  result = dal.OnceAgain(userId, entId, billNo, loginId, out bool flag, jgjb, khType, cartType, bs);
         return(Json(new { success = flag, message = result }));
     }
     catch (Exception ex)
     {
         LogQueue.Write(LogType.Error, "Cart/OnceAgain", ex.Message.ToString());
         return(Json(new { success = false, message = ex.Message }));
     }
 }
Ejemplo n.º 4
0
        public bool InsertCart(int mid, decimal price, int number, int pid)
        {
            T_Cart          cart    = new T_Cart();
            T_Protuct       produce = new T_Protuct();
            T_ProductDetail pdetail = new T_ProductDetail();
            UserBll         userbll = new UserBll();

            cart.CreateDate      = DateTime.Now;
            cart.ProductPrice    = price;
            cart.ProductNumber   = number;
            cart.ProductdetailId = mid;
            cart.ProductId       = pid;

            cart.UserId = userbll.GetUserIdByToken();
            ProductBll pbll = new ProductBll();

            CartDal cartdal = new CartDal();

            produce = pbll.GetProductById(pid);
            pdetail = pbll.GetPDetailById(mid);
            if (pdetail != null)
            {
                cart.Specification = pdetail.Specification;
                cart.Size          = pdetail.Size;
            }
            if (produce != null)
            {
                cart.ProductName = produce.ProductTitle;
                cart.ImgUrl      = produce.Imgurl1;
                // cart.Specification=produce.sp
            }
            return(cartdal.InsertCart(cart));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 删除购物车商品
 /// </summary>
 /// <param name="entId">企业Id</param>
 /// <param name="userId">用户id</param>
 /// <param name="dltType">删除类型(单条one/全部all)</param>
 /// <param name="cartId">购物车Id</param>
 /// <returns></returns>
 public JsonResult DeleteCartGoods(string entId, string userId, string dltType, string cartId, string cartType = "", string ywyId = "")
 {
     try
     {
         if (string.IsNullOrEmpty(userId))
         {
             return(Json(new { success = false, message = "用户未登录,请先登录" }));
         }
         if (dltType == "" || (dltType == "one" && cartId == ""))
         {
             return(Json(new { success = false, message = "必传参数不能为空" }));
         }
         CartDal dal  = new CartDal();
         bool    flag = dal.DeleteCart(entId, userId, dltType, cartId, cartType, ywyId);
         if (flag)
         {
             return(Json(new { success = true, message = "操作成功" }));
         }
         else
         {
             return(Json(new { success = false, message = "E006" }));
         }
     }
     catch (Exception ex)
     {
         LogQueue.Write(LogType.Error, "Cart/DeleteCartGoods", ex.Message.ToString());
         return(Json(new { success = false, message = ex.Message.ToString() }));
     }
 }
        //return cart list
        public ActionResult getCartProductsByJSON()
        {
            Cartdal = new CartDal();
            List <Cart> CartList = Cartdal.cart.ToList <Cart>();

            return(Json(CartList, JsonRequestBehavior.AllowGet));
        }
        //function add item to cart
        public ActionResult AddToCart()
        {
            CartDal dal  = new CartDal();
            Cart    cart = new Cart();

            cart.Model = Request.Form["Model"].ToString();
            string mo = Request.Form["Model"].ToString();

            cart.Type  = Request.Form["Type"].ToString();
            cart.Price = Convert.ToInt32(Request.Form["Price"]);


            List <Cart> p = (from x in dal.cart where x.Model.Contains(mo) select x).ToList();

            if (p.Count == 0)
            {
                cart.CartQuantity++;
                dal.cart.Add(cart);
            }
            else if (p.Count == 1)
            {
                var cartv = dal.cart.First(m => m.Model == mo);
                cart.CartQuantity = cartv.CartQuantity;


                cart.CartQuantity++;
                var ToDeleteC = dal.cart.First(m => m.Model == mo);
                dal.cart.Remove(ToDeleteC);
                dal.cart.Add(cart);
            }

            dal.SaveChanges();
            UpdateMQuantity(cart.Model, "Add");
            return(Json(cart, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 8
0
        public bool DelCartById(int CartId)
        {
            CartDal cartdal = new CartDal();
            UserBll userbll = new UserBll();
            int     userid  = userbll.GetUserIdByToken();

            return(cartdal.DelCartById(CartId, userid));
        }
Ejemplo n.º 9
0
        public int GetCartNumByUserId(int userid)
        {
            CartDal cartdal = new CartDal();

            if (cartdal.GetCartListByUserId(userid) != null)
            {
                return(cartdal.GetCartListByUserId(userid).Count());
            }
            else
            {
                return(0);
            }
        }
        //removes item from cart
        public ActionResult RemoveFromCart()
        {
            //if (((string)Session["type"]).Equals("Employee"))

            CartDal dal = new CartDal();
            Cart    pro = new Cart();

            pro.Model = Request.Form["Model"].ToString();
            string mo = Request.Form["Model"].ToString();

            List <Cart> p = (from x in dal.cart where x.Model.Contains(mo) select x).ToList();

            if (ModelState.IsValid && p.Count != 0)
            {
                //there  is such model ... delete him

                var ToDelete = dal.cart.First(m => m.Model == pro.Model);
                // Delete
                pro.Type         = ToDelete.Type;
                pro.CartQuantity = ToDelete.CartQuantity;
                pro.Price        = ToDelete.Price;
                dal.cart.Remove(ToDelete);
                dal.SaveChanges();
                UpdateMQuantity(mo, "Remove");

                if (pro.CartQuantity > 1)
                {
                    pro.CartQuantity--;
                    dal.cart.Add(pro);
                    dal.SaveChanges();
                }


                List <Cart> cartL1 = dal.cart.ToList <Cart>();
                return(Json(cartL1, JsonRequestBehavior.AllowGet));
            }

            else
            {
                return(RedirectToAction("ShoppingCart", "Buying"));
            }
        }
Ejemplo n.º 11
0
 public JsonResult CartList(string entId, string userId, string goodsList, string ywyId = "")
 {
     try
     {
         if (string.IsNullOrEmpty(userId))
         {
             return(Json(new { success = false, message = "用户未登录,请先登录" }));
         }
         ///获取用户信息
         UserInfoDal     dal  = new UserInfoDal();
         List <UserInfo> user = dal.GetUserInfo(userId, entId);
         if (user.Count <= 0)
         {
             return(Json(new { success = false, message = "E002" }));
         }
         CartDal           cdal    = new CartDal();
         List <CartEenDoc> cartDoc = new List <CartEenDoc>();
         ///获取购物车商品机构列表
         DataTable dtCartEnt = cdal.GetCartEntList(userId);
         ///获取购物车信息
         if (dtCartEnt == null || dtCartEnt.Rows.Count <= 0)
         {
             return(Json(new { success = false, messageCode = "E002", message = "无数据" }));
         }
         foreach (DataRow dr in dtCartEnt.Rows)
         {
             CartEenDoc model = new CartEenDoc();
             model.EntId    = dr["entId"].ToString();
             model.EntName  = dr["entname"].ToString();
             model.cartlist = cdal.GetCartList(dr["entId"].ToString(), userId, goodsList, user[0].Pricelevel, user[0].KhType, ywyId);
             cartDoc.Add(model);
         }
         return(Json(new { success = true, list = cartDoc }));
     }
     catch (Exception ex)
     {
         LogQueue.Write(LogType.Error, "Cart/CartList", ex.Message.ToString());
         return(Json(new { success = false, message = ex.Message.ToString() }));
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 组合商品加入购物车
 /// </summary>
 /// <param name="userId">用户Id</param>
 /// <param name="entId">企业Id</param>
 /// <param name="fabh">方案编号</param>
 /// <param name="num">组数</param>
 /// <returns></returns>
 public JsonResult AddCartGroup(string userId, string entId, string cartType, string fabh, decimal num, string bs = "")
 {
     try
     {
         if (string.IsNullOrEmpty(userId))
         {
             return(Json(new { success = false, message = "用户未登录,请先登录" }));
         }
         if (num <= 0)
         {
             return(Json(new { success = false, message = "购买组数不能小于0" }));
         }
         //获取组合商品信息
         PromotionDal pdal = new PromotionDal();
         DataTable    dt   = pdal.GetGroupInfo(entId, userId, fabh);
         if (dt.Rows.Count <= 0)
         {
             return(Json(new { success = true, message = "该组合不存在" }));
         }
         StringBuilder strSql = new StringBuilder();
         string        msg    = "";
         foreach (DataRow dr in dt.Rows)
         {
             ///客户经营范围验证
             if (decimal.Parse(dr["giftquantity"].ToString()) * num > decimal.Parse(dr["stock_quantity"].ToString()))
             {
                 msg = dr["sub_title"].ToString() + "库存不足";
                 return(Json(new { success = true, message = msg }));
             }
         }
         CartDal dal = new CartDal();
         msg = dal.CartAddGroup(entId, userId, num, fabh, out int flag, bs, cartType);
         return(Json(new { success = flag == 0?true:false, message = msg }));
     }
     catch (Exception ex)
     {
         LogQueue.Write(LogType.Error, "Cart/AddCartGroup", ex.Message.ToString());
         return(Json(new { success = false, message = "E005" }));
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 商品添加购物车
        /// </summary>
        /// <param name="entId">企业id</param>
        /// <param name="userId">用户id</param>
        /// <param name="article_Id">商品id</param>
        /// <param name="quantity">数量</param>
        /// <param name="cartType">购物车类型</param>
        /// <param name="fabh">促销方案编号</param>
        /// <param name="bs">'XQ'商品详情/''购物车</param>
        /// <returns></returns>
        public JsonResult CartAdd(string entId, string userId, string article_Id, decimal quantity, string cartType, string fabh, string bs = "", string ywyId = "")
        {
            try
            {
                ///获取用户信息
                UserInfoDal     userInfo = new UserInfoDal();
                List <UserInfo> user     = userInfo.GetUserInfo(userId ?? "", entId);

                if (string.IsNullOrEmpty(userId))
                {
                    return(Json(new { success = false, message = "用户未登录,请先登录" }));
                }
                else if (quantity <= 0)
                {
                    return(Json(new { success = false, message = "购买数量不能小于0" }));
                }
                else if (user[0].Status == 1)
                {
                    return(Json(new { success = false, message = "该账号未通过审核,无法购买商品" }));
                }
                ////客户经营范围拦截
                CartDal dal  = new CartDal();
                bool    flag = dal.CartAdd(entId, userId, article_Id, quantity, cartType, fabh, bs, ywyId);
                if (flag)
                {
                    ///获取购物车条目数
                    int num = dal.GetCartCount(entId, userId, ywyId);
                    return(Json(new { success = true, num = num, message = "加入购物车成功" }));
                }
                else
                {
                    return(Json(new { success = true, message = "加入失败" }));
                }
            }
            catch (Exception ex)
            {
                LogQueue.Write(LogType.Error, "Cart/CartAdd", ex.Message.ToString());
                return(Json(new { success = false, message = ex.Message.ToString() }));
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 快速下单商品加入购物车
 /// </summary>
 /// <param name="entId"></param>
 /// <param name="userId"></param>
 /// <param name="IdOrNum"></param>
 /// <returns></returns>
 public JsonResult SetCarProducts(string entId, string userId, string IdOrNum)
 {
     try
     {
         if (string.IsNullOrEmpty(userId))
         {
             return(Json(new { success = false, message = "用户未登录,请先登录" }));
         }
         CartDal       dal         = new CartDal();
         var           proModel    = IdOrNum.Split('|');//id,num|id,num|
         List <string> successlist = new List <string>();
         List <string> errorlist   = new List <string>();
         if (proModel.Length > 0)
         {
             foreach (var porobj in proModel)
             {
                 if (porobj != null && porobj != "")
                 {
                     var pro = porobj.Split(',');
                     if (pro.Length == 2)
                     {
                         bool flag = dal.CartAdd(entId, userId, pro[0], decimal.Parse(pro[1]), "PC", "", "XQ");
                         if (flag)
                         {
                             successlist.Add(pro[0]);
                         }
                         else
                         {
                             errorlist.Add(pro[0]);
                         }
                     }
                     else
                     {
                         return(Json(new { success = false, num = 0, message = "请检查下单商品的拼接!" }));
                     }
                 }
                 else
                 {
                     return(Json(new { success = false, num = 0, message = "请检查下单组合的拼接!" }));
                 }
             }
         }
         else
         {
             return(Json(new { success = false, num = 0, message = "请选择加入购物车的商品!" }));
         }
         if (errorlist.Count == 0)
         {
             return(Json(new { success = true, num = successlist.Count, message = "加入购物车成功" }));
         }
         else if (successlist.Count == 0)
         {
             return(Json(new { success = false, num = 0, message = "加入购物车全部失败" }));
         }
         else
         {
             return(Json(new { success = true, num = -1, message = "未全部加入购物车,某些商品加入失败" }));
         }
     }
     catch (Exception ex)
     {
         LogQueue.Write(LogType.Error, "Cart/CartAdd", ex.Message.ToString());
         return(Json(new { success = false, message = ex.Message.ToString() }));
     }
 }
Ejemplo n.º 15
0
        public List <T_Cart> GetCartListByUserId(int userid)
        {
            CartDal cartdal = new CartDal();

            return(cartdal.GetCartListByUserId(userid));
        }