| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.goods.domain.TGoods; |
| | | import com.ruoyi.goods.domain.TGoodsType; |
| | | import com.ruoyi.goods.domain.TOrder; |
| | | 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.ITGoodsService; |
| | | import com.ruoyi.goods.service.ITGoodsTypeService; |
| | | import com.ruoyi.goods.service.ITOrderService; |
| | | import com.ruoyi.goods.service.*; |
| | | import com.ruoyi.goods.vo.TGoodsVO; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RestController |
| | | @RequestMapping("/base/goods") |
| | | public class TGoodsController { |
| | | @Autowired |
| | | @Resource |
| | | private ITGoodsService goodsService; |
| | | @Autowired |
| | | private ITGoodsTypeService goodsTypeService; |
| | | @Autowired |
| | | private ITOrderService orderService; |
| | | @Resource |
| | | private IRecipientService recipientService; |
| | | @Resource |
| | | private IRegionService regionService; |
| | | |
| | | @PostMapping("/listType") |
| | | @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"}) |
| | | public R<PageInfo<TGoodsType>> listType(@RequestBody GoodsTypeQuery query){ |
| | | public R<PageInfo<TGoodsType>> listType(@RequestBody GoodsTypeQuery query) { |
| | | QueryWrapper<TGoodsType> wrapper = new QueryWrapper<>(); |
| | | if (StringUtils.hasLength(query.getName())){ |
| | | if (StringUtils.hasLength(query.getName())) { |
| | | wrapper.like("name", query.getName()); |
| | | } |
| | | // wrapper.ne("isDelete",1); |
| | |
| | | res.setRecords(list); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | @PostMapping("/goodList") |
| | | @ApiOperation(value = "商品列表查询", tags = {"学习端-商品列表"}) |
| | | public R<PageInfo<TGoods>> listType(@RequestBody GoodQueryDTO goodQuery) { |
| | | List<String> type = goodQuery.getType(); |
| | | String keywords = goodQuery.getKeywords(); |
| | | // 初始化条件构造器 |
| | | QueryWrapper<TGoods> wrapper = new QueryWrapper<>(); |
| | | wrapper = keywords != null && "".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper; |
| | | // 类型匹配 todo |
| | | wrapper = type.isEmpty() ? wrapper : wrapper.in(""); |
| | | wrapper.eq("isDelete", 0); |
| | | return R.ok(goodsService.page(new PageInfo<>(goodQuery.getPageNumber(), goodQuery.getPageSize()), wrapper)); |
| | | } |
| | | |
| | | @PostMapping("/addGoodsType") |
| | | @ApiOperation(value = "添加", tags = {"后台-商品类型管理"}) |
| | | public R addGoodsType(@RequestBody TGoodsType dto) { |
| | | goodsTypeService.save(dto); |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | @PostMapping("/updateGoodsType") |
| | | @ApiOperation(value = "修改", tags = {"后台-商品类型管理"}) |
| | | public R updateGoodsType(@RequestBody TGoodsType dto) { |
| | | goodsTypeService.updateById(dto); |
| | | return R.ok("修改成功"); |
| | | } |
| | | |
| | | @PostMapping("/deleteGoodsType/{id}") |
| | | @ApiOperation(value = "删除", tags = {"后台-商品类型管理"}) |
| | | public R deleteGoodsType(@PathVariable("id")Integer id) { |
| | | public R deleteGoodsType(@PathVariable("id") Integer id) { |
| | | TGoodsType byId = goodsTypeService.getById(id); |
| | | byId.setIsDelete(1); |
| | | goodsTypeService.removeById(byId); |
| | | return R.ok("删除成功"); |
| | | } |
| | | |
| | | @PostMapping("/listAll") |
| | | @ApiOperation(value = "列表查询", tags = {"后台-商品管理"}) |
| | | public R<PageInfo<TGoods>> listAll(@RequestBody GoodsTypeQuery query){ |
| | | public R<PageInfo<TGoods>> listAll(@RequestBody GoodsTypeQuery query) { |
| | | QueryWrapper<TGoods> wrapper = new QueryWrapper<>(); |
| | | if (StringUtils.hasLength(query.getName())){ |
| | | if (StringUtils.hasLength(query.getName())) { |
| | | wrapper.like("name", query.getName()); |
| | | } |
| | | wrapper.orderByDesc("id"); |
| | |
| | | res.setRecords(list); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | @PostMapping("/addGoods") |
| | | @ApiOperation(value = "添加", tags = {"后台-商品管理"}) |
| | | public R addGoods(@RequestBody TGoods dto) { |
| | | goodsService.save(dto); |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | @PostMapping("/deleteGoods/{id}") |
| | | @ApiOperation(value = "删除", tags = {"后台-商品管理"}) |
| | | public R deleteGoods(@PathVariable("id") Integer id) { |
| | |
| | | goodsService.removeById(byId); |
| | | return R.ok("删除成功"); |
| | | } |
| | | |
| | | @PostMapping("/updateGoods") |
| | | @ApiOperation(value = "修改", tags = {"后台-商品管理"}) |
| | | public R updateGoods(@RequestBody TGoods dto) { |
| | | goodsService.updateById(dto); |
| | | return R.ok("修改成功"); |
| | | } |
| | | |
| | | @PostMapping("/getGoodsInfo/{id}") |
| | | @ApiOperation(value = "查看详情", tags = {"后台-商品管理"}) |
| | | public R<TGoodsVO> getGoodsInfo(@PathVariable("id") Integer id) { |
| | | TGoodsVO tGoodsVO = new TGoodsVO(); |
| | | TGoods byId = goodsService.getById(id); |
| | | BeanUtils.copyProperties(byId,tGoodsVO); |
| | | BeanUtils.copyProperties(byId, tGoodsVO); |
| | | long goodsId = orderService.count(new QueryWrapper<TOrder>().eq("goodsId", id)); |
| | | tGoodsVO.setInventory(goodsId); |
| | | tGoodsVO.setIntegral(byId.getIntegral()); |
| | | return R.ok(tGoodsVO); |
| | | } |
| | | |
| | | @PostMapping("/getGoodsTypeList") |
| | | @ApiOperation(value = "获取商品类型列表", tags = {"后台-商品管理"}) |
| | | public R<List<TGoodsType>> getGoodsInfo() { |
| | | List<TGoodsType> res = goodsTypeService.list(new QueryWrapper<TGoodsType>()); |
| | | List<TGoodsType> res = goodsTypeService.list(new QueryWrapper<>()); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | /** |
| | | * 兑换记录 |
| | | */ |
| | | @GetMapping("/exchangeRecord") |
| | | @ApiOperation(value = "兑换记录", tags = {"兑换记录"}) |
| | | public R<List<TOrder>> exchangeRecord() { |
| | | return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, SecurityUtils.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()); |
| | | } |
| | | |
| | | /** |
| | | * 新增收货地址/修改收货地址 |
| | | */ |
| | | @PostMapping("/addressSaveOrUpdate") |
| | | @ApiOperation(value = "新增收货地址/修改收货地址", tags = {"新增收货地址/修改收货地址"}) |
| | | public R<String> addressSave(@RequestBody Recipient recipient) { |
| | | return R.ok(recipientService.addressSaveOrUpdate(recipient)); |
| | | } |
| | | |
| | | /** |
| | | * 删除收货地址 |
| | | */ |
| | | @GetMapping("/addressDelete") |
| | | @ApiOperation(value = "删除收货地址", tags = {"删除收货地址"}) |
| | | public R<String> addressDelete(@RequestParam String id) { |
| | | return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); |
| | | } |
| | | |
| | | /** |
| | | * 修改订单收货地址 |
| | | * |
| | | * @param orderId 订单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) |
| | | .eq(TOrder::getId, orderId).eq(TOrder::getState, 1).update()); |
| | | } |
| | | |
| | | /** |
| | | * 收货地址省市区三级联动 |
| | | */ |
| | | @GetMapping("/addressTree") |
| | | @ApiOperation(value = "收货地址省市区三级联动", tags = {"收货地址省市区三级联动"}) |
| | | public R<List<Region>> addressTree() { |
| | | return R.ok(regionService.addressTree()); |
| | | } |
| | | |
| | | /** |
| | | * 可兑换商品推荐 |
| | | */ |
| | | @GetMapping("/goodRecommend") |
| | | @ApiOperation(value = "可兑换商品推荐", tags = {"可兑换商品推荐"}) |
| | | public R<List<TGoodsVO>> goodRecommend(@RequestParam String userId) { |
| | | List<TGoodsVO> res = goodsService.goodRecommend(userId); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | /** |
| | | * 商品详情 |
| | | * |
| | | * @param goodId 商品id |
| | | */ |
| | | @GetMapping("/goodDetail") |
| | | @ApiOperation(value = "商品详情", tags = {"商品详情"}) |
| | | public R<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("goodDetail", goods); |
| | | // 商品分类详情 |
| | | result.put("goodTypeDetail", goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list()); |
| | | // 已兑换人数 |
| | | result.put("number", goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId())); |
| | | // 用户收货地址 |
| | | if (SecurityUtils.getUserId() != null) { |
| | | result.put("address", recipientService.lambdaQuery() |
| | | .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one()); |
| | | } |
| | | return R.ok(result); |
| | | } |
| | | |
| | | /** |
| | | * 商城-立即兑换 |
| | | */ |
| | | @GetMapping("/redeemNow") |
| | | @ApiOperation(value = "商城-立即兑换", tags = {"立即兑换"}) |
| | | public R<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)); |
| | | } |
| | | |
| | | /** |
| | | * 商品兑换 |
| | | * |
| | | * @param goodExchange 商品信息 |
| | | */ |
| | | @PostMapping("/goodExchange") |
| | | @ApiOperation(value = "商品兑换-确认", tags = {"商品兑换-确认"}) |
| | | public R<Object> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { |
| | | Recipient recipient = recipientService.getById(goodExchange.getRecipientId()); |
| | | return R.ok(goodsService.goodExchange(goodExchange, recipient)); |
| | | } |
| | | |
| | | } |
| | | |