public ActionResult ExamActivity(Guid aid) { try { var cacheGetFlag = GetOperateFlagCache(); if (cacheGetFlag) { return(Json(new { Status = 0, Message = "现在有人正在操作请稍等下。。。。" })); } var cacheSetStartFlag = SetOperateFlagStartCache(); if (!cacheSetStartFlag) { return(Json(new { Status = 0, Message = "服务器异常,请再点击审核" })); } var origin = QiangGouManager.FetchQiangGouAndProducts(aid) ?? new QiangGouModel(); var result = QiangGouManager.ExamActivity(aid); if (result > 0) { var after = QiangGouManager.FetchQiangGouAndProducts(aid); var chandata = LogChangeDataManager.GetLogChangeData(origin, after); var beforeValue = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item1); var afterValue = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item2); var oprLog = new FlashSaleProductOprLog(); oprLog.OperateUser = ThreadIdentity.Operator.Name; oprLog.CreateDateTime = DateTime.Now; oprLog.BeforeValue = JsonConvert.SerializeObject(beforeValue); oprLog.AfterValue = JsonConvert.SerializeObject(afterValue); oprLog.LogType = "FlashSaleLog"; oprLog.LogId = after.ActivityID.ToString(); oprLog.Operation = "审核活动"; LoggerManager.InsertLog("FlashSaleOprLog", oprLog); LoggerManager.InsertFlashSaleLog(chandata.Item1, beforeValue.HashKey); LoggerManager.InsertFlashSaleLog(chandata.Item2, afterValue.HashKey); UpdateToCache(aid, false, origin.ActiveType); } //throw new Exception(); return(Json(new { code = result })); } catch (Exception e) { return(Json(new { code = -3, msg = e.Message + e.InnerException + e.StackTrace })); } finally { SetOperateFlagEndCache(); } }
public ActionResult Save(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); List <QiangGouDiffModel> qiangGouDiff = new List <QiangGouDiffModel>(); if (QiangGouDiff != null) { qiangGouDiff = JsonConvert.DeserializeObject <List <QiangGouDiffModel> >(QiangGouDiff); } if (!model.Products.Any()) { return(Json(new { Status = 0, Message = "保存失败【活动无产品】" })); } var result = QiangGouManager.Save(model, qiangGouDiff); if (result.Item1 == -1) { return(Json(new { Status = 0, Message = "保存失败【闪购活动时间不允许重叠】" })); } if (result.Item1 == -3) { return(Json(new { Status = 0, Message = "刷新缓存失败【请手动刷新】" })); } else 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 = "保存成功" })); } return(Json(new { Status = 0, Message = "保存失败【未知错误】" })); } catch (Exception e) { return(Json(new { Status = 0, Message = e.Message + e.InnerException + e.StackTrace })); } finally { SetOperateFlagEndCache(); } }