/// <summary> /// 保存活动(修改或创建) /// </summary> /// <param name="model">活动数据</param> /// <param name="products">产品数据</param> /// <param name="qiangGouDiff">同步数据</param> /// <returns></returns> public ActionResult PostSave(QiangGouModel model, string products, string qiangGouDiff) { try { if (model == null) { return(Json(new { Status = 0, Message = "保存失败【活动内容为空】" })); } var cacheGetFlag = GetOperateFlagCache(); if (cacheGetFlag) { return(Json(new { Status = 0, Message = "现在有人正在操作请稍等下。。。。" })); } var cacheSetStartFlag = SetOperateFlagStartCache(); if (!cacheSetStartFlag) { return(Json(new { Status = 0, Message = "服务器异常,请再点击保存" })); } // 是否更新标识 var isUpdate = model.ActivityID != null; var origin = new QiangGouModel(); // 更新 查询活动详细数据 if (isUpdate) { origin = QiangGouManager.FetchQiangGouAndProducts(model.ActivityID.Value); } // 序列化产品数据 model.Products = JsonConvert.DeserializeObject <List <QiangGouProductModel> >(products); // 产品不存在 退出 if (!model.Products.Any()) { return(Json(new { Status = 0, Message = "保存失败【活动无产品】" })); } // 存在差异产品 并序列化成list var diffQiangGouList = new List <QiangGouDiffModel>(); if (qiangGouDiff != null) { diffQiangGouList = JsonConvert.DeserializeObject <List <QiangGouDiffModel> >(qiangGouDiff); } var result = QiangGouManager.SyncSave(model, diffQiangGouList); switch (result.Item1) { case -1: return(Json(new { Status = 0, Message = "保存失败【闪购活动时间不允许重叠】" })); case -3: return(Json(new { Status = 0, Message = "刷新缓存失败【请手动刷新】" })); default: if (result.Item1 > 0) { QiangGouModel after; if (model.ActivityID != null && !model.NeedExam) { after = QiangGouManager.FetchQiangGouAndProducts(model.ActivityID.Value); } else { after = QiangGouManager.FetchQiangGouAndProductsTemp(model.ActivityID.Value); } var request = new ActivityTypeRequest { ActivityId = model.ActivityID.Value, StartDateTime = model.StartDateTime, EndDateTime = model.EndDateTime, Status = 1, Type = 1 }; var activityTypeResult = QiangGouManager.RecordActivityType(request); if (!activityTypeResult) { return(Json(new { Status = 0, Message = "保存失败重试" })); } if (isUpdate) { var chandata = LogChangeDataManager.GetLogChangeData(origin, after); var beforeValue = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item1); var afterValue = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item2); var oprLog = new FlashSaleProductOprLog { OperateUser = ThreadIdentity.Operator.Name, CreateDateTime = DateTime.Now, BeforeValue = JsonConvert.SerializeObject(beforeValue), AfterValue = JsonConvert.SerializeObject(afterValue), LogType = "FlashSaleLog", LogId = result.Item2.ToString(), Operation = model.NeedExam ? "修改活动到待审核" : "修改活动" }; LoggerManager.InsertLog("FlashSaleOprLog", oprLog); LoggerManager.InsertFlashSaleLog(chandata.Item1, beforeValue.HashKey); LoggerManager.InsertFlashSaleLog(chandata.Item2, afterValue.HashKey); } else { var afterValue = QiangGouManager.GenerateSimpleQiangGouModel(after); var oprLog = new FlashSaleProductOprLog { OperateUser = ThreadIdentity.Operator.Name, CreateDateTime = DateTime.Now, BeforeValue = JsonConvert.SerializeObject(Json(new { actvityid = result.Item2.ToString() })), AfterValue = JsonConvert.SerializeObject(afterValue), LogType = "FlashSaleLog", LogId = result.Item2.ToString(), Operation = model.NeedExam ? "新建活动到待审核" : "新建活动" }; LoggerManager.InsertLog("FlashSaleOprLog", oprLog); LoggerManager.InsertFlashSaleLog(after, afterValue.HashKey); } if (model.ActivityID != null && !model.NeedExam) { var cache = UpdateToCache(model.ActivityID.Value, false, model.ActiveType); if (cache == false) { return(Json(new { Status = 0, Message = "刷新缓存失败【请手动刷新】" })); } } return(Json(new { Status = 1, Message = "保存成功" })); } break; } return(Json(new { Status = 0, Message = "保存失败【未知错误】" })); } catch (Exception e) { return(Json(new { Status = 0, Message = e.Message + e.InnerException + e.StackTrace })); } finally { SetOperateFlagEndCache(); } }