| | |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.goods.domain.*; |
| | | import com.ruoyi.goods.dto.GoodExchangeDTO; |
| | | import com.ruoyi.goods.dto.GoodQueryDTO; |
| | | import com.ruoyi.goods.dto.GoodsTypeQuery; |
| | | import com.ruoyi.goods.service.*; |
| | | import com.ruoyi.goods.vo.TGoodsVO; |
| | | import com.ruoyi.system.api.model.LoginUserParent; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private IRecipientService recipientService; |
| | | @Resource |
| | | private IRegionService regionService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @PostMapping("/listType") |
| | | @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"}) |
| | |
| | | */ |
| | | @GetMapping("/exchangeRecord") |
| | | @ApiOperation(value = "兑换记录", tags = {"兑换记录"}) |
| | | public R<List<TOrder>> exchangeRecord() { |
| | | return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, SecurityUtils.getUserId()) |
| | | public AjaxResult<List<TOrder>> exchangeRecord() { |
| | | return AjaxResult.success(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUserStudy().getUserid()) |
| | | .orderByDesc(TOrder::getCreateTime).list()); |
| | | } |
| | | |
| | | /** |
| | | * 兑换记录 |
| | | */ |
| | |
| | | */ |
| | | @GetMapping("/shopAddress") |
| | | @ApiOperation(value = "获取用户收货地址", tags = {"获取用户收货地址"}) |
| | | public R<List<Recipient>> shopAddress() { |
| | | return R.ok(recipientService.lambdaQuery().eq(Recipient::getUserId, |
| | | SecurityUtils.getUserId()).list()); |
| | | public AjaxResult<List<Recipient>> shopAddress() { |
| | | return AjaxResult.success(recipientService.lambdaQuery().eq(Recipient::getUserId, |
| | | tokenService.getLoginUserStudy().getUserid()).list()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/addressSaveOrUpdate") |
| | | @ApiOperation(value = "新增收货地址/修改收货地址", tags = {"新增收货地址/修改收货地址"}) |
| | | public R<String> addressSave(@RequestBody Recipient recipient) { |
| | | recipient.setUserId(SecurityUtils.getUserId().intValue()); |
| | | return R.ok(recipientService.addressSaveOrUpdate(recipient)); |
| | | public AjaxResult<String> addressSave(@RequestBody Recipient recipient) { |
| | | recipient.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | return AjaxResult.success(recipientService.addressSaveOrUpdate(recipient)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/addressDelete") |
| | | @ApiOperation(value = "删除收货地址", tags = {"删除收货地址"}) |
| | | public R<String> addressDelete(@RequestParam String id) { |
| | | return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<String> addressDelete(@RequestParam String id) { |
| | | return AjaxResult.success(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/updateOrderAddress") |
| | | @ApiOperation(value = "修改订单收货地址", tags = {"修改订单收货地址"}) |
| | | public R<Boolean> updateOrderAddress(@RequestParam String orderId, @RequestParam String address) { |
| | | return R.ok(orderService.lambdaUpdate().set(TOrder::getConsigneeAddress, address) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true), |
| | | @ApiImplicitParam(value = "完整收货地址", name = "address", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<Boolean> updateOrderAddress(@RequestParam String orderId, @RequestParam String address) { |
| | | return AjaxResult.success(orderService.lambdaUpdate().set(TOrder::getConsigneeAddress, address) |
| | | .eq(TOrder::getId, orderId).eq(TOrder::getState, 1).update()); |
| | | } |
| | | |
| | |
| | | */ |
| | | @GetMapping("/addressTree") |
| | | @ApiOperation(value = "收货地址省市区三级联动", tags = {"收货地址省市区三级联动"}) |
| | | public R<List<Region>> addressTree() { |
| | | return R.ok(regionService.addressTree()); |
| | | public AjaxResult<List<Region>> addressTree() { |
| | | return AjaxResult.success(regionService.addressTree()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/goodRecommend") |
| | | @ApiOperation(value = "可兑换商品推荐", tags = {"可兑换商品推荐"}) |
| | | public R<List<TGoodsVO>> goodRecommend(String userId) { |
| | | return R.ok(goodsService.goodRecommend(userId)); |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public R<List<TGoodsVO>> goodRecommend() { |
| | | return R.ok(goodsService.goodRecommend(tokenService.getLoginUserStudy().getUserid())); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/goodDetail") |
| | | @ApiOperation(value = "商品详情", tags = {"商品详情"}) |
| | | public R<Map<String, Object>> goodDetail(@RequestParam String goodId) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> goodDetail(@RequestParam String goodId) { |
| | | Map<String, Object> result = new HashMap<>(8); |
| | | // 商品详情 |
| | | TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | |
| | | // 已兑换人数 |
| | | result.put("number", goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId())); |
| | | // 用户收货地址 |
| | | if (SecurityUtils.getUserId() != null) { |
| | | if (tokenService.getLoginUserStudy().getUserid() != null) { |
| | | result.put("address", recipientService.lambdaQuery() |
| | | .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one()); |
| | | .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()).eq(Recipient::getIsDefault, 1).one()); |
| | | } |
| | | return R.ok(result); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/redeemNow") |
| | | @ApiOperation(value = "商城-立即兑换", tags = {"立即兑换"}) |
| | | public R<Map<String, Object>> redeemNow(@RequestParam String goodId) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> redeemNow(@RequestParam String goodId) { |
| | | Recipient recipient = recipientService.lambdaQuery() |
| | | .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one(); |
| | | return R.ok(goodsService.redeemNow(goodId, recipient)); |
| | | .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()).eq(Recipient::getIsDefault, 1).one(); |
| | | return AjaxResult.success(goodsService.redeemNow(goodId, recipient)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/goodExchange") |
| | | @ApiOperation(value = "商品兑换-确认", tags = {"商品兑换-确认"}) |
| | | public R<Object> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { |
| | | public AjaxResult<Object> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { |
| | | Recipient recipient = recipientService.getById(goodExchange.getRecipientId()); |
| | | return R.ok(goodsService.goodExchange(goodExchange, recipient)); |
| | | return AjaxResult.success(goodsService.goodExchange(goodExchange, recipient)); |
| | | } |
| | | |
| | | } |