/// <summary>
        /// 加入到购物车
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string AddShopCart(MshoppingCart model)
        {
            if (!this.CheckIsLogin())
            {
                return("-1");
            }

            model.userId   = Session["loginuserId"] + string.Empty;
            model.userName = Session["loginuserName"] + string.Empty;
            return(new ShoppingCartBus().AddShopCart(model));
        }
Пример #2
0
        /// <summary>
        /// 根据用户ID获取其全部购物车产品
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <MshoppingCart> GetAllShoppingCartListBySserId(string userId)
        {
            string sql = @"select sc.shoppingCartId,sc.userId,sc.userName,sc.productId,
                           p.productname,p.productformat,sc.buyNum,p.origPrice,p.sellPrice,
                           sc.totalPrice,sc.isDelete,sc.isEffective,sc.great_time,
                           sc.modify_time from shoppingCart as sc 
                           JOIN product as p on sc.productId = p.productId 
                           where sc.userId=?userId;";

            List <MySqlParameter> parameterList = new List <MySqlParameter>();
            MySqlParameter        parameter     = parameter = new MySqlParameter("?userId", MySqlDbType.VarChar, 25);

            parameter.Value = userId;
            parameterList.Add(parameter);

            List <MshoppingCart> listModel = null;

            using (MySqlDataReader sqlDataReader = PKMySqlHelper.ExecuteReader(sql, parameterList.ToArray()))
            {
                if (sqlDataReader != null)
                {
                    listModel = new List <MshoppingCart>();
                    while (sqlDataReader.Read())
                    {
                        MshoppingCart model = new MshoppingCart();
                        model.shoppingCartId = sqlDataReader["shoppingCartId"] != DBNull.Value ? sqlDataReader["shoppingCartId"].ToString() : string.Empty;
                        model.userId         = sqlDataReader["userId"] != DBNull.Value ? sqlDataReader["userId"].ToString() : string.Empty;
                        model.userName       = sqlDataReader["userName"] != DBNull.Value ? sqlDataReader["userName"].ToString() : string.Empty;
                        model.userName       = Base64.DecodeBase64(model.userName);

                        model.productId = sqlDataReader["productId"] != DBNull.Value ? sqlDataReader["productId"].ToString() : string.Empty;

                        model.productname   = sqlDataReader["productname"] != DBNull.Value ? sqlDataReader["productname"].ToString() : string.Empty;
                        model.productformat = sqlDataReader["productformat"] != DBNull.Value ? sqlDataReader["productformat"].ToString() : string.Empty;
                        model.buyNum        = sqlDataReader["buyNum"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["buyNum"].ToString()) : 0;
                        model.origPrice     = sqlDataReader["origPrice"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["origPrice"].ToString()) : 0M;
                        model.sellPrice     = sqlDataReader["sellPrice"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["sellPrice"].ToString()) : 0M;
                        model.totalPrice    = sqlDataReader["totalPrice"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["totalPrice"].ToString()) : 0M;

                        model.great_time  = sqlDataReader["great_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["great_time"].ToString()) : DateTime.MinValue;
                        model.modify_time = sqlDataReader["modify_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["modify_time"].ToString()) : DateTime.MinValue;
                        listModel.Add(model);
                    }
                }
            }

            return(listModel);
        }
Пример #3
0
        /// <summary>
        /// 根据用户ID和产品id获取其对应的购买产品的购物车信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public MshoppingCart GetShoppingCartListByUserIdAndProductId(string userId, string productId)
        {
            string sql = "select shoppingCartId,userId,userName,productId,productname,productformat,buyNum,origPrice,sellPrice,totalPrice,isDelete,isEffective,great_time,modify_time from shoppingCart where userId=?userId and productId=?productId;";

            List <MySqlParameter> parameterList = new List <MySqlParameter>();
            MySqlParameter        parameter     = parameter = new MySqlParameter("?userId", MySqlDbType.VarChar, 25);

            parameter.Value = userId;
            parameterList.Add(parameter);

            parameter       = parameter = new MySqlParameter("?productId", MySqlDbType.VarChar, 25);
            parameter.Value = productId;
            parameterList.Add(parameter);

            MshoppingCart model = null;

            using (MySqlDataReader sqlDataReader = PKMySqlHelper.ExecuteReader(sql, parameterList.ToArray()))
            {
                if (sqlDataReader != null)
                {
                    if (sqlDataReader.Read())
                    {
                        model = new MshoppingCart();
                        model.shoppingCartId = sqlDataReader["shoppingCartId"] != DBNull.Value ? sqlDataReader["shoppingCartId"].ToString() : string.Empty;
                        model.userId         = sqlDataReader["userId"] != DBNull.Value ? sqlDataReader["userId"].ToString() : string.Empty;
                        model.userName       = sqlDataReader["userName"] != DBNull.Value ? sqlDataReader["userName"].ToString() : string.Empty;
                        model.userName       = Base64.DecodeBase64(model.userName);

                        model.productId = sqlDataReader["productId"] != DBNull.Value ? sqlDataReader["productId"].ToString() : string.Empty;

                        model.productname   = sqlDataReader["productname"] != DBNull.Value ? sqlDataReader["productname"].ToString() : string.Empty;
                        model.productformat = sqlDataReader["productformat"] != DBNull.Value ? sqlDataReader["productformat"].ToString() : string.Empty;
                        model.buyNum        = sqlDataReader["buyNum"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["buyNum"].ToString()) : 0;
                        model.origPrice     = sqlDataReader["origPrice"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["origPrice"].ToString()) : 0M;
                        model.sellPrice     = sqlDataReader["sellPrice"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["sellPrice"].ToString()) : 0M;
                        model.totalPrice    = sqlDataReader["totalPrice"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["totalPrice"].ToString()) : 0M;

                        model.great_time  = sqlDataReader["great_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["great_time"].ToString()) : DateTime.MinValue;
                        model.modify_time = sqlDataReader["modify_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["modify_time"].ToString()) : DateTime.MinValue;
                    }
                }
            }

            return(model);
        }
Пример #4
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));
        }
Пример #5
0
 /// <summary>
 /// 新增订单
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Add(MshoppingCart model)
 {
     return(opertService.Add(model));
 }
Пример #6
0
        /// <summary>
        /// 加入到购物车
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string AddShopCart(MshoppingCart model)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            try
            {
                bool addResult = true;

                ShoppingCartService opert = new ShoppingCartService();
                //// 补全产品信息
                Mproduct product = new ProductBus().GetProductById(model.productId);
                if (product == null || string.IsNullOrEmpty(product.productid))
                {
                    addResult = false;
                }
                else
                {
                    string productformatunit = product.productformatunit == "0" ? "个" :
                                               product.productformatunit == "1" ? "袋" :
                                               product.productformatunit == "2" ? "斤" :
                                               product.productformatunit == "3" ? "瓶" :
                                               product.productformatunit == "4" ? "升" :
                                               product.productformatunit == "5" ? "听" :
                                               product.productformatunit == "4" ? "升" :
                                               product.productformatunit == "6" ? "件" :
                                               product.productformatunit == "7" ? "盒" :
                                               product.productformatunit == "8" ? "包" :
                                               product.productformatunit == "9" ? "提" : "双";
                    model.origPrice     = product.origprice;
                    model.productformat = $"{product.productformat}/{productformatunit}";
                    model.productname   = product.productname;
                    model.sellPrice     = product.sellprice;

                    //// 首先根据产id和用户 ID获取一次购物车信息
                    MshoppingCart shopCartModel = opert.GetShoppingCartListByUserIdAndProductId(model.userId, model.productId);

                    if (model.buyNum > 0)
                    {
                        ///// 加购物车
                        if (shopCartModel != null && !string.IsNullOrEmpty(shopCartModel.shoppingCartId))
                        {
                            /////  数量加1
                            addResult = opert.UpdatePriceAndNum(shopCartModel.shoppingCartId, model.userId,
                                                                model.origPrice, model.sellPrice, model.totalPrice + (model.sellPrice * model.buyNum), model.buyNum);
                        }
                        else
                        {
                            //// 新增
                            model.shoppingCartId = PublicTools.GetRandomNumberByTime();
                            addResult            = opert.Add(model);
                        }
                    }
                    else
                    {
                        //// 减购物车
                        if (shopCartModel != null && !string.IsNullOrEmpty(shopCartModel.shoppingCartId))
                        {
                            if (shopCartModel.buyNum <= (-model.buyNum))
                            {
                                //// 直接删除
                                addResult = opert.DeleteShoppingCartById(shopCartModel.shoppingCartId, shopCartModel.userId);
                            }
                            else
                            {
                                /////  数量减1
                                addResult = opert.UpdatePriceAndNum(shopCartModel.shoppingCartId, model.userId,
                                                                    model.origPrice, model.sellPrice, model.totalPrice + shopCartModel.totalPrice, model.buyNum);
                            }
                        }
                    }
                }


                if (addResult)
                {
                    mwxResult.errmsg  = "操作成功!";
                    mwxResult.errcode = 0;
                }
                else
                {
                    mwxResult.errmsg = "操作失败!";
                }
            }
            catch (Exception ex)
            {
                mwxResult.errmsg = "操作失败!";
                LogOpert.AddWeiXinMessage("系统异常:" + ex.Message);
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }
Пример #7
0
        /// <summary>
        /// 新增订单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Add(MshoppingCart model)
        {
            //// sql语句
            string sql = "INSERT INTO shoppingCart (shoppingCartId,userId,userName,productId,productname,productformat,buyNum,origPrice,sellPrice,totalPrice,isDelete,isEffective,great_time,modify_time) " +
                         "VALUES(?shoppingCartId, ?userId, ?userName, ?productId, ?productname, ?productformat, ?buyNum, ?origPrice, ?sellPrice, ?totalPrice, ?isDelete, ?isEffective, ?great_time, ?modify_time)";

            List <MySqlParameter> parameterList = new List <MySqlParameter>();
            MySqlParameter        parameter     = new MySqlParameter("?shoppingCartId", MySqlDbType.VarChar, 25);

            parameter.Value = model.shoppingCartId;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?userId", MySqlDbType.VarChar, 25);
            parameter.Value = model.userId;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?userName", MySqlDbType.VarChar, 500);
            parameter.Value = Base64.EncodeBase64(model.userName);
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?productId", MySqlDbType.VarChar, 25);
            parameter.Value = model.productId;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?productname", MySqlDbType.VarChar, 100);
            parameter.Value = model.productname;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?productformat", MySqlDbType.VarChar, 50);
            parameter.Value = model.productformat;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?buyNum", MySqlDbType.Int32);
            parameter.Value = model.buyNum;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?origPrice", MySqlDbType.Decimal);
            parameter.Value = model.origPrice;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?sellPrice", MySqlDbType.Decimal);
            parameter.Value = model.sellPrice;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?totalPrice", MySqlDbType.Decimal);
            parameter.Value = model.totalPrice;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?isDelete", MySqlDbType.Int16, 1);
            parameter.Value = 0;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?isEffective", MySqlDbType.Int16, 1);
            parameter.Value = 1;
            parameterList.Add(parameter);

            DateTime dateTime = System.DateTime.Now;

            parameter       = new MySqlParameter("?great_time", MySqlDbType.DateTime);
            parameter.Value = dateTime;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?modify_time", MySqlDbType.DateTime);
            parameter.Value = dateTime;
            parameterList.Add(parameter);

            //// 执行操作
            return(PKMySqlHelper.ExecuteNonQuery(sql, parameterList.ToArray()) > 0);
        }