public async Task <RpsData <bool> > UseGoods(ParamUseGoods param) { var userGood = await _context.UserGoods.SingleAsync(x => x.UserId == param.Id && x.GoodsType == param.Type && x.GoodsType != MallGoodsTypeEnum.金币); if (userGood.Num > 0) { userGood.Num -= 1; _context.GoodsUseHistories.Add(new GoodsUseHistory() { CreateDateTime = DateTime.Now, GoodsType = userGood.GoodsType, Num = 1, UserId = userGood.UserId }); var result = await _context.SaveChangesAsync() > 0; if (result) { return(RpsData <bool> .Ok(true)); } else { return(RpsData <bool> .Error("保存出错")); } } return(RpsData <bool> .Error("数量不足,请先购买")); }
public async Task <IActionResult> UseGoods([FromBody] ParamUseGoods useGoods) { return(await ActionWrapAsync(async() => { ResultData <RpsData <bool> > result = new ResultData <RpsData <bool> >(); var param = HttpContext.User.GetUserBase(useGoods); result.Data = await _gameService.UseGoods(param); return result; })); }
public async Task <RpsData <bool> > UseGoods(ParamUseGoods param) { return(await _gameRepository.UseGoods(param)); }