Bläddra i källkod

头部购物车迁移

chao 4 år sedan
förälder
incheckning
303084c1a1

+ 0 - 26
src/main/java/com/caimei/www/controller/authorized/ShoppingController.java

@@ -1,17 +1,9 @@
 package com.caimei.www.controller.authorized;
 
 import com.caimei.www.controller.BaseController;
-import com.caimei.www.pojo.JsonModel;
-import com.caimei.www.pojo.order.CartItem;
-import com.caimei.www.service.page.ShoppingService;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
 
-import java.util.List;
-import java.util.Map;
 
 /**
  * 购物车
@@ -24,13 +16,6 @@ public class ShoppingController extends BaseController {
 
 	private static final String SHOPPING_CART_PATH = "shopping/cart";
 	private static final String SHOPPING_CONFIRM_PATH = "shopping/confirm";
-
-    private ShoppingService shoppingService;
-    @Autowired
-    public void setShoppingService(ShoppingService shoppingService) {
-        this.shoppingService = shoppingService;
-    }
-
     /**
      * 购物车列表页
      */
@@ -47,15 +32,4 @@ public class ShoppingController extends BaseController {
         return SHOPPING_CONFIRM_PATH;
     }
 
-    /**
-     * 顶部购物车数据
-     * @return
-     */
-    @GetMapping("/header/cart")
-    @ResponseBody
-    public JsonModel<List<CartItem>> getHeadCarts(Integer userId) {
-        return shoppingService.getHeaderCart(userId);
-    }
-
-
 }

+ 14 - 6
src/main/java/com/caimei/www/mapper/ShoppingDao.java

@@ -17,23 +17,31 @@ import java.util.List;
  */
 @Mapper
 public interface ShoppingDao {
-    /**
+/*
+    */
+/**
      * 顶部购物车数据
-     */
+     *//*
+
     List<CartItem> getHeadCarts(Integer userId);
 
-    /**
+    */
+/**
      * 购物车列表-供应商
      * @param userId
      * @return
-     */
+     *//*
+
     List<CartSupplier> getCartSuppliers(Integer userId);
 
-    /**
+    */
+/**
      * 根据供应商ID查询购物车列表
      * @param supplierId
      * @return
-     */
+     *//*
+
     List<CartItem> getShoppingCartBySupplierId(@Param("supplierId") Integer supplierId, @Param("userId") Integer userId);
+*/
 
 }

+ 0 - 29
src/main/java/com/caimei/www/service/page/ShoppingService.java

@@ -1,29 +0,0 @@
-package com.caimei.www.service.page;
-
-import com.caimei.www.pojo.JsonModel;
-import com.caimei.www.pojo.order.CartItem;
-import com.caimei.www.pojo.order.CartSupplier;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Description
- *
- * @author : Charles
- * @date : 2020/7/23
- */
-public interface ShoppingService {
-    /**
-     * 顶部购物车数据
-     * @param userId
-     * @return
-     */
-    JsonModel<List<CartItem>> getHeaderCart(Integer userId);
-    /**
-     * 购物车列表
-     * @param userId
-     * @return
-     */
-    JsonModel<Map<String, Object>> getShoppingCarts(Integer userId);
-}

+ 0 - 136
src/main/java/com/caimei/www/service/page/impl/ShoppingServiceImpl.java

@@ -1,136 +0,0 @@
-package com.caimei.www.service.page.impl;
-
-import com.caimei.www.mapper.ShoppingDao;
-import com.caimei.www.mapper.AccountDao;
-import com.caimei.www.pojo.JsonModel;
-import com.caimei.www.pojo.order.CartItem;
-import com.caimei.www.pojo.order.CartSupplier;
-import com.caimei.www.pojo.account.Account;
-import com.caimei.www.service.CommonServiceUtil;
-import com.caimei.www.service.page.ShoppingService;
-import com.caimei.www.utils.ImageUtil;
-import com.caimei.www.utils.PriceUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Description
- *
- * @author : Charles
- * @date : 2020/7/23
- */
-@Slf4j
-@Service
-public class ShoppingServiceImpl implements ShoppingService {
-    @Value("${caimei.wwwDomain}")
-    private String domain;
-    @Resource
-    private ShoppingDao shoppingDao;
-    @Resource
-    private AccountDao accountDao;
-    @Resource
-    private CommonServiceUtil commonServiceUtil;
-    /**
-     * 顶部购物车数据
-     *
-     * @param userId
-     * @return
-     */
-    @Override
-    public JsonModel<List<CartItem>> getHeaderCart(Integer userId) {
-        if (userId == null || userId == 0) { return JsonModel.error("参数异常", null);}
-        List<CartItem> headCarts = shoppingDao.getHeadCarts(userId);
-        return JsonModel.success(headCarts);
-    }
-
-    /**
-     * 购物车列表
-     *
-     * @param userId
-     * @return
-     */
-    @Override
-    public JsonModel<Map<String, Object>> getShoppingCarts(Integer userId) {
-        if (userId == null || userId == 0) { return JsonModel.error("参数异常", null);}
-        List<CartSupplier> cartSuppliers = shoppingDao.getCartSuppliers(userId);
-        List<CartItem> invalidCarts = new ArrayList<>();
-        Account account = accountDao.getUserById(userId);
-        AtomicInteger totalCount = new AtomicInteger();
-        AtomicInteger totalSize = new AtomicInteger();
-        AtomicReference<Double> totalPrice = new AtomicReference<>(0d);
-        cartSuppliers.forEach(supplier -> {
-            List<CartItem> cartItems = shoppingDao.getShoppingCartBySupplierId(supplier.getId(), userId);
-            AtomicReference<Double> supplierPrice = new AtomicReference<>(0d);
-            AtomicInteger itemCount = new AtomicInteger();
-            Iterator<CartItem> iterator = cartItems.iterator();
-            while (iterator.hasNext()) {
-                CartItem cartItem = iterator.next();
-                cartItem.setImage(ImageUtil.getImageURL("product", cartItem.getImage(), 0, domain));
-                if (cartItem.getValidFlag() == 2) {
-                    // 已上架
-                    cartItem.setStatus(0);
-                    // 价格是否可见
-                    boolean priceVisible = (cartItem.getPriceFlag() == 0 || (cartItem.getPriceFlag() == 2 && account.getIdentity() ==2));
-                    if (priceVisible) {
-                        // 设置商品价格
-                        commonServiceUtil.setCartItemPrice(cartItem, userId);
-                        // 该供应商下价格累加
-                        supplierPrice.updateAndGet(v -> v + PriceUtil.add(supplierPrice, cartItem.getPrice()).doubleValue());
-                        itemCount.incrementAndGet();
-                        totalCount.updateAndGet(v -> v + cartItem.getNumber());
-                    } else {
-                        // 失效商品
-                        if (cartItem.getPriceFlag() == 1){
-                            // 未公开价格
-                            cartItem.setStatus(6);
-                        } else if (cartItem.getPriceFlag() == 2) {
-                            // 价格仅会员可见
-                            cartItem.setStatus(5);
-                        }
-                    }
-                } else {
-                    // 失效商品
-                    if (cartItem.getValidFlag() == 0) {
-                        // 后台逻辑删除
-                        cartItem.setStatus(1);
-                    } else if (cartItem.getValidFlag() == 9) {
-                        // 已冻结
-                        cartItem.setStatus(2);
-
-                    } else if (cartItem.getValidFlag() == 3) {
-                        // 已下架
-                        cartItem.setStatus(3);
-                    } else if (cartItem.getStock() == null || cartItem.getStock() == 0) {
-                        // 售罄
-                        cartItem.setStatus(4);
-                    } else if (cartItem.getStock() != null && (cartItem.getStock() < cartItem.getMin() || cartItem.getStock() < cartItem.getNumber())) {
-                        // 库存不足
-                        cartItem.setStatus(7);
-                    }
-                    invalidCarts.add(cartItem);
-                    iterator.remove();
-                }
-            }
-            supplier.setCartList(cartItems);
-            supplier.setTotalPrice(supplierPrice.get());
-            supplier.setCount(itemCount.get());
-            totalPrice.updateAndGet(v -> v + PriceUtil.add(totalPrice, supplierPrice.get()).doubleValue());
-            totalSize.updateAndGet(v -> v + itemCount.get());
-        });
-        cartSuppliers.removeIf(supplier -> (null != supplier && supplier.getCount() == 0));
-        Map<String, Object> resultMap = new HashMap<>();
-        resultMap.put("list", cartSuppliers);
-        resultMap.put("invalid", invalidCarts);
-        resultMap.put("totalSize", totalSize);
-        resultMap.put("totalCount", totalCount);
-        resultMap.put("totalPrice", totalPrice);
-        return JsonModel.success(resultMap);
-    }
-
-}

+ 0 - 53
src/main/resources/mapper/ShoppingMapper.xml

@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.caimei.www.mapper.ShoppingDao">
-    <select id="getHeadCarts" resultType="com.caimei.www.pojo.order.CartItem">
-		select
-			p.productID as id,
-			p.`name` as `name`,
-			p.mainImage as image,
-			p.price1 as price,
-			p.unit as unit,
-			c.productCount as number
-		from cm_cart c
-		left join product p on c.productID=p.productID
-		where p.validFlag='2'
-		and c.userID = #{userId}
-		and p.price1TextFlag != '1'
-        and p.stock != '0'
-        and p.stock <![CDATA[ >= ]]> c.productCount
-	</select>
-	<select id="getCartSuppliers" resultType="com.caimei.www.pojo.order.CartSupplier">
-		select
-			s.shopID as id,
-			s.name,
-			s.logo
-		from cm_cart c
-		left join product p on c.productID = p.productID
-		left join shop s on p.shopID = s.shopID
-		where c.userID = #{userId}
-		group by s.shopID
-		order by MAX(c.addTime) desc
-	</select>
-	<select id="getShoppingCartBySupplierId" resultType="com.caimei.www.pojo.order.CartItem">
-		select
-			c.cm_cartID as id,
-			p.productID as productId,
-			p.`name` as `name`,
-			p.mainImage as image,
-			p.price1 as price,
-			p.unit as unit,
-			p.step as step,
-			p.minBuyNumber as min,
-			p.price1TextFlag as priceFlag,
-			p.ladderPriceFlag as ladderFlag,
-			p.validFlag as validFlag,
-			p.stock as stock,
-			c.productCount as number
-		from product p
-		left join cm_cart c on c.productID = p.productID
-		where p.shopID = #{supplierId} and c.userID = #{userId}
-		order by c.addTime desc
-	</select>
-
-</mapper>

+ 1 - 0
src/main/resources/static/css/product/detail.h5.css

@@ -18,6 +18,7 @@ li{list-style:none}
 .priceTag {position: absolute;left: 20vw;}
 .productBox .detailBox .row>i{font-style:normal;margin-right:2vw}
 .productBox .detailBox .row>em{font-style:normal;color:#4A4F58}
+.productBox .detailBox .row>em.p{font-weight:bold;}
 .productBox .detailBox .row>em.ser{color:#93979F;display:inline-block;margin-right:4vw}
 .productBox .detailBox .row>em.ser:before{content:'\2713';display:inline-block;width:3.4vw;height:3.4vw;text-align:center;line-height:3.4vw;font-size:3.4vw;background:#E15616;border-radius:1.7vw;color:#FFF;margin-right:1.4vw}
 .productBox .detailBox .price{height:21vw}

+ 1 - 0
src/main/resources/static/css/product/detail.pc.css

@@ -30,6 +30,7 @@ li{list-style:none;}
 .productBox .detailBox .row .l:after{content:'';display:inline-block;width:100%}
 .productBox .detailBox .row>i{font-style:normal;}
 .productBox .detailBox .row>em{font-style:normal;color:#333333;margin-left: 15px}
+.productBox .detailBox .row>em.p{font-weight:bold;}
 .productBox .detailBox .row>em.ser{color:#93979F;display:inline-block;margin-right:20px;}
 .productBox .detailBox .row>em.ser:before{width:20px;height:20px;margin-right:5px;background-position:-60px 0;vertical-align:text-top;}
 .productBox .detailBox .price{height:24px}

+ 12 - 12
src/main/resources/static/js/account/login.js

@@ -93,16 +93,16 @@ var loginPage = new Vue({
                         // 登录成功页面跳转
                         var forwardUrl = document.referrer;
                         var getHrefUrl = $("#spiServer").val();
-                        if(forwardUrl=="" || forwardUrl==undefined || forwardUrl==null || forwardUrl == getHrefUrl){
+                        if (forwardUrl && forwardUrl!=getHrefUrl){
+                            window.location.href = forwardUrl;
+                        }else{
                             if(_userIdentity == 4 || _userIdentity ==2){
-                                location.href = '/user/dashboard.html';
+                                window.location.href = '/user/dashboard.html';
                             }else if(_userIdentity == 3){
-                                location.href = '/supplier/dashboard.html';
+                                window.location.href = '/supplier/dashboard.html';
                             }else{
-                                location.href="/index.html";
+                                window.location.href="/index.html";
                             }
-                        }else{
-                            location.href=""+forwardUrl+"";
                         }
                     }else if(response.code == -4){
                         window.location.href = '/bind.html';
@@ -158,16 +158,16 @@ var loginPage = new Vue({
                         // 登录成功页面跳转
                         var forwardUrl = document.referrer;
                         var getHrefUrl = $("#spiServer").val();
-                        if(forwardUrl || forwardUrl == getHrefUrl){
+                        if (forwardUrl && forwardUrl!=getHrefUrl){
+                            window.location.href = forwardUrl;
+                        }else{
                             if(_userIdentity == 4 || _userIdentity ==2){
-                                location.href = '/user/dashboard.html';
+                                window.location.href = '/user/dashboard.html';
                             }else if(_userIdentity == 3){
-                                location.href = '/supplier/dashboard.html';
+                                window.location.href = '/supplier/dashboard.html';
                             }else{
-                                location.href="/index.html";
+                                window.location.href="/index.html";
                             }
-                        }else{
-                            location.href=""+forwardUrl+"";
                         }
                     } else {// 登录失败
                         CAIMEI.Alert(response.msg,'确定',false);

+ 4 - 2
src/main/resources/static/js/base.js

@@ -71,7 +71,7 @@ var globalHead = new Vue({
         // 头部购物车数据
         getHeadCart: function(userId) {
             var _self = this;
-            $.getJSON("/header/cart?userId="+userId).done(function (r) {
+            tokenAjax("get", "/shoppingCart/header/cart", {userId: userId},function (r) {
                 if (r.code === 0 && r.data) {
                     _self.headCart.cartList = r.data;
                     _self.headCart.cartCount = r.data.length;
@@ -204,7 +204,9 @@ $(function(){
     }
     // 去登录弹窗
     $('body').on("click", '.toLogin',function () {
-        loginAert('<span>你还未登录</span><span>请登录后再进行购买</span>', '去登录');
+        //loginAert('<span>你还未登录</span><span>请登录后再进行购买</span>', '去登录');
+        localStorage.setItem("loginBeforePath", window.location.href);
+        window.location.href = '/login.html';
     });
     // 退出登录
     $('body').on("click", '.toLogOut',function () {

+ 6 - 3
src/main/resources/templates/product/detail.html

@@ -56,15 +56,18 @@
                             <em v-if="priceObj.priceFlag==1">¥价格未公开</em>
                             <em v-else-if="priceObj.priceFlag==2 && priceObj.userIdentity!=2">¥会员可见</em>
                             <template v-else-if="priceObj.priceFlag==0 || priceObj.userIdentity==2 || (priceObj.userIdentity==3 && priceObj.supplierId==GLOBAL_SHOP_ID)">
-                                <em class="p" v-text="'¥'+parseFloat(priceObj.price).toFixed(2)"></em>
+                                <em v-if="priceObj.actStatus==1 && promotions && promotions.type==1 && promotions.mode==1" class="p">
+                                    <del v-text="'¥'+parseFloat(priceObj.originalPrice).toFixed(2)"></del>
+                                </em>
+                                <em v-else class="p" v-text="'¥'+parseFloat(priceObj.price).toFixed(2)"></em>
                             </template>
                             <em v-else>¥<i :class="'icon mIcon i'+priceObj.priceGrade"></i></em>
                         </template>
                         <em v-else>¥<i :class="'icon mIcon i'+priceObj.priceGrade"></i></em>
                     </div>
-                    <template v-if="GLOBAL_USER_ID && GLOBAL_USER_ID>0 && (priceObj.priceFlag==0 || (priceObj.priceFlag==2 && priceObj.userIdentity==2) || (priceObj.userIdentity==3 && priceObj.supplierId==GLOBAL_SHOP_ID))">
+                    <template v-if="GLOBAL_USER_ID && GLOBAL_USER_ID>0 && priceObj.normalPrice>0 && (priceObj.priceFlag==0 || (priceObj.priceFlag==2 && priceObj.userIdentity==2) || (priceObj.userIdentity==3 && priceObj.supplierId==GLOBAL_SHOP_ID))">
                         <div class="row"> <span class="l">市场价</span><i>:</i>
-                             <em class="pricedeail" :class="priceObj.actStatus==1?'original-price':''">¥{{priceObj.normalPrice}}</em>
+                             <em><del>¥{{priceObj.normalPrice.toFixed(2)}}</del></em>
                         </div>
                     </template>
                     <div class="row" v-if="priceObj.actStatus==1||priceObj.ladderPriceFlag==1" ><span class="l">促销</span><i>:</i>