1
0
Переглянути джерело

修改下架商品,删除商品小程序后台逻辑处理

hyq 6 роки тому
батько
коміт
49e8fb5b05

+ 1 - 0
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -481,6 +481,7 @@ public class GoodsServiceImpl implements GoodsService {
         for (Integer id : ids) {
             GoodsEntity goodsEntity = queryObject(id);
             goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
+            goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
             goodsEntity.setUpdateUserId(user.getUserId());
             goodsEntity.setUpdateTime(new Date());
             result += goodsDao.update(goodsEntity);

+ 29 - 22
kmall-api/src/main/java/com/kmall/api/api/ApiCartController.java

@@ -100,6 +100,7 @@ public class ApiCartController extends ApiBaseAction {
         param.put("user_id", loginUser.getId());
         Long storeId = getStoreId();
         param.put("store_id", storeId);
+        param.put("merchSn", getMerchSn());
         List<CartVo> cartList = cartService.queryList(param);
 
         List<CartVo> validCartList = cartService.queryValidCartList(param);
@@ -230,15 +231,25 @@ public class ApiCartController extends ApiBaseAction {
         Integer number = jsonParam.getInteger("number");
         //判断商品是否可以购买
         GoodsVo goodsInfo = goodsService.queryObject(goodsId);
-        if (null == goodsInfo || goodsInfo.getIs_delete() == 1) {
+        if (null == goodsInfo || goodsInfo.getIs_delete() == 1 || goodsInfo.getIs_on_sale() == 0) {
             return toResponsFail("商品已下架");
         }
         Long storeId = getStoreId();
         //取得规格的信息,判断规格库存
-        ProductVo productInfo = productService.queryObjectByStoreId(productId, storeId);
+        /*ProductVo productInfo = productService.queryObjectByStoreId(productId, storeId);
         if (null == productInfo) {
             return toResponsFail("商品已下架");
         }
+        if(productInfo.getStock_num() <= 0){
+            return toResponsFail("库存不足");
+        }*/
+        ProductVo productInfo = productService.queryByStoreId(productId, storeId);
+        if (null == productInfo) {
+            return toResponsFail("商品已下架");
+        }
+        if(productInfo.getStock_num() == null || number > productInfo.getStock_num() || productInfo.getStock_num() <= 0){
+            return toResponsFail("该商品库存不足");
+        }
         if (null == productInfo.getRetail_price()) {
             productInfo.setRetail_price(goodsInfo.getRetail_price());
             productInfo.setMarket_price(goodsInfo.getMarket_price());
@@ -251,11 +262,7 @@ public class ApiCartController extends ApiBaseAction {
         cartParam.put("store_id", storeId);
         List<CartVo> cartInfoList = cartService.queryList(cartParam);
         CartVo cartInfo = null != cartInfoList && cartInfoList.size() > 0 ? cartInfoList.get(0) : null;
-        if (null == cartInfo) {
-            if(productInfo.getStock_num() <= 0){
-                return toResponsFail("库存不足");
-            }
-            //添加规格名和值
+        if (null == cartInfo) {//添加规格名和值
             cartInfo = new CartVo();
 
             cartInfo.setGoods_id(goodsId);
@@ -296,7 +303,7 @@ public class ApiCartController extends ApiBaseAction {
         Long goodsId = jsonParam.getLong("goodsId");
         //判断商品是否可以购买
         GoodsVo goodsInfo = goodsService.queryObject(goodsId);
-        if (null == goodsInfo || goodsInfo.getIs_delete() == 1) {
+        if (null == goodsInfo || goodsInfo.getIs_delete() == 1 || goodsInfo.getIs_on_sale() == 0) {
             return toResponsFail("商品已下架");
         }
         Long storeId = getStoreId();
@@ -320,7 +327,7 @@ public class ApiCartController extends ApiBaseAction {
         for (OrderGoodsVo goodsVo : orderGoodsVos) {
             //判断商品是否可以购买
             GoodsVo goodsInfo = goodsService.queryObject(goodsVo.getGoods_id());
-            if (null == goodsInfo || goodsInfo.getIs_delete() == 1) {
+            if (null == goodsInfo || goodsInfo.getIs_delete() == 1 || goodsInfo.getIs_on_sale() == 0) {
                 return toResponsFail("商品已下架");
             }
         }
@@ -330,8 +337,8 @@ public class ApiCartController extends ApiBaseAction {
             if (null == productInfo) {
                 return toResponsFail("商品已下架");
             }
-            if(productInfo.getStock_num() == null || goodsVo.getNumber() > productInfo.getStock_num() || productInfo.getStock_num() == 0){
-                return toResponsFail("该商品暂无库存");
+            if(productInfo.getStock_num() == null || goodsVo.getNumber() > productInfo.getStock_num() || productInfo.getStock_num() <= 0){
+                return toResponsFail("该商品库存不足");
             }
             CartVo cartInfo = new CartVo();
             cartInfo.setGoods_id(goodsVo.getGoods_id());
@@ -417,19 +424,19 @@ public class ApiCartController extends ApiBaseAction {
         Integer id = jsonParam.getInteger("id");
         boolean isAdd = true;
         //取得规格的信息,判断规格库存
-        ProductVo productInfo = productService.queryObjectByStoreId(productId, storeId);
-        if (null == productInfo || productInfo.getStock_num() == 0) {
-//            String[] productIds = new String[1];
-//            productIds[0] = productId + "";
-//            cartService.deleteByProductIds(productIds, storeId);
-            return this.toResponsObject(400, "商品已下架", "");
+        ProductVo productInfo = productService.queryByStoreId(productId, storeId);
+        if (null == productInfo) {
+            return this.toResponsObject(400, "商品已下架", getCart());
         }
-        String msg = "";
-        if (productInfo.getStock_num() < number) {
-            msg = "库存不足,仅剩余" + productInfo.getStock_num();
-            number = productInfo.getStock_num();
-//            return this.toResponsObject(400, "库存不足,仅剩余" + productInfo.getStock_num(), "");
+        if(productInfo.getStock_num() == null || number > productInfo.getStock_num() || productInfo.getStock_num() <= 0){
+            return this.toResponsObject(400, "该商品库存不足", getCart());
         }
+        String msg = "";
+//        if (productInfo.getStock_num() < number) {
+//            msg = "库存不足,仅剩余" + productInfo.getStock_num();
+//            number = productInfo.getStock_num();
+////            return this.toResponsObject(400, "库存不足,仅剩余" + productInfo.getStock_num(), "");
+//        }
         //判断是否已经存在product_id购物车商品
         CartVo cartInfo = cartService.queryObject(id);
         //只是更新number

+ 5 - 2
kmall-api/src/main/resources/mybatis/mapper/ApiCartMapper.xml

@@ -55,7 +55,7 @@
         left join mall_goods b on a.goods_id = b.id
         left join mall_product c on c.goods_id = a.goods_id and c.id = a.product_id
         left join mall_product_store_rela psr on psr.product_id = c.id and psr.store_id = #{store_id}
-        where 1 = 1  and b.is_delete = 0
+        where 1 = 1  and b.is_delete = 0 and b.is_on_sale = 1
         and psr.stock_num > 0
         <if test="user_id != null">
             AND a.user_id = #{user_id}
@@ -95,7 +95,10 @@
         left join mall_product c on c.goods_id = a.goods_id and c.id = a.product_id
         left join mall_product_store_rela psr on psr.product_id = c.id and psr.store_id = #{store_id}
         where 1 = 1
-        and psr.stock_num = 0
+        and (psr.stock_num = 0 or b.is_on_sale = 0)
+        <if test="merchSn != null">
+            and a.merch_sn = #{merchSn}
+        </if>
         <if test="user_id != null">
             AND a.user_id = #{user_id}
         </if>

+ 1 - 1
kmall-api/src/main/resources/mybatis/mapper/ApiFootprintMapper.xml

@@ -34,7 +34,7 @@
         left join mall_goods g on f.goods_id = g.id
         LEFT JOIN mall_product_store_rela psr ON psr.goods_id = g.id
         <where>
-            1=1 and psr.stock_num >0  and g.is_delete = 0
+            1=1 and psr.stock_num >0  and g.is_delete = 0 and g.is_on_sale = 1
             <if test="user_id != null">
                 and f.user_id = #{user_id}
             </if>

+ 1 - 1
kmall-api/src/main/resources/mybatis/mapper/ApiGoodsCrashMapper.xml

@@ -40,7 +40,7 @@
         mall_goods_crash a
         LEFT JOIN mall_goods b ON a.goods_crash_id = b.id
         LEFT JOIN mall_product_store_rela c ON c.product_id = a.product_crash_id
-        WHERE 1=1 and c.stock_num > 0 AND b.is_delete = 0
+        WHERE 1=1 and c.stock_num > 0 AND b.is_delete = 0 and b.is_on_sale = 1
         <if test="goods_id != null and goods_id != ''">
             AND a.goods_id = #{goods_id}
         </if>

+ 2 - 1
wx-mall/pages/cart/cart.js

@@ -264,7 +264,7 @@ Page({
       id: id
     }, 'POST').then(function (res) {
       if (res.errno === 0) {
-        console.log(res.data);
+        // console.log(res.data);
         that.setCommonData(res);
       } else {
         // util.showErrorToast(res.errmsg);
@@ -278,6 +278,7 @@ Page({
         that.setData({
           cartGoods: that.data.cartGoods
         });
+        that.setCommonData(res);
       }
       that.setCheckedData();
     });

+ 1 - 1
wx-mall/pages/cart/cart.wxss

@@ -42,7 +42,7 @@ page {
 .no-cart .c {
   width: 100%;
   height: auto;
-  margin-top: 300rpx;
+  margin-top: 120rpx;
 }
 
 .no-cart .c image {

+ 4 - 0
wx-mall/pages/goods/goods.js

@@ -389,6 +389,10 @@ Page({
               title: _res.errmsg,
               icon: 'none'
             })
+            that.hideSwitchAttrPop();
+            that.setData({
+              stockNum: 0
+            });
           }
         });
 

+ 3 - 3
wx-mall/pages/goods/goods.wxml

@@ -38,7 +38,7 @@
   </view>
   <view>   
   <!-- 滚动的卡片布局 -->
-  <view class='goodsimgs'>
+  <view class='goodsimgs' bindtap="hideSwitchAttrPop">
     <view class='content-wrapper'>
       <view class='scroll-wrapper'>
         <scroll-view class='scroll-view'>
@@ -277,7 +277,7 @@
     </view>
   </view>
 </scroll-view>
-  <view class='shelves-view' wx:if="{{stockNum ==0}}">
+  <view class='shelves-view' wx:if="{{stockNum ==0 || goods.is_on_sale == 0}}">
     <view class="shelves">
       <text class='shelves-text'>已下架</text>
     </view>
@@ -296,5 +296,5 @@
       </view>
     </view>
     <!-- <view class="c">立即购买</view> -->
-    <view class='{{stockNum ==0?"r-disable":"r"}}' bindtap='{{stockNum ==0?"":"addToCart"}}'>加入购物车</view>
+    <view class='{{stockNum ==0 || goods.is_on_sale == 0?"r-disable":"r"}}' bindtap='{{stockNum ==0 || goods.is_on_sale == 0?"":"addToCart"}}'>加入购物车</view>
   </view>