12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package com.fdkankan.ucenter.controller;
- import com.fdkankan.common.util.JwtUtil;
- import com.fdkankan.ucenter.common.BaseController;
- import com.fdkankan.ucenter.common.Result;
- import com.fdkankan.ucenter.service.ICartService;
- import com.fdkankan.ucenter.vo.request.CartParam;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.Arrays;
- import java.util.List;
- /**
- * 购物车
- */
- @RestController
- @RequestMapping("/ucenter/user/cart")
- public class CartController extends BaseController {
- @Autowired
- ICartService cartService;
- /**
- * 添加购物车
- */
- @PostMapping("/add")
- public Result add(@RequestBody CartParam param){
- param.setUserName(JwtUtil.getUsername(getToken()));
- cartService.add(param);
- return Result.success();
- }
- /**
- * 购物车商品减或移除
- */
- @PostMapping(value = "/remove")
- public Result remove(@RequestBody CartParam param){
- param.setUserName(JwtUtil.getUsername(getToken()));
- cartService.delete(param);
- return Result.success();
- }
- /**
- * 查找会员的购物车记录
- *
- */
- @PostMapping(value = "/list")
- public Result list() throws Exception {
- String username = JwtUtil.getUsername(getToken());
- return Result.success(cartService.listByUser(username));
- }
- /**
- * 删除购物车
- *
- */
- @PostMapping(value = "/delete")
- public Result delete(@RequestBody CartParam param) throws Exception {
- if (StringUtils.isEmpty(param.getIds())){
- return Result.failure("ids为空");
- }
- String[] split = param.getIds().split(",");
- List<String> ids = Arrays.asList(split);
- cartService.deleteIds(ids);
- return Result.success();
- }
- }
|