Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

wangming 1 день назад
Родитель
Сommit
cea5db5fb7

+ 13 - 1
yami-shop-bean/src/main/java/com/yami/shop/bean/model/CategoryProd.java

@@ -12,8 +12,10 @@ package com.yami.shop.bean.model;
 
 import com.baomidou.mybatisplus.annotation.*;
 import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import java.io.Serializable;
+import java.util.Date;
 
 @Data
 @TableName("tz_category_prod")
@@ -24,7 +26,6 @@ public class CategoryProd implements Serializable {
     /**
      * 分类id
      */
-
     private Long categoryId;
 
     /**
@@ -35,8 +36,19 @@ public class CategoryProd implements Serializable {
 
     private String code;
 
+    /**
+     * 门店
+     */
+    private Long shopId;
+
     /**
      * 0 正常,1 删除
      */
     private Integer isDelete;
+
+    /**
+     * 创建时间
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
 }

+ 6 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/model/ShopCategory.java

@@ -100,6 +100,12 @@ public class ShopCategory implements Serializable {
     @TableField(exist = false)
     private String subName;
 
+    /**
+     * 商品数量
+     */
+    @TableField(exist = false)
+    private Integer prodCount;
+
     @TableField(exist = false)
     private List<ShopCategory> children;
 }

+ 5 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/model/ShopSku.java

@@ -59,6 +59,11 @@ public class ShopSku implements Serializable {
      */
     private Integer shopSkuStocks;
 
+    /**
+     * 可售状态 (1-可售,0-不可售)
+     */
+    private Integer saleStatus;
+
     /**
      * 0 正常 1 已被删除
      */

+ 27 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/param/CategoryProductDTO.java

@@ -0,0 +1,27 @@
+package com.yami.shop.bean.param;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Data
+public class CategoryProductDTO {
+    /**
+     * 门店分类id
+     */
+    @NotNull(message = "门店分类id不能为空")
+    private Long categoryId;
+
+     /**
+     * 分类code
+     */
+     @NotNull(message = "分类code不能为空")
+    private String code;
+
+    /**
+     *  商品idList
+     */
+    private List<Long> prodIdList;
+
+}

+ 0 - 1
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/OrderRefundController.java

@@ -94,7 +94,6 @@ public class OrderRefundController {
         IPage<OrderRefundVo> page1 = orderRefundService.orderRefundPage(page, orderRefund);
         for (OrderRefundVo record : page1.getRecords()) {
             record.setOrderRefundSkuList(orderRefundskuMapper.selectByRefundId(record.getRefundId()));
-
         }
         return R.SUCCESS(page1);
     }

+ 12 - 0
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/ShopCategoryController.java

@@ -3,6 +3,7 @@ package com.yami.shop.platform.controller;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yami.shop.bean.model.ShopCategory;
+import com.yami.shop.bean.param.CategoryProductDTO;
 import com.yami.shop.common.util.PageParam;
 import com.yami.shop.common.util.R;
 import com.yami.shop.service.IShopCategoryService;
@@ -91,6 +92,7 @@ public class ShopCategoryController {
     @PostMapping("/import")
     @ApiOperation(value = "导入门店前台类目", notes = "导入门店前台类目")
     public R importCategory(@RequestParam("file") MultipartFile file) {
+
         shopCategoryService.importCategory(file);
         return R.SUCCESS();
     }
@@ -185,6 +187,16 @@ public class ShopCategoryController {
         return R.FAIL("删除门店前台类目失败");
     }
 
+    /**
+     * 绑定分类商品
+     */
+    @PostMapping("/categoryProduct")
+    @ApiOperation(value = "绑定门店分类商品", notes = "绑定门店分类商品")
+    public R categoryProduct(@Valid @RequestBody CategoryProductDTO categoryProductDTO) {
+        shopCategoryService.categoryProduct(categoryProductDTO);
+        return R.SUCCESS("绑定商品成功");
+    }
+
 
 
 }

+ 8 - 0
yami-shop-service/src/main/java/com/yami/shop/dao/ShopCategoryMapper.java

@@ -41,4 +41,12 @@ public interface ShopCategoryMapper extends BaseMapper<ShopCategory> {
      *
      */
     int  deleteByParentCode(@Param("parentCode") String parentCode);
+
+    /**
+     * 根据名称查询门店对应分类
+     * @param shopId 门店id
+     * @param name 分类名称
+     * @return 门店对应分类
+     */
+    List<ShopCategory> selectListAll(@Param("shopId") Long shopId, @Param("name") String name);
 }

+ 8 - 2
yami-shop-service/src/main/java/com/yami/shop/service/IShopCategoryService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.yami.shop.bean.model.Category;
 import com.yami.shop.bean.model.ShopCategory;
+import com.yami.shop.bean.param.CategoryProductDTO;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
@@ -21,8 +22,7 @@ public interface IShopCategoryService extends IService<ShopCategory> {
      * 查询全部(树形)
      * @return List<FrontCategory>
      */
-    List<ShopCategory> treeShopCategory(Long shopId,
-                                          String name);
+    List<ShopCategory> treeShopCategory(Long shopId, String name);
 
     /**
      * 导出门店前台类目导入模板
@@ -43,4 +43,10 @@ public interface IShopCategoryService extends IService<ShopCategory> {
      * @return
      */
     IPage<Category> listByParentIdAndShopId(Long parentId, Long shopId, Integer current, Integer size);
+
+    /**
+     * 绑定分类商品
+     * @param categoryProductDTO 分类商品参数
+     */
+    void categoryProduct(CategoryProductDTO categoryProductDTO);
 }

+ 1 - 1
yami-shop-service/src/main/java/com/yami/shop/service/hb/impl/HBFrontCategoryService.java

@@ -84,7 +84,7 @@ public class HBFrontCategoryService implements IHBFrontCategoryService {
                     frontCategoryMapper.insert(frontCategory);
 
                     //添加门店分类
-                    addShopCategory(frontCategory, 1L, 5104238L);
+//                    addShopCategory(frontCategory, 1L, 5104238L);
                 } else {
                     frontCategory.setId(frontCategory1.getId());
                     frontCategoryMapper.updateById(frontCategory);

+ 117 - 15
yami-shop-service/src/main/java/com/yami/shop/service/hb/impl/HBGoodsService.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.yami.shop.bean.dto.hb.HBBaseReq;
 import com.yami.shop.bean.model.*;
 import com.yami.shop.common.util.hb.HBR;
@@ -41,6 +42,9 @@ public class HBGoodsService implements IHBGoodsService {
     private final SkuMapper skuMapper;
     private final ShopSkuMapper shopSkuMapper;
     private final ShopDetailMapper shopDetailMapper;
+
+    private final FrontCategoryMapper frontCategoryMapper;
+    private final ShopCategoryMapper shopCategoryMapper;
     private final CategoryProdMapper categoryProdMapper;
 
     @Override
@@ -177,18 +181,42 @@ public class HBGoodsService implements IHBGoodsService {
     @Override
     public HBR updateGoodsStatus(JSONObject hbRequest) {
         try {
-            String bodyStr = hbRequest.getString("body");
+            JSONObject bodyStr = hbRequest.getJSONObject("body");
             log.info("商品,body:{}", bodyStr);
-            JSONObject bodyJson = JSON.parseObject(bodyStr); // 使用Fastjson的解析方法
-//            String outStationNo = bodyJson.getString("outStationNo");
-            String skuId = bodyJson.getString("skuId");
-            String stationId = bodyJson.getString("stationId");
 
-            String selfSkuStatus = getSelfSkuStatus(skuId, stationId);
-            log.info("商品状态变更查询:{}", selfSkuStatus);
-            //处理商品状态
+            JSONArray data = bodyStr.getJSONArray("data");// 使用Fastjson的解析方法
+            String selfSkuStatus = getSelfSkuStatus(data);
+            JSONObject skuInfo = JSON.parseObject(selfSkuStatus);
+            JSONArray jsonArray = skuInfo.getJSONObject("result").getJSONObject("result").getJSONArray("stationProductList");
+            for (Object datum : jsonArray) {
+                JSONObject jsonObject = JSON.parseObject(datum.toString());
+                String skuId = jsonObject.getString("skuId");
+                String stationId = jsonObject.getString("stationId");
+                Integer saleStatus = jsonObject.getInteger("saleStatus");//1 可售,0不可售
+
+                log.info("商品状态变更查询:{}", selfSkuStatus);
+
+                //处理商品状态
+                ShopDetail shopDetail = shopDetailMapper.selectOne(new LambdaUpdateWrapper<ShopDetail>()
+                        .eq(ShopDetail::getHbStationId, stationId));
+                Sku sku = skuMapper.selectByHbSkuId(skuId);
+                shopSkuMapper.update(new ShopSku(), new LambdaUpdateWrapper<ShopSku>()
+                        .set(ShopSku::getSaleStatus, saleStatus)
+                        .eq(ShopSku::getSkuId, sku.getSkuId())
+                        .eq(ShopSku::getShopId, shopDetail.getShopId()));
+
+                //处理门店-分类管理
+                List<CategoryProd> categoryProds = categoryProdMapper.selectList(new LambdaQueryWrapper<CategoryProd>()
+                        .eq(CategoryProd::getProdId, sku.getProdId())
+                        .eq(CategoryProd::getIsDelete, 0));
+                for (CategoryProd categoryProd : categoryProds) {
+                    FrontCategory frontCategory = frontCategoryMapper.selectOne(new LambdaQueryWrapper<FrontCategory>()
+                            .eq(FrontCategory::getCode, categoryProd.getCode()));
+                    addShopCategory(frontCategory, shopDetail.getShopId(), shopDetail.getHbStationId());
+                }
 
 
+            }
         } catch (Exception e) {
             log.error("商品失败:{}", e.getMessage(), e);
             return HBR.error("未知异常");
@@ -197,6 +225,65 @@ public class HBGoodsService implements IHBGoodsService {
         return HBR.success();
     }
 
+    /**
+     * 添加门店分类
+     *
+     * @param frontCategory 前台分类
+     * @param shopId        门店id
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void addShopCategory(FrontCategory frontCategory, Long shopId, String hbShopId) {
+        ShopCategory shopCategoryByCode = shopCategoryMapper.selectOne(new LambdaQueryWrapper<ShopCategory>()
+                .eq(ShopCategory::getCode, frontCategory.getCode())
+                .eq(ShopCategory::getShopId, shopId)
+                .eq(ShopCategory::getIsDelete, 0));
+
+        if (shopCategoryByCode != null) {
+            log.info("门店分类已存在,无需添加");
+            return;
+        }
+        ShopCategory shopCategory = new ShopCategory();
+        shopCategory.setCode(frontCategory.getCode());
+        shopCategory.setName(frontCategory.getName());
+        if (frontCategory.getParentCode() == null || frontCategory.getParentCode().equals("0")) {
+            shopCategory.setPid(0L);
+            shopCategory.setParentCode("0");
+        } else {
+            ShopCategory shopCategoryByCode1 = shopCategoryMapper.selectOne(new LambdaQueryWrapper<ShopCategory>()
+                    .eq(ShopCategory::getCode, frontCategory.getParentCode())
+                    .eq(ShopCategory::getShopId, shopId)
+                    .eq(ShopCategory::getIsDelete, 0));
+            if (shopCategoryByCode1 == null) {
+                //不存在门店分类父类目添加
+                FrontCategory frontCategoryParent = frontCategoryMapper.selectOne(new LambdaQueryWrapper<FrontCategory>()
+                        .eq(FrontCategory::getCode, frontCategory.getParentCode())
+                        .eq(FrontCategory::getIsDelete, 0));
+                addShopCategory(frontCategoryParent, shopId, hbShopId);
+
+                shopCategoryByCode1 = shopCategoryMapper.selectOne(new LambdaQueryWrapper<ShopCategory>()
+                        .eq(ShopCategory::getCode, frontCategory.getParentCode())
+                        .eq(ShopCategory::getShopId, shopId)
+                        .eq(ShopCategory::getIsDelete, 0));
+            }
+            shopCategory.setPid(shopCategoryByCode1.getId());
+            shopCategory.setParentCode(shopCategoryByCode1.getCode());
+        }
+
+        shopCategory.setShopId(shopId);
+        shopCategory.setHbShopId(hbShopId);
+        shopCategory.setLabel(frontCategory.getLabel());
+        shopCategory.setIcon(frontCategory.getIcon());
+        shopCategory.setPic(frontCategory.getPic());
+        shopCategory.setLevel(frontCategory.getLevel());
+        shopCategory.setIsDelete(0);
+        shopCategory.setOperateUser("admin");
+        shopCategory.setNum(frontCategory.getNum());
+        shopCategory.setIsLeaves(frontCategory.getIsLeaves());
+
+        shopCategoryMapper.insert(shopCategory);
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public HBR updateGoodsPrice(JSONObject hbRequest) {
@@ -393,18 +480,19 @@ public class HBGoodsService implements IHBGoodsService {
      *
      * @return 门店品售卖状态信息
      */
-    public String getSelfSkuStatus(String skuId, String stationId) {
+    public String getSelfSkuStatus(JSONArray data) {
         HBBaseReq<Object> build = HBBaseReq.create();
         build.setAppId(hbSignUtil.getAppId());
         JSONObject jsonObject = new JSONObject();
-        List<JSONObject> onlineProductDTO = new ArrayList();
-        jsonObject.put("skuId", skuId);//海博商品编码
-        jsonObject.put("stationId", stationId);//海博门店编码
-        onlineProductDTO.add(jsonObject);
-        build.setBody(JSON.toJSONString(onlineProductDTO));
+        jsonObject.put("data", data);
+//        List<JSONObject> onlineProductDTO = new ArrayList();
+//        jsonObject.put("skuId", skuId);//海博商品编码
+//        jsonObject.put("stationId", stationId);//海博门店编码
+//        onlineProductDTO.add(jsonObject);
+        build.setBody(JSON.toJSONString(jsonObject));
         build.setSign(hbSignUtil.signMd5(build));
-        String post = post(hbSignUtil.getHBHost() + "/api/productStation/getSelfSkuStatus", build);
         log.info("post 商品查询请求参数:{}", JSON.toJSONString(build));
+        String post = post(hbSignUtil.getHBHost() + "/api/productStation/getSelfSkuStatus", build);
         log.info("post 商品查询结果:{}", post);
         return post;
     }
@@ -551,7 +639,21 @@ public class HBGoodsService implements IHBGoodsService {
                 .eq(CategoryProd::getCode, ztFrontCategoryCodeLevel));
         if (integer == null) {
             categoryProdMapper.insert(categoryProd);
+
+        }
+        //门店分类处理
+        List<ShopSku> shopCategoryList = shopSkuMapper.selectList(new LambdaQueryWrapper<ShopSku>()
+                .eq(ShopSku::getSpuId, spuId)
+                .eq(ShopSku::getIsDelete, 0));
+
+        for (ShopSku shopSku : shopCategoryList) {
+            FrontCategory frontCategory = frontCategoryMapper.selectOne(new LambdaQueryWrapper<FrontCategory>()
+                    .eq(FrontCategory::getCode, ztFrontCategoryCodeLevel));
+            ShopDetail shopDetail = shopDetailMapper.selectById(shopSku.getShopId());
+
+            addShopCategory(frontCategory, shopSku.getShopId(), shopDetail.getHbStationId());
         }
+
     }
 
 

+ 32 - 8
yami-shop-service/src/main/java/com/yami/shop/service/impl/ShopCategoryServiceImpl.java

@@ -9,11 +9,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yami.shop.bean.dto.ShopCategoryExcelDTO;
 import com.yami.shop.bean.model.*;
+import com.yami.shop.bean.param.CategoryProductDTO;
 import com.yami.shop.common.exception.GlobalException;
-import com.yami.shop.dao.FrontCategoryMapper;
-import com.yami.shop.dao.LabelMapper;
-import com.yami.shop.dao.ShopCategoryMapper;
-import com.yami.shop.dao.ShopDetailMapper;
+import com.yami.shop.dao.*;
+import com.yami.shop.service.CategoryProdService;
 import com.yami.shop.service.IShopCategoryService;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -26,6 +25,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletResponse;
 import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -43,6 +43,7 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
     private final ShopCategoryMapper shopCategoryMapper;
 
     private final FrontCategoryMapper frontCategoryMapper;
+    private final CategoryProdMapper categoryProdMapper;
 
     private final ShopDetailMapper shopDetailMapper;
     private final LabelMapper labelMapper;
@@ -51,10 +52,7 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
     @Override
     public List<ShopCategory> treeShopCategory(Long shopId, String name) {
         // 获取所有未删除的前台类目
-        List<ShopCategory> shopCategories = shopCategoryMapper.selectList(new LambdaQueryWrapper<ShopCategory>()
-                .like(name != null, ShopCategory::getName, name)
-                .eq(ShopCategory::getIsDelete, 0)
-                .eq(shopId != null, ShopCategory::getShopId, shopId));
+        List<ShopCategory> shopCategories = shopCategoryMapper.selectListAll(shopId, name);
         // 构建树形结构
         return shopCategories; // 假设根节点的parentCode为"0"
 //        return buildCategoryTree(shopCategories, "0"); // 假设根节点的parentCode为"0"
@@ -184,6 +182,32 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
         return res;
     }
 
+    @Override
+    public void categoryProduct(CategoryProductDTO categoryProductDTO) {
+        List<Long> prodIdList = categoryProductDTO.getProdIdList();
+        if (ObjectUtils.isEmpty(prodIdList)){
+            new GlobalException("新增商品为空!请选择商品");
+        }
+        for (Long aLong : prodIdList) {
+
+            Integer integer = categoryProdMapper.selectCount(new LambdaQueryWrapper<CategoryProd>().eq(CategoryProd::getProdId, aLong)
+                    .eq(CategoryProd::getIsDelete, 0)
+                    .eq(CategoryProd::getCode, categoryProductDTO.getCode()));
+
+            if (integer > 0) {
+                new GlobalException("该门店分类对应商品已存在!请勿重复添加");
+            }
+            CategoryProd categoryProd = new CategoryProd();
+            categoryProd.setCategoryId(categoryProductDTO.getCategoryId());
+            categoryProd.setProdId(aLong);
+            categoryProd.setCode(categoryProductDTO.getCode());
+            categoryProd.setIsDelete(0);
+            categoryProd.setCreateTime(new Date());
+            categoryProdMapper.insert(categoryProd);
+
+        }
+    }
+
     /**
      * 添加对应的二级和三级类目
      *

+ 1 - 1
yami-shop-service/src/main/resources/mapper/OrderRefundMapper.xml

@@ -443,7 +443,6 @@
         COUNT(CASE WHEN return_money_sts = 40 THEN 1 END) AS withdrawApplyCount,
         COUNT(CASE WHEN return_money_sts = 60 THEN 1 END) AS sellerAcceptCount,
         COUNT(CASE WHEN return_money_sts = 65 THEN 1 END) AS buyerDeliveryCount,
-        COUNT(CASE WHEN return_money_sts = 40 THEN 1 END) AS shippingCount,
         COUNT(CASE WHEN return_money_sts = 70 THEN 1 END) AS refundCompleteCount
         FROM tz_order_refund
         <where>
@@ -500,6 +499,7 @@
                 AND refund.create_time &lt;= #{orderRefund.endTime}
             </if>
         </where>
+        order by refund.apply_time desc
     </select>
 
     <select id="selectInfoById" resultMap="OrderRefundVoMap">

+ 66 - 0
yami-shop-service/src/main/resources/mapper/ShopCategoryMapper.xml

@@ -12,6 +12,72 @@
           and f.is_delete = 0
     </select>
 
+
+    <select id="selectListAll" resultType="com.yami.shop.bean.model.ShopCategory">
+        SELECT fc.* , count(cp.id) as prodCount
+        FROM tz_shop_category fc
+        left join tz_category_prod cp on fc.code = cp.code and cp.shop_id = #{shopId}
+        WHERE fc.is_delete = 0
+        <if test="shopId">and fc.shop_id = #{shopId}</if>
+        <if test="name != null and name != ''">
+            AND (
+            fc.name like concat('%',#{name},'%')
+
+            OR fc.level = 2 AND fc.parent_code IN (
+            SELECT code FROM tz_shop_category
+            WHERE name like concat('%',#{name},'%')
+            AND level = 1
+            AND is_delete = 0
+            <if test="shopId">AND shop_id = #{shopId}</if>
+            )
+            OR fc.level = 3 AND fc.parent_code IN (
+            SELECT code FROM tz_shop_category
+            WHERE parent_code IN (
+            SELECT code FROM tz_shop_category
+            WHERE name like concat('%',#{name},'%')
+            AND level = 1
+            AND is_delete = 0
+            <if test="shopId">AND shop_id = #{shopId}</if>
+            ) AND is_delete = 0
+            )
+
+            OR fc.level = 1 AND  fc.code IN (
+            SELECT parent_code FROM tz_shop_category
+            WHERE name like concat('%',#{name},'%')
+            AND level = 2
+            AND is_delete = 0
+            <if test="shopId">AND shop_id = #{shopId}</if>
+            )
+            OR fc.level = 3 AND  fc.parent_code IN (
+            SELECT code FROM tz_shop_category
+            WHERE name like concat('%',#{name},'%')
+            AND level = 2
+            AND is_delete = 0
+            <if test="shopId">AND shop_id = #{shopId}</if>
+            )
+
+            OR fc.level = 2 AND fc.code IN (
+            SELECT parent_code FROM tz_shop_category
+            WHERE name like concat('%',#{name},'%')
+            AND level = 3
+            AND is_delete = 0
+            <if test="shopId">AND shop_id = #{shopId}</if>
+            )
+            OR fc.level = 1 AND fc.code IN (
+            SELECT parent_code FROM tz_shop_category
+            WHERE code IN (
+            SELECT parent_code FROM tz_shop_category
+            WHERE name like concat('%',#{name},'%')
+            AND level = 3
+            AND is_delete = 0
+            <if test="shopId">AND shop_id = #{shopId}</if>
+            ) AND is_delete = 0
+            )
+            )
+        </if>
+        group by fc.id
+    </select>
+
     <update id="deleteByCode">
         UPDATE tz_front_category
         SET is_delete = 1