feat(手机端): 购物车模块

完善购物车模块
master
hequan_waynaqua 4 years ago
parent 13d50437e9
commit f577ef4d46

@ -37,6 +37,11 @@ public class R {
return R.error();
}
public static R result(boolean b, String msg) {
if (b) return R.success();
return R.error(msg);
}
public static R error(String msg) {
R r = new R();
r.code = 500;

@ -1,26 +1,14 @@
package com.wayn.mobile.api.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wayn.common.base.BaseController;
import com.wayn.common.core.domain.shop.Goods;
import com.wayn.common.core.domain.shop.GoodsProduct;
import com.wayn.common.core.domain.system.User;
import com.wayn.common.core.service.shop.IGoodsProductService;
import com.wayn.common.core.service.shop.IGoodsService;
import com.wayn.common.util.R;
import com.wayn.mobile.api.domain.Cart;
import com.wayn.mobile.api.service.ICartService;
import com.wayn.mobile.framework.security.util.SecurityUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
/**
* <p>
*
@ -42,11 +30,26 @@ public class CartController extends BaseController {
return iCartService.list(userId);
}
@PostMapping("add")
@PostMapping
public R add(@RequestBody Cart cart) {
return iCartService.addCart(cart);
}
@PutMapping
public R update(@RequestBody Cart cart) {
return R.result(iCartService.updateById(cart));
}
@PostMapping("addNum/{cartId}/{number}")
public R addNum(@PathVariable Long cartId, @PathVariable Integer number) {
return iCartService.addNum(cartId, number);
}
@PostMapping("minusNum/{cartId}/{number}")
public R minusNum(@PathVariable Long cartId, @PathVariable Integer number) {
return iCartService.minusNum(cartId, number);
}
@DeleteMapping("{cartId}")
public R delete(@PathVariable Long cartId) {
return R.result(iCartService.removeById(cartId));

@ -46,4 +46,8 @@ public interface ICartService extends IService<Cart> {
* @return R
*/
R list(Long userId);
R addNum(Long cartId, Integer number);
R minusNum(Long cartId, Integer number);
}

@ -110,4 +110,14 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements IC
.eq("user_id", userId));
return R.success().add("data", cartList);
}
@Override
public R addNum(Long cartId, Integer number) {
return R.result(update().setSql("number = number + 1").eq("id", cartId).update(), "添加失败");
}
@Override
public R minusNum(Long cartId, Integer number) {
return R.result(update().setSql("number = number - 1").eq("id", cartId).last("and number > 1").update(), "最少购买一件");
}
}

Loading…
Cancel
Save