| | |
| | | import io.swagger.annotations.ApiOperationSupport; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @PostMapping("/addGoods") |
| | | @ApiOperation(value = "添加", tags = {"后台-商品管理"}) |
| | | public R addGoods(@RequestBody TGoods dto) { |
| | | if (dto.getTotal()!=null){ |
| | | dto.setSurplus(dto.getTotal()); |
| | | }else{ |
| | | dto.setSurplus(0); |
| | | } |
| | | goodsService.save(dto); |
| | | return R.ok("添加成功"); |
| | | } |
| | |
| | | @PostMapping("/updateGoods") |
| | | @ApiOperation(value = "修改", tags = {"后台-商品管理"}) |
| | | public R updateGoods(@RequestBody TGoods dto) { |
| | | if (dto.getTotal()!=null){ |
| | | dto.setSurplus(dto.getTotal()); |
| | | }else{ |
| | | dto.setSurplus(0); |
| | | } |
| | | goodsService.updateById(dto); |
| | | return R.ok("修改成功"); |
| | | } |
| | |
| | | } |
| | | TOrder byId = orderService.getById(id); |
| | | byId.setState(3); |
| | | byId.setCompleteTime(new Date()); |
| | | return R.ok(orderService.updateById(byId)); |
| | | } |
| | | |
| | |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public R<GoodDetailVO> goodDetail(@RequestParam String goodId) { |
| | | if (tokenService.getLoginUserStudy() == null) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | // 商品详情 |
| | | TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | | if (null == goods) { |
| | |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public R<GoodDetailVO> goodDetailParent(@RequestParam String goodId) { |
| | | if (tokenService.getLoginUser1() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | // if (tokenService.getLoginUser1() == null) { |
| | | // return R.tokenError("登录失效"); |
| | | // } |
| | | // 商品详情 |
| | | TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | | if (null == goods) { |
| | |
| | | // 商品分类详情 |
| | | List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list(); |
| | | // 已兑换人数 |
| | | int number = goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId()); |
| | | int number = 0; |
| | | if (null != goods.getBasicCount()) { |
| | | number += goods.getBasicCount(); |
| | | } |
| | | number += orderService.getGoodBuyNumber(goods.getId()); |
| | | return R.ok(new GoodDetailVO(goods, goodsTypes, number)); |
| | | } |
| | | |
| | |
| | | } |
| | | Recipient recipient = recipientService.lambdaQuery() |
| | | .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()) |
| | | .eq(Recipient::getIsDefault, 1).one(); |
| | | .eq(Recipient::getIsDefault, 1) |
| | | .eq(Recipient::getDisabled, 0).one(); |
| | | GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient); |
| | | LocalDateTime currentDateTime = LocalDateTime.now(); |
| | | // 格式化日期和时间信息 |
| | |
| | | Random random = new Random(); |
| | | StringBuilder randomPart = new StringBuilder(); |
| | | for (int i = 0; i < 3; i++) { |
| | | randomPart.append((char) (random.nextInt(26) + 'A')); // 大写字母 |
| | | // 大写字母 |
| | | randomPart.append((char) (random.nextInt(26) + 'A')); |
| | | } |
| | | // 组合订单编号 |
| | | String orderNumber = formattedDateTime + randomPart.toString(); |
| | | String orderNumber = formattedDateTime + randomPart; |
| | | goodDetailVO.setOrderNumber(orderNumber); |
| | | return R.ok(goodDetailVO); |
| | | } |
| | |
| | | @PostMapping("/goodExchange") |
| | | @ApiOperation(value = "家长端-商品兑换确认", tags = {"家长端-商品兑换确认"}) |
| | | public R goodExchange(@RequestBody GoodExchangeDTO goodExchange) { |
| | | System.err.println("家长兑换:"); |
| | | Recipient recipient = recipientService.getById(Integer.valueOf(goodExchange.getRecipientId())); |
| | | return goodsService.goodExchange1(goodExchange, recipient); |
| | | } |
| | |
| | | @PostMapping("/goodExchangeStudy") |
| | | @ApiOperation(value = "商品兑换确认", tags = {"学习端-商城"}) |
| | | @ApiOperationSupport(order = 42) |
| | | public R goodExchangeStudy(@RequestBody GoodExchangeDTO goodExchange) { |
| | | public R<String> goodExchangeStudy(@RequestBody @Validated GoodExchangeDTO goodExchange) { |
| | | System.err.println("学习兑换:"); |
| | | Recipient recipient = recipientService.getById(goodExchange.getRecipientId()); |
| | | return goodsService.goodExchange(goodExchange, recipient); |
| | | } |