/// <summary> /// 根据pkid获取用户优惠券接口 /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async ValueTask <OperationResult <GetCouponByIDResponse> > GetCouponByIDAsync(GetCouponByIDRequest request, CancellationToken cancellationToken) { PromotionCodeEntity entity = await _PromotionCodeRepository.GetCouponByIDAsync(request.pkid, cancellationToken).ConfigureAwait(false); if (entity == null) { return(OperationResult.FromError <GetCouponByIDResponse>("-1", "未获取到信息")); } GetCouponByIDResponse result = ObjectMapper.ConvertTo <PromotionCodeEntity, GetCouponByIDResponse>(entity); result.ReduceCost = (Math.Abs(result.Discount - result.ReduceCost) < 1) ? result.ReduceCost : result.Discount; result.LeastCost = (Math.Abs(result.MinMoney ?? 0 - result.LeastCost) < 1) ? result.LeastCost : (result.MinMoney ?? 0); if (result.GetRuleID > 0) { var getRuleModel = await _CouponGetRuleRepository.GetByPKIDAsync(result.GetRuleID, cancellationToken).ConfigureAwait(false); result.GetRuleGUID = getRuleModel.GetRuleGUID; result.Quantity = getRuleModel.Quantity ?? 0; result.GetQuantity = getRuleModel.GetQuantity; result.GetRuleName = getRuleModel.PromtionName; } if (result.RuleId > 0) { var useRuleModel = await _CouponUseRuleRepository.GetByPKIDAsync(result.RuleId, cancellationToken).ConfigureAwait(false); result.PromotionType = useRuleModel.PromotionType; result.RuleName = useRuleModel.Name; result.RuleDescription = useRuleModel.RuleDescription; result.OrderPayMethod = useRuleModel.OrderPayMethod; result.EnabledGroupBuy = useRuleModel.EnabledGroupBuy ? 1 : 0; result.InstallType = useRuleModel.InstallType.ToString(); } return(OperationResult.FromResult(result)); }
/// <summary> /// 提交领取规则审核到工单系统 /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <int> CommitWorkOrderForCouponGetRuleAuditAsync(CreateCouponGetRuleAuditRequest request, CancellationToken cancellationToken) { CommitWorkOrderForCouponGetRuleAuditRequest apiRequest = ObjectMapper.ConvertTo <CreateCouponGetRuleAuditRequest, CommitWorkOrderForCouponGetRuleAuditRequest>(request); apiRequest.WorkOrderTypeId = Convert.ToInt32(_AppSettingOptions.WorkOrderTypeIdForCouponGetRuleAudit); apiRequest.TaskOwner = request.Auditor; apiRequest.UserEmail = request.Applicant; apiRequest.Quantity = request.Quantity?.ToString("N0"); apiRequest.SumDiscount = string.Format("{0:N2}", (request.Quantity * request.Discount)); //获取使用规则信息 var useRule = await _ICouponUseRuleRepository.GetByPKIDAsync(request.RuleID, cancellationToken).ConfigureAwait(false); apiRequest.PromotionType = useRule.PromotionType; apiRequest.EnabledGroupBuy = useRule.EnabledGroupBuy; apiRequest.RuleDescription = string.IsNullOrWhiteSpace(useRule.RuleDescription) ? "无" : useRule.RuleDescription; apiRequest.CouponUseRuleDetailURL = _AppSettingOptions.SettingHost + "/Promotion/PromotionDetailNew?id=" + request.RuleID; try { _logger.Info($"CommitWorkOrderForCouponGetRuleAuditAsync result postData= {JsonConvert.SerializeObject(apiRequest)}"); var httpClient = _clientFactory.CreateClient("HttpTimeoutForCommitWorkOrder");//设置超时时间 var responseMessage = await httpClient.PostAsJsonAsync(_AppSettingOptions.CommitWorkOrderApiURL, apiRequest).ConfigureAwait(false); string response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); _logger.Info($"CommitWorkOrderForCouponGetRuleAuditAsync result response ={response}"); var responseModel = JsonConvert.DeserializeObject <CommitWorkOrderForCouponGetRuleAuditResponse>(response); if (responseModel.Code == 1) { return(Convert.ToInt32(responseModel.ResponseContent)); } _logger.Error($"CommitWorkOrderForCouponGetRuleAuditAsync fail Message ={responseModel?.Message}"); return(0); } catch (Exception ex) { _logger.Error($"CommitWorkOrderForCouponGetRuleAuditAsync Exception apiRequest ={JsonConvert.SerializeObject(apiRequest)}", ex); return(0); } }