/// <summary> /// 新增团购活动 /// </summary> /// <returns></returns> public object AddActive(FightGroupActiveModel model) { var result = new Result { success = false, msg = "未知错误", status = -1 }; FightGroupActiveModel data = new FightGroupActiveModel(); if (model.EndTime.Date < DateTime.Now.Date) { throw new HimallException("错误的结束时间"); } if (model.EndTime.Date < model.StartTime.Date) { throw new HimallException("错误的结束时间"); } //数据有效性验证 //model.CheckValidation(); /*var skudata = FightGroupApplication.GetNewActiveItems(model.ProductId.Value).skulist; * foreach (var item in model.ActiveItems) * { * var cursku = skudata.FirstOrDefault(d => d.SkuId == item.SkuId); * if (cursku != null) * { * if (item.ActiveStock > cursku.ProductStock) * { * throw new HimallException(item.SkuId + "错误的活动库存"); * } * } * else * { * model.ActiveItems.Remove(item); * } * }*/ try { //model.ShopId = CurrentUserId; //model.ShopId = 1; model.LimitQuantity = 1; model.Seconds = 86400; model.AddTime = DateTime.Now; model.IconUrl = model.ProductDefaultImage; FightGroupApplication.AddActive(model); result = new Result { success = true, msg = "操作成功", status = 1 }; } catch (Exception ex) { result = new Result { success = false, msg = ex.Message, status = -1 }; } return(Json(result)); }
public JsonResult AddActive(FightGroupActiveModel model) { var result = new Result { success = false, msg = "未知错误", status = -1 }; FightGroupActiveModel data = new FightGroupActiveModel(); if (model.EndTime.Date < DateTime.Now.Date) { throw new MallException("错误的结束时间"); } if (model.EndTime.Date < model.StartTime.Date) { throw new MallException("错误的结束时间"); } var market = MarketApplication.GetMarketService(CurrentSellerManager.ShopId, MarketType.FightGroup); if (market != null) { var endtime = MarketApplication.GetServiceEndTime(market.Id); var newEnd = DateTime.Parse(endtime.ToString("yyyy-MM-dd") + " 23:59:59"); if (newEnd < model.EndTime.Date) { throw new MallException(string.Format("活动结束时间不得超过服务到期时间,<br/>您的服务到期时间为{0}", newEnd.ToString("yyyy-MM-dd HH:mm:ss"))); } } else { throw new MallException("您没有订购此服务"); } //数据有效性验证 model.CheckValidation(); if (!FightGroupApplication.ProductCanJoinActive(model.ProductId)) { throw new MallException("该商品已参与拼团或其他营销活动,请重新选择"); } var skudata = FightGroupApplication.GetNewActiveItems(model.ProductId).skulist; foreach (var item in model.ActiveItems) { var cursku = skudata.FirstOrDefault(d => d.SkuId == item.SkuId); if (cursku != null) { if (item.ActiveStock > cursku.ProductStock) { throw new MallException(item.SkuName + "错误的活动库存"); } } else { model.ActiveItems.Remove(item); } } if (ModelState.IsValid) { TryUpdateModelAsync(data); data.ShopId = CurShopId; data.IconUrl = SaveActiveIcon(data.IconUrl); model = data; FightGroupApplication.AddActive(data); ProductManagerApplication.SaveCaculateMinPrice(model.ProductId, CurrentShop.Id); result = new Result { success = true, msg = "操作成功", status = 1 }; } else { result = new Result { success = false, msg = "数据异常,请检查数据有效性", status = -1 }; } return(Json(result)); }
public JsonResult AddActive(FightGroupActiveModel model) { var result = new Result { success = false, msg = "未知错误", status = -1 }; FightGroupActiveModel data = new FightGroupActiveModel(); if (model.EndTime.Date < DateTime.Now.Date) { throw new HimallException("错误的结束时间"); } if (model.EndTime.Date < model.StartTime.Date) { throw new HimallException("错误的结束时间"); } //数据有效性验证 model.CheckValidation(); if (!FightGroupApplication.ProductCanJoinActive(model.ProductId.Value)) { throw new HimallException("该商品已参与拼团或其他营销活动,请重新选择"); } var skudata = FightGroupApplication.GetNewActiveItems(model.ProductId.Value).skulist; foreach (var item in model.ActiveItems) { var cursku = skudata.FirstOrDefault(d => d.SkuId == item.SkuId); if (cursku != null) { if (item.ActiveStock > cursku.ProductStock) { throw new HimallException(item.SkuId + "错误的活动库存"); } } else { model.ActiveItems.Remove(item); } } if (ModelState.IsValid) { UpdateModel(data); data.ShopId = CurShopId; data.IconUrl = SaveActiveIcon(data.IconUrl); model = data; FightGroupApplication.AddActive(data); result = new Result { success = true, msg = "操作成功", status = 1 }; } else { result = new Result { success = false, msg = "数据异常,请检查数据有效性", status = -1 }; } return(Json(result)); }