Przeglądaj źródła

第三方商户库存共享api模块修改

hyq 6 lat temu
rodzic
commit
d686a36de7

+ 111 - 15
kmall-api/src/main/java/com/kmall/api/api/ApiCartController.java

@@ -49,19 +49,24 @@ public class ApiCartController extends ApiBaseAction {
 
     @Autowired
     private ApiFreightService apiFreightService;
+    @Autowired
+    private ApiThirdMerchantBizService apiThirdMerchantBizService;
+    @Autowired
+    private ApiStoreService apiStoreService;
 
     /**
      * 获取购物车中的数据
      */
     @GetMapping("getCartMoney")
     public Object getCartMoney(@LoginUser UserVo loginUser, String checkCart) {
+        Long storeId = getStoreId();
         Map<String, Object> resultObj = Maps.newHashMap();
         //查询列表数据
         Map param = Maps.newHashMap();
         param.put("user_id", loginUser.getId());
-        Long storeId = getStoreId();
         param.put("store_id", storeId);
         param.put("checkCart",checkCart);
+        param.putAll(setIsStockShare(storeId));
         List<CartVo> cartList = cartService.queryList(param);
         //获取购物车统计信息
         Integer goodsCount = 0;
@@ -89,6 +94,19 @@ public class ApiCartController extends ApiBaseAction {
         return resultObj;
     }
 
+    private Map setIsStockShare(Long storeId){
+        Map param = Maps.newHashMap();
+        StoreVo storeVo = apiStoreService.queryObject(storeId);
+        if(storeVo != null) {
+            ThirdMerchantBizVo thirdMerchantBiz = apiThirdMerchantBizService.getThirdMerchangByCode(storeVo.getThirdPartyMerchCode());
+            if (null == thirdMerchantBiz) {
+                return toResponsFail("第三方商户为空");
+            }
+            param.put("isStockShare", thirdMerchantBiz.getIsStockShare());
+        }
+        return param;
+    }
+
     /**
      * 获取购物车中的数据
      */
@@ -104,6 +122,7 @@ public class ApiCartController extends ApiBaseAction {
         param.put("store_id", storeId);
         param.put("merchSn", getMerchSn());
         param.put("checkCart", checkCart);
+        param.putAll(setIsStockShare(storeId));
         List<CartVo> cartList = cartService.queryList(param);
         List<CartVo> validCartList = cartService.queryValidCartList(param);
         //获取购物车统计信息
@@ -196,6 +215,7 @@ public class ApiCartController extends ApiBaseAction {
         param.put("user_id", loginUser.getId());
         Long storeId = getStoreId();
         param.put("store_id", storeId);
+        param.putAll(setIsStockShare(storeId));
         List<CartVo> cartList = cartService.queryList(param);
         //获取购物车统计信息
         Integer goodsCount = 0;
@@ -256,7 +276,26 @@ public class ApiCartController extends ApiBaseAction {
         if (null == productInfo) {
             return toResponsFail("商品已下架");
         }
-        if(productInfo.getStock_num() == null || number > productInfo.getStock_num() || productInfo.getStock_num() <= 0){
+        Integer stockNum = 0;
+        ThirdMerchantBizVo thirdMerchantBizVo = apiThirdMerchantBizService.getThirdMerchangByCode(goodsInfo.getThirdPartyMerchCode());
+        if(null == thirdMerchantBizVo){
+            return toResponsFail("商品已下架");
+        }
+        //// TODO: 2019/3/5  普通商品不受共享库存影响,直接取门店配置库存
+        if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())
+                || goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())
+                || goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_10.getItem())){
+            stockNum = productInfo.getStock_num();
+        }
+        if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
+            if (thirdMerchantBizVo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())){
+                stockNum = goodsInfo.getGoods_number();
+            }
+            if (thirdMerchantBizVo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())){
+                stockNum = productInfo.getStock_num();
+            }
+        }
+        if(stockNum == null || number > stockNum || stockNum <= 0){
             return toResponsFail("该商品库存不足");
         }
         if (null == productInfo.getRetail_price()) {
@@ -269,6 +308,7 @@ public class ApiCartController extends ApiBaseAction {
         cartParam.put("product_id", productId);
         cartParam.put("user_id", loginUser.getId());
         cartParam.put("store_id", storeId);
+        cartParam.put("isStockShare", thirdMerchantBizVo.getIsStockShare());
         List<CartVo> cartInfoList = cartService.queryList(cartParam);
         CartVo cartInfo = null != cartInfoList && cartInfoList.size() > 0 ? cartInfoList.get(0) : null;
         if (null == cartInfo) {//添加规格名和值
@@ -288,17 +328,17 @@ public class ApiCartController extends ApiBaseAction {
             cartInfo.setGoods_specification_ids(productInfo.getGoods_specification_ids());
             cartInfo.setChecked(1);
             cartInfo.setGoodsBizType(goodsInfo.getGoodsBizType());//业务类型
-            cartInfo.setStockNum(productInfo.getStock_num());
+            cartInfo.setStockNum(stockNum);
             cartInfo.setMerchSn(goodsInfo.getMerchSn());
             cartInfo.setSku(goodsInfo.getSku());
             cartService.save(cartInfo);
         } else {
-            if(number + cartInfo.getNumber() > productInfo.getStock_num()){
+            if(number + cartInfo.getNumber() > stockNum){
                 return toResponsFail("商品选购数量(含购物车已加购数量)已超过库存");
             }
             cartInfo.setNumber(cartInfo.getNumber() + number);
             cartInfo.setGoodsBizType(goodsInfo.getGoodsBizType());//业务类型
-            cartInfo.setStockNum(productInfo.getStock_num());
+            cartInfo.setStockNum(stockNum);
             cartInfo.setSku(goodsInfo.getSku());
             cartService.update(cartInfo);
         }
@@ -336,20 +376,33 @@ public class ApiCartController extends ApiBaseAction {
         Map params = Maps.newHashMap();
         params.put("order_id", orderId);
         List<OrderGoodsVo> orderGoodsVos = apiOrderGoodsService.queryList(params);
+        Integer stockNum = 0;
+        Long storeId = getStoreId();
         for (OrderGoodsVo goodsVo : orderGoodsVos) {
             //判断商品是否可以购买
+            ProductVo productInfo = productService.queryByStoreId(goodsVo.getProduct_id(), storeId);
+            if (null == productInfo) {
+                return toResponsFail("商品已下架");
+            }
             GoodsVo goodsInfo = goodsService.queryObjectByStoreId(goodsVo.getGoods_id(), getStoreId());
             if (null == goodsInfo || goodsInfo.getIs_delete() == 1 || goodsInfo.getIs_on_sale() == 0) {
                 return toResponsFail("商品已下架");
             }
-        }
-        Long storeId = getStoreId();
-        for (OrderGoodsVo goodsVo : orderGoodsVos) {
-            ProductVo productInfo = productService.queryByStoreId(goodsVo.getProduct_id(), storeId);
-            if (null == productInfo) {
-                return toResponsFail("商品已下架");
+            // TODO: 2019/3/5  普通商品不受共享库存影响,直接取门店配置库存
+            if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())
+                    || goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())
+                    || goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_10.getItem())){
+                stockNum = productInfo.getStock_num();
+            }
+            if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())) {
+                if (goodsInfo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())) {
+                    stockNum = goodsInfo.getGoods_number();
+                }
+                if (goodsInfo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
+                    stockNum = productInfo.getStock_num();
+                }
             }
-            if(productInfo.getStock_num() == null || goodsVo.getNumber() > productInfo.getStock_num() || productInfo.getStock_num() <= 0){
+            if(stockNum == null || goodsVo.getNumber() > stockNum || stockNum <= 0){
                 return toResponsFail("该商品库存不足");
             }
             CartVo cartInfo = new CartVo();
@@ -367,7 +420,7 @@ public class ApiCartController extends ApiBaseAction {
             cartInfo.setGoods_specification_ids(goodsVo.getGoods_specification_ids());
             cartInfo.setChecked(1);
             cartInfo.setGoodsBizType(goodsVo.getOrderBizType());
-            cartInfo.setStockNum(productInfo.getStock_num());
+            cartInfo.setStockNum(stockNum);
             cartInfo.setMerchSn(goodsVo.getMerchSn());
             cartInfo.setSku(goodsVo.getSku());
 
@@ -377,6 +430,7 @@ public class ApiCartController extends ApiBaseAction {
             map.put("goods_id",goodsVo.getGoods_id());
             map.put("product_id",goodsVo.getProduct_id());
             map.put("number",goodsVo.getNumber());
+            map.put("isStockShare", goodsInfo.getIsStockShare());
             List<CartVo> list= cartService.queryList(map);
             if(list != null && list.size() > 0){
                 for (CartVo vo:list) {
@@ -401,6 +455,21 @@ public class ApiCartController extends ApiBaseAction {
         Integer goodsId = jsonParam.getInteger("goodsId");
         Integer productId = jsonParam.getInteger("productId");
         Integer number = jsonParam.getInteger("number");
+
+        GoodsVo goodsInfo = goodsService.queryObjectByStoreId(Long.valueOf(goodsId), getStoreId());
+        if (null == goodsInfo || goodsInfo.getIs_delete() == 1 || goodsInfo.getIs_on_sale() == 0) {
+            return toResponsFail("商品已下架");
+        }
+        ThirdMerchantBizVo thirdMerchantBiz = apiThirdMerchantBizService.getThirdMerchangByCode(goodsInfo.getThirdPartyMerchCode());
+        if(null == thirdMerchantBiz){
+            return toResponsFail("商品已下架");
+        }
+        /*if (thirdMerchantBiz.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())){
+            stockNum = goodsInfo.getGoods_number();
+        }
+        if (thirdMerchantBiz.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())){
+            stockNum = productInfo.getStock_num();
+        }*/
         //判断购物车中是否存在此规格商品
         Map cartParam = Maps.newHashMap();
         cartParam.put("goods_id", goodsId);
@@ -408,6 +477,7 @@ public class ApiCartController extends ApiBaseAction {
         Long storeId = getStoreId();
         cartParam.put("store_id", storeId);
         cartParam.put("user_id", loginUser.getId());
+        cartParam.put("isStockShare", thirdMerchantBiz.getIsStockShare());
         List<CartVo> cartInfoList = cartService.queryList(cartParam);
         CartVo cartInfo = null != cartInfoList && cartInfoList.size() > 0 ? cartInfoList.get(0) : null;
         int cart_num = 0;
@@ -437,12 +507,35 @@ public class ApiCartController extends ApiBaseAction {
         Integer id = jsonParam.getInteger("id");
         String checkCart = jsonParam.getString("checkCart");
         boolean isAdd = true;
+        Integer stockNum = 0;
+        GoodsVo goodsInfo = goodsService.queryObjectByStoreId(Long.valueOf(goodsId), getStoreId());
+        if (null == goodsInfo || goodsInfo.getIs_delete() == 1 || goodsInfo.getIs_on_sale() == 0) {
+            return toResponsFail("商品已下架");
+        }
         //取得规格的信息,判断规格库存
         ProductVo productInfo = productService.queryByStoreId(productId, storeId);
         if (null == productInfo) {
             return this.toResponsObject(400, "商品已下架", getCart(checkCart));
         }
-        if(productInfo.getStock_num() == null || number > productInfo.getStock_num() || productInfo.getStock_num() <= 0){
+        ThirdMerchantBizVo thirdMerchantBiz = apiThirdMerchantBizService.getThirdMerchangByCode(goodsInfo.getThirdPartyMerchCode());
+        if(null == thirdMerchantBiz){
+            return toResponsFail("商品已下架");
+        }
+        // TODO: 2019/3/5  普通商品不受共享库存影响,直接取门店配置库存
+        if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())
+                || goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())
+                || goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_10.getItem())){
+            stockNum = productInfo.getStock_num();//门店库存
+        }
+        if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
+            if (thirdMerchantBiz.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())){
+                stockNum = goodsInfo.getGoods_number();
+            }
+            if (thirdMerchantBiz.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())){
+                stockNum = productInfo.getStock_num();
+            }
+        }
+        if(stockNum == null || number > stockNum || stockNum <= 0){
             return this.toResponsObject(400, "该商品库存不足", getCart(checkCart));
         }
         String msg = "";
@@ -456,7 +549,7 @@ public class ApiCartController extends ApiBaseAction {
         //只是更新number
         if (cartInfo.getProduct_id().equals(productId)) {
             cartInfo.setNumber(number);
-            cartInfo.setStockNum(productInfo.getStock_num());
+            cartInfo.setStockNum(stockNum);
             cartService.update(cartInfo);
             return toResponsObject(0, msg, getCart(checkCart));
         }
@@ -465,6 +558,7 @@ public class ApiCartController extends ApiBaseAction {
         cartParam.put("goodsId", goodsId);
         cartParam.put("productId", productId);
         cartParam.put("store_id", storeId);
+        cartParam.put("isStockShare", thirdMerchantBiz.getIsStockShare());
         List<CartVo> cartInfoList = cartService.queryList(cartParam);
         CartVo newcartInfo = null != cartInfoList && cartInfoList.size() > 0 ? cartInfoList.get(0) : null;
         if (null == newcartInfo) {
@@ -544,6 +638,7 @@ public class ApiCartController extends ApiBaseAction {
         Map param = Maps.newHashMap();
         param.put("user_id", loginUser.getId());
         param.put("store_id", getStoreId());
+        param.putAll(setIsStockShare(getStoreId()));
         List<CartVo> cartList = cartService.queryList(param);
         //获取购物车统计信息
         Integer goodsCount = 0;
@@ -702,6 +797,7 @@ public class ApiCartController extends ApiBaseAction {
         param.put("user_id", loginUser.getId());
         Long storeId = getStoreId();
         param.put("store_id", storeId);
+        param.putAll(setIsStockShare(storeId));
         List<CartVo> cartList = cartService.queryList(param);
         //获取购物车统计信息
         BigDecimal checkedGoodsAmount = new BigDecimal(0.00);

+ 7 - 2
kmall-api/src/main/java/com/kmall/api/api/ApiFootprintController.java

@@ -107,7 +107,9 @@ public class ApiFootprintController extends ApiBaseAction {
      * 猜你喜欢
      */
     @GetMapping("glist")
-    public Object glist(@LoginUser UserVo loginUser,String storeId,String checkCart) {
+    public Object glist(@LoginUser UserVo loginUser,String storeId,String checkCart,
+                        @RequestParam(value = "page", defaultValue = "1") Integer
+                                page, @RequestParam(value = "size", defaultValue = "4") Integer size) {
         Map resultObj = Maps.newHashMap();
 
         //查询列表数据
@@ -119,7 +121,10 @@ public class ApiFootprintController extends ApiBaseAction {
         params.put("bizType", true);
         params.put("store_id", storeId);
         params.put("checkCart", checkCart);
-        List<FootprintVo> footprintVos = footprintService.queryList(params);
+        params.put("page", page);
+        params.put("limit", size);
+        Query query = new Query(params);
+        List<FootprintVo> footprintVos = footprintService.queryList(query);
         List<FootprintVo> list = new ArrayList();
         if (null != footprintVos) {
             for (FootprintVo vo : footprintVos) {

+ 81 - 9
kmall-api/src/main/java/com/kmall/api/api/ApiGoodsController.java

@@ -7,6 +7,7 @@ import com.kmall.api.entity.*;
 import com.kmall.api.service.*;
 import com.kmall.api.util.ApiBaseAction;
 import com.kmall.api.util.ApiPageUtils;
+import com.kmall.common.constant.Dict;
 import com.kmall.common.utils.DateUtils;
 import com.kmall.common.utils.Query;
 import com.kmall.common.utils.enums.CouponTypeEnum;
@@ -71,6 +72,10 @@ public class ApiGoodsController extends ApiBaseAction {
 
     @Autowired
     private ApiFreightService apiFreightService;
+    @Autowired
+    private ApiThirdMerchantBizService apiThirdMerchantBizService;
+    @Autowired
+    private ApiStoreService apiStoreService;
 
     /**
      */
@@ -209,10 +214,24 @@ public class ApiGoodsController extends ApiBaseAction {
         Map cartMap= Maps.newHashMap();
         cartMap.put("user_id",userId);
         cartMap.put("goods_id",info.getId());
+        cartMap.put("store_id", storeId);
+        cartMap.put("isStockShare", info.getIsStockShare());
         List<CartVo> cartVoList = cartService.queryList(cartMap);
 
         FreightEntity freightEntity = apiFreightService.queryObjectByGoodsId(info.getId(), getStoreId());
-        //
+
+        Integer stockNum = 0;
+        if(info.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
+            if (info.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())) {
+                stockNum = info.getGoods_number();
+                info.setSell_volume(info.getGoods_sell_volume());
+            }
+            if (info.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
+                stockNum = info.getStockNum();
+            }
+        }else {
+            stockNum = info.getStockNum();
+        }
         resultObj.put("info", info);
 
         resultObj.put("attribute", attribute);
@@ -221,7 +240,7 @@ public class ApiGoodsController extends ApiBaseAction {
         resultObj.put("comment", comment);
         resultObj.put("specificationList", specificationList);
         resultObj.put("productList", productEntityList);
-        resultObj.put("stockNum", productEntityList.size()!=0? productEntityList.get(0).getStock_num():0);
+        resultObj.put("stockNum", stockNum);
         resultObj.put("cartNumber", cartVoList.size()!=0? cartVoList.get(0).getNumber():0);
         resultObj.put("defaultFreight", freightEntity != null? freightEntity.getDefaultFreight() :0);
 
@@ -334,14 +353,14 @@ public class ApiGoodsController extends ApiBaseAction {
         params.put("is_hot", isHot);
         params.put("page", page);
         params.put("limit", size);
-        params.put("order", sort);
-        params.put("sidx", order);
+//        params.put("order", sort);
+//        params.put("sidx", order);
         params.put("goodsBizType", goodsBizType);
         params.put("store_id", getStoreId());
         params.put("notGoodsBizType", true);
         //
         if (null != sort && sort.equals("price")) {
-            params.put("sidx", "a.retail_price");
+            params.put("sidx", "psr1.retail_price");
             params.put("order", order);
         } else {
             params.put("sidx", "a.id");
@@ -422,10 +441,20 @@ public class ApiGoodsController extends ApiBaseAction {
     @IgnoreAuth
     @GetMapping("hotGoodsList")
     public Object hotGoodsList(@LoginUser UserVo loginUser, Integer categoryId,
+                               @RequestParam(value = "page", defaultValue = "1") Integer
+                                       page, @RequestParam(value = "size", defaultValue = "10") Integer size,
                                String sort, String order) {
         Map reusltObj = Maps.newHashMap();
         //
         Long store_id = getStoreId();
+        StoreVo storeVo = apiStoreService.queryObject(store_id);
+        ThirdMerchantBizVo thirdMerchantBiz = new ThirdMerchantBizVo();
+        if(storeVo != null) {
+            thirdMerchantBiz = apiThirdMerchantBizService.getThirdMerchangByCode(storeVo.getThirdPartyMerchCode());
+            if (null == thirdMerchantBiz) {
+                return toResponsFail("第三方商户为空");
+            }
+        }
         Map params = Maps.newHashMap();
         //筛选的分类
         List<CategoryVo> filterCategory = new ArrayList();
@@ -472,7 +501,7 @@ public class ApiGoodsController extends ApiBaseAction {
         }
         params.put("category_parent_id", categoryId);
         params.put("fields", "a.id,a.name,a.goods_brief,a.list_pic_url,psr1.retail_price," +
-                "psr1.market_price,b.id as product_id");
+                "psr1.market_price,b.id as product_id,psr1.stock_num");
         params.put("is_hot", "1");
         params.put("is_delete", 0);
         params.put("store_id", store_id);
@@ -482,9 +511,34 @@ public class ApiGoodsController extends ApiBaseAction {
                 params.put("order", order);
             }
         }
-        List<GoodsVo> hotGoods = goodsService.queryHotGoodsList(params);
 
         reusltObj.put("filterCategory", filterCategory);
+        params.put("isStockShare", thirdMerchantBiz.getIsStockShare());
+
+        params.put("page", page);
+        params.put("limit", size);
+        Query query = new Query(params);
+        List<GoodsVo> hotGoods = goodsService.queryHotGoodsList(query);
+        // 当前购物车中
+        List<CartVo> cartList = new ArrayList();
+        if (null != getUserId()) {
+            //查询列表数据
+            Map cartParam = Maps.newHashMap();
+            cartParam.put("user_id", getUserId());
+            cartParam.put("store_id", getStoreId());
+            cartParam.put("isStockShare", thirdMerchantBiz.getIsStockShare());
+
+            cartList = cartService.queryList(cartParam);
+        }
+        if (null != cartList && cartList.size() > 0 && null != hotGoods && hotGoods.size() > 0) {
+            for (GoodsVo goodsVo : hotGoods) {
+                for (CartVo cartVo : cartList) {
+                    if (goodsVo.getId().equals(cartVo.getGoods_id())) {
+                        goodsVo.setCart_num(cartVo.getNumber());
+                    }
+                }
+            }
+        }
         reusltObj.put("goodsList", hotGoods);
 
         return toResponsSuccess(reusltObj);
@@ -537,7 +591,9 @@ public class ApiGoodsController extends ApiBaseAction {
      */
     @IgnoreAuth
     @GetMapping("related")
-    public Object related(@LoginUser UserVo loginUser, Long id) {
+    public Object related(@LoginUser UserVo loginUser, Long id,
+                          @RequestParam(value = "page", defaultValue = "1") Integer
+                                  page, @RequestParam(value = "size", defaultValue = "4") Integer size) {
         Map<String, Object> resultObj = Maps.newHashMap();
         Map param = Maps.newHashMap();
         param.put("goods_id", id);
@@ -558,6 +614,10 @@ public class ApiGoodsController extends ApiBaseAction {
                 paramRelated.put("notGoodsBizType", true);
                 paramRelated.put("fields", "a.id, a.name, a.list_pic_url, psr1.retail_price,b.id as product_id");
                 paramRelated.put("category_id", goodsCategory.getCategory_id());
+                paramRelated.put("limit", size);
+                paramRelated.put("offset", (page - 1) * size);
+                paramRelated.put("sidx", "a.create_time");
+                paramRelated.put("order", "desc");
                 relatedGoods = goodsService.queryList(paramRelated);
             }
         } else {
@@ -566,6 +626,10 @@ public class ApiGoodsController extends ApiBaseAction {
             paramRelated.put("notGoodsBizType", true);
             paramRelated.put("goods_ids", relatedGoodsIds);
             paramRelated.put("fields", "a.id, a.name, a.list_pic_url, psr1.retail_price,b.id as product_id");
+            paramRelated.put("limit", size);
+            paramRelated.put("offset", (page - 1) * size);
+            paramRelated.put("sidx", "a.create_time");
+            paramRelated.put("order", "desc");
             relatedGoods = goodsService.queryList(paramRelated);
         }
         resultObj.put("goodsList", relatedGoods);
@@ -608,7 +672,7 @@ public class ApiGoodsController extends ApiBaseAction {
         params.put("store_id", getStoreId());
         //
         if (null != sort && sort.equals("price")) {
-            params.put("sidx", "retail_price");
+            params.put("sidx", "psr1.retail_price");
             params.put("order", order);
         } else if (null != sort && sort.equals("sell")) {
             params.put("sidx", "psr1.sell_volume");
@@ -644,6 +708,14 @@ public class ApiGoodsController extends ApiBaseAction {
             Map cartParam = Maps.newHashMap();
             cartParam.put("user_id", getUserId());
             cartParam.put("store_id", storeId);
+            StoreVo storeVo = apiStoreService.queryObject(storeId);
+            if(storeVo != null) {
+                ThirdMerchantBizVo thirdMerchantBiz = apiThirdMerchantBizService.getThirdMerchangByCode(storeVo.getThirdPartyMerchCode());
+                if (null == thirdMerchantBiz) {
+                    return toResponsFail("第三方商户为空");
+                }
+                cartParam.put("isStockShare", thirdMerchantBiz.getIsStockShare());
+            }
             cartList = cartService.queryList(cartParam);
         }
         if (null != cartList && cartList.size() > 0 && null != goodsList && goodsList.size() > 0) {

+ 5 - 28
kmall-api/src/main/java/com/kmall/api/api/ApiIndexController.java

@@ -48,6 +48,10 @@ public class ApiIndexController extends ApiBaseAction {
     private ApiOrderService apiOrderService;
     @Autowired
     private ApiUserService apiUserService;
+    @Autowired
+    private ApiThirdMerchantBizService apiThirdMerchantBizService;
+    @Autowired
+    private ApiStoreService apiStoreService;
 
     /**
      * app首页
@@ -83,34 +87,7 @@ public class ApiIndexController extends ApiBaseAction {
         param.put("order", "asc ");
         List<ChannelVo> channel = channelService.queryList(param);
         resultObj.put("channel", channel);
-        // 超级折扣,需要门店过滤
-        param = Maps.newHashMap();
-        param.put("fields", "distinct a.id,a.name,a.goods_brief,a.list_pic_url,psr1.retail_price,psr1.market_price,b.id as product_id,psr1.stock_num");
-        param.put("is_hot", "1");
-        param.put("offset", 0);
-        param.put("limit", 20);
-        param.put("is_delete", 0);
-        param.put("store_id", storeId);
-        List<GoodsVo> hotGoods = goodsService.queryHotGoodsList(param);
-        resultObj.put("hotGoodsList", hotGoods);
-        // 当前购物车中
-        List<CartVo> cartList = new ArrayList();
-        if (null != userId) {
-            //查询列表数据
-            Map cartParam = Maps.newHashMap();
-            cartParam.put("user_id", userId);
-            cartParam.put("store_id", storeId);
-            cartList = cartService.queryList(cartParam);
-        }
-        if (null != cartList && cartList.size() > 0 && null != hotGoods && hotGoods.size() > 0) {
-            for (GoodsVo goodsVo : hotGoods) {
-                for (CartVo cartVo : cartList) {
-                    if (goodsVo.getId().equals(cartVo.getGoods_id())) {
-                        goodsVo.setCart_num(cartVo.getNumber());
-                    }
-                }
-            }
-        }
+
         return toResponsSuccess(resultObj);
     }
 

+ 7 - 0
kmall-api/src/main/java/com/kmall/api/dao/ApiGoodsMapper.java

@@ -21,4 +21,11 @@ public interface ApiGoodsMapper extends BaseDao<GoodsVo> {
     List<GoodsVo> queryCatalogProductList(Map<String, Object> params);
 
     GoodsVo queryObjectByStoreId(@Param("id") Long id, @Param("storeId") Long storeId);
+
+    /**
+     * 更新共享库存
+     *
+     * @return
+     */
+    void updateGoodsStock(GoodsVo goodsVo);
 }

+ 6 - 0
kmall-api/src/main/java/com/kmall/api/dao/ApiProductMapper.java

@@ -12,6 +12,12 @@ import org.springframework.stereotype.Component;
  */
 @Component
 public interface ApiProductMapper extends BaseDao<ProductVo> {
+    /**
+     * 暂时无用
+     * @param id
+     * @param store_id
+     * @return
+     */
     ProductVo queryObjectByStoreId(@Param("id") Long id, @Param("store_id") Long store_id);
 
     /**

+ 20 - 0
kmall-api/src/main/java/com/kmall/api/dao/ApiThirdMerchantBizMapper.java

@@ -0,0 +1,20 @@
+package com.kmall.api.dao;
+
+import com.kmall.api.entity.GoodsVo;
+import com.kmall.api.entity.ThirdMerchantBizVo;
+import com.kmall.common.dao.BaseDao;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Scott
+ * @email
+ * @date 2017-08-11 09:16:45
+ */
+@Component
+public interface ApiThirdMerchantBizMapper extends BaseDao<ThirdMerchantBizVo> {
+    ThirdMerchantBizVo getThirdMerchangByCode(@Param("thirdMerchantCode")String thirdMerchantCode);
+}

+ 20 - 0
kmall-api/src/main/java/com/kmall/api/entity/CartVo.java

@@ -68,6 +68,26 @@ public class CartVo implements Serializable {
 
     private String merchSn;
 
+    private Integer goodsNumber;
+
+    private String isStockShare;
+
+    public String getIsStockShare() {
+        return isStockShare;
+    }
+
+    public void setIsStockShare(String isStockShare) {
+        this.isStockShare = isStockShare;
+    }
+
+    public Integer getGoodsNumber() {
+        return goodsNumber;
+    }
+
+    public void setGoodsNumber(Integer goodsNumber) {
+        this.goodsNumber = goodsNumber;
+    }
+
     public String getMerchSn() {
         return merchSn;
     }

+ 49 - 1
kmall-api/src/main/java/com/kmall/api/entity/GoodsVo.java

@@ -57,8 +57,10 @@ public class GoodsVo implements Serializable {
     private BigDecimal market_price;
     //零售价格(现价)
     private BigDecimal retail_price;
-    //销售量
+    //门店销售量
     private Integer sell_volume;
+    //商品销售量
+    private Integer goods_sell_volume;
     //主sku product_id
     private Integer primary_product_id;
     //单位价格,单价
@@ -109,6 +111,52 @@ public class GoodsVo implements Serializable {
 
     private String merchName;
 
+    /**
+     * 第三方商户代码
+     */
+    private String thirdPartyMerchCode;
+
+    private String isStockShare;
+
+    public void addSellVolume() {
+        if (null == sell_volume) {
+            sell_volume = 1;
+        } else {
+            sell_volume++;
+        }
+    }
+
+    public void minusSellVolume() {
+        if (null == sell_volume || 0 == sell_volume) {
+            sell_volume = 0;
+        } else {
+            sell_volume--;
+        }
+    }
+    public Integer getGoods_sell_volume() {
+        return goods_sell_volume;
+    }
+
+    public void setGoods_sell_volume(Integer goods_sell_volume) {
+        this.goods_sell_volume = goods_sell_volume;
+    }
+
+    public String getThirdPartyMerchCode() {
+        return thirdPartyMerchCode;
+    }
+
+    public void setThirdPartyMerchCode(String thirdPartyMerchCode) {
+        this.thirdPartyMerchCode = thirdPartyMerchCode;
+    }
+
+    public String getIsStockShare() {
+        return isStockShare;
+    }
+
+    public void setIsStockShare(String isStockShare) {
+        this.isStockShare = isStockShare;
+    }
+
     public Integer getStoreId() {
         return storeId;
     }

+ 203 - 0
kmall-api/src/main/java/com/kmall/api/entity/ThirdMerchantBizVo.java

@@ -0,0 +1,203 @@
+package com.kmall.api.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 第三方商户表实体
+ * 表名 third_merchant_biz
+ *
+ * @author emato
+ * @email admin@qhdswl.com
+ * @date 2019-02-15 11:43:32
+ */
+public class ThirdMerchantBizVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 第三方商户编号,主键编号
+     */
+    private Integer thirdMerchSn;
+
+    private String merchSn;
+    /**
+     * 第三方商户代码
+     */
+    private String thirdPartyMerchCode;
+    /**
+     * 第三方商户名称
+     */
+    private String thirdPartyMerchName;
+
+    private String isStockShare;
+
+    private String isStoreUserShare;
+
+
+    /**
+     * 是否有效,0:有效,1:无效
+     */
+    private String isValid;
+    /**
+     * 创建人序号
+     */
+    private String createrSn;
+    /**
+     * 创建时间,yyyy-MM-dd HH:mm:ss
+     */
+    private Date createTime;
+    /**
+     * 
+     */
+    private String moderSn;
+    /**
+     * 修改时间,yyyy-MM-dd HH:mm:ss
+     */
+    private Date modTime;
+    /**
+     * 时间戳
+     */
+    private Date tstm;
+
+    public String getIsStoreUserShare() {
+        return isStoreUserShare;
+    }
+
+    public void setIsStoreUserShare(String isStoreUserShare) {
+        this.isStoreUserShare = isStoreUserShare;
+    }
+
+    public String getIsStockShare() {
+        return isStockShare;
+    }
+
+    public void setIsStockShare(String isStockShare) {
+        this.isStockShare = isStockShare;
+    }
+
+    public String getMerchSn() {
+        return merchSn;
+    }
+
+    public void setMerchSn(String merchSn) {
+        this.merchSn = merchSn;
+    }
+
+    /**
+     * 设置:第三方商户编号,主键编号
+     */
+    public void setThirdMerchSn(Integer thirdMerchSn) {
+        this.thirdMerchSn = thirdMerchSn;
+    }
+
+    /**
+     * 获取:第三方商户编号,主键编号
+     */
+    public Integer getThirdMerchSn() {
+        return thirdMerchSn;
+    }
+    /**
+     * 设置:第三方商户代码
+     */
+    public void setThirdPartyMerchCode(String thirdPartyMerchCode) {
+        this.thirdPartyMerchCode = thirdPartyMerchCode;
+    }
+
+    /**
+     * 获取:第三方商户代码
+     */
+    public String getThirdPartyMerchCode() {
+        return thirdPartyMerchCode;
+    }
+    /**
+     * 设置:第三方商户名称
+     */
+    public void setThirdPartyMerchName(String thirdPartyMerchName) {
+        this.thirdPartyMerchName = thirdPartyMerchName;
+    }
+
+    /**
+     * 获取:第三方商户名称
+     */
+    public String getThirdPartyMerchName() {
+        return thirdPartyMerchName;
+    }
+    /**
+     * 设置:是否有效,0:有效,1:无效
+     */
+    public void setIsValid(String isValid) {
+        this.isValid = isValid;
+    }
+
+    /**
+     * 获取:是否有效,0:有效,1:无效
+     */
+    public String getIsValid() {
+        return isValid;
+    }
+    /**
+     * 设置:创建人序号
+     */
+    public void setCreaterSn(String createrSn) {
+        this.createrSn = createrSn;
+    }
+
+    /**
+     * 获取:创建人序号
+     */
+    public String getCreaterSn() {
+        return createrSn;
+    }
+    /**
+     * 设置:创建时间,yyyy-MM-dd HH:mm:ss
+     */
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    /**
+     * 获取:创建时间,yyyy-MM-dd HH:mm:ss
+     */
+    public Date getCreateTime() {
+        return createTime;
+    }
+    /**
+     * 设置:
+     */
+    public void setModerSn(String moderSn) {
+        this.moderSn = moderSn;
+    }
+
+    /**
+     * 获取:
+     */
+    public String getModerSn() {
+        return moderSn;
+    }
+    /**
+     * 设置:修改时间,yyyy-MM-dd HH:mm:ss
+     */
+    public void setModTime(Date modTime) {
+        this.modTime = modTime;
+    }
+
+    /**
+     * 获取:修改时间,yyyy-MM-dd HH:mm:ss
+     */
+    public Date getModTime() {
+        return modTime;
+    }
+    /**
+     * 设置:时间戳
+     */
+    public void setTstm(Date tstm) {
+        this.tstm = tstm;
+    }
+
+    /**
+     * 获取:时间戳
+     */
+    public Date getTstm() {
+        return tstm;
+    }
+}

+ 81 - 18
kmall-api/src/main/java/com/kmall/api/service/ApiOrderService.java

@@ -106,9 +106,37 @@ public class ApiOrderService {
         List<OrderGoodsVo> goodsList = apiOrderGoodsMapper.queryList(orderGoodsParam);
         for (OrderGoodsVo orderGoodsVo : goodsList) {
             ProductVo productInfo = apiProductMapper.queryByStoreId(orderGoodsVo.getProduct_id(), order.getStore_id());
-            productInfo.setStock_num(productInfo.getStock_num() + orderGoodsVo.getNumber());
-            productInfo.minusSellVolume();
-            apiProductMapper.updateStockNum(productInfo);
+
+            GoodsVo goodsInfo = apiGoodsMapper.queryObjectByStoreId(orderGoodsVo.getGoods_id(), order.getStore_id());
+            if (null == goodsInfo || goodsInfo.getIs_delete() == 1 || goodsInfo.getIs_on_sale() == 0) {
+                throw new RRException("订单提交失败:商品不存在");
+            }
+            Integer stockNum = 0;
+            // TODO: 2019/3/5  普通商品不受共享库存影响,直接取门店配置库存
+            if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
+                if (goodsInfo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())) {
+                    //还原商户商品库存
+                    stockNum = goodsInfo.getGoods_number();
+                    goodsInfo.setGoods_number(stockNum + orderGoodsVo.getNumber());
+                    goodsInfo.minusSellVolume();
+                    apiGoodsMapper.updateGoodsStock(goodsInfo);
+                }
+                if (goodsInfo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
+                    //还原门店库存
+                    stockNum = productInfo.getStock_num();
+                    productInfo.setStock_num(stockNum + orderGoodsVo.getNumber());
+                    productInfo.minusSellVolume();
+                    productInfo.setGoods_id(goodsInfo.getId());
+                    apiProductMapper.updateStockNum(productInfo);
+                }
+            }else {
+                //还原门店库存
+                stockNum = productInfo.getStock_num();
+                productInfo.setStock_num(stockNum + orderGoodsVo.getNumber());
+                productInfo.setGoods_id(goodsInfo.getId());
+                productInfo.minusSellVolume();
+                apiProductMapper.updateStockNum(productInfo);
+            }
         }
         update(order);
         // 判断是否有优惠券
@@ -200,21 +228,47 @@ public class ApiOrderService {
             return resultObj;
         }
         // 检查库存和更新库存
-        List<ProductVo> productVos = new ArrayList();
+//        List<ProductVo> productVos = new ArrayList();
         for (CartVo goodsItem : checkedGoodsList) {
+            Integer stockNum = 0;
             //取得规格的信息,判断规格库存
+            GoodsVo goodsInfo = apiGoodsMapper.queryObjectByStoreId(goodsItem.getGoods_id(), storeId);
+            if (null == goodsInfo || goodsInfo.getIs_delete() == 1 || goodsInfo.getIs_on_sale() == 0) {
+                throw new RRException("订单提交失败:商品不存在");
+            }
             ProductVo productInfo = apiProductMapper.queryByStoreId(goodsItem.getProduct_id(), storeId);
+
             synchronized (productInfo){
-                if (null == productInfo || null == productInfo.getStock_num() || productInfo.getStock_num() < goodsItem.getNumber()) {
-                    resultObj.put("errno", 400);
-                    resultObj.put("errmsg", "库存不足,仅剩余" + productInfo.getStock_num());
-                    return resultObj;
+                if (null == productInfo) {
+                    throw new RRException("订单提交失败:商品已下架");
+                }
+                // TODO: 2019/3/5  普通商品不受共享库存影响,直接取门店配置库存
+                if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
+                    if (goodsInfo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())) {
+                        stockNum = goodsInfo.getGoods_number();
+                    }
+                    if (goodsInfo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
+                        stockNum = productInfo.getStock_num();
+                    }
+                }else {
+                    stockNum = productInfo.getStock_num();
+                }
+                if (null == stockNum || stockNum < goodsItem.getNumber() || stockNum <= 0) {
+                    throw new RRException("订单提交失败:库存不足,仅剩余" + stockNum);
                 }else{
-                    productInfo.setStock_num(productInfo.getStock_num() - goodsItem.getNumber());
-                    productInfo.setStore_id(storeId);
-                    productInfo.addSellVolume();
-                    productVos.add(productInfo);
-                    apiProductMapper.updateStockNum(productInfo);
+                    if(goodsInfo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
+                        if (goodsInfo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())) {
+                            //扣减商户商品库存
+                            updateGoodsStock(goodsInfo,stockNum,goodsItem);
+                        }
+                        if (goodsInfo.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
+                            //扣减门店库存
+                            updateStock(productInfo,goodsInfo,stockNum,goodsItem,storeId);
+                        }
+                    }else {
+                        //扣减门店库存
+                        updateStock(productInfo,goodsInfo,stockNum,goodsItem,storeId);
+                    }
                 }
             }
         }
@@ -381,6 +435,20 @@ public class ApiOrderService {
 
         return resultObj;
     }
+    private void updateGoodsStock(GoodsVo goodsVo,Integer stockNum,CartVo goodsItem){
+        goodsVo.setGoods_number(stockNum - goodsItem.getNumber());
+        goodsVo.addSellVolume();
+        goodsVo.setId(goodsVo.getId());
+        apiGoodsMapper.updateGoodsStock(goodsVo);
+    }
+    private void updateStock(ProductVo productInfo,GoodsVo goodsVo,Integer stockNum,CartVo goodsItem,Long storeId){
+        productInfo.setStock_num(stockNum - goodsItem.getNumber());
+        productInfo.setStore_id(storeId);
+        productInfo.addSellVolume();
+        productInfo.setGoods_id(goodsVo.getId());
+//        productVos.add(productInfo);
+        apiProductMapper.updateStockNum(productInfo);
+    }
 
     /**
      * 设置订单数据
@@ -557,23 +625,18 @@ public class ApiOrderService {
         if(orderInfo.getFreight_price()!=0 && !"0".equalsIgnoreCase(orderInfo.getCoupon_price()+"")){
             //运费-优惠券
             BigDecimal rateTotal = freightPrice.subtract(orderInfo.getCoupon_price());
-
             //商品结算平摊价格(含优惠券、运费金额) = 单商品总价 + 单商品总价/订单总价(不含运费、不含优惠券) * 运费与优惠券合计税率
             settlePrice = goodsTotal.add(rate.multiply(rateTotal));
         }else{
             if(orderInfo.getFreight_price()!=0){
                 //运费税率 = 单商品总价/订单总价(不含运费)* 运费金额
                 BigDecimal freightRate = rate.multiply(freightPrice);
-
                 //商品结算平摊价格(含运费金额) = 单商品总价+运费税率
                 settlePrice = goodsTotal.add(freightRate);
-
             }
             if(!"0".equalsIgnoreCase(orderInfo.getCoupon_price()+"")){
-
                 //优惠券税率 = 单商品总价/订单总价(不含优惠券)* 优惠券金额
                 BigDecimal couponRate = rate.multiply(orderInfo.getCoupon_price());
-
                 //商品结算平摊价格(含优惠券金额) = 单商品总价-优惠券税率
                 settlePrice = goodsTotal.subtract(couponRate);
             }

+ 62 - 0
kmall-api/src/main/java/com/kmall/api/service/ApiThirdMerchantBizService.java

@@ -0,0 +1,62 @@
+package com.kmall.api.service;
+
+import com.kmall.api.dao.ApiFreightMapper;
+import com.kmall.api.dao.ApiThirdMerchantBizMapper;
+import com.kmall.api.entity.FreightEntity;
+import com.kmall.api.entity.ThirdMerchantBizVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Service实现类
+ *
+ * @author
+ */
+@Service
+public class ApiThirdMerchantBizService {
+    @Autowired
+    private ApiThirdMerchantBizMapper thirdMerchantBizMapper;
+
+    
+    public ThirdMerchantBizVo queryObject(Integer id) {
+        return thirdMerchantBizMapper.queryObject(id);
+    }
+
+    
+    public List<ThirdMerchantBizVo> queryList(Map<String, Object> map) {
+        return thirdMerchantBizMapper.queryList(map);
+    }
+
+    
+    public int queryTotal(Map<String, Object> map) {
+        return thirdMerchantBizMapper.queryTotal(map);
+    }
+
+    
+    public int save(ThirdMerchantBizVo thirdMerchantBizVo) {
+        return thirdMerchantBizMapper.save(thirdMerchantBizVo);
+    }
+
+    
+    public int update(ThirdMerchantBizVo thirdMerchantBizVo) {
+        return thirdMerchantBizMapper.update(thirdMerchantBizVo);
+    }
+
+    
+    public int delete(Integer id) {
+        return thirdMerchantBizMapper.delete(id);
+    }
+
+    
+    public int deleteBatch(Integer[]ids) {
+        return thirdMerchantBizMapper.deleteBatch(ids);
+    }
+
+
+    public ThirdMerchantBizVo getThirdMerchangByCode(String thirdMerchantCode) {
+        return thirdMerchantBizMapper.getThirdMerchangByCode(thirdMerchantCode);
+    }
+}

+ 32 - 4
kmall-api/src/main/resources/mybatis/mapper/ApiCartMapper.xml

@@ -28,6 +28,8 @@
         <result column="tstm" property="tstm" jdbcType="TIMESTAMP" />
         <result property="stockNum" column="productStockNum"/>
         <result property="merchSn" column="merch_sn"/>
+        <result property="goodsNumber" column="goods_number"/>
+
     </resultMap>
 
     <sql id="Base_Column_List" >
@@ -50,13 +52,23 @@
     <select id="queryList" resultMap="cartMap">
         select a.*,
         b.list_pic_url as list_pic_url,
-        psr.retail_price as retail_product_price,psr.stock_num 'productStockNum'
+        psr.retail_price as retail_product_price,psr.stock_num 'productStockNum',
+        b.goods_number,mb.is_stock_share isStockShare
         from mall_cart a
         left join mall_goods b on a.goods_id = b.id
+        left join third_merchant_biz mb on b.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=b.merch_sn
         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 and b.is_on_sale = 1
-        and psr.stock_num > 0
+        <if test="isStockShare == 1 and checkCart != null and checkCart == '00'">
+            and b.goods_number > 0
+        </if>
+        <if test="isStockShare == 0 and checkCart != null and checkCart == '00'">
+            and psr.stock_num > 0
+        </if>
+        <if test="checkCart != null and checkCart == '11'">
+            and psr.stock_num > 0
+        </if>
         <if test="checkCart != null and checkCart == '00'">
             and b.goods_biz_type != '11'
         </if>
@@ -101,7 +113,15 @@
         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 or b.is_on_sale = 0)
+        <if test="isStockShare == 1 and checkCart != null and checkCart == '00'">
+            and (b.goods_number = 0 or b.is_on_sale = 0)
+        </if>
+        <if test="isStockShare == 0 and checkCart != null and checkCart == '00'">
+            and (psr.stock_num = 0 or b.is_on_sale = 0)
+        </if>
+        <if test="checkCart != null and checkCart == '11'">
+            and (psr.stock_num = 0 or b.is_on_sale = 0)
+        </if>
         <if test="checkCart != null and checkCart == '00'">
             and b.goods_biz_type != '11'
         </if>
@@ -146,7 +166,15 @@
         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 and b.is_on_sale = 1
-        and psr.stock_num > 0
+        <if test="isStockShare == 1 and checkCart != null and checkCart == '00'">
+            and b.goods_number > 0
+        </if>
+        <if test="isStockShare == 0 and checkCart != null and checkCart == '00'">
+            and psr.stock_num > 0
+        </if>
+        <if test="checkCart != null and checkCart == '11'">
+            and psr.stock_num > 0
+        </if>
         <if test="checkCart != null and checkCart == '00'">
             and b.goods_biz_type != '11'
         </if>

+ 50 - 10
kmall-api/src/main/resources/mybatis/mapper/ApiGoodsMapper.xml

@@ -49,6 +49,10 @@
         <result property="storeId" column="store_id"/>
         <result property="merchSn" column="merch_sn"/>
         <result property="merchName" column="merch_name"/>
+        <result column="third_party_merch_code" property="thirdPartyMerchCode" />
+        <result column="isStockShare" property="isStockShare" />
+        <result property="goods_sell_volume" column="goods_sell_volume"/>
+
     </resultMap>
 
     <sql id="Base_Column_List" >
@@ -57,7 +61,7 @@
         extra_price, is_new, goods_unit, primary_pic_url, list_pic_url, retail_price, sell_volume,
         primary_product_id, unit_price, promotion_desc, promotion_tag, app_exclusive_price,
         is_app_exclusive, is_limited, is_hot, market_price, creater_sn, create_time, moder_sn,
-        mod_time, tstm,goods_desc,goods_rate
+        mod_time, tstm,goods_desc,goods_rate,third_party_merch_code
     </sql>
 
     <select id="queryObject" resultMap="goodsMap">
@@ -94,8 +98,9 @@
         psr1.store_id,
         psr1.market_price,
         psr1.stock_num,
-        a.goods_desc,a.goods_biz_type,a.goods_rate
+        a.goods_desc,a.goods_biz_type,a.goods_rate,a.third_party_merch_code,mb.is_stock_share isStockShare
         from mall_goods a LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
+        left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
 		where a.id = #{value}
 	</select>
 
@@ -122,7 +127,7 @@
         a.primary_pic_url,
         a.list_pic_url,
         psr1.retail_price,
-        a.sell_volume,
+        psr1.sell_volume,
         a.primary_product_id,
         a.unit_price,
         a.promotion_desc,
@@ -136,8 +141,9 @@
         psr1.store_id,
         psr1.market_price,
         psr1.stock_num,
-        a.goods_desc,a.goods_biz_type,a.goods_rate
+        a.goods_desc,a.goods_biz_type,a.goods_rate,a.third_party_merch_code,mb.is_stock_share isStockShare,a.sell_volume goods_sell_volume
         from mall_goods a left join mall_merch m on a.merch_sn = m.merch_sn
+        left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
         LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
         where a.id = #{id} and psr1.store_id = #{storeId}
     </select>
@@ -150,12 +156,15 @@
         <if test="fields == null or fields == ''">
             a.*
         </if>
-        ,psr1.stock_num,psr1.category_id,psr1.brand_id,psr1.attribute_category
+        ,psr1.stock_num,psr1.category_id,psr1.brand_id,psr1.attribute_category,a.third_party_merch_code
+        ,a.goods_biz_type,a.goods_number,mb.is_stock_share isStockShare
         from mall_goods a
         LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
+        left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
         LEFT JOIN mall_product b ON b.id = psr1.product_id
         left join mall_category c on psr1.category_id = c.id
-        where 1 = 1 and a.is_delete != 1 and psr1.stock_num > 0 and a.is_on_sale = 1
+        where 1 = 1
+        and a.is_delete != 1  and a.is_on_sale = 1
         <if test="is_new != null and is_new != ''">
             and a.is_new = #{is_new}
         </if>
@@ -220,10 +229,22 @@
         <if test="fields == null or fields == ''">
             a.*,b.id as product_id,psr1.category_id,psr1.brand_id,psr1.attribute_category
         </if>
+        ,a.goods_biz_type,
+        a.goods_number,
+        a.third_party_merch_code third_party_merch_code,
+        mb.is_stock_share isStockShare
         from mall_goods a
         LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
+        left join third_merchant_biz mb on mb.third_party_merch_code = a.third_party_merch_code and mb.merch_sn=a.merch_sn
         LEFT JOIN mall_product b ON b.id = psr1.product_id
-        where 1 = 1 and b.id is not null and psr1.stock_num > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
+        where 1 = 1
+        <if test="isStockShare == 1">
+            and (a.goods_number > 0  or psr1.stock_num > 0 )
+        </if>
+        <if test="isStockShare == 0">
+            and psr1.stock_num > 0
+        </if>
+        and b.id is not null and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
         <if test="is_new != null and is_new != ''">
             and a.is_new = #{is_new}
         </if>
@@ -271,19 +292,22 @@
     </select>
 
     <select id="queryCatalogProductList" resultMap="goodsMap">
-        select a.id, a.name, a.list_pic_url,psr1.category_id,psr1.brand_id,psr1.attribute_category , psr1.market_price, psr1.retail_price, a.goods_brief, b.id AS product_id,psr1.stock_num
+        select a.id, a.name, a.list_pic_url,psr1.category_id,psr1.brand_id,psr1.attribute_category , psr1.market_price, psr1.retail_price, a.goods_brief, b.id AS product_id,
+        psr1.stock_num,a.third_party_merch_code,a.goods_biz_type,a.goods_number,
+        mb.is_stock_share isStockShare
         <if test="is_group != null and is_group == true">
            ,gg.id as group_id
         </if>
         FROM
         mall_goods a
         LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
+        left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
         LEFT JOIN mall_product b ON b.id = psr1.product_id
         <if test="is_group != null and is_group == true">
             left join mall_goods_group gg on gg.goods_id = a.id
         </if>
         WHERE
-        1 = 1 AND psr1.stock_num > 0 and b.id > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
+        1 = 1  and b.id > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
         <if test="is_new != null and is_new != ''">
             and a.is_new = #{is_new}
         </if>
@@ -346,7 +370,14 @@
         select count(*)
         from mall_goods a
         left join mall_product_store_rela s on a.id = s.goods_id and a.merch_sn = s.merch_sn
-        where 1 = 1 and a.is_on_sale = 1 AND s.stock_num > 0
+        left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
+        where 1 = 1 and a.is_on_sale = 1
+        <if test="isStockShare == 1">
+          and (a.goods_number > 0  or s.stock_num > 0 )
+        </if>
+        <if test="isStockShare == 0">
+            and s.stock_num > 0
+        </if>
         <if test="storeId != null and storeId != ''">
             and s.store_id = #{storeId}
         </if>
@@ -393,4 +424,13 @@
             and a.goods_biz_type in ('00','11')
         </if>
     </select>
+
+    <update id="updateGoodsStock" parameterType="com.kmall.api.entity.GoodsVo">
+        update mall_goods a
+        <set>
+            <if test="goods_number != null">a.`goods_number` = #{goods_number},</if>
+            <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
+        </set>
+        where a.id = #{id}
+    </update>
 </mapper>

+ 5 - 3
kmall-api/src/main/resources/mybatis/mapper/ApiProductMapper.xml

@@ -95,8 +95,9 @@
         FROM
         mall_product a
         LEFT JOIN mall_product_store_rela b ON a.id = b.product_id
+        left join mall_goods g on g.id=b.goods_id
         <where>
-            b.stock_num > 0
+            1=1 and (g.goods_number > 0  or b.stock_num > 0 )
             <if test="goods_id != null">
                 and a.goods_id = #{goods_id}
             </if>
@@ -122,8 +123,9 @@
         FROM
         mall_product a
         LEFT JOIN mall_product_store_rela b ON a.id = b.product_id
+        left join mall_goods g on g.id=b.goods_id
         <where>
-            b.stock_num > 0
+            1=1 and (g.goods_number > 0  or b.stock_num > 0 )
             <if test="goods_id != null">
                 and a.goods_id = #{goods_id}
             </if>
@@ -139,7 +141,7 @@
             <if test="stock_num != null">a.`stock_num` = #{stock_num},</if>
             <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
         </set>
-        where a.product_id = #{id} and a.store_id = #{store_id}
+        where a.product_id = #{id} and a.store_id = #{store_id} and a.goods_id = #{goods_id}
     </update>
 
     <update id="updateSellVolumeNum" parameterType="com.kmall.api.entity.ProductVo">

+ 183 - 0
kmall-api/src/main/resources/mybatis/mapper/ApiThirdMerchantBizMapper.xml

@@ -0,0 +1,183 @@
+<?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.kmall.api.dao.ApiThirdMerchantBizMapper">
+
+    <resultMap type="com.kmall.api.entity.ThirdMerchantBizVo" id="thirdMerchantBizMap">
+        <result property="thirdMerchSn" column="third_merch_sn"/>
+		<result property="merchSn" column="merch_sn"/>
+        <result property="thirdPartyMerchCode" column="third_party_merch_code"/>
+        <result property="thirdPartyMerchName" column="third_party_merch_name"/>
+		<result property="isStockShare" column="is_stock_share"/>
+		<result property="isStoreUserShare" column="is_store_user_share"/>
+        <result property="isValid" column="is_valid"/>
+        <result property="createrSn" column="creater_sn"/>
+        <result property="createTime" column="create_time"/>
+        <result property="moderSn" column="moder_sn"/>
+        <result property="modTime" column="mod_time"/>
+        <result property="tstm" column="tstm"/>
+    </resultMap>
+
+	<select id="queryObject" resultType="com.kmall.api.entity.ThirdMerchantBizVo">
+		select
+			`third_merch_sn`,
+            `merch_sn`,
+			`third_party_merch_code`,
+			`third_party_merch_name`,
+			`is_valid`,
+			is_stock_share,
+			is_store_user_share,
+			`creater_sn`,
+			`create_time`,
+			`moder_sn`,
+			`mod_time`,
+			`tstm`
+		from third_merchant_biz
+		where third_merch_sn = #{id}
+	</select>
+
+	<select id="findByMerchSn" resultType="com.kmall.api.entity.ThirdMerchantBizVo">
+		select
+		`third_merch_sn`,
+		`merch_sn`,
+		`third_party_merch_code`,
+		`third_party_merch_name`,
+		`is_valid`,
+		is_stock_share,
+		is_store_user_share,
+		`creater_sn`,
+		`create_time`,
+		`moder_sn`,
+		`mod_time`,
+		`tstm`
+		from third_merchant_biz
+		where merch_sn = #{value}
+	</select>
+
+	<select id="getThirdMerchangByCode" resultType="com.kmall.api.entity.ThirdMerchantBizVo">
+		select
+		`third_merch_sn`,
+		`merch_sn`,
+		`third_party_merch_code`,
+		`third_party_merch_name`,
+		`is_valid`,
+		is_stock_share,
+		is_store_user_share,
+		`creater_sn`,
+		`create_time`,
+		`moder_sn`,
+		`mod_time`,
+		`tstm`
+		from third_merchant_biz
+		where third_party_merch_code = #{thirdMerchantCode}
+	</select>
+
+	<select id="queryList" resultType="com.kmall.api.entity.ThirdMerchantBizVo">
+		select
+    		`third_merch_sn`,
+			`merch_sn`,
+    		`third_party_merch_code`,
+    		`third_party_merch_name`,
+    		`is_valid`,
+			is_stock_share,
+		is_store_user_share,
+    		`creater_sn`,
+    		`create_time`,
+    		`moder_sn`,
+    		`mod_time`,
+    		`tstm`
+		from third_merchant_biz
+		WHERE 1=1
+		<if test="name != null and name.trim() != ''">
+			AND name LIKE concat('%',#{name},'%')
+		</if>
+		<if test="merchSn != null and merchSn.trim() != ''">
+			and merch_sn = #{merchSn}
+		</if>
+		<if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
+			and third_party_merch_code = #{thirdPartyMerchCode}
+		</if>
+        <choose>
+            <when test="sidx != null and sidx.trim() != ''">
+                order by ${sidx} ${order}
+            </when>
+			<otherwise>
+                order by third_merch_sn desc
+			</otherwise>
+        </choose>
+		<if test="offset != null and limit != null">
+			limit #{offset}, #{limit}
+		</if>
+	</select>
+	
+ 	<select id="queryTotal" resultType="int">
+		select count(*) from third_merchant_biz
+		WHERE 1=1
+        <if test="name != null and name.trim() != ''">
+            AND name LIKE concat('%',#{name},'%')
+        </if>
+		<if test="merchSn != null and merchSn.trim() != ''">
+			and merch_sn = #{merchSn}
+		</if>
+		<if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
+			and third_party_merch_code = #{thirdPartyMerchCode}
+		</if>
+	</select>
+
+	<insert id="save" parameterType="com.kmall.api.entity.ThirdMerchantBizVo" useGeneratedKeys="true" keyProperty="thirdMerchSn">
+		insert into third_merchant_biz(
+			`merch_sn`,
+			`third_party_merch_code`,
+			`third_party_merch_name`,
+			`is_valid`,
+			is_stock_share,
+			is_store_user_share,
+			`creater_sn`,
+			`create_time`,
+			`moder_sn`,
+			`mod_time`,
+			`tstm`)
+		values(
+			#{merchSn},
+			#{thirdPartyMerchCode},
+			#{thirdPartyMerchName},
+			#{isValid},
+			#{isStockShare},
+			#{isStoreUserShare},
+			#{createrSn},
+			#{createTime},
+			#{moderSn},
+			#{modTime},
+			#{tstm})
+	</insert>
+
+	<update id="update" parameterType="com.kmall.api.entity.ThirdMerchantBizVo">
+		update third_merchant_biz 
+		<set>
+			<if test="merchSn != null">`merch_sn` = #{merchSn},</if>
+			<if test="thirdPartyMerchCode != null">`third_party_merch_code` = #{thirdPartyMerchCode}, </if>
+			<if test="thirdPartyMerchName != null">`third_party_merch_name` = #{thirdPartyMerchName}, </if>
+			<if test="isValid != null">`is_valid` = #{isValid}, </if>
+			<if test="isStockShare != null">`is_stock_share` = #{isStockShare}, </if>
+			<if test="isStoreUserShare != null">`is_store_user_share` = #{isStoreUserShare}, </if>
+			<if test="createrSn != null">`creater_sn` = #{createrSn}, </if>
+			<if test="createTime != null">`create_time` = #{createTime}, </if>
+			<if test="moderSn != null">`moder_sn` = #{moderSn}, </if>
+			<if test="modTime != null">`mod_time` = #{modTime}, </if>
+			<if test="tstm != null">`tstm` = #{tstm}</if>
+		</set>
+		where third_merch_sn = #{thirdMerchSn}
+	</update>
+	
+	<delete id="delete">
+		delete from third_merchant_biz where third_merch_sn = #{value}
+	</delete>
+	
+	<delete id="deleteBatch">
+		delete from third_merchant_biz where third_merch_sn in 
+		<foreach item="thirdMerchSn" collection="array" open="(" separator="," close=")">
+			#{thirdMerchSn}
+		</foreach>
+	</delete>
+
+</mapper>