/// <summary>
        /// 更新优惠券审核记录
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <int> UpdateCouponGetRuleAuditAsync(GetCouponRuleAuditModel request, CancellationToken cancellationToken)
        {
            GetCouponRuleAuditEntity entity = ObjectMapper.ConvertTo <GetCouponRuleAuditModel, GetCouponRuleAuditEntity>(request);
            int pkid = await _ICouponGetRuleAuditRepository.UpdateAsync(entity, cancellationToken).ConfigureAwait(false) ? entity.PKID : 0;

            return(pkid);
        }
        /// <summary>
        /// 批量作废优惠券 - 根据优惠券渠道
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async override ValueTask <OperationResult <ObsoleteCouponListReponse> > ObsoleteCouponListByChannelAsync([FromBody] ObsoleteCouponsByChannelRequest request)
        {
            if (!request.IsPassed)
            {
                return(OperationResult.FromError <ObsoleteCouponListReponse>("-1", request.ErrorMsg));
            }

            //根据渠道和pkid筛选优惠券
            var couponList = await promotionCodeRepository.GetPKIDByCodeChannelANDPKIDAsync(request, HttpContext.RequestAborted).ConfigureAwait(false);

            couponList = couponList.Where(p => p.Status == 0).ToList();

            ObsoleteCouponListReponse response = new ObsoleteCouponListReponse();
            ObsoleteCouponRequest     ObsoleteCouponRequest = ObjectMapper.ConvertTo <ObsoleteCouponsByChannelRequest, ObsoleteCouponRequest>(request);

            foreach (var item in couponList)
            {
                ObsoleteCouponRequest.PromotionPKID = item.PKID;
                ObsoleteCouponRequest.UserID        = item.UserId;
                var flag = await _CouponManager.ObsoleteCouponAsync(ObsoleteCouponRequest, HttpContext.RequestAborted).ConfigureAwait(false);

                if (flag.Result)
                {
                    response.SuccessedIDs += ObsoleteCouponRequest.PromotionPKID + ",";
                }
                else
                {
                    response.FaidedIDs += ObsoleteCouponRequest.PromotionPKID + ",";
                }
            }
            return(OperationResult.FromResult(response));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 人员信息查询
        /// </summary>
        /// <param name="request">查询条件</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <PagedModel <GetUserListResponse> > GetUserListAsync(GetUserListRequest request, CancellationToken cancellationToken)
        {
            PagedModel <GetUserListResponse> result = new PagedModel <GetUserListResponse>()
            {
                Pager = new PagerModel()
                {
                    CurrentPage = request.CurrentPage,
                    PageSize    = request.PageSize
                }
            };

            try
            {
                int count = await _IUserRepository.GetUserListCountAsync(request, cancellationToken).ConfigureAwait(false);

                result.Pager.Total = count;
                if (count > 0)
                {
                    var entities = await _IUserRepository.GetUserListAsync(request, cancellationToken).ConfigureAwait(false);

                    List <GetUserListResponse> source = ObjectMapper.ConvertTo <UserEntity, GetUserListResponse>(entities).ToList();
                    result.Source = source;
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"UserManager GetUserListAsync Exception", ex);
                throw;
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 作废优惠券
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <OperationResult <bool> > ObsoleteCouponAsync(ObsoleteCouponRequest request, CancellationToken cancellationToken)
        {
            var coupon = await _PromotionCodeRepository.GetCouponByIDAsync(request.PromotionPKID, cancellationToken).ConfigureAwait(false);

            if (coupon == null)
            {
                return(OperationResult.FromError <bool>("-1", "优惠券不存在"));
            }
            if (coupon.UserId != request.UserID)
            {
                return(OperationResult.FromError <bool>("-2", "优惠券所属人不匹配 请检查入参userid"));
            }
            if (coupon.Status != 0)
            {
                return(OperationResult.FromError <bool>("-2", "优惠券已使用或者已作废"));
            }

            var result = await _PromotionCodeRepository.ObsoleteCouponAsync(request, cancellationToken).ConfigureAwait(false);

            if (result)
            {
                PromotionOprLogEntity entity = ObjectMapper.ConvertTo <ObsoleteCouponRequest, PromotionOprLogEntity>(request);
                entity.Referer         = request.Message;
                entity.UserID          = coupon.UserId;
                entity.Operation       = CouponOperateEnum.作废.ToString();
                entity.OperationDetail = string.Format("OldStatus={0};NewStatus={1}", coupon.Status, (int)CouponOperateEnum.作废);
                await _IPromotionOprLogRepository.CreateAsync(entity, cancellationToken).ConfigureAwait(false);
            }
            return(OperationResult.FromResult(result));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 查询用户的优惠券
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <List <CouponModel> > GetCouponByUserIDAsync(GetCouponByUserIDRequest request, CancellationToken cancellationToken)
        {
            List <CouponModel> result             = new List <CouponModel>();
            List <CouponModel> resultHistorysList = new List <CouponModel>(); //归档用户优惠券
            List <CouponModel> resultNowList      = new List <CouponModel>(); //正在使用的用户优惠券

            try
            {
                if (request.IsHistory == 1 || request.IsHistory == 0)
                {
                    var entities = await _PromotionCodeRepository.GetHistoryCouponByUserIDAsync(request.UserID, cancellationToken).ConfigureAwait(false);

                    resultHistorysList = ObjectMapper.ConvertTo <PromotionCodeEntity, CouponModel>(entities).ToList();
                    foreach (var item in resultHistorysList)
                    {
                        item.IsHistory = 1;
                    }
                    result.AddRange(resultHistorysList);
                }
                if (request.IsHistory == 2 || request.IsHistory == 0)
                {
                    var entities = await _PromotionCodeRepository.GetCouponByUserIDAsync(request.UserID, cancellationToken).ConfigureAwait(false);

                    resultNowList = ObjectMapper.ConvertTo <PromotionCodeEntity, CouponModel>(entities).ToList();
                    result.AddRange(resultNowList);
                }
            }
            catch (Exception ex)
            {
                _logger.Info($"CouponManager GetCouponByUserIDAsync Exception", ex);
                throw;
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取模块和模块内容列表
        /// </summary>
        /// <returns></returns>
        public List <MemberPageModuleListModel> GetMemberPageModuleList()
        {
            MemberPageModuleListModel        model = null;
            List <MemberPageModuleListModel> list  = new List <MemberPageModuleListModel>();

            using (var conn = ProcessConnection.OpenConfigurationReadOnly)
            {
                var moduleList = moduleDAL.GetMemberPageModuleList(conn);
                if (moduleList.Any())
                {
                    var contentList = contentDAL.GetMemberPageModuleContentList(conn, moduleList.First().MemberPageID);
                    foreach (var item in moduleList)
                    {
                        //添加模块数据
                        model = new MemberPageModuleListModel();
                        model = ObjectMapper.ConvertTo <MemberPageModuleModel, MemberPageModuleListModel>(item);
                        model.MemberPageModuleID = item.PKID;
                        model.ModuleDisplayIndex = item.DisplayIndex;
                        list.Add(model);
                        //添加模块内容数据
                        list.AddRange(ObjectMapper.ConvertTo <MemberPageModuleContentModel, MemberPageModuleListModel>(contentList.Where(t => t.MemberPageModuleID == item.PKID)));
                    }
                }
            }
            return(list);
        }
Exemplo n.º 7
0
        /// <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>
        /// 分页查询  领取规则审核 list
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <List <GetCouponRuleAuditModel> > GetCouponGetRuleAuditListAsync(GetCouponGetRuleAuditListRequest request, CancellationToken cancellationToken)
        {
            List <GetCouponRuleAuditEntity> entity = await _ICouponGetRuleAuditRepository.GetCouponGetRuleAuditListAsync(request, cancellationToken).ConfigureAwait(false);

            List <GetCouponRuleAuditModel> models = ObjectMapper.ConvertTo <GetCouponRuleAuditEntity, GetCouponRuleAuditModel>(entity).ToList();

            return(models);
        }
        public async ValueTask <List <GetCouponRuleAuditModel> > GetListByGetCouponRulePKIDAsync(int GetCouponRulePKID, CancellationToken cancellationToken)
        {
            List <GetCouponRuleAuditModel> models = new List <GetCouponRuleAuditModel>();
            var entities = await _ICouponGetRuleAuditRepository.GetListByGetCouponRulePKIDAsync(GetCouponRulePKID, cancellationToken).ConfigureAwait(false);

            models = ObjectMapper.ConvertTo <GetCouponRuleAuditEntity, GetCouponRuleAuditModel>(entities).ToList();
            return(models);
        }
        /// <summary>
        /// 根据工单获取 领取规则的审核信息
        /// </summary>
        /// <param name="WorkOrderId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <List <GetCouponRuleAuditModel> > GetCouponGetRuleAuditByWorkOrderIdAsync(int WorkOrderId, CancellationToken cancellationToken)
        {
            var entity = await _ICouponGetRuleAuditRepository.GetEntityByWorkOrderIdAsync(WorkOrderId, cancellationToken).ConfigureAwait(false);

            List <GetCouponRuleAuditModel> models = ObjectMapper.ConvertTo <GetCouponRuleAuditEntity, GetCouponRuleAuditModel>(entity).ToList();

            return(models);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 根据任务id获取 发券规则
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <List <PromotionTaskPromotionListModel> > GetCouponRuleByTaskIDAsync(GetCouponRuleByTaskIDRequest request, CancellationToken cancellationToken)
        {
            var entity = await promotionTaskPromotionListRepository.GetPromotionTaskPromotionListByPromotionTaskIdAsync(request.PromotionTaskId, cancellationToken).ConfigureAwait(false);

            var result = ObjectMapper.ConvertTo <PromotionTaskPromotionListEntity, PromotionTaskPromotionListModel>(entity);

            return(result.ToList());
        }
        public async ValueTask <CouponGetRuleModel> GetByPKIDAsync(int PKID, CancellationToken cancellationToken)
        {
            CouponGetRuleEntity entity = await _ICouponGetRuleRepository.GetByPKIDAsync(PKID, cancellationToken).ConfigureAwait(false);

            CouponGetRuleModel model = ObjectMapper.ConvertTo <CouponGetRuleEntity, CouponGetRuleModel>(entity);

            return(model);
        }
        /// <summary>
        /// 获取所有业务线 [不包括已删除]
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <List <PromotionBusinessLineConfigResponse> > GetPromotionBusinessLineConfigListAsync(CancellationToken cancellationToken)
        {
            var result = await _ICouponGetRuleRepository.GetPromotionBusinessLineConfigListAsync(cancellationToken).ConfigureAwait(false);

            List <PromotionBusinessLineConfigResponse> models = ObjectMapper.ConvertTo <PromotionBusinessLineConfigEntity, PromotionBusinessLineConfigResponse>(result).ToList();

            return(models);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 获取优惠券 任务列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <List <PromotionTaskModel> > GetPromotionTaskListAsync(GetPromotionTaskListRequest request, CancellationToken cancellationToken)
        {
            var entities = await promotionTaskRepository.GetPromotionTaskListAsync(request, cancellationToken).ConfigureAwait(false);

            var result = ObjectMapper.ConvertTo <PromotionTaskEntity, PromotionTaskModel>(entities).ToList();

            return(result);
        }
        public async Task <bool> CalculateUserGrade()
        {
            using (var client = new Tuhu.Service.Member.MembershipsGradeClient())
            {
                var  pageSize = 50;
                long minPKID  = 0;
                var  maxDate  = DateTime.Now.AddYears(-1);
                var  request  = new QueryUserObjectInfoRequest()
                {
                    PageIndex = 1,
                    MinPkId   = minPKID,
                    PageSize  = pageSize,
                    StartDate = maxDate
                };
                var totalCount = await client.GetNeedCalculateUserGradeCountAsync(request);

                var pageIndex = 1;
                var PageCount = (totalCount.Result - 1) / pageSize + 1;
                while (pageIndex <= PageCount)
                {
                    pageIndex++;
                    request = new QueryUserObjectInfoRequest
                    {
                        MinPkId   = minPKID,
                        PageIndex = pageIndex,
                        PageSize  = pageSize,
                    };
                    try
                    {
                        var dataList = await client.GetNeedCalculateUserGradeDataAsync(request);

                        if (dataList.Result == null || !dataList.Result.Any())
                        {
                            continue;
                        }
                        minPKID = dataList.Result.Max(t => t.PKID);
                        var calculateRequst = ObjectMapper.ConvertTo <UserObjectInfoResponse, CalculateUserGradeRequest>(dataList.Result);
                        await client.CaculateUserGradeListAsync(calculateRequst.ToList());
                    }
                    catch (Exception e)
                    {
                        Logger.Info($"获取或计算会员任务时出现异常");
                        Logger.Info($"获取或计算会员任务时出现异常:" + e.ToString());
                        continue;
                    }
                }
                return(true);
            }
        }
        /// <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>
        /// 根据userid获取  一分钱洗车优惠券领取记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task <OperationResult <List <WashCarCouponRecordModel> > > GetWashCarCouponListByUseridsAsync(GetWashCarCouponListByUseridsRequest request)
        {
            List <WashCarCouponRecordModel> models = new List <WashCarCouponRecordModel>();

            try
            {
                var result = await DalWashCarCouponRecord.GetWashCarCouponListByUseridsAsync(request.UserID);

                models = ObjectMapper.ConvertTo <WashCarCouponRecordEntity, WashCarCouponRecordModel>(result).ToList();
                return(OperationResult.FromResult(models));
            }
            catch (Exception ex)
            {
                return(OperationResult.FromError <List <WashCarCouponRecordModel> >("500", ex.Message));
            }
        }
        /// <summary>
        /// 根据优惠券id获取  一分钱洗车优惠券领取记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task <OperationResult <WashCarCouponRecordModel> > GetWashCarCouponInfoByPromotionCodeIDAsync(GetWashCarCouponInfoByPromotionCodeIDRequest request)
        {
            WashCarCouponRecordModel models = new WashCarCouponRecordModel();

            try
            {
                var result = await DalWashCarCouponRecord.GetWashCarCouponListByPromotionCodeIDAsync(request.PromotionCodeID);

                models = ObjectMapper.ConvertTo <WashCarCouponRecordEntity, WashCarCouponRecordModel>(result).FirstOrDefault();
                return(OperationResult.FromResult(models));
            }
            catch (Exception ex)
            {
                return(OperationResult.FromError <WashCarCouponRecordModel>("500", ex.Message));
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// 获取区域列表
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <param name="IsALL">是否全部(默认否)</param>
        /// <returns></returns>
        public async ValueTask <List <GetRegionListResponse> > GetRegionListAsync(CancellationToken cancellationToken, bool IsALL = false)
        {
            List <GetRegionListResponse> result = new List <GetRegionListResponse>();

            try
            {
                var entities = await _RegionRepository.GetRegionListAsync(cancellationToken, IsALL).ConfigureAwait(false);

                result = ObjectMapper.ConvertTo <RegionEntity, GetRegionListResponse>(entities).ToList();
            }
            catch (Exception ex)
            {
                _logger.Error($"RegionManager GetRegionListAsync Exception", ex);
                throw;
            }
            return(result);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 获取活动信息
        /// </summary>
        /// <param name="ActivityID">活动ID</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <GetActivityResponse> GetActivityInfoAsync(int ActivityID, CancellationToken cancellationToken)
        {
            GetActivityResponse result = new GetActivityResponse();

            try
            {
                var entities = await _IActivityRepository.GetActivityInfoAsync(ActivityID, cancellationToken).ConfigureAwait(false);

                result = ObjectMapper.ConvertTo <ActivityEntity, GetActivityResponse>(entities);
            }
            catch (Exception ex)
            {
                _logger.Error($"ActivityManager GetActivityAsync Exception", ex);
                throw;
            }
            return(result);
        }
Exemplo n.º 21
0
        public async Task <JsonResult> GetUserPermissionByPage(UserPermissionRequest request)
        {
            var returnValue = new List <UserPermissionViewModel>();

            if (request == null)
            {
                return(Json(new { code = -1, msg = "无参数信息", count = 0, data = returnValue }, JsonRequestBehavior.AllowGet));
            }
            if (request.Page <= 0)
            {
                request.Page = 1;
            }
            if (request.Limit <= 0)
            {
                request.Limit = 50;
            }
            var memberBll    = new MemberService();
            var requestModel = new UserPermissionModel {
                Name = request.PermissionName,
                MembershipsGradeId = request.MembershipsGradeId
            };
            var count           = DALUserPermission.QueryPageCount(requestModel);
            var dataResult      = DALUserPermission.QueryPageList(requestModel, request.Page, request.Limit);
            var memberGradeList = await memberBll.GetMembershipsGradeListAsync();

            if (memberGradeList != null && memberGradeList.Count > 0 && dataResult != null && dataResult.Count > 0)
            {
                foreach (var userPermission in dataResult)
                {
                    var viewModel  = ObjectMapper.ConvertTo <UserPermissionModel, UserPermissionViewModel>(userPermission);
                    var gradeModel = memberGradeList.Find(t => t.PKID == userPermission.MembershipsGradeId);
                    viewModel.LastUpdateDateTime = userPermission.LastUpdateDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                    viewModel.CreateDatetime     = userPermission.CreateDatetime.ToString("yyyy-MM-dd HH:mm:ss");
                    if (gradeModel != null)
                    {
                        viewModel.MembershipsGradeName = gradeModel.GradeName;
                    }
                    returnValue.Add(viewModel);
                }
            }
            return(Json(new { code = 0, msg = "加载成功", count = count, data = returnValue.OrderByDescending(t => t.Id) }, JsonRequestBehavior.AllowGet));
        }
        /// <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);
            }
        }
        /// <summary>
        /// 根据guid获取优惠券领取规则 【加缓存】
        /// </summary>
        /// <param name="GetRuleGUID"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <CouponGetRuleModel> GetCouponGetRuleCahceByGuidAsync(Guid GetRuleGUID, CancellationToken cancellationToken)
        {
            CouponGetRuleEntity entity = new CouponGetRuleEntity();

            using (var client = _ICacheHelper.CreateCacheClient(GlobalConstant.RedisClient))
            {
                var result = await client.GetOrSetAsync(string.Format(GlobalConstant.RedisKeyForGetRule, GetRuleGUID),
                                                        async() => await _ICouponGetRuleRepository.GetCouponGetRuleByGuidAsync(GetRuleGUID, cancellationToken).ConfigureAwait(false),
                                                        GlobalConstant.RedisTTLForGetRule).ConfigureAwait(false);

                if (result.Success)
                {
                    entity = result.Value;
                }
                else
                {
                    entity = await _ICouponGetRuleRepository.GetCouponGetRuleByGuidAsync(GetRuleGUID, cancellationToken).ConfigureAwait(false);
                }
            }
            CouponGetRuleModel model = ObjectMapper.ConvertTo <CouponGetRuleEntity, CouponGetRuleModel>(entity);

            return(model);
        }
        /// <summary>
        ///  新增 一分钱洗车优惠券领取记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task <OperationResult <bool> > CreateWashCarCouponAsync(WashCarCouponRecordModel request)
        {
            try
            {
                #region 新增时 数据验证
                string validMSG = "";
                if (request == null)
                {
                    validMSG = "请求参数不能为空";
                }
                else if (string.IsNullOrWhiteSpace(request.CarNo))
                {
                    validMSG = "车牌号不能为空";
                }
                else if (Guid.Empty == request.UserID)
                {
                    validMSG = "用户不能为空";
                }
                else if (request.PromotionCodeID <= 0)
                {
                    validMSG = "优惠券不能为空";
                }
                if (!string.IsNullOrWhiteSpace(validMSG))
                {
                    return(OperationResult.FromError <bool>("-1", validMSG));
                }
                #endregion
                WashCarCouponRecordEntity entity = ObjectMapper.ConvertTo <WashCarCouponRecordModel, WashCarCouponRecordEntity>(request);
                var result = await DalWashCarCouponRecord.CreateWashCarCouponAsync(entity);

                return(OperationResult.FromResult(result > 0));
            }
            catch (Exception ex)
            {
                return(OperationResult.FromError <bool>("500", ex.Message));
            }
        }
Exemplo n.º 25
0
        /// <summary>
        ///  作废优惠券 - 批量
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async override ValueTask <OperationResult <ObsoleteCouponListReponse> > ObsoleteCouponListAsync([FromBody] ObsoleteCouponListRequest request)
        {
            if (!request.IsPassed)
            {
                return(OperationResult.FromError <ObsoleteCouponListReponse>("-1", request.ErrorMsg));
            }
            if (request.IsObsoleteAll)
            {
                GetCouponByUserIDRequest getCouponByUserIDRequest = new GetCouponByUserIDRequest()
                {
                    UserID    = request.UserID,
                    IsHistory = 2
                };
                var couponList = await _CouponManager.GetCouponByUserIDAsync(getCouponByUserIDRequest, HttpContext.RequestAborted).ConfigureAwait(false);

                request.PromotionPKIDList = couponList.Where(p => p.Status == 0).Select(p => p.PKID).ToList();
            }
            ObsoleteCouponListReponse response = new ObsoleteCouponListReponse();
            ObsoleteCouponRequest     ObsoleteCouponRequest = ObjectMapper.ConvertTo <ObsoleteCouponListRequest, ObsoleteCouponRequest>(request);

            foreach (var item in request.PromotionPKIDList)
            {
                ObsoleteCouponRequest.PromotionPKID = item;
                var flag = await _CouponManager.ObsoleteCouponAsync(ObsoleteCouponRequest, HttpContext.RequestAborted).ConfigureAwait(false);

                if (flag.Result)
                {
                    response.SuccessedIDs += ObsoleteCouponRequest.PromotionPKID + ",";
                }
                else
                {
                    response.FaidedIDs += ObsoleteCouponRequest.PromotionPKID + ",";
                }
            }
            return(OperationResult.FromResult(response));
        }
        /// <summary>
        /// 审核成功 同步到领取规则
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <int> SaveAuditToGetRuleAsync(GetCouponRuleAuditModel request, CancellationToken cancellationToken)
        {
            int pkid = 0;

            try
            {
                CouponGetRuleEntity entity = ObjectMapper.ConvertTo <GetCouponRuleAuditModel, CouponGetRuleEntity>(request);
                entity.PKID = request.GetCouponRulePKID;
                if (entity.PKID > 0)
                {
                    pkid = await _ICouponGetRuleRepository.UpdateAsync(entity, cancellationToken).ConfigureAwait(false) ? entity.PKID : 0;
                }
                else
                {
                    pkid = await _ICouponGetRuleRepository.CreateAsync(entity, cancellationToken).ConfigureAwait(false);
                }
                return(pkid);
            }
            catch (Exception ex)
            {
                _logger.Error($"UpdateCouponGetRuleAuditAsync Exception {JsonConvert.SerializeObject(request)}", ex);
                return(0);
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// 更新优惠券审核状态 【工单审核成功通知MQ中调用】
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async override ValueTask <OperationResult <bool> > UpdateCouponGetRuleAuditAsync([FromBody] UpdateCouponGetRuleAuditRequest request)
        {
            #region 1.更新审核记录的状态  并 添加日志
            //1.获取优惠券审核的信息
            var couponGetRuleAuditList = await _ICouponGetRuleAuditManager.GetCouponGetRuleAuditByWorkOrderIdAsync(request.WorkOrderId, HttpContext.RequestAborted).ConfigureAwait(false);

            GetCouponRuleAuditModel couponGetRuleAuditModelBefore = couponGetRuleAuditList.Where(p => p.AuditStatus == (int)WorkOrderAuditStatusEnum.审批中).FirstOrDefault();
            if (couponGetRuleAuditModelBefore == null)
            {
                return(OperationResult.FromError <bool>("-1", $@"未查询到WorkOrderId ={request.WorkOrderId}审核记录"));
            }
            GetCouponRuleAuditModel couponGetRuleAuditModelAfter = ObjectMapper.ConvertTo <GetCouponRuleAuditModel, GetCouponRuleAuditModel>(couponGetRuleAuditModelBefore);
            couponGetRuleAuditModelAfter.Auditor = request.Auditor;
            WorkOrderAuditStatusEnum status;
            Enum.TryParse(request.AuditStatus, out status);
            couponGetRuleAuditModelAfter.AuditStatus   = (int)(status);
            couponGetRuleAuditModelAfter.AuditDateTime = request.AuditDateTime == new DateTime() ? DateTime.Now : request.AuditDateTime;
            couponGetRuleAuditModelAfter.AuditMessage  = request.AuditMessage;
            couponGetRuleAuditModelAfter.Auditor       = request.Auditor;
            //更新审核记录的审核信息
            var UpdateAudit = await _ICouponGetRuleAuditManager.UpdateCouponGetRuleAuditAsync(couponGetRuleAuditModelAfter, HttpContext.RequestAborted).ConfigureAwait(false);

            if (UpdateAudit == 0)
            {
                return(OperationResult.FromError <bool>("-1", $@"更新审核记录异常"));
            }
            //2.添加日志
            GetCouponGetRuleAuditorResponse response = new GetCouponGetRuleAuditorResponse();
            var ConfigResult = await _IConfigLogService.InsertDefaultLogQueue(GlobalConstant.LogTypeCouponGetRuleAudit, JsonConvert.SerializeObject(new
            {
                ObjectId    = couponGetRuleAuditModelBefore.PKID,
                ObjectType  = GlobalConstant.LogObjectTypeCouponGetRuleAudit,
                BeforeValue = JsonConvert.SerializeObject(couponGetRuleAuditModelBefore),
                AfterValue  = JsonConvert.SerializeObject(couponGetRuleAuditModelAfter),
                Operate     = "修改审核记录",
                Author      = couponGetRuleAuditModelAfter.Auditor
            })).ConfigureAwait(false);

            #endregion

            #region 2.将审核通过的内容更新到领取规则表 & 推送给申请人 & 添加日志

            if (couponGetRuleAuditModelAfter.AuditStatus == (int)WorkOrderAuditStatusEnum.审批通过) //审核通过
            {
                //审核成功 同步到领取规则
                var pkid = await _ICouponGetRuleManager.SaveAuditToGetRuleAsync(couponGetRuleAuditModelAfter, HttpContext.RequestAborted).ConfigureAwait(false);

                if (pkid == 0)
                {
                    return(OperationResult.FromError <bool>("-1", "审核成功,更新优惠券领取规则失败"));
                }
                else//更新优惠券领取规则 成功
                {
                    ConfigResult = await _IConfigLogService.InsertDefaultLogQueue(GlobalConstant.LogTypeCouponGetRuleAudit, JsonConvert.SerializeObject(new
                    {
                        ObjectId    = pkid,
                        ObjectType  = GlobalConstant.LogObjectTypeCouponGetRule,
                        BeforeValue = "",
                        AfterValue  = JsonConvert.SerializeObject(couponGetRuleAuditModelAfter),
                        Operate     = "审核成功同步优惠券领取规则",
                        Author      = couponGetRuleAuditModelAfter.Auditor
                    })).ConfigureAwait(false);

                    //3.更新优惠券领取规则的缓存
                    var refreshResult = await _ICreatePromotionService.RefreshGetCouponRulesCache(couponGetRuleAuditModelAfter.GetRuleGUID).ConfigureAwait(false);
                }
            }
            #endregion
            return(OperationResult.FromResult(UpdateAudit > 0));
        }