/// <summary>
 /// 获取购物车商品数量
 /// </summary>
 public int GetChartCount()
 {
     int count = 0;
     BLL.ShoppingCartBase cart = new BLL.ShoppingCartBase();
     var list = cart.GetModelList(" sc_IsDel = 0 and m_ID = " + LoginMember.m_ID);
     if (list != null)
     {
         count = list.Sum(m => m.sc_pCount.Value);
     }
     return count;
 }
        //下方菜单
        public ActionResult bottomMenu()
        {
            int count = 0;
            BLL.ShoppingCartBase cart = new BLL.ShoppingCartBase();
            if (LoginMember != null)
            {
                var list = cart.GetModelList(" sc_IsDel = 0 and m_ID = " + LoginMember.m_ID);
                if (list != null)
                {
                    count = list.Sum(m => m.sc_pCount.Value);
                }
            }

                ViewData["count"] = count;
                return View();
        }
예제 #3
0
 /// <summary>
 /// 获取购物车数据
 /// </summary>
 /// <returns>有数据返回true</returns>
 public bool GetChartList()
 {
     //会员ID
     if (LoginMember != null)
     {
         BLL.ShoppingCartBase shop = new BLL.ShoppingCartBase();
         var list = shop.GetModelList(" sc_Status = 0 and sc_IsDel = 0 and m_ID = " + LoginMember.m_ID);
         //获取SKU Id列表
         string ids = "";
         foreach (var model in list)
         {
             if (!string.IsNullOrWhiteSpace(ids))
             {
                 ids += ",";
             }
             ids += model.sku_ID;
         }
         if (!string.IsNullOrWhiteSpace(ids))
         {
             var dt = new BLL.SKUBase().GetSKUDetial(" and sku_ID in (" + ids + ")", true);
             if (dt != null && dt.Rows.Count != 0)
             {
                 dt.Columns.Add("sc_pCount", Type.GetType("System.Int32"));//商品数量
                 dt.Columns.Add("sc_pCountStatus", Type.GetType("System.String"));//商品库存状态
                 dt.Columns.Add("sc_IsGP", Type.GetType("System.Boolean"));//团购标识
                 foreach (DataRow row in dt.Rows)
                 {
                     var model = list.Where(m => m.sku_ID == Convert.ToInt32(row["sku_ID"])).FirstOrDefault();
                     if (model != null)
                     {
                         row["sc_pCount"] = model.sc_pCount;
                         string sql = " sku_ID = " + row["sku_ID"] + " and gp_IsDel = 0 and gp_StatusCode = 0 and gp_EndTime > '" + DateTime.Now + "' and gp_pCount-gp_SaleCount>0";
                         if (model.sc_IsGP)
                         {
                             //团购
                             var gpBase = _gpBase.GetModelList(sql).FirstOrDefault();
                             if (gpBase != null)
                             {
                                 //团购取团购价格
                                 row["sku_Price"] = gpBase.gp_pPric;
                                 row["sc_IsGP"] = true;
                                 if (model.sc_pCount <= gpBase.gp_pCount - gpBase.gp_SaleCount)
                                 {
                                     row["sc_pCountStatus"] = "有货";
                                 }
                                 else
                                 {
                                     row["sc_pCountStatus"] = "库存不足";
                                 }
                             }
                             else
                             {
                                 row["sc_pCountStatus"] = "团购结束";
                             }
                         }
                         else
                         {
                             row["sc_IsGP"] = false;
                             //库存
                             var skuBase = _skuBase.GetModel(Convert.ToInt32(row["sku_ID"]));
                             if (model.sc_pCount <= skuBase.sku_Stock)
                             {
                                 row["sc_pCountStatus"] = "有货";
                             }
                             else
                             {
                                 row["sc_pCountStatus"] = "库存不足";
                             }
                         }
                     }
                 }
                 ViewData["chartList"] = dt;
                 return true;
             }
         }
         return false;
     }
     else
     {
         Response.Redirect("/wapLogin/Login");
         return false;
     }
 }
예제 #4
0
        public string insertintoCart()
        {
            int pid = 0;
            int count = 0;
            int result = 0;
            bool result2 = false;
            string mm = "";
            decimal pric=0;
            if (!string.IsNullOrEmpty(RequestBase.GetString("skuid")))
            {
                pid = int.Parse(RequestBase.GetString("skuid").ToString());
            }

            if (!string.IsNullOrEmpty(RequestBase.GetString("pric")))
            {
                pric = decimal.Parse(RequestBase.GetString("pric").ToString());
            }

            if (!string.IsNullOrEmpty(RequestBase.GetString("count")))
            {
                count = int.Parse(RequestBase.GetString("count").ToString());
            }
            if (Request.Cookies["UserInfo"] != null)
            {
                int mid = (CookieEncrypt.DeserializeObject(System.Web.HttpContext.Current.Request.Cookies["UserInfo"].Value) as Model.MemberBase).m_ID;
                Model.ShoppingCartBase scmodel = new ShoppingCartBase();

                var model = new ListModel();
                model.vmgblist = new BLL.vm_GBDetails().GetModelList(" gp_isdel=0 and gp_statuscode=0  and sku_id=" + pid + " and gp_pCount-gp_SaleCount>0");
                if (model.vmgblist.Count > 0)
                {
                    var sclist = new BLL.ShoppingCartBase().GetModelList(" m_ID=" + mid + " and sku_ID=" + model.vmgblist[0].sku_ID + " and sc_IsDel=0 and sc_IsGP=1");
                    if (sclist.Count > 0)
                    {
                        Model.ShoppingCartBase upmodel = new BLL.ShoppingCartBase().GetModel(sclist[0].sc_ID);
                        //改数量
                        upmodel.sc_pCount += count;
                        upmodel.sc_pPric = pric;
                        upmodel.sc_CreateOn = DateTime.Now;
                        upmodel.sc_IsGP = true;
                        result2 = new BLL.ShoppingCartBase().Update(upmodel);

                    }
                    else
                    {
                        //添加
                        scmodel.m_ID = mid;
                        scmodel.sc_pCount = count;
                        scmodel.sc_pPric = pric;
                        scmodel.sc_CreateOn = DateTime.Now;
                        scmodel.sku_ID = pid;
                        scmodel.sc_IsGP = true;
                        result = new BLL.ShoppingCartBase().Add(scmodel);
                    }
                    if (result > 0 || result2)
                    {
                        int? pcount = 0;
                        decimal? ppric;
                        decimal pricecount = 0;
                        int? allpcount = 0;
                        var scalllist = new BLL.ShoppingCartBase().GetModelList("  m_ID=" + mid + " and sc_IsDel=0");
                        //ViewData["pcount"] = sclist.Count;
                        foreach (var item in scalllist)
                        {
                            pcount = item.sc_pCount;
                            ppric = item.sc_pPric;
                            pricecount += decimal.Parse(((double)pcount * (double)ppric).ToString());
                            allpcount += pcount;
                        }
                        string html = "<div class=\"modal\" id=\"chart-modal\"><a class=\"close\"   id=\"close\" onclick=\"closeit()\">X</a><div class=\"yes-chart\"><div class=\"yes-icon alignleft\"></div><div class=\"chart-font alignright\"><dl><dt><strong>添加成功!</strong></dt><dd>购物车共有<span> " + allpcount + "</span>件商品,商品总价:<span>¥ " + pricecount + " </span></dd></dl><div class=\"clear\"></div><a class=\"total-chart\" href=\"/Chart/Chart\">去购物车结算 ></a><a class=\"go-shop\" href=\"javascript:void(0)\" id=\"keepshopping\" onclick=\"closeit()\">继续购物</a></div><!--chart-font end--></div>";
                        return html;
                    }
                    else
                    {
                        mm = "fail";
                        return mm;
                    }
                }
                else
                {
                    string html = "<div class=\"modal\" id=\"chart-modal\"><a class=\"close\"   id=\"close\" onclick=\"closeit()\">X</a><div class=\"yes-chart\"><div class=\"no-icon alignleft\"></div><div class=\"chart-font alignright\"><dl><dt><strong>该款团购已被抢光啦,下次记得早点来哦!</strong></dt></dl><div class=\"clear\"></div><a class=\"total-chart\" href=\"/Chart/Chart\">去购物车结算 ></a><a class=\"go-shop\" href=\"javascript:void(0)\" id=\"keepshopping\" onclick=\"closeit()\">继续购物</a></div><!--chart-font end--></div>";
                    return html;
                }
            }
            else
            {
                mm = "nologon";

                return mm;
            }
        }
        /// <summary>
        /// 购物车
        /// </summary>
        /// <returns></returns>
        private string shopcartMethod()
        {
            string result = "";
            string pid = Form["p_id"];
            string p_chima = Form["p_chima"];
            string p_yanse = Form["p_yanse"];
            string p_commoditynum = Form["p_commoditynum"];
            DataTable dtsku = new BLL.SKUBase().GetList(" sku_IsDel=0 and p_ID= "+pid).Tables[0];
            string  pt_id= new BLL.ProductBase().GetModel(int.Parse(pid)).pt_ID.ToString();//商品小类型
            string ptp_id= new BLL.ProductTypeBase().GetModel(int.Parse(pt_id)).pt_ParentId.ToString();//商品大类型
            if (System.Web.HttpContext.Current.Request.Cookies[":userlogin"] == null || System.Web.HttpContext.Current.Request.Cookies[":userlogin"].Value == "")//如果没有用户登录
            {
                result = "{'result':'error_login'}";
            }
            else {//如果有用户登录

                Model.MemberBase mbmodel = CookieEncrypt.DeserializeObject(System.Web.HttpContext.Current.Request.Cookies[":userlogin"].Value) as MemberBase;

                if (ptp_id == "488" || ptp_id == "489") //是男鞋或女鞋
                {
                    if (p_chima == "0")
                    {
                        result = "{'result':'error_chima'}";
                    }
                    else if (p_yanse == "0")
                    {
                        result = "{'result':'error_yanse'}";
                    }
                    else
                    { //尺码 颜色都选择后  写入购物车

                        Model.ShoppingCartBase scmodel = new ShoppingCartBase();
                        scmodel.sku_ID = int.Parse(dtsku.Rows[0]["sku_ID"].ToString());
                        scmodel.m_ID = mbmodel.m_ID;
                        scmodel.sc_pCount =int.Parse( p_commoditynum);
                        scmodel.sc_pPric = Convert.ToDecimal(dtsku.Rows[0]["sku_Price"]);
                        scmodel.sc_CreateOn = DateTime.Now;
                        scmodel.sc_IsDel = false;
                        scmodel.sc_Status = false;
                        scmodel.sc_IsGP = false;
                        scmodel.sc_chima = p_chima;
                        scmodel.sc_yanse = p_yanse;

                        int re= new BLL.ShoppingCartBase().Add(scmodel);
                        if (re > 0)
                        {
                            result = "{'result':'success'}";
                        }
                        else {
                            result = "{'result':'error_data'}";
                        }
                    }
                }
                else//如果选择的商品不是鞋子那么尺码颜色设为0
                {
                    Model.ShoppingCartBase scmodel = new ShoppingCartBase();
                    scmodel.sku_ID = int.Parse(dtsku.Rows[0]["sku_id"].ToString());
                    scmodel.m_ID = mbmodel.m_ID;
                    scmodel.sc_pCount = int.Parse(p_commoditynum);
                    scmodel.sc_pPric = Convert.ToDecimal(dtsku.Rows[0]["sku_Price"]);
                    scmodel.sc_CreateOn = DateTime.Now;
                    scmodel.sc_IsDel = false;
                    scmodel.sc_Status = false;
                    scmodel.sc_IsGP = false;
                    scmodel.sc_chima = p_chima;
                    scmodel.sc_yanse = p_yanse;

                    int re = new BLL.ShoppingCartBase().Add(scmodel);
                    if (re > 0)
                    {
                        result = "{'result':'success'}";
                    }
                    else
                    {
                        result = "{'result':'error_data'}";
                    }
                }
            }
            return result;
        }
        /// <summary>
        /// 删除购物车单个物品信息
        /// </summary>
        /// <returns></returns>
        private string removeshop()
        {
            string result = "";
            string scid = Form["sc_id"];
            try
            {
                Model.ShoppingCartBase scmodel = new BLL.ShoppingCartBase().GetModel(int.Parse(scid));
                scmodel.sc_IsDel = true;
                bool re = new BLL.ShoppingCartBase().Update(scmodel);
                if (re)
                {
                    result = "1";
                }
                else {
                    result = "0";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
        /// <summary>
        /// 生成订单详细
        /// </summary>
        public void CreateOrderSKUDetail(int orderID)
        {
            try
            {
                var context = System.Web.HttpContext.Current;
                string mID = context.Request.Params["mID"];
                string ids = context.Request.Params["ids"];
                BLL.ShoppingCartBase shop = new BLL.ShoppingCartBase();
                string idslist = ids.Trim(',');
                var list = shop.GetModelList(" sc_IsDel = 0 and m_ID = " + mID + " and sku_ID in (" + idslist + ")");
                BLL.OrderSKUDetail bos = new BLL.OrderSKUDetail();
                BLL.ShoppingCartBase bscb = new BLL.ShoppingCartBase();
                BLL.GroupPurchaseBase bgpb = new BLL.GroupPurchaseBase();
                BLL.SKUBase bskuB = new BLL.SKUBase();

                foreach (var model in list)
                {
                    //生成订单详情
                    Model.OrderSKUDetail mosd = new Model.OrderSKUDetail();
                    mosd.o_ID = orderID;
                    mosd.os_pCount = model.sc_pCount;
                    mosd.sku_ID = model.sku_ID;
                    mosd.os_IsGP = model.sc_IsGP;
                    mosd.os_Price = model.sc_pPric;
                    mosd.os_chima=model.sc_chima;
                    mosd.os_yanse=model.sc_yanse;
                    //更改购物车状态
                    bscb.ChangeStatus(true, Convert.ToInt32(mID), model.sku_ID.ToString());
                    //减少库存,增加售出数量
                    var msku = bskuB.GetModel(model.sku_ID.Value);
                    msku.sku_Stock = msku.sku_Stock - model.sc_pCount;
                    msku.sku_SalesCount = msku.sku_SalesCount+ model.sc_pCount.Value;
                    //判断库存
                    if (msku.sku_Stock < 0)
                    {
                        throw new Exception("库存不足");
                    }

                    bskuB.Update(msku);
                    if (model.sc_IsGP)
                    {
                        //增加团购卖出数量
                        string sql = " sku_ID = " + model.sku_ID.Value + " and gp_IsDel = 0 and gp_StatusCode = 0 and gp_StartTime <= '" + DateTime.Now + "' and gp_EndTime >= '" + DateTime.Now + "'";
                        var mgp = bgpb.GetModelList(sql).FirstOrDefault();
                        if (mgp != null)
                        {
                            mgp.gp_SaleCount += model.sc_pCount.Value;
                            if (mgp.gp_SaleCount > mgp.gp_pCount.Value)
                            {
                                throw new Exception("库存不足");
                            }
                            bgpb.Update(mgp);
                        }
                    }
                    bos.Add(mosd);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public string insertintoCart()
        {
            int skuid = 0;
            int count = 0;
            int result = 0;
            bool result2=false;
            string mm = "";
            decimal pric = 0;
            if (!string.IsNullOrEmpty(RequestBase.GetString("skuid")))
            {
                skuid = int.Parse(RequestBase.GetString("skuid").ToString());
            }
            if (!string.IsNullOrEmpty(RequestBase.GetString("count")))
            {
                count = int.Parse(RequestBase.GetString("count").ToString());
            }
            if (LoginMember != null)
            {
                int mid = (CookieEncrypt.DeserializeObject(System.Web.HttpContext.Current.Request.Cookies["UserInfo"].Value) as Model.MemberBase).m_ID;
                Model.ShoppingCartBase scmodel = new ShoppingCartBase();
                Model.SKUBase skumodel = new BLL.SKUBase().GetModelList(" sku_ID=" + skuid)[0];
                if (skumodel.sku_Stock > 0)
                {
                    model.vmpinfolist = new BLL.vw_PInfo().GetModelList(" p_IsDel=0 and p_StatusCode=0 and p_SellStatus=1  and sku_ID= " + skuid);//商品信息
                    var sclist = new BLL.ShoppingCartBase().GetModelList(" m_ID=" + mid + " and sku_ID=" + skuid + " and sc_IsDel=0");
                    if (sclist.Count > 0)
                    {
                        Model.ShoppingCartBase upmodel = new BLL.ShoppingCartBase().GetModel(sclist[0].sc_ID);
                        //改数量
                        string sql = " sku_ID=" + skuid + " and gp_StatusCode=0 and gp_IsDel=0 and gp_EndTime > '" + DateTime.Now + "'";
                        var gplist = new BLL.GroupPurchaseBase().GetModelList(sql);
                        if (gplist.Count > 0)
                        {
                            upmodel.sc_pPric = decimal.Parse(gplist[0].gp_pPric.ToString());
                            upmodel.sc_IsGP = true;
                        }
                        else
                        {
                            if (model.vmpinfolist.Count>0)
                            upmodel.sc_pPric = decimal.Parse(model.vmpinfolist[0].sku_Price.ToString());
                            upmodel.sc_IsGP = false;
                        }
                        upmodel.sc_pCount += count;
                        //upmodel.sc_pPric = model.vmpinfolist[0].sku_Price;
                        upmodel.sc_CreateOn = DateTime.Now;
                        result2 = new BLL.ShoppingCartBase().Update(upmodel);

                    }
                    else
                    {
                        //添加
                        string sql = " sku_ID=" + skuid + " and gp_StatusCode=0 and gp_IsDel=0 and gp_EndTime > '" + DateTime.Now + "'";
                        var gplist = new BLL.GroupPurchaseBase().GetModelList(sql);
                        if (gplist.Count > 0)
                        {
                            scmodel.sc_pPric = decimal.Parse(gplist[0].gp_pPric.ToString());
                            scmodel.sc_IsGP = true;
                        }
                        else
                        {
                            if (model.vmpinfolist.Count > 0)
                                scmodel.sc_pPric = decimal.Parse(model.vmpinfolist[0].sku_Price.ToString());
                            scmodel.sc_IsGP = false;
                        }
                        scmodel.m_ID = mid;
                        scmodel.sc_pCount = count;
                        //scmodel.sc_pPric = pric;
                        scmodel.sc_CreateOn = DateTime.Now;
                        scmodel.sku_ID = skuid;
                        result = new BLL.ShoppingCartBase().Add(scmodel);
                    }
                    if (result > 0 || result2)
                    {
                        int? pcount = 0;
                        decimal? ppric;
                        decimal pricecount = 0;
                        int? allpcount = 0;
                        var scalllist = new BLL.ShoppingCartBase().GetModelList("  m_ID=" + mid + "and sc_IsDel=0");
                        //ViewData["pcount"] = sclist.Count;
                        foreach (var item in scalllist)
                        {
                            pcount = item.sc_pCount;
                            ppric = item.sc_pPric;
                            pricecount += decimal.Parse(((double)pcount * (double)ppric).ToString());
                            allpcount += pcount;
                        }
                        string html = "<div class=\"modal\" id=\"chart-modal\"><a class=\"close\"   id=\"close\" onclick=\"closeit()\">X</a><div class=\"yes-chart\"><div class=\"yes-icon alignleft\"></div><div class=\"chart-font alignright\"><dl><dt><strong>添加成功!</strong></dt><dd>购物车共有<span> " + allpcount + "</span>件商品,商品总价:<span>¥ " + pricecount + " </span></dd></dl><div class=\"clear\"></div><a class=\"total-chart\" href=\"/Chart/Chart\" style=\"width:140px;\">去购物车结算 ></a><a class=\"go-shop\" href=\"javascript:void(0)\" id=\"keepshopping\" onclick=\"closeit()\">继续购物</a></div><!--chart-font end--></div><!--yes-chart end-->";
                        return html;
                    }
                    else
                    {
                        mm = "fail";
                        return mm;
                    }
                }
                else
                {
                    string html = "<div class=\"modal\" id=\"chart-modal\"><a class=\"close\"   id=\"close\" onclick=\"closeit()\">X</a><div class=\"yes-chart\"><div class=\"yes-icon alignleft\"></div><div class=\"chart-font alignright\"><dl><dt><strong>库存不足,添加失败!</strong></dt></dl><div class=\"clear\"></div><a class=\"total-chart\" href=\"/Chart/Chart\" style=\"width:140px;\">去购物车结算 ></a><a class=\"go-shop\" href=\"javascript:void(0)\" id=\"keepshopping\" onclick=\"closeit()\">继续购物</a></div><!--chart-font end--></div><!--yes-chart end-->";
                    return html;
                    //<div class=\"clear\"></div><div class=\"shop-cont\"><h2>购买该商品的用户还购买了</h2><ul class=\"shop-list\"><li><div class=\"pro-img\"><a href=\"#\"><img src=\"images/products/proList_ad_01.jpg\" alt=\"产品图片\" /></a></div><p><a href=\"#\">SUMACO素玛哥牌多口味进口 ...</a></p><p><span>¥23.90</span><del>¥23.90</del></p></li><li><div class=\"pro-img\"><a href=\"#\"><img src=\"images/products/proList_ad_02.jpg\" alt=\"产品图片\" /></a></div><p><a href=\"#\">SUMACO素玛哥牌多口味进口 ...</a></p><p><span>¥23.90</span><del>¥23.90</del></p></li><li><div class=\"pro-img\"><a href=\"#\"><img src=\"images/products/proList_ad_03.jpg\" alt=\"产品图片\" /></a></div><p><a href=\"#\">SUMACO素玛哥牌多口味进口 ...</a></p><p><span>¥23.90</span><del>¥23.90</del></p></li><li><div class=\"pro-img\"><a href=\"#\"><img src=\"images/products/proList_ad_04.jpg\" alt=\"产品图片\" /></a></div><p><a href=\"#\">SUMACO素玛哥牌多口味进口 ...</a></p><p><span>¥23.90</span><del>¥23.90</del></p></li></ul></div><!--shop-cont end--></div><!--chart-modal end-->
                }
            }
            else
            {
                mm = "nologon";

                return mm;
            }
        }
예제 #9
0
        /// <summary>
        /// 加载商品清单
        /// </summary>
        //public object GetProductsList(string ids)
        //{
        //    ids = ids.Trim(',');
        //    //会员ID
        //    BLL.ShoppingCartBase shop = new BLL.ShoppingCartBase();
        //    var list = shop.GetModelList(" sc_IsDel = 0 and m_ID = " + mimodel.m_ID + "and sku_ID in (" + ids + ")");
        //    if (!string.IsNullOrWhiteSpace(ids))
        //    {
        //        var dt = new BLL.SKUBase().GetSKUDetial(" and sku_ID in (" + ids + ")", true);
        //        if (dt != null)
        //        {
        //            dt.Columns.Add("sc_pCount", Type.GetType("System.Int32"));//商品数量
        //            dt.Columns.Add("sc_pCountStatus", Type.GetType("System.String"));//商品库存状态
        //            dt.Columns.Add("sc_IsGP", Type.GetType("System.Boolean"));//团购标识
        //            foreach (DataRow row in dt.Rows)
        //            {
        //                var model = list.Where(m => m.sku_ID == Convert.ToInt32(row["sku_ID"])).FirstOrDefault();
        //                if (model != null)
        //                {
        //                    row["sc_pCount"] = model.sc_pCount;
        //                    string sql = " sku_ID = " + row["sku_ID"] + " and gp_IsDel = 0 and gp_StatusCode = 0 and gp_StartTime <= '" + DateTime.Now + "' and gp_EndTime >= '" + DateTime.Now + "'";
        //                    //团购
        //                    var gpBase = _gpBase.GetModelList(sql).FirstOrDefault();
        //                    if (gpBase != null)
        //                    {
        //                        //团购取团购价格
        //                        row["sku_Price"] = gpBase.gp_pPric;
        //                        row["sc_IsGP"] = true;
        //                        if (model.sc_pCount <= gpBase.gp_pCount - gpBase.gp_SaleCount)
        //                        {
        //                            row["sc_pCountStatus"] = "有货";
        //                        }
        //                        else
        //                        {
        //                            row["sc_pCountStatus"] = "库存不足";
        //                        }
        //                    }
        //                    else
        //                    {
        //                        row["sc_IsGP"] = false;
        //                        //库存
        //                        var skuBase = _skuBase.GetModel(Convert.ToInt32(row["sku_ID"]));
        //                        if (model.sc_pCount <= skuBase.sku_Stock)
        //                        {
        //                            row["sc_pCountStatus"] = "有货";
        //                        }
        //                        else
        //                        {
        //                            row["sc_pCountStatus"] = "库存不足";
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        ViewData["OrderProducts"] = dt;
        //    }
        //    return ViewData["OrderProducts"];
        //}
        public object GetProductsList(string ids)
        {
            ids = ids.Trim(',');
            //会员ID
            BLL.ShoppingCartBase shop = new BLL.ShoppingCartBase();
            var list = shop.GetModelList(" sc_IsDel = 0 and m_ID = " + mimodel.m_ID + "and sku_ID in (" + ids + ")");

            if (!string.IsNullOrWhiteSpace(ids))
            {
                //var dt = new BLL.SKUBase().GetSKUDetial(" and sku_ID in (" + ids + ")", true);
                var dt = new BLL.ShoppingCartBase().GetList(" sc_isdel=0 and sc_Status=0 and sc_IsGP=0 and m_ID="+mimodel.m_ID).Tables[0];
                if (dt != null)
                {
                    dt.Columns.Add("sc_pCount2", Type.GetType("System.Int32"));//商品数量
                    dt.Columns.Add("sc_pCountStatus", Type.GetType("System.String"));//商品库存状态
                    dt.Columns.Add("sc_IsGP2", Type.GetType("System.Boolean"));//团购标识
                    foreach (DataRow row in dt.Rows)
                    {
                        var model = list.Where(m => m.sc_ID == Convert.ToInt32(row["sc_ID"])).FirstOrDefault();
                        if (model != null)
                        {
                            row["sc_pCount2"] = model.sc_pCount;
                            string sql = " sku_ID = " + row["sku_ID"] + " and gp_IsDel = 0 and gp_StatusCode = 0 and gp_StartTime <= '" + DateTime.Now + "' and gp_EndTime >= '" + DateTime.Now + "'";
                            //团购
                            var gpBase = _gpBase.GetModelList(sql).FirstOrDefault();
                            if (gpBase != null)
                            {
                                //团购取团购价格
                                row["sku_Price"] = gpBase.gp_pPric;
                                row["sc_IsGP2"] = true;
                                if (model.sc_pCount <= gpBase.gp_pCount - gpBase.gp_SaleCount)
                                {
                                    row["sc_pCountStatus"] = "有货";
                                }
                                else
                                {
                                    row["sc_pCountStatus"] = "库存不足";
                                }
                            }
                            else
                            {
                                row["sc_IsGP2"] = false;
                                //库存
                                var skuBase = _skuBase.GetModel(Convert.ToInt32(row["sku_ID"]));
                                if (model.sc_pCount <= skuBase.sku_Stock)
                                {
                                    row["sc_pCountStatus"] = "有货";
                                }
                                else
                                {
                                    row["sc_pCountStatus"] = "库存不足";
                                }
                            }
                        }
                    }
                }
                ViewData["OrderProducts"] = dt;
            }
            return ViewData["OrderProducts"];
        }
예제 #10
0
        public string buyagain()
        {
            string message = "";
            int oid = 0;
            string where = "";
            int mid = 0;
            if (LoginMember != null)
            {
                if (!string.IsNullOrEmpty(RequestBase.GetString("oid")))
                {
                    oid = int.Parse(RequestBase.GetString("oid"));
                }
                mid = (CookieEncrypt.DeserializeObject(System.Web.HttpContext.Current.Request.Cookies["UserInfo"].Value) as Model.MemberBase).m_ID;
                ViewBag.ordersku = vobll.GetModelList(" m_ID=" + mid + " and o_ID=os_oID and o_Code='" + obll.GetModel(oid).o_Code+"'");
                string skulist = "";
                string countlist = "";
                foreach (var sku in ViewBag.ordersku)
                {
                    skulist += sku.sku_ID + ",";
                    countlist += sku.os_pCount + ",";
                }
                skulist = skulist.Substring(0, skulist.Length - 1);
                countlist = countlist.Substring(0, countlist.Length - 1);
                string[] skuid = skulist.Split(',');
                string[] count = countlist.Split(',');
                int skuinsert = 0;
                for (int i = 0; i < skuid.Length; i++)
                {
                    Model.ShoppingCartBase scmodel = new Model.ShoppingCartBase();
                    Model.SKUBase skumodel =new BLL.SKUBase().GetModel(int.Parse(skuid[i]));
                    if (skumodel.sku_Stock > 0)
                    {
                        skuinsert += 1;
                    }
                }

                if (skuinsert == skuid.Length)
                {
                    int rn = 0;
                    int result = 0;
                    bool result2 = false;
                    for (int i = 0; i < skuid.Length; i++)
                    {
                        Model.ShoppingCartBase scmodel = new Model.ShoppingCartBase();
                        var shopsku = new BLL.ShoppingCartBase().GetModelList(" m_ID="+mid+" and sku_ID="+skuid[i]+" and sc_IsDel=0");
                        Model.SKUBase skumodel = new BLL.SKUBase().GetModel(int.Parse(skuid[i]));
                        if (shopsku.Count > 0)
                        {
                            scmodel = new BLL.ShoppingCartBase().GetModel(shopsku[0].sc_ID);
                            scmodel.sc_pCount =shopsku[0].sc_pCount+ int.Parse(count[i]);
                            result2 = new BLL.ShoppingCartBase().Update(scmodel);
                        }
                        else
                        {
                            scmodel.m_ID = mid;
                            scmodel.sc_pCount = int.Parse(count[i]);
                            scmodel.sku_ID = int.Parse(skuid[i]);
                            scmodel.sc_CreateOn = DateTime.Now;
                            scmodel.sc_pPric = skumodel.sku_Price;
                            result = new BLL.ShoppingCartBase().Add(scmodel);
                        }
                        if (result > 0||result2)
                        {
                            rn += 1;
                        }
                    }
                    if (rn == skuid.Length)
                    {
                        message = "添加成功";
                    }
                    else
                    {
                        message = "添加失败";
                    }
                }
                else
                {
                    message = "库存不足";
                }
                    return message;
            }
            else
            {
                Response.Redirect("/Index/Index");
                return message;
            }
        }