/// <summary> /// 根据服务码调快修获取服务码快修维护的信息 /// </summary> /// <param name="serviceCodes"></param> /// <returns></returns> public static async Task <IEnumerable <ServiceCode> > GetServiceCodeDetailsByCodes(IEnumerable <string> serviceCodes) { using (var client = new ServiceCodeClient()) { var serviceResult = await client.SelectServiceCodeDetailsByCodesAsync(serviceCodes); serviceResult.ThrowIfException(true); return(serviceResult.Result); } }
public static async Task <IEnumerable <string> > GenerateServiceCode(string pid, int num, string name, long orderId, DateTime?endTime) { using (var client = new ServiceCodeClient()) { GenerateServiceCodeRequest request = new GenerateServiceCodeRequest() { TuhuOrderId = orderId, ServiceId = pid, ServiceName = name, OverdueTime = endTime, GenerateNum = num }; var serviceResult = await client.GenerateVOLServiceCodeAsync(request); serviceResult.ThrowIfException(true); return(serviceResult.Result); } }
public static IEnumerable<ServiceCode> GetServiceCodeDetailsByCodes(IEnumerable<string> serviceCodes) { IEnumerable<ServiceCode> result = null; try { using (var client = new ServiceCodeClient()) { var serviceResult = client.SelectServiceCodeDetailsByCodes(serviceCodes); serviceResult.ThrowIfException(true); result = serviceResult.Result; } } catch (Exception ex) { logger.Error(ex); } return result ?? new List<ServiceCode>(); }
/// <summary> /// 根据TuhuOrderId获取服务码信息 /// </summary> /// <param name="tuhuOrderId"></param> /// <returns></returns> public async static Task <ServiceCode> FetchServiceCodeByTuhuOrderIdAsync(int tuhuOrderId) { ServiceCode result = null; try { using (var client = new ServiceCodeClient()) { var getResult = await client.FetchServiceCodeByTuhuOrderIdAsync(tuhuOrderId); getResult.ThrowIfException(true); result = getResult.Result; } } catch (Exception ex) { Logger.Error(ex); } return(result); }
public static async Task <bool> RevertVOLServiceCode(List <string> serviceCodes) { var result = false; if (serviceCodes != null && serviceCodes.Any()) { using (var client = new ServiceCodeClient()) { var request = new RevertVOLServiceCodeRequest() { ServiceCodes = serviceCodes }; var serviceResult = await client.RevertVOLServiceCodeAsync(request); serviceResult.ThrowIfException(true); result = serviceResult.Result; } } return(result); }
public async Task <bool> RevertServiceCodes(IEnumerable <string> serviceCodes, string channel, string source) { var result = false; if (serviceCodes != null && serviceCodes.Any()) { using (var client = new ServiceCodeClient()) { var request = new RevertServiceCodesRequest { Source = source, Channel = channel, ServiceCodes = serviceCodes.ToList() }; var serviceResult = await client.RevertServiceCodesAsync(request); result = serviceResult.Result; } } return(result); }
/// <summary> /// 修改大客户美容服务码 /// </summary> /// <param name="model"></param> /// <param name="pkids"></param> /// <returns></returns> public static bool UpdateBeautyServicePackageDetailCodes(ServiceCodeDetail model, string user, ServiceCodeDetail oldCode) { var result = false; try { if (model.StartTime != null && model.EndTime != null) { using (var dbhelper = new Tuhu.Component.Common.SqlDbHelper(writeConnStr)) { dbhelper.BeginTransaction(); var upResult = true; if (model.PackageDetailCodeId > 0) { var oldValue = BeautyServicePackageDal.GetBeautyServicePackageDetailCodeByPKID(model.PackageDetailCodeId); if (oldValue != null) { #region 只更新服务码起止时间 其余数据保持不变 var newValue = new BeautyServicePackageDetailCode { PKID = model.PackageDetailCodeId, UserId = oldValue.UserId, PackageDetailId = oldValue.PackageDetailId, ServiceCode = oldValue.ServiceCode, IsActive = oldValue.IsActive, StartTime = model.StartTime, EndTime = model.EndTime, PackageCode = oldValue.PackageCode, VipUserId = oldValue.VipUserId }; #endregion upResult = BeautyServicePackageDal.UpdateBeautyServicePackageDetailCodes(dbhelper, newValue); } else { upResult = false; } } if (upResult) { using (var client = new ServiceCodeClient()) { var kxChangeCodeTimeModel = new ChangeCodeTimeRequest { ServiceCodes = new List <string>() { model.ServiceCode }, OverdueTime = model.EndTime }; var kxChangeResult = client.ChangeOverdueTime(kxChangeCodeTimeModel); kxChangeResult.ThrowIfException(true); if (kxChangeResult.Success && kxChangeResult.Result != null && kxChangeResult.Result.SuccessServiceCode.Count() > 0 && string.Equals(kxChangeResult.Result.SuccessServiceCode.FirstOrDefault(), model.ServiceCode)) { result = true; dbhelper.Commit(); var log = new BaoYangOprLog { LogType = "修改大客户美容服务码", IdentityID = oldCode.ServiceCode, OldValue = JsonConvert.SerializeObject(oldCode), NewValue = JsonConvert.SerializeObject(model), Remarks = $"修改服务码有效期:服务码开始时间从{oldCode.StartTime}变更为{model.StartTime},结束时间从{oldCode.EndTime}变更为{model.EndTime}", OperateUser = user, }; LoggerManager.InsertLog("BeautyOprLog", log); } else { throw new Exception($"快修服务修改服务码有效期失败,请求信息:{JsonConvert.SerializeObject(kxChangeCodeTimeModel)},返回信息:{JsonConvert.SerializeObject(kxChangeResult)}"); } } } } } } catch (Exception ex) { Logger.Error(ex.Message, ex); } return(result); }
/// <summary> /// 根据批次号更新服务码起始时间 /// </summary> /// <param name="user"></param> /// <param name="batchCode"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <returns></returns> public static async Task <Tuple <bool, string> > UpdateBeautyServiceCodeTimeByBatchCode(string user, string batchCode, DateTime startTime, DateTime endTime) { var result = false; var msg = string.Empty; try { var writeStr = BeautyServicePackageDal.GetTuhuGrouponWriteConnstr(); using (var dbhelper = new SqlDbHelper(writeStr)) { dbhelper.BeginTransaction(); var updateCodeResult = BeautyServicePackageDal.UpdateBeautyServicePackageDetailCodeTimeByBatchCode(dbhelper, batchCode, startTime, endTime); if (!updateCodeResult) { throw new Exception("根据批次号更新服务码时间失败,方法UpdateBeautyServicePackageDetailCodeTimeByBatchCode"); } var serviceCodes = BeautyServicePackageDal.SelectServiceCodesByBatchCode(batchCode); if (serviceCodes != null && serviceCodes.Any()) { if (serviceCodes.Count() > 10000) { throw new Exception("暂时不支持服务码数量大于10000的修改操作"); } using (var client = new ServiceCodeClient()) { var batchSize = 1000; var index = 0; while (index < serviceCodes.Count()) { var batchCodes = serviceCodes.Skip(index).Take(batchSize).ToList(); var kxChangeCodeTimeModel = new ChangeCodeTimeRequest { ServiceCodes = batchCodes, OverdueTime = endTime }; var kxChangeResult = client.ChangeOverdueTime(kxChangeCodeTimeModel); if (!kxChangeResult.Success) { throw kxChangeResult.Exception; } if (kxChangeResult.Result != null && kxChangeResult.Result.FailServiceCode != null && kxChangeResult.Result.FailServiceCode.Any()) { var serviceCodeFailedLog = new BeautyOprLog { LogType = "ChangeOverdueTimeFailedCodes", IdentityID = $"{batchCode}", OldValue = null, NewValue = JsonConvert.SerializeObject(kxChangeResult.Result.FailServiceCode), Remarks = $"根据批次号修改服务码过期时间失败,批次:{batchCode},OverdueTime应该改为:{endTime}", OperateUser = user, }; LoggerManager.InsertLog("BeautyOprLog", serviceCodeFailedLog); } index += batchSize; } dbhelper.Commit(); result = true; } } } } catch (Exception ex) { msg = ex.Message; Logger.Error(ex.Message, ex); } return(new Tuple <bool, string>(result, msg)); }
public static Tuple <bool, string> UpdateBeautyServicePackageDetail(BeautyServicePackageDetail packageDetail) { bool result = false; var msg = string.Empty; var writeStr = BeautyServicePackageDal.GetTuhuGrouponWriteConnstr(); using (var dbhelper = new SqlDbHelper(writeStr)) { try { var oldValue = GetBeautyServicePackageDetail(packageDetail.PKID); dbhelper.BeginTransaction(); var updatePackageDetailResult = BeautyServicePackageDal.UpdateBeautyServicePackageDetail(dbhelper, packageDetail); if (!updatePackageDetailResult) { throw new Exception("更新服务码配置失败"); } if (packageDetail.IsServiceCodeGenerated && (oldValue.ServiceCodeStartTime != packageDetail.ServiceCodeStartTime || oldValue.ServiceCodeEndTime != packageDetail.ServiceCodeEndTime)) { if (oldValue.ServiceCodeNum > 10000) { throw new Exception("大于10000暂时不支持修改"); } var updateServiceCodeTimeResult = BeautyServicePackageDal.UpdateServiceCodeTime(dbhelper, packageDetail.PKID, packageDetail.ServiceCodeStartTime, packageDetail.ServiceCodeEndTime); if (!updateServiceCodeTimeResult) { throw new Exception("更新服务码时间失败"); } if (oldValue.ServiceCodeEndTime != packageDetail.ServiceCodeEndTime && packageDetail.ServiceCodeEndTime != null) { var serviceCodes = (GetBeautyServicePackageDetailCodesByPackageDetailId(packageDetail.PKID))?.Select(t => t.ServiceCode)?.ToList(); if (serviceCodes != null && serviceCodes.Any()) { using (var client = new ServiceCodeClient()) { var batchSize = 1000; var index = 0; while (index < serviceCodes.Count) { var batchCodes = serviceCodes.Skip(index).Take(batchSize).ToList(); var kxChangeCodeTimeModel = new ChangeCodeTimeRequest { ServiceCodes = batchCodes, OverdueTime = Convert.ToDateTime(packageDetail.ServiceCodeEndTime) }; var kxChangeResult = client.ChangeOverdueTime(kxChangeCodeTimeModel); if (!kxChangeResult.Success) { throw kxChangeResult.Exception; } if (kxChangeResult.Result != null && kxChangeResult.Result.FailServiceCode != null && kxChangeResult.Result.FailServiceCode.Any()) { var serviceCodeFailedLog = new BeautyOprLog { LogType = "ChangeOverdueTimeFailedCodes", IdentityID = $"{packageDetail.PKID}", OldValue = null, NewValue = JsonConvert.SerializeObject(kxChangeResult.Result.FailServiceCode), Remarks = $"修改服务码过期时间失败", OperateUser = packageDetail.UpdateUser, }; LoggerManager.InsertLog("BeautyOprLog", serviceCodeFailedLog); } index += batchSize; } } } } } dbhelper.Commit(); result = true; var log = new BeautyOprLog { LogType = "UpdateBeautyServicePackageDetail", IdentityID = $"{packageDetail.PKID}", OldValue = JsonConvert.SerializeObject(oldValue), NewValue = JsonConvert.SerializeObject(packageDetail), Remarks = $"修改集团客户礼包详情,详情ID为{packageDetail.PKID}", OperateUser = packageDetail.UpdateUser, }; LoggerManager.InsertLog("BeautyOprLog", log); } catch (Exception ex) { msg = ex.Message; dbhelper.Rollback(); Logger.Error(ex.Message, ex); }; } return(new Tuple <bool, string>(result, msg)); }