44323
2024-06-06 b679205246bbe94e1e83db6f8e26d04668afd402
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson2.util.UUIDUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.security.service.TokenService;
@@ -162,6 +163,7 @@
    @PostMapping("/addGoods")
    @ApiOperation(value = "添加", tags = {"后台-商品管理"})
    public R addGoods(@RequestBody TGoods dto) {
        dto.setSurplus(dto.getTotal());
        goodsService.save(dto);
        return R.ok("添加成功");
    }
@@ -211,12 +213,31 @@
    }
    @GetMapping("/exchangeRecordParent")
    @ApiOperation(value = "家长端-兑换记录", tags = {"家长端-兑换记录"})
    public R<List<TOrder>> exchangeRecordParent() {
    public R<Page<TOrder>> exchangeRecordParent(Integer pageNumber,Integer pageSize) {
        if (tokenService.getLoginUser1() == null){
            return R.tokenError("登录失效");
        }
        return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUser1().getUserid())
                .orderByDesc(TOrder::getCreateTime).list());
        Page<TOrder> page = orderService.page(new Page<>(pageNumber, pageSize), new QueryWrapper<TOrder>().eq("userId", tokenService.getLoginUser1().getUserid())
                .orderByDesc("createTime"));
        List<TOrder> records = page.getRecords();
        for (TOrder tOrder : records) {
            TGoods byId = goodsService.getById(tOrder.getGoodsId());
            tOrder.setName(byId.getName());
            tOrder.setImg(byId.getCoverImg());
            StringBuilder stringBuilder = new StringBuilder();
            if (StringUtils.hasLength(byId.getTypeIds())){
                String[] split = byId.getTypeIds().split(",");
                for (String s : split) {
                    TGoodsType byId1 = goodsTypeService.getById(s);
                    stringBuilder.append(byId1.getName()).append("|");
                }
                // 去除最后一个字符
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
                tOrder.setType(stringBuilder.toString());
            }
        }
        return R.ok(page);
    }
    /**
@@ -279,6 +300,14 @@
        Recipient byId = recipientService.getById(id);
        byId.setIsDefault(1);
        recipientService.updateById(byId);
        // 如果设置为默认地址 那么要将之前的默认地址取消掉
        List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
                .eq("userId", tokenService.getLoginUser1().getUserid())
                .ne("id",byId.getId()));
        for (Recipient recipient1 : userId) {
            recipient1.setIsDefault(0);
            recipientService.updateById(recipient1);
        }
        return R.ok();
    }
    /**
@@ -296,6 +325,14 @@
        Recipient byId = recipientService.getById(id);
        byId.setIsDefault(1);
        recipientService.updateById(byId);
        // 如果设置为默认地址 那么要将之前的默认地址取消掉
        List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
                .eq("userId", tokenService.getLoginUser1().getUserid())
                .ne("id",byId.getId()));
        for (Recipient recipient1 : userId) {
            recipient1.setIsDefault(0);
            recipientService.updateById(recipient1);
        }
        return R.ok();
    }
@@ -353,6 +390,15 @@
    @ApiOperation(value = "学习端-新增收货地址/修改收货地址", tags = {"学习端-新增收货地址/修改收货地址"})
    public R<String> addressSave(@RequestBody Recipient recipient) {
        recipient.setUserId(tokenService.getLoginUserStudy().getUserid());
        if (recipient.getIsDefault() == 1){
            // 如果设置为默认地址 那么要将之前的默认地址取消掉
            List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
                    .eq("userId", tokenService.getLoginUser1().getUserid()));
            for (Recipient recipient1 : userId) {
                recipient1.setIsDefault(0);
                recipientService.updateById(recipient1);
            }
        }
        recipientService.addressSaveOrUpdate(recipient);
        return R.ok();
    }
@@ -362,11 +408,33 @@
    @PostMapping("/addressSaveOrUpdateParent")
    @ApiOperation(value = "家长端-新增收货地址/修改收货地址", tags = {"家长端-新增收货地址/修改收货地址"})
    public R<String> addressSaveOrUpdateParent(@RequestBody Recipient recipient) {
        if (tokenService.getLoginUser1() == null){
            return R.tokenError("登录失效!");
        }
        recipient.setUserId(tokenService.getLoginUser1().getUserid());
        if (recipient.getId() == null){
        if (recipient.getId() != null){
            if (recipient.getIsDefault() == 1){
                // 如果设置为默认地址 那么要将之前的默认地址取消掉
                List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
                        .eq("userId", tokenService.getLoginUser1().getUserid()));
                for (Recipient recipient1 : userId) {
                    recipient1.setIsDefault(0);
                    recipientService.updateById(recipient1);
                }
            }
            recipientService.updateById(recipient);
        }else{
            if (recipient.getIsDefault() == 1){
                // 如果设置为默认地址 那么要将之前的默认地址取消掉
                List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
                        .eq("userId", tokenService.getLoginUser1().getUserid()));
                for (Recipient recipient1 : userId) {
                    recipient1.setIsDefault(0);
                    recipientService.updateById(recipient1);
                }
            }
            recipientService.save(recipient);
        }
        return R.ok();
    }
@@ -390,7 +458,7 @@
    @ApiImplicitParams({
            @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "String", required = true)
    })
    public R<String> addressDeleteParent(@RequestParam String id) {
    public R<String> addressDeleteParent(@RequestParam Integer id) {
        return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!");
    }
@@ -428,7 +496,7 @@
        }
        Recipient userId = recipientService.getById(recipientId);
        TOrder byId = orderService.getById(orderId);
        byId.setConsigneeName(userId.getAddress());
        byId.setConsigneeName(userId.getRecipient());
        byId.setConsigneePhone(userId.getRecipientPhone());
        byId.setConsigneeAddress(userId.getAddress());
        orderService.updateById(byId);
@@ -556,6 +624,15 @@
        Recipient recipient = recipientService.lambdaQuery()
                .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid())
                .eq(Recipient::getIsDefault, 1).one();
        if (recipient == null){
            // 随便取一条地址数据
            List<Recipient> list = recipientService.lambdaQuery()
                    .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid())
                    .eq(Recipient::getIsDefault, 1).list();
            if (!list.isEmpty()){
                recipient = list.get(0);
            }
        }
        GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient);
        LocalDateTime currentDateTime = LocalDateTime.now();
        // 格式化日期和时间信息
@@ -580,9 +657,9 @@
     * @param goodExchange 商品信息
     */
    @PostMapping("/goodExchange")
    @ApiOperation(value = "学习端-商品兑换确认", tags = {"家长端-商品兑换确认"})
    @ApiOperation(value = "家长端-商品兑换确认", tags = {"家长端-商品兑换确认"})
    public R goodExchange(@RequestBody GoodExchangeDTO goodExchange) {
        Recipient recipient = recipientService.getById(goodExchange.getRecipientId());
        Recipient recipient = recipientService.getById(Integer.valueOf(goodExchange.getRecipientId()));
        return goodsService.goodExchange1(goodExchange, recipient);
    }
    @PostMapping("/goodExchangeStudy")