Ejemplo n.º 1
0
        /// <summary>
        /// 修改满减活动
        /// </summary>
        /// <returns></returns>
        public ActionResult EditActive(long id)
        {
            FullDiscountActive      data  = FullDiscountApplication.GetActive(id);
            FullDiscountActiveModel model = new FullDiscountActiveModel();

            if (data == null || data.ShopId != CurShopId)
            {
                throw new HimallException("错误的活动编号");
            }
            model.Id           = data.Id;
            model.ActiveName   = data.ActiveName;
            model.StartTime    = data.StartTime;
            model.EndTime      = data.EndTime;
            model.IsAllProduct = data.IsAllProduct;
            model.RuleJSON     = JsonConvert.SerializeObject(data.Rules);
            var proids = data.Products.Select(d => d.ProductId).ToArray();

            model.ProductIds = string.Join(",", proids);

            var sermodel = FullDiscountApplication.GetMarketService(CurShopId);

            model.EndServerTime = sermodel.EndTime.Value.Date.AddDays(1).AddMinutes(-1);

            return(View(model));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加满减活动
        /// </summary>
        /// <returns></returns>
        public ActionResult AddActive()
        {
            FullDiscountActiveModel model = new FullDiscountActiveModel();

            model.ShopId       = CurShopId;
            model.StartTime    = DateTime.Now;
            model.EndTime      = DateTime.Now.AddMonths(1);
            model.IsAllProduct = true;
            model.RuleJSON     = "";

            var sermodel = FullDiscountApplication.GetMarketService(CurShopId);

            model.EndServerTime = sermodel.EndTime.Value.Date.AddDays(1).AddMinutes(-1);

            return(View(model));
        }
Ejemplo n.º 3
0
        public JsonResult EditActive(FullDiscountActiveModel model)
        {
            var result = new Result {
                success = false, msg = "未知错误", status = -1
            };

            if (string.IsNullOrWhiteSpace(model.ActiveName))
            {
                model.ActiveName = model.ActiveName.Trim();
            }
            FullDiscountActive data = FullDiscountApplication.GetActive(model.Id);

            if (data == null || data.ShopId != CurShopId)
            {
                throw new HimallException("错误的活动编号");
            }
            if (model.EndTime.Date < model.StartTime.Date)
            {
                throw new HimallException("错误的结束时间");
            }
            //数据有效性验证
            model.CheckValidation();
            List <FullDiscountRules> rules = JsonConvert.DeserializeObject <List <FullDiscountRules> >(model.RuleJSON);

            if (rules == null)
            {
                throw new HimallException("优惠规则异常");
            }
            rules = rules.OrderBy(d => d.Quota).ToList();
            CheckRules(rules);
            List <long> proids = new List <long>();

            if (model.IsAllProduct)
            {
                proids.Add(-1);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(model.ProductIds))
                {
                    proids = model.ProductIds.Split(',').Where(d => !string.IsNullOrWhiteSpace(d)).Select(d => long.Parse(d)).ToList();
                    List <long> cannotjoin = CheckCanNotJoinProduct(proids, data.Id);
                    if (cannotjoin.Count > 0)
                    {
                        result = new Result {
                            success = false, msg = string.Join(",", cannotjoin.ToArray()), status = -2
                        };
                        return(Json(result));
                    }
                }
            }
            var sermodel = FullDiscountApplication.GetMarketService(CurShopId);

            if (model.EndTime > sermodel.EndTime.Value.Date.AddDays(1))
            {
                throw new HimallException("活动结束时间不可超过服务时间");
            }

            if (ModelState.IsValid)
            {
                List <FullDiscountActiveProduct> products = proids.Select(d => new FullDiscountActiveProduct {
                    ProductId = d
                }).ToList();

                data.Id           = model.Id;
                data.ActiveName   = model.ActiveName;
                data.EndTime      = model.EndTime;
                data.ShopId       = CurShopId;
                data.IsAllProduct = model.IsAllProduct;
                data.Rules        = rules;
                data.Products     = products;
                FullDiscountApplication.UpdateActive(data);

                result = new Result {
                    success = true, msg = "操作成功", status = 1
                };
            }
            else
            {
                result = new Result {
                    success = false, msg = "数据异常,请检查数据有效性", status = -1
                };
            }
            return(Json(result));
        }