/// <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)); }
/// <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)); }