Example #1
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() }));
            }
        }
Example #2
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() }));
     }
 }