jiangqs
2023-04-30 dca0031ad5552679d6dfbb80d6edd7adbfc7ec2c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.ruoyi.order.controller.miniapp;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.order.domain.dto.AppBaseBathDto;
import com.ruoyi.order.domain.dto.AppGoodsInfoGetDto;
import com.ruoyi.order.domain.dto.AppShoppingCartAddDto;
import com.ruoyi.order.domain.dto.AppShoppingCartChangeDto;
import com.ruoyi.order.domain.vo.AppGoodsInfoVo;
import com.ruoyi.order.service.goods.GoodsService;
import com.ruoyi.order.service.goods.ShopGoodsService;
import com.ruoyi.order.service.order.ShoppingCartService;
import com.ruoyi.system.api.RemoteMemberService;
import com.ruoyi.system.api.domain.poji.member.Member;
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;
 
/**
 * @author jqs34
 * @ClassName AppGoodsController
 * @description: TODO
 * @date 2023年04月20日
 * @version: 1.0
 */
@Api(value = "小程序商品相关接口", tags = "小程序商品相关接口", description = "小程序商品相关接口")
@RestController
@RequestMapping("/app/home")
public class AppGoodsController {
 
    @Autowired
    private GoodsService goodsService;
 
    @Autowired
    private RemoteMemberService memberService;
 
    @Autowired
    private ShoppingCartService shoppingCartService;
 
    @RequestMapping(value = "/getGoodsInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取商品详情")
    public R<AppGoodsInfoVo> getGoodsInfo(@RequestBody AppGoodsInfoGetDto appGoodsInfoGetDto) {
        Long userId = SecurityUtils.getUserId();
        if(userId!=null){
            Member member = memberService.getMember(userId).getData();
            if(member!=null&&member.getRealtionShopId()!=null){
                appGoodsInfoGetDto.setShopId(member.getRealtionShopId());
            }
        }
        AppGoodsInfoVo appGoodsInfoVo = goodsService.getGoodsInfo(appGoodsInfoGetDto);
        return R.ok(appGoodsInfoVo);
    }
 
    @RequestMapping(value = "/addShoppingCart", method = RequestMethod.POST)
    @ApiOperation(value = "添加购物车")
    public R addShoppingCart(@RequestBody AppShoppingCartAddDto appShoppingCartAddDto) {
        Long userId = SecurityUtils.getUserId();
        if(userId!=null){
            Member member = memberService.getMember(userId).getData();
            appShoppingCartAddDto.setUserId(userId);
            if(member!=null&&member.getRealtionShopId()!=null){
                appShoppingCartAddDto.setShopId(member.getRealtionShopId());
            }
        }
        shoppingCartService.addShoppingCart(appShoppingCartAddDto);
        return R.ok();
    }
 
    @RequestMapping(value = "/changeShoppingCart", method = RequestMethod.POST)
    @ApiOperation(value = "修改购物车")
    public R changeShoppingCart(@RequestBody AppShoppingCartChangeDto appShoppingCartChangeDto) {
        Long userId = SecurityUtils.getUserId();
        if(userId!=null){
            Member member = memberService.getMember(userId).getData();
            appShoppingCartChangeDto.setUserId(userId);
            if(member!=null&&member.getRealtionShopId()!=null){
                appShoppingCartChangeDto.setShopId(member.getRealtionShopId());
            }
        }
        shoppingCartService.changeShoppingCart(appShoppingCartChangeDto);
        return R.ok();
    }
 
    @RequestMapping(value = "/deleteShoppingCart", method = RequestMethod.POST)
    @ApiOperation(value = "删除购物车")
    public R changeShoppingCart(@RequestBody AppBaseBathDto appBaseBathDto) {
        Long userId = SecurityUtils.getUserId();
        if(userId!=null){
            Member member = memberService.getMember(userId).getData();
            appBaseBathDto.setUserId(userId);
        }
        shoppingCartService.deleteShoppingCart(appBaseBathDto);
        return R.ok();
    }
}