/// <summary>
        /// 创建优惠券领取规则记录
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <int> CreateCouponGetRuleAsync(CreateCouponGetRuleAuditRequest request, CancellationToken cancellationToken)
        {
            try
            {
                GetCouponRuleAuditEntity entity = ObjectMapper.ConvertTo <CreateCouponGetRuleAuditRequest, GetCouponRuleAuditEntity>(request);
                var pkid = await _ICouponGetRuleAuditRepository.CreateAsync(entity, cancellationToken).ConfigureAwait(false);

                return(pkid);
            }
            catch (Exception ex)
            {
                _logger.Error($"CreateCouponGetRuleAuditAsync Exception {JsonConvert.SerializeObject(request)}", ex);
                return(0);
            }
        }
        /// <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);
            }
        }
Exemple #3
0
        /// <summary>
        /// 创建优惠券审核记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async override ValueTask <OperationResult <int> > CreateCouponGetRuleAuditAsync([FromBody] CreateCouponGetRuleAuditRequest request)
        {
            if (request.Applicant == "*****@*****.**")
            {
                request.Applicant = "*****@*****.**";
            }
            //1.获取审核第一步的 审核人
            GetCouponGetRuleAuditorRequest getCouponGetRuleAuditorRequest = new GetCouponGetRuleAuditorRequest()
            {
                Step           = 1,
                Applicant      = request.Applicant,
                BusinessLineId = request.BusinessLineId,
                DepartmentId   = request.DepartmentId,
            };

            if (request.GetCouponRulePKID > 0)//修改
            {
                //判断是否存在 审核中的 记录
                var list = await _ICouponGetRuleAuditManager.GetListByGetCouponRulePKIDAsync(request.GetCouponRulePKID, HttpContext.RequestAborted).ConfigureAwait(false);

                if (list.Where(p => p.AuditStatus == 1).Any())
                {
                    return(OperationResult.FromError <int>("-1", "此优惠券正在审核中不支持编辑,请前往【审核列表】查看审核信息"));
                }
                //获取 原领取规则信息
                var originalGetRule = await _ICouponGetRuleManager.GetByPKIDAsync(request.GetCouponRulePKID, HttpContext.RequestAborted).ConfigureAwait(false);

                request.GetRuleGUID = originalGetRule.GetRuleGUID;
            }

            var GetCouponGetRuleAuditorResult = await _ICouponGetRuleAuditManager.GetCouponGetRuleAuditorAsync(getCouponGetRuleAuditorRequest, HttpContext.RequestAborted).ConfigureAwait(false);

            if (GetCouponGetRuleAuditorResult.Success || GetCouponGetRuleAuditorResult.Result != null)
            {
                request.Auditor = GetCouponGetRuleAuditorResult.Result.Auditors;
            }
            else
            {
                return(OperationResult.FromError <int>(GetCouponGetRuleAuditorResult.ErrorCode, GetCouponGetRuleAuditorResult.ErrorMessage));
            }

            //2.提交到工单系统
            var workOrderId = await _ICouponGetRuleAuditManager.CommitWorkOrderForCouponGetRuleAuditAsync(request, HttpContext.RequestAborted).ConfigureAwait(false);

            request.AuditStatus = (int)WorkOrderAuditStatusEnum.审批中;
            if (workOrderId == 0)
            {
                return(OperationResult.FromError <int>("-1", "提交到工单失败,请重试"));
            }
            request.WorkOrderId = workOrderId;
            //3.添加审核记录
            var pkid = await _ICouponGetRuleAuditManager.CreateCouponGetRuleAuditAsync(request, HttpContext.RequestAborted).ConfigureAwait(false);

            if (pkid > 0)
            {
                //4.添加审核的提交日志
                var ConfigResult = await _IConfigLogService.InsertDefaultLogQueue(GlobalConstant.LogTypeCouponGetRuleAudit, JsonConvert.SerializeObject(new
                {
                    ObjectId    = pkid,
                    ObjectType  = GlobalConstant.LogObjectTypeCouponGetRuleAudit,
                    BeforeValue = "",
                    AfterValue  = JsonConvert.SerializeObject(request),
                    Operate     = "添加审核记录",
                    Author      = request.Applicant
                })).ConfigureAwait(false);

                return(OperationResult.FromResult(pkid));
            }
            else
            {
                return(OperationResult.FromError <int>("-2", "CreateCouponGetRuleAuditAsync Exception"));
            }
        }