mitao
2025-01-17 afa0dbb4f54e7244835dd67ec33c3e545f122f71
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/miniapp/AppGoodsController.java
@@ -4,24 +4,25 @@
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.goods.domain.vo.AppShoppingCartVo;
import com.ruoyi.system.api.domain.dto.AppBaseBathDto;
import com.ruoyi.goods.domain.dto.AppGoodsInfoGetDto;
import com.ruoyi.goods.domain.dto.AppShoppingCartAddDto;
import com.ruoyi.goods.domain.dto.AppShoppingCartChangeDto;
import com.ruoyi.goods.domain.vo.AppGoodsInfoVo;
import com.ruoyi.goods.domain.vo.AppShoppingCartVo;
import com.ruoyi.goods.service.goods.GoodsService;
import com.ruoyi.goods.service.goods.ShoppingCartService;
import com.ruoyi.system.api.constant.AppErrorConstant;
import com.ruoyi.system.api.domain.dto.AppBaseBathDto;
import com.ruoyi.system.api.domain.poji.member.Member;
import com.ruoyi.system.api.service.RemoteMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
@@ -36,13 +37,13 @@
@RequestMapping("/app/goods")
public class AppGoodsController extends BaseController {
    @Autowired
    @Resource
    private GoodsService goodsService;
    @Autowired
    @Resource
    private RemoteMemberService memberService;
    @Autowired
    @Resource
    private ShoppingCartService shoppingCartService;
    @RequestMapping(value = "/getGoodsInfo", method = RequestMethod.POST)
@@ -54,8 +55,11 @@
            if(member!=null&&member.getRelationShopId()!=null){
                appGoodsInfoGetDto.setShopId(member.getRelationShopId());
            }else{
                throw new ServiceException("请先获取附近商户定位");
                appGoodsInfoGetDto.setShopId(appGoodsInfoGetDto.getPositionShopId());
            }
        }
        if(appGoodsInfoGetDto.getShopId()==null){
            throw new ServiceException(AppErrorConstant.NO_POSITION);
        }
        AppGoodsInfoVo appGoodsInfoVo = goodsService.getGoodsInfo(appGoodsInfoGetDto);
        return R.ok(appGoodsInfoVo);
@@ -78,7 +82,7 @@
        if(userId != null){
            Member member = memberService.getMember(userId).getData();
            appShoppingCartAddDto.setUserId(userId);
            if(appShoppingCartAddDto.getShopId()==null&&member!=null&&member.getRelationShopId()!=null){
            if(member!=null&&member.getBindingFlag()==1&&member.getRelationShopId()!=null){
                appShoppingCartAddDto.setShopId(member.getRelationShopId());
            }
        }
@@ -93,7 +97,7 @@
        if(userId!=null){
            Member member = memberService.getMember(userId).getData();
            appShoppingCartChangeDto.setUserId(userId);
            if(member!=null&&member.getRelationShopId()!=null){
            if(member!=null&&member.getBindingFlag()==1&&member.getRelationShopId()!=null){
                appShoppingCartChangeDto.setShopId(member.getRelationShopId());
            }
        }
@@ -110,6 +114,14 @@
        return R.ok();
    }
    @RequestMapping(value = "/countShoppingCart", method = RequestMethod.POST)
    @ApiOperation(value = "获取购物车数量")
    public R<Integer> countShoppingCart() {
        Long userId = SecurityUtils.getUserId();
        Member member = memberService.getMember(userId).getData();
        Long shopId = member.getRelationShopId();
        Integer count = shoppingCartService.countShoppingCart(userId, shopId);
        return R.ok(count);
    }
}