|
@@ -3,6 +3,7 @@ package com.qs.mp.web.controller.api.admin;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.IService;
|
|
|
import com.qs.mp.admin.domain.Coupon;
|
|
|
import com.qs.mp.admin.domain.Goods;
|
|
@@ -10,6 +11,7 @@ import com.qs.mp.admin.domain.GoodsCategory;
|
|
|
import com.qs.mp.admin.domain.GoodsSku;
|
|
|
import com.qs.mp.admin.domain.param.CouponParam;
|
|
|
import com.qs.mp.admin.domain.param.GoodsParam;
|
|
|
+import com.qs.mp.admin.domain.param.GoodsQueryParam;
|
|
|
import com.qs.mp.admin.domain.vo.GoodsListVO;
|
|
|
import com.qs.mp.admin.domain.vo.GoodsVO;
|
|
|
import com.qs.mp.admin.service.IGoodsCategoryService;
|
|
@@ -83,10 +85,21 @@ public class GoodsMgrController extends BaseApiController {
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/list")
|
|
|
- public TableDataInfo list(@RequestBody Goods goods) {
|
|
|
- List<GoodsListVO> list = new ArrayList<GoodsListVO>();
|
|
|
+ public TableDataInfo list(@RequestBody GoodsQueryParam queryParam) {
|
|
|
startPage();
|
|
|
- List<Goods> goodsList = goodsService.list(new LambdaQueryWrapper<Goods>());
|
|
|
+ LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<Goods>();
|
|
|
+ queryWrapper.like(null != queryParam && StringUtils.isNotBlank(queryParam.getTitle()), Goods::getTitle, queryParam.getTitle());
|
|
|
+ queryWrapper.eq(null != queryParam && StringUtils.isNotBlank(queryParam.getGoodsId()), Goods::getGoodsId, queryParam.getGoodsId());
|
|
|
+ // 成本
|
|
|
+ queryWrapper.ge(null != queryParam && null != queryParam.getMinCost(), Goods::getCost, queryParam.getMinCost());
|
|
|
+ queryWrapper.le(null != queryParam && null != queryParam.getMaxCost(), Goods::getCost, queryParam.getMaxCost());
|
|
|
+ // 价格
|
|
|
+ queryWrapper.ge(null != queryParam && null != queryParam.getMinValue(), Goods::getValue, queryParam.getMinValue());
|
|
|
+ queryWrapper.le(null != queryParam && null != queryParam.getMaxValue(), Goods::getValue, queryParam.getMaxValue());
|
|
|
+ // 状态
|
|
|
+ queryWrapper.eq(null != queryParam && null != queryParam.getStatus(), Goods::getStatus, queryParam.getStatus());
|
|
|
+ queryWrapper.eq(Goods::getIsDeleted, 0);
|
|
|
+ List<Goods> goodsList = goodsService.list(queryWrapper);
|
|
|
List<GoodsListVO> goodsListVOList = mapperFacade.mapAsList(goodsList, GoodsListVO.class);
|
|
|
TableDataInfo res = getDataTable(goodsList);
|
|
|
res.setRows(goodsListVOList);
|
|
@@ -132,13 +145,14 @@ public class GoodsMgrController extends BaseApiController {
|
|
|
@ApiOperation(value = "新增商品信息", notes = "后台商品管理新增商品")
|
|
|
@PostMapping("/create")
|
|
|
public AjaxResult channelCreate(@Validated @RequestBody GoodsParam goodsParam) {
|
|
|
- if (goodsParam.getGoodsId() != null && goodsParam.getGoodsId() != 0) {
|
|
|
+ if (StringUtils.isNotBlank(goodsParam.getGoodsId())) {
|
|
|
return AjaxResult.error("该商品已存在");
|
|
|
}
|
|
|
Goods goods = mapperFacade.map(goodsParam, Goods.class);
|
|
|
// 1、校验名称是否重复(商品表)
|
|
|
LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(Goods::getTitle, goods.getTitle());
|
|
|
+ queryWrapper.eq(Goods::getIsDeleted, 0);
|
|
|
int titleCount = goodsService.count(queryWrapper);
|
|
|
if(titleCount > 0) {
|
|
|
return AjaxResult.error("商品名称" + goods.getTitle() + "已存在!");
|
|
@@ -177,8 +191,7 @@ public class GoodsMgrController extends BaseApiController {
|
|
|
@ApiOperation(value = "编辑商品信息", notes = "后台商品管理修改商品信息")
|
|
|
@PostMapping("/update")
|
|
|
public AjaxResult channelUpdate(@Validated @RequestBody GoodsParam goodsParam) {
|
|
|
-
|
|
|
- if (goodsParam.getGoodsId() == null || goodsParam.getGoodsId() == 0) {
|
|
|
+ if (null == goodsParam || StringUtils.isBlank(goodsParam.getGoodsId())) {
|
|
|
return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
}
|
|
|
Goods oldGoods = goodsService.getById(goodsParam.getGoodsId());
|
|
@@ -190,6 +203,7 @@ public class GoodsMgrController extends BaseApiController {
|
|
|
if(!goods.getTitle().equals(oldGoods.getTitle())) {
|
|
|
LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(Goods::getTitle, goods.getTitle());
|
|
|
+ queryWrapper.eq(Goods::getIsDeleted, 0);
|
|
|
int titleCount = goodsService.count(queryWrapper);
|
|
|
if(titleCount > 0) {
|
|
|
return AjaxResult.error("商品名称" + goods.getTitle() + "已存在!");
|
|
@@ -264,23 +278,17 @@ public class GoodsMgrController extends BaseApiController {
|
|
|
return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
}
|
|
|
// 商品未下架, 不允许删除
|
|
|
- if(goods.getStatus().equals("")) {
|
|
|
-
|
|
|
+ if(goods.getStatus().equals("on")) {
|
|
|
+ return AjaxResult.error("商品未下架,不允许删除");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- GoodsVO goodsVo = new GoodsVO();
|
|
|
- BeanUtils.copyProperties(goods, goodsVo);
|
|
|
- // 查询SKU列表
|
|
|
- List<GoodsSku> skuList = new ArrayList<>();
|
|
|
- LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(GoodsSku::getGoodsId, goods.getGoodsId());
|
|
|
- queryWrapper.orderByDesc(GoodsSku::getCreatedTime);
|
|
|
- skuList = goodsSkuService.list(queryWrapper);
|
|
|
- if(null != skuList && skuList.size() > 0) {
|
|
|
- goodsVo.setSkuList(skuList);
|
|
|
+ LambdaUpdateWrapper<Goods> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(Goods::getIsDeleted, 1);
|
|
|
+ updateWrapper.eq(Goods::getGoodsId, goods.getGoodsId());
|
|
|
+ boolean res = goodsService.update(updateWrapper);
|
|
|
+ if(!res) {
|
|
|
+ return AjaxResult.error("商品删除失败");
|
|
|
}
|
|
|
- return AjaxResult.success(goodsVo);
|
|
|
+ return AjaxResult.success("商品删除成功");
|
|
|
}
|
|
|
|
|
|
}
|