zjh
2025-06-05 2c19fa65dc87ea8f3d81f84154f4eeabff7f8d00
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.ltkj.web.controller.mall;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.core.domain.model.LoginUser;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.framework.config.JwtUtils;
import com.ltkj.framework.config.UserHoder;
import com.ltkj.hosp.domain.TjPackage;
import com.ltkj.hosp.domain.TjPackageProject;
import com.ltkj.hosp.domain.Wxuser;
import com.ltkj.hosp.service.ITjPackageProjectService;
import com.ltkj.hosp.service.ITjPackageService;
import com.ltkj.mall.domain.MallCart;
import com.ltkj.mall.service.IMallCartService;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.ast.Var;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
 
/**
 * @Company: 西安路泰科技有限公司
 * @Author: zjh
 * @Date: 2023/7/13 08:39
 */
 
 
@RestController
@RequestMapping("/cus/mall/cart")
@Api(tags = "体检小程序购物车")
public class WxMallCartController {
 
    @Resource
    private IMallCartService cartService;
    @Resource
    private ITjPackageService packageService;
    @Resource
    private ITjPackageProjectService ppservice;
 
    @GetMapping("/getMyCart")
    @ApiOperation(value = "查询当前用户的购物车信息")
    public AjaxResult getMyCart() {
        Wxuser wxuser = UserHoder.getWxuser();
        if (null != wxuser) {
            LambdaQueryWrapper<MallCart> wq = new LambdaQueryWrapper<>();
            wq.eq(MallCart::getUserId, wxuser.getId());
            List<MallCart> list = cartService.list(wq);
            return AjaxResult.success(list);
        }
        return AjaxResult.error("获取信息失败!!!");
    }
 
    @PostMapping("/addMyCart")
    @ApiOperation(value = "添加当前用户的购物车信息")
    public AjaxResult addMyCart(@RequestBody MallCart cart) {
        Wxuser wxuser = UserHoder.getWxuser();
        if (null != wxuser) {
            LambdaQueryWrapper<MallCart> wqq = new LambdaQueryWrapper<>();
            wqq.eq(MallCart::getUserId, wxuser.getId());
            wqq.eq(MallCart::getGoodsId, cart.getGoodsId());
            MallCart one = cartService.getOne(wqq);
            if (null != one) {
                return AjaxResult.success("该套餐已存在 请勿重复添加");
            }
            TjPackage tjPackage = packageService.getTjPackageByPacId(String.valueOf(cart.getGoodsId()));
            if (null != tjPackage.getPrice()) {
                cart.setPrice(tjPackage.getPrice());
            } else {
                cart.setPrice(new BigDecimal("0").setScale(2));
            }
            cart.setUserId(wxuser.getId());
            cart.setPicUrl(tjPackage.getPacPhone());
            cart.setGoodsName(tjPackage.getPacName());
            cartService.save(cart);
            return AjaxResult.success("添加成功!");
        }
        return AjaxResult.error("获取信息失败!!!");
    }
 
    @DeleteMapping("/removeMyCart")
    @ApiOperation(value = "删除当前用户的购物车信息")
    public AjaxResult removeMyCart(@RequestBody List<Long> ids) {
        if (null != ids && ids.size() > 0) {
            cartService.removeByIds(ids);
            return AjaxResult.success("操作成功");
        }
        return AjaxResult.error("获取信息失败!!!");
    }
}