Exemplo n.º 1
0
        public void RemovePromotionSku(string redisNo, string spu, string sku)
        {
            var model = CacheHelper.AutoCache <List <RedisPromotionSpuModel> >(
                "SFO2O.SJ_" + redisNo, "", () =>
            {
                return(new List <RedisPromotionSpuModel>());
            });

            var spuModel = model.FirstOrDefault(p => p.Spu == spu);

            if (spuModel != null)
            {
                spuModel.AddTime = DateTime.Now;
                var skuModel = spuModel.Skus.FirstOrDefault(p => p.sku == sku);

                if (skuModel != null)
                {
                    spuModel.Skus.Remove(skuModel);
                }
            }

            if (spuModel.Skus.Count == 0)
            {
                model.Remove(spuModel);
            }

            RedisCacheHelper.Add("SFO2O.SJ_" + redisNo, model, 30);
        }
Exemplo n.º 2
0
        public ActionResult GetSupplierSkus(string productName, string redisNo, int promotionId)
        {
            var page = new PageDTO()
            {
                PageIndex = this.PageNo,
                PageSize  = this.PageSize
            };

            var model = CacheHelper.AutoCache <List <RedisPromotionSpuModel> >(
                "SFO2O.SJ_" + redisNo, "", () =>
            {
                return(new List <RedisPromotionSpuModel>());
            });

            var skus = _bll.GetSpuulierSkus(this.CurrentUser.SupplierID, productName, page);


            foreach (var skuItem in skus.Items)
            {
                if (skuItem.skuProStatus == "true" && skuItem.PromotionId != promotionId)//不是当前促销的商品
                {
                    skuItem.PromotionPrice = -1;
                    skuItem.PromotionRate  = -1;
                    continue;
                }

                if (promotionId <= 0 && model.Count == 0)//新建促销
                {
                    skuItem.PromotionPrice = -1;
                    skuItem.PromotionRate  = -1;
                    continue;
                }

                if (model != null && model.Count > 0)
                {
                    var sku = skuItem.Sku;

                    var promotionSpu = model.FirstOrDefault(p => p.Spu == skuItem.spu);

                    if (promotionSpu != null)
                    {
                        var promotionSku = promotionSpu.Skus.FirstOrDefault(p => p.sku == sku);

                        if (promotionSku != null)
                        {
                            skuItem.PromotionPrice = promotionSku.PromotionPrice;
                            skuItem.PromotionRate  = promotionSku.PromotionRate;
                        }
                    }
                }
            }


            return(View(skus));
        }
Exemplo n.º 3
0
        public ActionResult GetSelectPromotionSkus(string redisNo)
        {
            var model = CacheHelper.AutoCache <List <RedisPromotionSpuModel> >(
                "SFO2O.SJ_" + redisNo, "", () =>
            {
                return(new List <RedisPromotionSpuModel>());
            });

            List <string> skuNo = new List <string>();

            foreach (var m in model)
            {
                foreach (var sku in m.Skus)
                {
                    if (!skuNo.Contains(sku.sku))
                    {
                        skuNo.Add(sku.sku);
                    }
                }
            }

            List <PromotionSkuListModel> skuInfos = new List <PromotionSkuListModel>();

            if (skuNo.Count > 0)
            {
                skuInfos = _bll.GetPromotionSkuInfo(skuNo);
            }

            if (model.Count > 0 && skuInfos.Count > 0)
            {
                foreach (var sku in skuInfos)
                {
                    var spuModel = model.FirstOrDefault(p => p.Spu == sku.spu);

                    if (spuModel == null || spuModel.Skus == null || spuModel.Skus.Count == 0)
                    {
                        continue;
                    }

                    var skuModel = spuModel.Skus.FirstOrDefault(p => p.sku == sku.Sku);

                    if (skuModel == null)
                    {
                        continue;
                    }

                    sku.PromotionPrice = skuModel.PromotionPrice;
                    sku.PromotionRate  = skuModel.PromotionRate;
                }
            }

            return(View(skuInfos));
        }
Exemplo n.º 4
0
        public void AddPromotionSku(string redisNo, string spu, string sku, decimal promotionPrice, decimal promotionRate)
        {
            var model = CacheHelper.AutoCache <List <RedisPromotionSpuModel> >(
                "SFO2O.SJ_" + redisNo, "", () =>
            {
                return(new List <RedisPromotionSpuModel>());
            });

            var spuModel = model.FirstOrDefault(p => p.Spu == spu);

            if (spuModel != null)
            {
                spuModel.AddTime = DateTime.Now;
                var skuModel = spuModel.Skus.FirstOrDefault(p => p.sku == sku);

                if (skuModel != null)
                {
                    skuModel.PromotionPrice = promotionPrice;
                    skuModel.PromotionRate  = promotionRate;
                }
                else
                {
                    spuModel.Skus.Add(new RedisPromotionSkuModel()
                    {
                        PromotionPrice = promotionPrice,
                        PromotionRate  = promotionRate,
                        sku            = sku
                    });
                }
            }


            if (spuModel == null || spuModel.Skus == null)
            {
                spuModel      = new RedisPromotionSpuModel();
                spuModel.Skus = new List <RedisPromotionSkuModel>();

                spuModel.Spu     = spu;
                spuModel.AddTime = DateTime.Now;
                spuModel.Skus.Add(new RedisPromotionSkuModel()
                {
                    PromotionPrice = promotionPrice,
                    PromotionRate  = promotionRate,
                    sku            = sku
                });

                model.Add(spuModel);
            }

            RedisCacheHelper.Add("SFO2O.SJ_" + redisNo, model, 30);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取当前登录用户的LoginUserModel
        /// </summary>
        /// <param name="Session"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static LoginUserModel GetUserInfo(HttpSessionStateBase Session, int userid)
        {
            var model = CacheHelper.AutoCache <LoginUserModel>(
                GetCacheKey(userid.ToString()), "", () =>
            {
                return(SupplierUserBll.GetLoginUserModelByUserID(userid));
            });

            if (model != null && (model.SupplierUserInfo.Status != 1 || model.SupplierUserInfo.SupplierStatus != 1))
            {
                //用户状态无效,使用户的会话失效
                model = null;
                RemoveCurrentLoginInfo();
            }
            return(model);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 保存促销
        /// </summary>
        /// <param name="redisNo">redis缓存ID</param>
        /// <param name="promotionId">促销ID</param>
        /// <param name="promotionName">促销名称</param>
        /// <param name="startTime">促销开始时间</param>
        /// <param name="endTime">促销结束时间</param>
        /// <param name="promotionLable">促销标签</param>
        /// <param name="promotionCost">促销费用</param>
        /// <returns></returns>
        public ActionResult SavePromotion(string redisNo, int promotionId, string promotionName, DateTime startTime, DateTime endTime, string promotionLable, int promotionCost)
        {
            var isSuccess = true;
            var message   = "";

            try
            {
                var promotionMainInfo = new PromotionMainInfoModel()
                {
                    EndTime        = endTime,
                    Id             = promotionId,
                    PromotionCost  = promotionCost,
                    PromotionLable = promotionLable,
                    PromotionName  = promotionName,
                    StartTime      = startTime,
                    SupplierId     = this.CurrentUser.SupplierID,
                    CreateBy       = this.CurrentUser.UserName
                };

                var model = CacheHelper.AutoCache <List <RedisPromotionSpuModel> >(
                    "SFO2O.SJ_" + redisNo, "", () =>
                {
                    return(new List <RedisPromotionSpuModel>());
                });

                if (model == null || model.Count == 0)
                {
                    message   = "促銷信息已過期";
                    isSuccess = false;
                }
                else
                {
                    _bll.SavePromotion(model, promotionMainInfo);
                }
            }
            catch (Exception ext)
            {
                LogHelper.Error(ext);
                message   = "申請失败";
                isSuccess = false;
            }

            return(Json(new { IsSuccess = isSuccess, Message = message }));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取当前登录用户的LoginUserModel
        /// </summary>
        /// <param name="Session"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static LoginUserModel GetCurrentUserInfo()
        {
            var Session = HttpContext.Current.Session;
            int userid  = 0;

            if (TryGetCurrentUserID(out userid) && userid > 0)
            {
                var model = CacheHelper.AutoCache <LoginUserModel>(
                    GetCacheKey(userid), "", () =>
                {
                    return(new AdminUserBLL().GetLoginUserByUserID(userid));
                });
                if (model != null && model.AdminUserInfo.Status != 1)
                {
                    //用户状态无效,使用户的会话失效
                    model = null;
                    RemoveCurrentLoginInfo();
                }
                return(model);
            }
            return(null);
        }