/// <summary> /// 插入到塞券记录 /// </summary> /// <param name="conn"></param> /// <param name="packageId"></param> /// <param name="batchCode"></param> /// <param name="ruleGUID"></param> /// <param name="isSendSms"></param> /// <param name="user"></param> /// <returns></returns> public static int InsertPromotionRecord (SqlConnection conn, VipPaintPackagePromotionRecordModel model) { #region Sql var sql = @"INSERT INTO Configuration..VipPaintPackagePromotionRecord ( PackageId , BatchCode , RuleGUID , IsSendSms , ToBOrder , CreateUser ) OUTPUT Inserted.PKID VALUES ( @PackageId , @BatchCode , @RulesGUID , @IsSendSms , @ToBOrder , @CreateUser )" ; #endregion var parameters = new[] { new SqlParameter("@PackageId", model.PackageId), new SqlParameter("@BatchCode", model.BatchCode), new SqlParameter("@RulesGUID", model.RuleGUID), new SqlParameter("@IsSendSms", model.IsSendSms), new SqlParameter("@ToBOrder", model.ToBOrder), new SqlParameter("@CreateUser", model.CreateUser) }; return(Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters))); }
/// <summary> /// 添加塞券记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool InsertPromotionRecord(VipPaintPackagePromotionRecordModel model) { var result = false; try { var pkid = dbScopeManagerConfiguration.Execute(conn => DalVipPaintPackage.InsertPromotionRecord(conn, model)); result = pkid > 0; if (pkid > 0) { model.PKID = pkid; model.CreateDateTime = DateTime.Now; model.LastUpdateDateTime = DateTime.Now; var log = new { ObjectType = "VipPaintPackage", ObjectId = $"PromotionRecord_{model.BatchCode}", BeforeValue = "", AfterValue = JsonConvert.SerializeObject(model), Remark = $"喷漆大客户套餐塞券,批次号:{model.BatchCode}", Creator = model.CreateUser }; LoggerManager.InsertLog("CommonConfigLog", log); } } catch (Exception ex) { Logger.Error("InsertBaoYangPackagePromotionRecord", ex); } return(result); }
public ActionResult UploadExcel(int packageId, Guid ruleGuid) { var result = false; if (packageId <= 0 || ruleGuid == Guid.Empty) { return(Json(new { Status = false, Msg = "未知的对象" })); } var files = Request.Files; if (files.Count < 1) { return(Json(new { Status = false, Msg = "请选择文件" })); } var file = files[0]; if (file.ContentType != "application/vnd.ms-excel" && file.ContentType != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { return(Json(new { Status = false, Msg = "请上传Excel文件" })); } var manager = new VipPaintPackageManager(); var isExist = manager.IsExistVipPaintFile(file.FileName); if (isExist) { return(Json(new { Status = false, Msg = $"{file.FileName}已导入成功,请勿重复导入" }, JsonRequestBehavior.AllowGet)); } var convertResult = ConvertExcelToList(file); if (!string.IsNullOrEmpty(convertResult.Item2)) { return(Json(new { Status = false, Msg = convertResult.Item2 })); } else if (convertResult.Item1 == null || !convertResult.Item1.Any()) { return(Json(new { Status = false, Msg = "Excel内容为空" })); } var validResult = manager.ValidatedUploadData(ruleGuid, convertResult.Item1); if (!validResult.Item1) { return(Json(new { Status = false, Msg = string.IsNullOrEmpty(validResult.Item2) ? "优惠券规则验证失败" : validResult.Item2 })); } #region 文件到服务器 var extension = Path.GetExtension(file.FileName); var stream = file.InputStream; var buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); stream.Position = 0; var uploadResult = new UploadFileManager().UploadFile(buffer, FileType.VipPaintPackage, extension, file.FileName, User.Identity.Name); #endregion //上传服务器成功插入一条塞券记录 if (!string.IsNullOrEmpty(uploadResult.Item1) && !string.IsNullOrEmpty(uploadResult.Item2)) { var isSendSms = manager.IsPackageSms(packageId); var model = new VipPaintPackagePromotionRecordModel() { PackageId = packageId, BatchCode = uploadResult.Item2, RuleGUID = ruleGuid, IsSendSms = isSendSms, ToBOrder = string.Empty, CreateUser = User.Identity.Name }; result = manager.InsertPromotionRecord(model); } return(Json(new { Status = result, Msg = result ? "上传成功" : "上传失败" }, JsonRequestBehavior.AllowGet)); }