public Dictionary <int, bool> InvalidCodes(List <int> codes, string user) { Dictionary <int, bool> result = new Dictionary <int, bool>(); List <PromotionCodeModel> promotionCodes = new List <PromotionCodeModel>(); using (var client = new PromotionClient()) { var serviceResult = client.GetPromotionCodeByIDs(new GetPromotionCodesRequest() { PKIDList = codes }); if (serviceResult.Success) { promotionCodes = serviceResult.Result.ToList(); } } foreach (var code in promotionCodes) { using (var client = new PromotionClient()) { var serviceResult = client.UpdateUserPromotionCodeStatus(new UpdateUserPromotionCodeStatusRequest() { Status = 3, PromotionCodeId = code.Pkid, OperationAuthor = user, Channel = "setting.tuhu.cn", UserID = Guid.Parse(code.UserId) }); if (serviceResult.Exception != null) { logger.Error(serviceResult.Exception); } result[code.Pkid] = serviceResult.Success && serviceResult.Result; } } foreach (var item in result) { if (item.Value) { dbScopeManager.Execute(conn => DALVipBaoYangPackage.UpdatePromotionRemarks(conn, item.Key, $"{user}于{DateTime.Now.ToString("yyyy年MM月dd日 hh:mm")}作废此券")); } } return(result); }
public List <BaoYangPackagePromotionDetailSimpleModel> GetPromotionDetailsByBatchCode(string batchCode, int index, int size) { var result = null as List <BaoYangPackagePromotionDetailSimpleModel>; if (!string.IsNullOrEmpty(batchCode)) { try { result = dbScopeReadManager.Execute(conn => DALVipBaoYangPackage.SelectPromotionDetailsByBatchCode(conn, batchCode, index, size)); } catch (Exception ex) { logger.Error(ex.Message, ex); } } if (result != null && result.Any()) { GetPromotionCodesRequest request = new GetPromotionCodesRequest() { PKIDList = result.Where(o => o.PromotionId.HasValue && o.PromotionId.Value > 0).Select(o => (int)o.PromotionId).ToList() }; using (var client = new PromotionClient()) { var serviceResult = client.GetPromotionCodeByIDs(request); if (serviceResult.Success && serviceResult.Result != null) { foreach (var detail in result) { if (detail.PromotionId > 0) { var code = serviceResult.Result.FirstOrDefault(o => o.Pkid == detail.PromotionId); detail.PromotionStatus = code != null ? code.Status : 2; if (!string.IsNullOrEmpty(code.UsedTime)) { detail.PromotionUsedTime = DateTime.Parse(code.UsedTime); } } } } } } return(result); }
public bool IsAllUnUsed(List <int> codes) { bool result = false; GetPromotionCodesRequest request = new GetPromotionCodesRequest() { PKIDList = codes }; using (var client = new PromotionClient()) { var serviceResult = client.GetPromotionCodeByIDs(request); if (serviceResult.Success && serviceResult.Result != null) { result = serviceResult.Result.All(o => o.Status == 0); } } return(result); }
/// <summary> /// 作废券 /// </summary> /// <param name="promotionIds"></param> /// <param name="user"></param> /// <returns></returns> public Dictionary <int, bool> InvalidCodes(List <int> promotionIds, string user) { Dictionary <int, bool> result = new Dictionary <int, bool>(); try { List <PromotionCodeModel> promotionCodes = new List <PromotionCodeModel>(); using (var client = new PromotionClient()) { var serviceResult = client.GetPromotionCodeByIDs(new GetPromotionCodesRequest() { PKIDList = promotionIds }); if (serviceResult.Success) { promotionCodes = serviceResult.Result.ToList(); } } foreach (var code in promotionCodes) { using (var client = new PromotionClient()) { var serviceResult = client.UpdateUserPromotionCodeStatus(new UpdateUserPromotionCodeStatusRequest() { Status = 3, PromotionCodeId = code.Pkid, OperationAuthor = user, Channel = "setting.tuhu.cn", UserID = Guid.Parse(code.UserId) }); if (serviceResult.Exception != null) { Logger.Error(serviceResult.Exception); } result[code.Pkid] = serviceResult.Success && serviceResult.Result; } } foreach (var item in result) { if (item.Value) { var log = new { ObjectId = $"PromotionDetail_{item.Key}", ObjectType = "VipPaintPackage", BeforeValue = JsonConvert.SerializeObject(item), AfterValue = "", Remark = $"喷漆大客户作废券:{user}于{DateTime.Now.ToString("yyyy年MM月dd日 hh:mm")}作废券Id{item.Key}", Creator = user }; LoggerManager.InsertLog("CommonConfigLog", log); dbScopeManagerConfiguration.Execute(conn => DalVipPaintPackage.UpdatePromotionDetailRemark(conn, item.Key, $"{user}于{DateTime.Now.ToString("yyyy年MM月dd日 hh:mm")}作废此券")); } } } catch (Exception ex) { Logger.Error("InvalidCodes", ex); } return(result); }
/// <summary> /// 填充订单信息至塞券详情记录 /// </summary> /// <param name="models"></param> /// <param name="batchCode"></param> /// <returns></returns> private List <VipPaintPromotionDetailViewModel> FillOrderForPromotionDetail(List <VipPaintPromotionDetailViewModel> models, string batchCode) { var package = dbScopeManagerProductcatalogRead.Execute(conn => DalVipPaintPackage.GetPackageConfigByBatchCode(conn, batchCode)); var promotions = null as List <PromotionCodeModel>; var promotionIds = models?.Where(w => w.PromotionId > 0).Select(s => s.PromotionId).ToList(); if (promotionIds != null && promotionIds.Any()) { using (var client = new PromotionClient()) { promotions = client.GetPromotionCodeByIDs(new GetPromotionCodesRequest() { PKIDList = promotionIds }).Result?.ToList(); } } if (package != null && string.Equals(package.SettlementMethod, SettlementMethod.ByPeriod.ToString())) { if (promotions != null && promotions.Any()) { promotions.ForEach(f => { var detail = models.FirstOrDefault(s => s.PromotionId == f.Pkid); var status = GetPromotionStatus(f.Status); if (detail != null) { detail.ToCOrder = f.OrderId > 0 ? Convert.ToString(f.OrderId) : string.Empty; if (f.OrderId > 0) { using (var orderClient = new Service.Order.OrderQueryClient()) { var orderResult = orderClient.GetOrderRelationShip(f.OrderId); if (orderResult.Success && orderResult.Result != null && orderResult.Result.Any()) { var toBOrder = orderResult.Result.FirstOrDefault().Value?.FirstOrDefault(); detail.ToBOrder = string.IsNullOrEmpty(toBOrder) ? detail.ToBOrder : toBOrder; } } } detail.Status = string.IsNullOrEmpty(status) ? detail.Status : status; } }); } } else if (package != null && string.Equals(package.SettlementMethod, SettlementMethod.PreSettled.ToString())) { var record = dbScopeManagerConfigurationRead.Execute(conn => DalVipPaintPackage.GetPromotionRecord(conn, batchCode)); if (promotions != null && promotions.Any()) { promotions.ForEach(f => { var detail = models.FirstOrDefault(s => s.PromotionId == f.Pkid); var status = GetPromotionStatus(f.Status); if (detail != null) { detail.ToCOrder = f.OrderId > 0 ? Convert.ToString(f.OrderId) : string.Empty; detail.Status = string.IsNullOrEmpty(status) ? detail.Status : status; } }); } if (record != null && !string.IsNullOrWhiteSpace(record.ToBOrder)) { models?.ForEach(s => s.ToBOrder = record.ToBOrder); } } return(models); }