public async Task <IActionResult> GetMallDetails([FromBody] ParamMallDetails param) { return(await ActionWrapAsync(async() => { ResultData <RpsData <IEnumerable <RpsMallDetail> > > result = new ResultData <RpsData <IEnumerable <RpsMallDetail> > >(); param = HttpContext.User.GetUserBase <ParamMallDetails>(param); result.Data = await _gameService.GetMallDetails(param); return result; })); }
/// <summary> /// 预计特价商品不会太多,所以采用的子查询 /// </summary> /// <param name="param"></param> /// <returns></returns> public async Task <RpsData <IEnumerable <RpsMallDetail> > > GetMallDetails(ParamMallDetails param) { var result = await _context.Malls.AsNoTracking() .WhereIf(param.Mode == 1, x => x.MallType == MallTypeEnum.道具商城) .WhereIf(param.Mode == 2, x => x.MallType == MallTypeEnum.金币商城) .Select(x => new RpsMallDetail() { Id = x.Id, Type = x.Type, MallType = x.MallType, Num = x.Num, Name = x.Name, RewardNum = x.RewardNum, LimitedTime = x.LimitedNum, LimitedPeriod = x.LimitedPeriod, Price = x.Price, Descroption = x.Description, Icon = x.Icon } ).ToListAsync(); var specialResult = result.Where(x => x.LimitedTime != 0); foreach (var item in specialResult) { var countHis = await _context.BuyGoodHistories .WhereIf(item.LimitedPeriod > 1, x => x.CreateDate.Date >= DateTime.Today.AddDays(1 - item.LimitedPeriod)) .WhereIf(item.LimitedPeriod == 1, x => x.CreateDate.Date >= DateTime.Today) .CountAsync(x => x.UserId == param.Id); if (countHis >= item.LimitedTime) { item.CanBuy = false; } } return(RpsData <IEnumerable <RpsMallDetail> > .Ok(result)); }
public async Task <RpsData <IEnumerable <RpsMallDetail> > > GetMallDetails(ParamMallDetails param) { return(await _gameRepository.GetMallDetails(param)); }