diff --git a/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/config/GulimallSessionConfig.java b/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/config/GulimallSessionConfig.java index f8f6e7eca56d791752b79c125d41a3c7c4a041f3..7e8e7f8cefb47ece390e800445328d6678654c39 100644 --- a/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/config/GulimallSessionConfig.java +++ b/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/config/GulimallSessionConfig.java @@ -12,11 +12,12 @@ public class GulimallSessionConfig { @Bean public CookieSerializer cookieSerializer(){ DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer(); - + // cookieSerializer.setDomainName("localhost"); cookieSerializer.setCookieName("GULISESSION"); return cookieSerializer; } + @Bean public RedisSerializer springSessionDefaultCookieSerializer(){ return new GenericJackson2JsonRedisSerializer(); } diff --git a/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/controller/LoginController.java b/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/controller/LoginController.java index b167b82e91d91e64a476884bbd55388802917c78..81843220aea2c0f077111c1df777f732337b36e8 100644 --- a/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/controller/LoginController.java +++ b/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/controller/LoginController.java @@ -5,14 +5,15 @@ import com.forth.common.constant.AuthServerConstant; import com.forth.common.utils.R; import com.forth.gulimall.gulimallauthserver.feign.MemberFeignService; import com.forth.gulimall.gulimallauthserver.feign.ThirdPartFeignService; -import com.forth.gulimall.gulimallauthserver.vo.MemberRespVo; +import com.forth.common.vo.MemberRespVo; + import com.forth.gulimall.gulimallauthserver.vo.UserLoginVo; import com.forth.gulimall.gulimallauthserver.vo.UserRegistVo; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; + import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; @@ -145,10 +146,10 @@ public String login(UserLoginVo vo, RedirectAttributes redirectAttributes, Http if(login.get("code").equals(0)){ MemberRespVo data = login.getData("data", new TypeReference() { }); - session.setAttribute("loginUser",data); - System.out.println("----"+session.getAttribute("loginUser")); + session.setAttribute(AuthServerConstant.LOGIN_USER,data); + System.out.println("----"+session.getAttribute(AuthServerConstant.LOGIN_USER)); - return "redirect:http://localhost:20000/reg.html"; + return "redirect:http://localhost:30000"; }else{ Map errors =new HashMap<>(); errors.put("msg","账号密码错误"); diff --git a/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/controller/OAuth2Controller.java b/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/controller/OAuth2Controller.java index cc83e0f5a6299626944c0644e8b41a2c0682320c..bf716f7715ddfa9e9666e1b288796e5a2a530bb3 100644 --- a/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/controller/OAuth2Controller.java +++ b/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/controller/OAuth2Controller.java @@ -2,6 +2,7 @@ package com.forth.gulimall.gulimallauthserver.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; +import com.forth.common.constant.AuthServerConstant; import com.forth.common.utils.R; import com.forth.gulimall.gulimallauthserver.feign.MemberFeignService; import com.forth.gulimall.gulimallauthserver.vo.MemberRespVo; @@ -14,7 +15,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; -import utils.HttpUtils; +import com.forth.gulimall.gulimallauthserver.utils.HttpUtils; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -63,14 +64,14 @@ public class OAuth2Controller { MemberRespVo data = oauthlogin.getData("data", new TypeReference() { }); System.out.println("登录成功:用户信息"+data); - session.setAttribute("loginUser",data); - System.out.println(session.getAttribute("loginUser")); + session.setAttribute(AuthServerConstant.LOGIN_USER,data); + System.out.println(session.getAttribute(AuthServerConstant.LOGIN_USER)); //TODO 1,默认发的令牌 key seeion 值 是唯一字符串 作用域 解决不了子域的session //TODO 2,使用json 的序列画 来存储到redis // servletResponse.addCookie("JSESSIONID","dadaa"); // log.info("登录成功:用户信息",data.toString()); //2,成功挑转首页 - return "redirect:http://localhost:20000/reg.html"; + return "redirect:http://localhost:30000/"; } else { } diff --git a/gulimall-auth-server/src/main/java/utils/HttpUtils.java b/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/utils/HttpUtils.java similarity index 99% rename from gulimall-auth-server/src/main/java/utils/HttpUtils.java rename to gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/utils/HttpUtils.java index 07ffa58376d065ef43c764d0198dbef4995e080b..143aaba2ae2bbc42f609795dc51cecf7ae1bffac 100644 --- a/gulimall-auth-server/src/main/java/utils/HttpUtils.java +++ b/gulimall-auth-server/src/main/java/com/forth/gulimall/gulimallauthserver/utils/HttpUtils.java @@ -1,4 +1,4 @@ -package utils; +package com.forth.gulimall.gulimallauthserver.utils; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; diff --git a/gulimall-auth-server/src/test/java/com/forth/gulimall/gulimallauthserver/GulimallAuthServerApplicationTests.java b/gulimall-auth-server/src/test/java/com/forth/gulimall/gulimallauthserver/GulimallAuthServerApplicationTests.java index 17240ad8272fc319449e2efa079eb39d57aefa76..1f886151664c413645102399d657c561e7dd3335 100644 --- a/gulimall-auth-server/src/test/java/com/forth/gulimall/gulimallauthserver/GulimallAuthServerApplicationTests.java +++ b/gulimall-auth-server/src/test/java/com/forth/gulimall/gulimallauthserver/GulimallAuthServerApplicationTests.java @@ -7,7 +7,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.StringRedisTemplate; -import utils.HttpUtils; +import com.forth.gulimall.gulimallauthserver.utils.HttpUtils; + import java.util.HashMap; import java.util.Map; diff --git a/gulimall-cart/pom.xml b/gulimall-cart/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..d8ae1c63d343abf4a53129a40c4f4f68bbc336c9 --- /dev/null +++ b/gulimall-cart/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.5.RELEASE + + + + com.forth.gulimall + gulimall-cart + 0.0.1-SNAPSHOT + gulimall-cart + 购物车 + + + 1.8 + Hoxton.SR8 + + + + + com.forth.gulimall + gulimall-common + 0.0.1-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + org.springframework.session + spring-session-data-redis + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/GulimallCartApplication.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/GulimallCartApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..3a8891d11d2d64f0440fc0f6a750f963501aac2c --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/GulimallCartApplication.java @@ -0,0 +1,20 @@ +package com.forth.gulimall.gulimall.cart; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; + +@EnableRedisHttpSession +@EnableDiscoveryClient +@EnableFeignClients +@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) +public class GulimallCartApplication { + + public static void main(String[] args) { + SpringApplication.run(GulimallCartApplication.class, args); + } + +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/config/GulimallSessionConfig.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/config/GulimallSessionConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..7a5f2fdea174ec5472c2e0751e6117fb47b89378 --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/config/GulimallSessionConfig.java @@ -0,0 +1,25 @@ +package com.forth.gulimall.gulimall.cart.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; +import org.springframework.session.web.http.CookieSerializer; +import org.springframework.session.web.http.DefaultCookieSerializer; +@EnableRedisHttpSession +@Configuration +public class GulimallSessionConfig { + @Bean + public CookieSerializer cookieSerializer(){ + DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer(); + + cookieSerializer.setDomainName("localhost"); + cookieSerializer.setCookieName("GULISESSION"); + return cookieSerializer; + } + @Bean + public RedisSerializer springSessionDefaultCookieSerializer(){ + return new GenericJackson2JsonRedisSerializer(); + } +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/config/GulimallWebConfig.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/config/GulimallWebConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..40c04b7ef1a1341cb41287e3ecbdebd9b0d1a266 --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/config/GulimallWebConfig.java @@ -0,0 +1,14 @@ +package com.forth.gulimall.gulimall.cart.config; + +import com.forth.gulimall.gulimall.cart.interceptor.CartInterceptor; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +@Configuration +public class GulimallWebConfig implements WebMvcConfigurer { + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new CartInterceptor()).addPathPatterns("/**"); + } +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/controller/CartController.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/controller/CartController.java new file mode 100644 index 0000000000000000000000000000000000000000..321010a95a9de3ca033a8e515ca2f02e34857055 --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/controller/CartController.java @@ -0,0 +1,21 @@ +package com.forth.gulimall.gulimall.cart.controller; + + +import com.forth.gulimall.gulimall.cart.interceptor.CartInterceptor; +import com.forth.gulimall.gulimall.cart.vo.UserInfoVo; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + + + +@Controller +public class CartController { +@GetMapping("/cart.html") +public String cartListPage(){ + + UserInfoVo userInfoVo = CartInterceptor.threadLocal.get(); + System.out.println("--------------"+userInfoVo); + + return "cartList"; +} +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/interceptor/CartInterceptor.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/interceptor/CartInterceptor.java new file mode 100644 index 0000000000000000000000000000000000000000..c1127958d7ec8ddcd7c64e32a1c5536189096d29 --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/interceptor/CartInterceptor.java @@ -0,0 +1,65 @@ +package com.forth.gulimall.gulimall.cart.interceptor; + +import com.forth.common.constant.AuthServerConstant; +import com.forth.common.constant.CartConstant; +import com.forth.common.vo.MemberRespVo; +import com.forth.gulimall.gulimall.cart.vo.UserInfoVo; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * 在执行目标方法判断用户的登录状态 封装传递给controller 目标请求 + */ + +public class CartInterceptor implements HandlerInterceptor { + public static ThreadLocal threadLocal=new ThreadLocal<>(); + + /** + * 目标方法执行之前 + * + * @param request + * @param response + * @param handler + * @return + * @throws Exception + */ + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + + + + UserInfoVo userInfoVo = new UserInfoVo(); + HttpSession session = request.getSession(); + MemberRespVo attribute = (MemberRespVo) session.getAttribute(AuthServerConstant.LOGIN_USER); + + if (attribute != null) { + userInfoVo.setUserId(attribute.getId()); + } else { + + } + + Cookie[] cookies = request.getCookies(); + if(cookies!=null &&cookies.length>0){ + for (Cookie cookie : cookies) { + //user-key + String name = cookie.getName(); + if (name.equals("GULISESSION")) { + System.out.println("-----------"); + } + if (name.equals(CartConstant.TEMP_USER_COOKIE_NAME)){ + userInfoVo.setUserKey(cookie.getValue()); + } + } + } + + + //目标方法执行之前 + threadLocal.set(userInfoVo); + return true; + } +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/service/CartService.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/service/CartService.java new file mode 100644 index 0000000000000000000000000000000000000000..ce53896282a3b183a9829203e555a1bdd273eb11 --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/service/CartService.java @@ -0,0 +1,5 @@ +package com.forth.gulimall.gulimall.cart.service; + +public interface CartService { + +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/service/impl/CartServiceImpl.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/service/impl/CartServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..615e6a8d1da19c785740350856d11fc728979403 --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/service/impl/CartServiceImpl.java @@ -0,0 +1,14 @@ +package com.forth.gulimall.gulimall.cart.service.impl; + +import com.forth.gulimall.gulimall.cart.service.CartService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; +@Slf4j +@Service +public class CartServiceImpl implements CartService { + + @Autowired + StringRedisTemplate redisTemplate; +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/Cart.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/Cart.java new file mode 100644 index 0000000000000000000000000000000000000000..dad68e4adc87c4daf5f3942eed5d3559b1c42b9a --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/Cart.java @@ -0,0 +1,73 @@ +package com.forth.gulimall.gulimall.cart.vo; + +import java.math.BigDecimal; +import java.util.List; + +public class Cart { + + List items; + private Integer countNum; + private Integer countType; + private BigDecimal totalAmount; + private BigDecimal reduce =new BigDecimal("0.00"); + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public Integer getCountNum() { + int count =0; + if(items!=null && items.size()>0){ + for (CartItem item :items){ + count += item.getCount(); + } + } + return count; + } + + + + public Integer getCountType() { + int count =0; + if(items!=null && items.size()>0){ + for (CartItem item :items){ + count += 1; + + } + } + return count; + + } + + + + public BigDecimal getTotalAmount() { + BigDecimal amount = new BigDecimal("0"); + //计算购物项的总价 + if(items!=null && items.size()>0){ + for (CartItem item :items){ + BigDecimal totalPrice = item.getTotalPrice(); + amount = amount.add(totalPrice); + } + } + //减去优惠的总价 + BigDecimal subtract = amount.subtract(getReduce()); + return subtract; + } + + public void setTotalAmount(BigDecimal totalAmount) { + this.totalAmount = totalAmount; + } + + public BigDecimal getReduce() { + return reduce; + } + + public void setReduce(BigDecimal reduce) { + this.reduce = reduce; + } +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/CartItem.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/CartItem.java new file mode 100644 index 0000000000000000000000000000000000000000..400349c7c59784e30f3172984b9ff2c5133e37b4 --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/CartItem.java @@ -0,0 +1,91 @@ +package com.forth.gulimall.gulimall.cart.vo; + + + +import java.math.BigDecimal; +import java.util.List; + +/** + * 购物车内容 + */ + +public class CartItem { + + private long skuId; + private boolean check =true; + private String title; + private String image; + private List skuAttr; + private BigDecimal price; + private Integer count; + private BigDecimal totalPrice; + + /** + * 计算当前项的总价 + * @return + */ + public BigDecimal getTotalPrice() { + + return this.price.multiply(new BigDecimal(""+this.count)); + } + + public long getSkuId() { + return skuId; + } + + public void setSkuId(long skuId) { + this.skuId = skuId; + } + + public boolean isCheck() { + return check; + } + + public void setCheck(boolean check) { + this.check = check; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public List getSkuAttr() { + return skuAttr; + } + + public void setSkuAttr(List skuAttr) { + this.skuAttr = skuAttr; + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + + public void setTotalPrice(BigDecimal totalPrice) { + this.totalPrice = totalPrice; + } +} diff --git a/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/UserInfoVo.java b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/UserInfoVo.java new file mode 100644 index 0000000000000000000000000000000000000000..19cf7bba7f56501e834d34b7c49f0500460b57be --- /dev/null +++ b/gulimall-cart/src/main/java/com/forth/gulimall/gulimall/cart/vo/UserInfoVo.java @@ -0,0 +1,12 @@ +package com.forth.gulimall.gulimall.cart.vo; + +import lombok.Data; +import lombok.ToString; + + +@Data +public class UserInfoVo { + + private Long userId; + private String userKey; +} diff --git a/gulimall-cart/src/main/resources/application.properties b/gulimall-cart/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..370b56737d3962ebed807a03e47b16d3c86275b7 --- /dev/null +++ b/gulimall-cart/src/main/resources/application.properties @@ -0,0 +1,17 @@ +server.port=30000 + +spring.application.name=gulimall-cart +spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 + + +spring.thymeleaf.cache=false +spring.mvc.view.prefix=/pages/ +spring.mvc.view.suffix=.html + +spring.session.store-type=redis + +spring.redis.host=39.97.249.66 +spring.redis.port=6379 + + + diff --git a/gulimall-cart/src/main/resources/templates/cartList.html b/gulimall-cart/src/main/resources/templates/cartList.html new file mode 100644 index 0000000000000000000000000000000000000000..d8e799ef27d31e2fb864727422abca92538ea527 --- /dev/null +++ b/gulimall-cart/src/main/resources/templates/cartList.html @@ -0,0 +1,802 @@ + + + + + 购物车 + + + + + + + + +
+ + + + +
+ + + + + +
+
+
+
+ 全部商品 + +
+ +
+
+
    +
  • 全选
  • +
  • 商品
  • +
  • 单价
  • +
  • 数量
  • +
  • 小计
  • +
  • 操作
  • +
+
+ +
+
    +
  • +
    + +
    +
      +
    1. +
    2. +
      +
      +

      + TCL 55A950C 55英寸32核 +

      +
      +
    3. +
    4. +

      4599.00

      +
    5. +
    6. +

      + - + 5 + + +

      +
    7. +
    8. +

      ¥22995.00

      +
    9. +
    10. +

      删除

      +
    11. +
    +
    +
  • + + +
+
+
+
+
    +
  • 全选
  • +
  • 删除选中的商品
  • +
  • 移到我的关注
  • +
  • 清除下柜商品
  • +
+
+
+   + +
    +
  • +
  • +
+
+
+
    +
  1. 总价:¥0.00
  2. + +
+
+
+
+
+
+ +
+

+ 删除 +

+
+
+
+
+
  • 删除商品?
  • +
  • 您可以选择移到关注,或删除商品。
  • +
    +
    +
    +
    + + +
    +
    +
    +

    + 删除 +

    +
    +
    +
    请至少选中一件商品!
    +
    +
    +
    +

    + 删除 +

    +
    +
    +
    +
    +
  • 移到关注
  • +
  • 移动后选中商品将不再购物车中显示
  • +
    +
    +
    +
    + + +
    +
    +
    +

    + 提示 +

    +
    +
    +
    没有下柜商品!
    +
    +
    + + + + + + + diff --git a/gulimall-cart/src/main/resources/templates/index.html b/gulimall-cart/src/main/resources/templates/index.html new file mode 100644 index 0000000000000000000000000000000000000000..0bf48c91fd83cd5137791902c048e01c7dd1c782 --- /dev/null +++ b/gulimall-cart/src/main/resources/templates/index.html @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + +
    + +
    +
    +
    +
    +
    +
    +

    商品已成功加入购物车

    + +
    + +
    +
    +
    +
    + +
    + + + + diff --git a/gulimall-cart/src/test/java/com/forth/gulimall/gulimall/cart/GulimallCartApplicationTests.java b/gulimall-cart/src/test/java/com/forth/gulimall/gulimall/cart/GulimallCartApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..f86fc42a0ce1ee845b6093e71bfb4da8cc34156b --- /dev/null +++ b/gulimall-cart/src/test/java/com/forth/gulimall/gulimall/cart/GulimallCartApplicationTests.java @@ -0,0 +1,13 @@ +package com.forth.gulimall.gulimall.cart; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class GulimallCartApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/gulimall-common/src/main/java/com/forth/common/constant/AuthServerConstant.java b/gulimall-common/src/main/java/com/forth/common/constant/AuthServerConstant.java index 62b4e5ceb8b2fc0dc90d1c0dec915b35237b9369..b55f5c8c2ce41d6d73e0cb8b366744de4da290c8 100644 --- a/gulimall-common/src/main/java/com/forth/common/constant/AuthServerConstant.java +++ b/gulimall-common/src/main/java/com/forth/common/constant/AuthServerConstant.java @@ -3,6 +3,6 @@ package com.forth.common.constant; public class AuthServerConstant { public static final String SMS_CODE_CACHE_PREFIX ="sms:code:"; - public static final String LOGIN_USER ="loginUser:"; + public static final String LOGIN_USER ="loginUser"; } diff --git a/gulimall-common/src/main/java/com/forth/common/constant/CartConstant.java b/gulimall-common/src/main/java/com/forth/common/constant/CartConstant.java new file mode 100644 index 0000000000000000000000000000000000000000..61cc389af9d0fba5e2aa9c5b338342054cbfef9c --- /dev/null +++ b/gulimall-common/src/main/java/com/forth/common/constant/CartConstant.java @@ -0,0 +1,6 @@ +package com.forth.common.constant; + +public class CartConstant { + + public static final String TEMP_USER_COOKIE_NAME="user-key"; +} diff --git a/gulimall-common/src/main/java/com/forth/common/vo/MemberRespVo.java b/gulimall-common/src/main/java/com/forth/common/vo/MemberRespVo.java new file mode 100644 index 0000000000000000000000000000000000000000..0134f3efe60810bb9f02a3ad64903632249aac3b --- /dev/null +++ b/gulimall-common/src/main/java/com/forth/common/vo/MemberRespVo.java @@ -0,0 +1,89 @@ +package com.forth.common.vo; + +import lombok.Data; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; +@ToString +@Data +public class MemberRespVo implements Serializable { + /** + * id + */ + + private Long id; + /** + * 会员等级id + */ + private Long levelId; + /** + * 用户名 + */ + private String username; + /** + * 密码 + */ + private String password; + /** + * 昵称 + */ + private String nickname; + /** + * 手机号码 + */ + private String mobile; + /** + * 邮箱 + */ + private String email; + /** + * 头像 + */ + private String header; + /** + * 性别 + */ + private Integer gender; + /** + * 生日 + */ + private Date birth; + /** + * 所在城市 + */ + private String city; + /** + * 职业 + */ + private String job; + /** + * 个性签名 + */ + private String sign; + /** + * 用户来源 + */ + private Integer sourceType; + /** + * 积分 + */ + private Integer integration; + /** + * 成长值 + */ + private Integer growth; + /** + * 启用状态 + */ + private Integer status; + /** + * 注册时间 + */ + private Date createTime; + + private String socialUid; + private String accessToken; + private Long expiresIn; + +} diff --git a/gulimall-gateway/src/main/resources/application.yml b/gulimall-gateway/src/main/resources/application.yml index c47a93ee9a13dbb81954c462a0ba1ef41ee1001d..181c026c532151e6af229ac7d98c5b0921953b16 100644 --- a/gulimall-gateway/src/main/resources/application.yml +++ b/gulimall-gateway/src/main/resources/application.yml @@ -25,6 +25,10 @@ spring: uri: lb://gulimall-auth-server predicates: - Host=auth.gulimall.com + - id: gulimall_auth_route + uri: lb://gulimall-cart + predicates: + - Host=cart.gulimall.com - id: product_route uri: lb://gulimall-product predicates: diff --git a/gulimall-member/src/main/java/com/forth/gulimall/member/service/impl/MemberServiceImpl.java b/gulimall-member/src/main/java/com/forth/gulimall/member/service/impl/MemberServiceImpl.java index 111096682759c59246a66db5425c0a745f5a8968..832ee45e6d3dbc6b0530de703d150b5a9aa9b113 100644 --- a/gulimall-member/src/main/java/com/forth/gulimall/member/service/impl/MemberServiceImpl.java +++ b/gulimall-member/src/main/java/com/forth/gulimall/member/service/impl/MemberServiceImpl.java @@ -99,7 +99,7 @@ public class MemberServiceImpl extends ServiceImpl impl //1,去数据库查询 MemberEntity entity = baseMapper.selectOne(new QueryWrapper().eq("username", loginacct).or() .eq("mobile", loginacct)); - System.out.println("1,--------" + entity.toString()); + // System.out.println("1,--------" + entity.toString()); if (entity == null) { //失败 return null; diff --git a/gulimall-third-party/pom.xml b/gulimall-third-party/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..3f37fc355ab75b4acc1528929078b3a1a0f63b8e --- /dev/null +++ b/gulimall-third-party/pom.xml @@ -0,0 +1,105 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.5.RELEASE + + + com.forth.gulimall + gulimall-third-party + 0.0.1-SNAPSHOT + gulimall-third-party + 第三服务 + + + 1.8 + Hoxton.SR8 + + + + + com.forth.gulimall + gulimall-common + 0.0.1-SNAPSHOT + + + com.baomidou + mybatis-plus-boot-starter + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + com.alibaba.cloud + spring-cloud-starter-alicloud-oss + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.1.0.RELEASE + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + diff --git a/gulimall-third-party/src/main/java/com/forth/gulimall/thirdparty/GulimallThirdPartyApplication.java b/gulimall-third-party/src/main/java/com/forth/gulimall/thirdparty/GulimallThirdPartyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..b57b6ea59598ed66630843fa29d8a58c9d02a4ff --- /dev/null +++ b/gulimall-third-party/src/main/java/com/forth/gulimall/thirdparty/GulimallThirdPartyApplication.java @@ -0,0 +1,15 @@ +package com.forth.gulimall.thirdparty; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@EnableDiscoveryClient +@SpringBootApplication +public class GulimallThirdPartyApplication { + + public static void main(String[] args) { + SpringApplication.run(GulimallThirdPartyApplication.class, args); + } + +} diff --git a/gulimall-third-party/src/main/resources/application.properties b/gulimall-third-party/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/gulimall-third-party/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/gulimall-third-party/src/main/resources/application.yml b/gulimall-third-party/src/main/resources/application.yml index 3f7f3da529296a439d505b08a5c7a021844f086c..5edc5eb2af8bbf9566f60afd6d4b423297b7aecf 100644 --- a/gulimall-third-party/src/main/resources/application.yml +++ b/gulimall-third-party/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 30000 + port: 25000 spring: cloud: diff --git a/gulimall-third-party/src/test/java/com/forth/gulimall/thirdparty/GulimallThirdPartyApplicationTests.java b/gulimall-third-party/src/test/java/com/forth/gulimall/thirdparty/GulimallThirdPartyApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..dddebb104dc7ca3f28a2aa0351cf1718a468dbea --- /dev/null +++ b/gulimall-third-party/src/test/java/com/forth/gulimall/thirdparty/GulimallThirdPartyApplicationTests.java @@ -0,0 +1,66 @@ +package com.forth.gulimall.thirdparty; + +import com.forth.gulimall.thirdparty.component.SmsComponent; +import com.forth.gulimall.thirdparty.utils.HttpUtils; +import org.apache.http.HttpResponse; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@SpringBootTest +class GulimallThirdPartyApplicationTests { + + @Test + void contextLoads() { + String code = UUID.randomUUID().toString().substring(0, 5); + System.out.println(code); + } + + @Autowired + SmsComponent smsComponent; + + @Test + public void testSendCode() { + smsComponent.SendSmsCode("17634362804", "789456"); + } + + @Test + public void sendSms() { + String host = "https://aliapi.market.alicloudapi.com"; + String path = "/smsApi/verifyCode/send"; + String method = "POST"; + String appcode = "0995740d4ffe4f64bd63dcea04160b07"; + Map headers = new HashMap(); + //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105 + headers.put("Authorization", "APPCODE " + appcode); + Map querys = new HashMap(); + querys.put("phone", "17634362804"); + querys.put("templateId", "540"); + querys.put("variables", "1234"); + Map bodys = new HashMap(); + + + try { + /** + * 重要提示如下: + * HttpUtils请从 + * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java + * 下载 + * + * 相应的依赖请参照 + * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml + */ + HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); + System.out.println(response.toString()); + //获取response的body + //System.out.println(EntityUtils.toString(response.getEntity())); + } catch (Exception e) { + e.printStackTrace(); + } + } +} + diff --git a/pom.xml b/pom.xml index a390882118dcb5dba9dae5184a88f8ecbea3ec14..560fd6d9e106979b317837b30f4c34e6bcccab71 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,7 @@ gulimall-gateway gulimall-auth-server gulimall-third-party + gulimall-cart