/// <summary> /// 获取喷漆打折价格体系 /// </summary> /// <param name="packageId"></param> /// <returns></returns> public ActionResult GetPackageConfig(int packageId) { var manager = new PaintDiscountConfigManager(); var result = manager.GetPaintDiscountPackage(packageId); return(Json(new { Status = result != null, Data = result }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 编辑城市门店配置 /// </summary> /// <param name="packageId"></param> /// <param name="regionShops"></param> /// <returns></returns> public ActionResult UpsertPackageRegion(int packageId, string regionShops) { if (packageId < 0) { return(Json(new { Status = false, Msg = "未知的喷漆打折价格体系" }, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrWhiteSpace(regionShops)) { return(Json(new { Status = false, Msg = "请配置门店和城市" }, JsonRequestBehavior.AllowGet)); } var manager = new PaintDiscountConfigManager(); var package = manager.GetPaintDiscountPackage(packageId); if (package == null) { return(Json(new { Status = false, Msg = "未知的喷漆打折价格体系" }, JsonRequestBehavior.AllowGet)); } var regionShopPair = null as List <RegionShopPairModel>; try { regionShopPair = JsonConvert.DeserializeObject <List <RegionShopPairModel> >(regionShops); } catch (Exception) { regionShopPair = null; } if (regionShopPair != null && regionShopPair.Any()) { if (regionShopPair.Any(s => (s.RegionId < 1 && s.ShopIds != null && s.ShopIds.Any()) || (s.ShopIds != null && s.ShopIds.Any(v => v < 1)))) { return(Json(new { Status = false, Msg = $"未知的门店" }, JsonRequestBehavior.AllowGet)); } var list = manager.ConvertToPackageRegionModel(packageId, regionShopPair); var exist = manager.GetRepeatPackageRegion(packageId, package.UserType, list); if (exist != null && exist.Any()) { return(Json(new { Status = false, Msg = string.Join("</br>", exist) }, JsonRequestBehavior.AllowGet)); } var result = manager.UpsertPackageRegion(packageId, package.UserType, list, User.Identity.Name); return(Json(new { Status = result, Msg = $"编辑{(result ? "成功" : "失败")}" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Status = false, Msg = $"请配置门店和城市" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult UploadExcel(int packageId = 0) { var files = Request.Files; if (files.Count < 1) { return(Json(new { Status = false, Msg = "请选择文件" }, JsonRequestBehavior.AllowGet)); } 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文件" }, JsonRequestBehavior.AllowGet)); } var convertResult = ConvertExcelToList(file); if (!string.IsNullOrEmpty(convertResult.Item2)) { return(Json(new { Status = false, Msg = convertResult.Item2 }, JsonRequestBehavior.AllowGet)); } else if (convertResult.Item1 == null || !convertResult.Item1.Any()) { return(Json(new { Status = false, Msg = "Excel内容为空" }, JsonRequestBehavior.AllowGet)); } else { var manager = new PaintDiscountConfigManager(); if (packageId > 0) { var package = manager.GetPaintDiscountPackage(packageId); if (package == null) { return(Json(new { Status = false, Msg = "未知的喷漆打折价格体系" }, JsonRequestBehavior.AllowGet)); } } var user = User.Identity.Name; convertResult.Item1.ForEach(s => s.PackageId = packageId); var result = manager.UploadPaintDiscountConfig(convertResult.Item1, user); return(Json(new { Status = result, Msg = $"导入{(result ? "成功" : "失败")}" } , JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 移除喷漆打折城市配置缓存 /// </summary> /// <param name="regionId"></param> /// <param name="userType"></param> /// <returns></returns> public ActionResult RemovePackageRegionCache(int packageId, List <int> regionIds) { var result = false; if (packageId < 1 || regionIds == null || !regionIds.Any()) { return(Json(new { Status = false, Msg = "未知的对象" }, JsonRequestBehavior.AllowGet)); } var manager = new PaintDiscountConfigManager(); var package = manager.GetPaintDiscountPackage(packageId); var userTypes = new List <bool>(); switch (package?.UserType) { case (int)UserType.AllUser: userTypes.AddRange(new List <bool>() { true, false }); break; case (int)UserType.NewUser: userTypes.Add(true); break; case (int)UserType.OldUser: userTypes.Add(false); break; default: break; } if (userTypes.Any()) { result = regionIds.All(regionId => userTypes.All(isnew => { var cacheKey = $"PaintDiscountPackageRegion/{regionId}/{isnew}"; return(manager.RemovePaintRedisCache(cacheKey)); })); } return(Json(new { Status = result, Msg = $"刷新缓存{(result ? "成功" : "失败")}" } , JsonRequestBehavior.AllowGet)); }
/// <summary> /// 导出数据至Excel /// </summary> /// <returns></returns> public ActionResult ExportExcel(int packageId = 0) { var workbook = new XSSFWorkbook(); var sheet = workbook.CreateSheet(); var row = sheet.CreateRow(0); var cell = null as ICell; var cellNum = 0; row.CreateCell(cellNum++).SetCellValue("PID"); row.CreateCell(cellNum++).SetCellValue("面数"); row.CreateCell(cellNum++).SetCellValue("活动价"); row.CreateCell(cellNum++).SetCellValue("权益名称"); row.CreateCell(cellNum++).SetCellValue("活动说明"); row.CreateCell(cellNum++).SetCellValue("活动图片"); cellNum = 0; sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 14 * 256); sheet.SetColumnWidth(cellNum++, 8 * 256); sheet.SetColumnWidth(cellNum++, 18 * 256); sheet.SetColumnWidth(cellNum++, 50 * 256); sheet.SetColumnWidth(cellNum++, 50 * 256); sheet.SetColumnWidth(cellNum++, 28 * 256); var manager = new PaintDiscountConfigManager(); var packageName = string.Empty; if (packageId > 0) { var package = manager.GetPaintDiscountPackage(packageId); if (package == null) { return(Json(new { Status = false, Msg = "未知的喷漆打折价格体系" }, JsonRequestBehavior.AllowGet)); } else { packageName = package.PackageName; } } var result = manager.GetPaintDiscountDetailByPackageId(packageId); if (result != null && result.Any()) { int modelRowCount = 1; foreach (var model in result) { int modelCol = 0; var modelRow = sheet.CreateRow(modelRowCount); modelRow.CreateCell(modelCol++).SetCellValue(model.ServicePid); modelRow.CreateCell(modelCol++).SetCellValue(model.SurfaceCount); modelRow.CreateCell(modelCol++).SetCellValue((double)model.ActivityPrice); modelRow.CreateCell(modelCol++).SetCellValue(model.ActivityName); modelRow.CreateCell(modelCol++).SetCellValue(model.ActivityExplain); modelRow.CreateCell(modelCol++).SetCellValue(model.ActivityImage); modelRowCount++; } } var ms = new MemoryStream(); workbook.Write(ms); return(File(ms.ToArray(), "application/x-xls", $"喷漆打折价格体系{packageName}的服务价格配置 {DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒")}.xlsx")); }