| | |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | |
| | | |
| | | // 类型匹配 todo |
| | | if (goodQuery.getType() != null && goodQuery.getType().size() > 0) { |
| | | for (String s : goodQuery.getType()) { |
| | | wrapper.apply("FIND_IN_SET('" + s + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | for (int i = 0; i < goodQuery.getType().size(); i++) { |
| | | // if (i == 0){ |
| | | // wrapper.apply("FIND_IN_SET('" + goodQuery.getType().get(i) + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | // }else{ |
| | | wrapper.or().apply("FIND_IN_SET('" + goodQuery.getType().get(i) + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | // } |
| | | } |
| | | } |
| | | wrapper.eq("isDelete", 0); |
| | |
| | | wrapper = keywords != null && !"".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper; |
| | | // 类型匹配 todo |
| | | if (goodQuery.getType() != null && goodQuery.getType().size() > 0) { |
| | | for (String s : goodQuery.getType()) { |
| | | wrapper.apply("FIND_IN_SET('" + s + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | for (int i = 0; i < goodQuery.getType().size(); i++) { |
| | | if (i == 0){ |
| | | wrapper.apply("FIND_IN_SET('" + goodQuery.getType().get(i) + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | }else{ |
| | | wrapper.or().apply("FIND_IN_SET('" + goodQuery.getType().get(i) + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | } |
| | | } |
| | | } |
| | | wrapper.eq("isDelete", 0); |
| | | // sort排序 |
| | | wrapper.orderByAsc("CASE WHEN sort IS NULL THEN 1 ELSE 0 END") |
| | | .orderByAsc("sort") |
| | | .orderByDesc("sort") |
| | | .orderByDesc("createTime"); |
| | | return R.ok(goodsService.page(new PageInfo<>(goodQuery.getPageNumber(), goodQuery.getPageSize()), wrapper)); |
| | | } |
| | |
| | | @ApiOperation(value = "修改", tags = {"后台-商品管理"}) |
| | | public R updateGoods(@RequestBody TGoods dto) { |
| | | TGoods byId = goodsService.getById(dto.getId()); |
| | | if (!Objects.equals(byId.getTotal(), dto.getTotal())){ |
| | | if (byId.getTotal()!=null && dto.getTotal()!=null &&!Objects.equals(byId.getTotal(), dto.getTotal())){ |
| | | // 如果修改了商品总数 那么需要再判断当前商品已被购买了多少 |
| | | List<TOrder> list = orderService.list(new QueryWrapper<TOrder>() |
| | | .eq("goodsId", dto.getId())); |
| | |
| | | temp += tOrder.getCount(); |
| | | } |
| | | if (dto.getTotal()<temp){ |
| | | return R.fail("商品总数不能小于当前商品已兑换数量,"+"当前商品已兑换数量为:"+temp); |
| | | return R.fail("商品总数不能小于当前商品已兑换数量,"+"当前商品已兑换数量为:"+temp); |
| | | } |
| | | } |
| | | goodsService.updateById(dto); |
| | |
| | | */ |
| | | @GetMapping("/exchangeRecord") |
| | | @ApiOperation(value = "学习端-兑换记录", tags = {"学习端-商城"}) |
| | | public R<List<ExchangeRecordVO>> exchangeRecord() { |
| | | public R<PageInfo<ExchangeRecordVO>> exchangeRecord(Integer pageNumber,Integer pageSize) { |
| | | PageInfo<ExchangeRecordVO> res = new PageInfo<>(pageNumber, pageSize); |
| | | LoginUserParent loginUserStudy = tokenService.getLoginUserStudy(); |
| | | if (null == loginUserStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | List<ExchangeRecordVO> exchangeRecord = orderService.exchangeRecord(tokenService.getLoginUserStudy().getUserid()); |
| | | List<ExchangeRecordVO> exchangeRecord = orderService.exchangeRecord(res,tokenService.getLoginUserStudy().getUserid()); |
| | | for (ExchangeRecordVO record : exchangeRecord) { |
| | | TGoods goods = goodsService.getById(record.getGoodsId()); |
| | | List<String> typeList; |
| | |
| | | } |
| | | record.setGoodsType(typeList); |
| | | } |
| | | return R.ok(exchangeRecord); |
| | | res.setRecords(exchangeRecord); |
| | | res.setTotal(exchangeRecord.size()); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | @GetMapping("/exchangeRecordParent") |
| | | @ApiOperation(value = "家长端-兑换记录", tags = {"家长端-兑换记录"}) |
| | | public R<List<ExchangeRecordVO>> exchangeRecordParent() { |
| | | public R<PageInfo<ExchangeRecordVO>> exchangeRecordParent(Integer pageNumber,Integer pageSize) { |
| | | PageInfo<ExchangeRecordVO> res = new PageInfo<>(pageNumber, pageSize); |
| | | if (tokenService.getLoginUser1() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | List<ExchangeRecordVO> exchangeRecord = orderService.exchangeRecord(tokenService.getLoginUser1().getUserid()); |
| | | List<ExchangeRecordVO> exchangeRecord = orderService.exchangeRecord(res,tokenService.getLoginUser1().getUserid()); |
| | | for (ExchangeRecordVO record : exchangeRecord) { |
| | | TGoods goods = goodsService.getById(record.getGoodsId()); |
| | | List<String> typeList; |
| | |
| | | } |
| | | record.setGoodsType(typeList); |
| | | } |
| | | return R.ok(exchangeRecord); |
| | | res.setRecords(exchangeRecord); |
| | | res.setTotal(exchangeRecord.size()); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (!Constants.ONE.equals(order.getState())) { |
| | | throw new GlobalException("订单已发货,无法修改收货地址!"); |
| | | } |
| | | order.setConsigneeName(recipient.getAddress()); |
| | | order.setConsigneeName(recipient.getRecipient()); |
| | | order.setConsigneePhone(recipient.getRecipientPhone()); |
| | | order.setConsigneeAddress(recipient.getAddress()); |
| | | order.setConsigneeAddress(recipient.getProvince()+recipient.getCity()+recipient.getAddress()); |
| | | orderService.updateById(order); |
| | | return R.ok(); |
| | | } |
| | |
| | | if (!Constants.ONE.equals(order.getState())) { |
| | | throw new GlobalException("订单已发货,无法修改收货地址!"); |
| | | } |
| | | order.setConsigneeName(recipient.getAddress()); |
| | | order.setConsigneeName(recipient.getRecipient()); |
| | | order.setConsigneePhone(recipient.getRecipientPhone()); |
| | | order.setConsigneeAddress(recipient.getAddress()); |
| | | order.setConsigneeAddress(recipient.getProvince()+recipient.getCity()+recipient.getAddress()); |
| | | orderService.updateById(order); |
| | | return R.ok(); |
| | | } |