From e8f8d89a4248cd4d0a7138cc2e5a36ea9b136699 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Tue, 11 Feb 2025 17:03:01 +0800
Subject: [PATCH] feat(mall): 添加订单一键发货和取消发货功能

---
 src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java |  150 +++++++++++++++++++++++++++-----------------------
 1 files changed, 81 insertions(+), 69 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
index 28e95b3..81b862c 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
@@ -2,6 +2,7 @@
 
 import cc.mrbird.febs.common.entity.FebsResponse;
 import cc.mrbird.febs.common.entity.QueryRequest;
+import cc.mrbird.febs.common.utils.MallUtils;
 import cc.mrbird.febs.mall.conversion.MallGoodsConversion;
 import cc.mrbird.febs.mall.dto.*;
 import cc.mrbird.febs.mall.entity.*;
@@ -13,6 +14,7 @@
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -63,7 +65,8 @@
         if (mallGoodsByGoodsName > 0) {
             return new FebsResponse().fail().message("商品名称不能重复");
         }
-        String goodsNo = addMallGoodsDto.getGoodsNo();
+        String goodsNo = MallUtils.getOrderNum("PT");
+        addMallGoodsDto.setGoodsNo(goodsNo);
         if (StrUtil.isEmpty(goodsNo)) {
             return new FebsResponse().fail().message("商品编号不能为空");
         }
@@ -72,16 +75,18 @@
             return new FebsResponse().fail().message("商品编号不能重复");
         }
         Integer carriageType = addMallGoodsDto.getCarriageType();
-        if(1 == carriageType){
-            if(ObjectUtil.isEmpty(addMallGoodsDto.getCarriageAmount())
-                    || BigDecimal.ZERO.compareTo(addMallGoodsDto.getCarriageAmount()) > 0){
-                return new FebsResponse().fail().message("固定邮费不能小于零");
-            }
-        }else{
-            Long carriageRuleId = addMallGoodsDto.getCarriageRuleId();
-            MallCarriageRule mallCarriageRule = mallCarriageRuleMapper.selectById(carriageRuleId);
-            if(ObjectUtil.isEmpty(mallCarriageRule)){
-                return new FebsResponse().fail().message("邮费模板不能为空");
+        if (addMallGoodsDto.getGoodsType() == 1) {
+            if (1 == carriageType) {
+                if (ObjectUtil.isEmpty(addMallGoodsDto.getCarriageAmount())
+                        || BigDecimal.ZERO.compareTo(addMallGoodsDto.getCarriageAmount()) > 0) {
+                    return new FebsResponse().fail().message("固定邮费不能小于零");
+                }
+            } else {
+                Long carriageRuleId = addMallGoodsDto.getCarriageRuleId();
+                MallCarriageRule mallCarriageRule = mallCarriageRuleMapper.selectById(carriageRuleId);
+                if (ObjectUtil.isEmpty(mallCarriageRule)) {
+                    return new FebsResponse().fail().message("邮费模板不能为空");
+                }
             }
         }
 
@@ -123,11 +128,11 @@
                     if (StrUtil.isEmpty(presentPrice)) {
                         return new FebsResponse().fail().message("商品规格现价不能为空");
                     }
-                    if (StrUtil.isEmpty(addSku.getLevelOnePrice())
-                    || StrUtil.isEmpty(addSku.getLevelTwoPrice())
-                            || StrUtil.isEmpty(addSku.getLevelThreePrice())) {
-                        return new FebsResponse().fail().message("商品规格级别价格不能为空");
-                    }
+//                    if (StrUtil.isEmpty(addSku.getLevelOnePrice())
+//                    || StrUtil.isEmpty(addSku.getLevelTwoPrice())
+//                            || StrUtil.isEmpty(addSku.getLevelThreePrice())) {
+//                        return new FebsResponse().fail().message("商品规格级别价格不能为空");
+//                    }
                     BigDecimal goodsWeight = addSku.getGoodsWeight();
                     if(BigDecimal.ZERO.compareTo(goodsWeight) > 0){
                         return new FebsResponse().fail().message("重量不能小于零");
@@ -195,11 +200,11 @@
             sku.setSkuImage(mallGoods.getThumb());
             sku.setSkuName(mallGoods.getGoodsName());
             sku.setCostPrice(mallGoods.getCostPrice());
-            sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
             sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
-            sku.setLevelOnePrice(mallGoods.getLevelOnePrice());
-            sku.setLevelTwoPrice(mallGoods.getLevelTwoPrice());
-            sku.setLevelThreePrice(mallGoods.getLevelThreePrice());
+            sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
+            sku.setLevelOnePrice(new BigDecimal(mallGoods.getPresentPrice()));
+            sku.setLevelTwoPrice(new BigDecimal(mallGoods.getPresentPrice()));
+            sku.setLevelThreePrice(new BigDecimal(mallGoods.getPresentPrice()));
             sku.setSkuVolume(mallGoods.getVolume());
             sku.setStock(mallGoods.getStock());
             sku.setStyleId(style.getId());
@@ -236,14 +241,13 @@
                 mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
                 mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
                 mallGoodsSku.setOriginalPrice(new BigDecimal(addMallGoodsSkuDto.getOriginalPrice()));
-//                mallGoodsSku.setPresentPrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
-                mallGoodsSku.setPresentPrice(new BigDecimal(addMallGoodsSkuDto.getOriginalPrice()));
-
-                mallGoodsSku.setLevelOnePrice(new BigDecimal(addMallGoodsSkuDto.getLevelOnePrice()));
-                mallGoodsSku.setLevelTwoPrice(new BigDecimal(addMallGoodsSkuDto.getLevelTwoPrice()));
-                mallGoodsSku.setLevelThreePrice(new BigDecimal(addMallGoodsSkuDto.getLevelThreePrice()));
-                mallGoodsSku.setStyleId(mallGoodsStyleSku.getId());
+                mallGoodsSku.setPresentPrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
                 mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice());
+
+                mallGoodsSku.setLevelOnePrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
+                mallGoodsSku.setLevelTwoPrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
+                mallGoodsSku.setLevelThreePrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
+                mallGoodsSku.setStyleId(mallGoodsStyleSku.getId());
                 mallGoodsSku.setGoodsId(mallGoods.getId());
                 mallGoodsSku.setGoodsWeight(addMallGoodsSkuDto.getGoodsWeight());
                 mallGoodsSku.setSample(addMallGoodsSkuDto.getSample());
@@ -485,9 +489,9 @@
             sku.setCostPrice(mallGoods.getCostPrice());
             sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
             sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
-            sku.setLevelOnePrice(mallGoods.getLevelOnePrice());
-            sku.setLevelTwoPrice(mallGoods.getLevelTwoPrice());
-            sku.setLevelThreePrice(mallGoods.getLevelThreePrice());
+            sku.setLevelOnePrice(new BigDecimal(mallGoods.getPresentPrice()));
+            sku.setLevelTwoPrice(new BigDecimal(mallGoods.getPresentPrice()));
+            sku.setLevelThreePrice(new BigDecimal(mallGoods.getPresentPrice()));
             sku.setSkuVolume(mallGoods.getVolume());
             sku.setStock(mallGoods.getStock());
             sku.setStyleId(style.getId());
@@ -551,14 +555,13 @@
                         mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
                         mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
                         mallGoodsSku.setOriginalPrice(addMallGoodsSkuDto.getOriginalPrice());
-//                        mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice());
-                        mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getOriginalPrice());
-                        mallGoodsSku.setLevelOnePrice(addMallGoodsSkuDto.getLevelOnePrice());
-                        mallGoodsSku.setLevelTwoPrice(addMallGoodsSkuDto.getLevelTwoPrice());
-                        mallGoodsSku.setLevelThreePrice(addMallGoodsSkuDto.getLevelThreePrice());
+                        mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice());
+                        mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice());
+                        mallGoodsSku.setLevelOnePrice(addMallGoodsSkuDto.getPresentPrice());
+                        mallGoodsSku.setLevelTwoPrice(addMallGoodsSkuDto.getPresentPrice());
+                        mallGoodsSku.setLevelThreePrice(addMallGoodsSkuDto.getPresentPrice());
                         mallGoodsSku.setStyleId(addMallGoodsSkuDto.getStyleId());
                         mallGoodsSku.setGoodsId(mallGoods.getId());
-                        mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice());
                         mallGoodsSku.setGoodsWeight(addMallGoodsSkuDto.getGoodsWeight());
                         mallGoodsSku.setSample(addMallGoodsSkuDto.getSample());
                         mallGoodsSkuMapper.updateById(mallGoodsSku);
@@ -571,13 +574,12 @@
                         mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
                         mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
                         mallGoodsSku.setOriginalPrice(addMallGoodsSkuDto.getOriginalPrice());
-//                        mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice());
-                        mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getOriginalPrice());
-                        mallGoodsSku.setLevelOnePrice(addMallGoodsSkuDto.getLevelOnePrice());
-                        mallGoodsSku.setLevelTwoPrice(addMallGoodsSkuDto.getLevelTwoPrice());
-                        mallGoodsSku.setLevelThreePrice(addMallGoodsSkuDto.getLevelThreePrice());
-                        mallGoodsSku.setStyleId(mallGoodsStyleSku.getId());
+                        mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice());
                         mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice());
+                        mallGoodsSku.setLevelOnePrice(addMallGoodsSkuDto.getPresentPrice());
+                        mallGoodsSku.setLevelTwoPrice(addMallGoodsSkuDto.getPresentPrice());
+                        mallGoodsSku.setLevelThreePrice(addMallGoodsSkuDto.getPresentPrice());
+                        mallGoodsSku.setStyleId(mallGoodsStyleSku.getId());
                         mallGoodsSku.setGoodsId(mallGoods.getId());
                         mallGoodsSku.setGoodsWeight(addMallGoodsSkuDto.getGoodsWeight());
                         mallGoodsSku.setSample(addMallGoodsSkuDto.getSample());
@@ -852,32 +854,36 @@
     @Override
     public FebsResponse couponRuleAdd(CouponRuleAddDto couponRuleAddDto) {
         String name = couponRuleAddDto.getName();
-        QueryWrapper<MallGoodsCoupon> objectQueryWrapper = new QueryWrapper<>();
-        objectQueryWrapper.eq("name",name);
-        List<MallGoodsCoupon> mallGoodsCoupons = mallGoodsCouponMapper.selectList(objectQueryWrapper);
+        List<MallGoodsCoupon> mallGoodsCoupons = mallGoodsCouponMapper.selectList(
+                new LambdaQueryWrapper<MallGoodsCoupon>()
+                        .select(MallGoodsCoupon::getId)
+                        .eq(MallGoodsCoupon::getName,name)
+        );
         if(CollUtil.isNotEmpty(mallGoodsCoupons)){
-            return new FebsResponse().fail().message("名称不能重复");
+            return new FebsResponse().fail().message("优惠卷名称重复了");
         }
 
         MallGoodsCoupon mallGoodsCoupon = new MallGoodsCoupon();
         mallGoodsCoupon.setName(name);
         mallGoodsCoupon.setExpireDay(couponRuleAddDto.getExpireDay());
         mallGoodsCoupon.setCostAmount(couponRuleAddDto.getCostAmount());
+        mallGoodsCoupon.setType(couponRuleAddDto.getType());
         mallGoodsCoupon.setRealAmount(couponRuleAddDto.getRealAmount());
         mallGoodsCouponMapper.insert(mallGoodsCoupon);
 
         Long couponId = mallGoodsCoupon.getId();
-        QueryWrapper<CouponGoods> objectQueryWrapperCoupon = new QueryWrapper<>();
-        objectQueryWrapperCoupon.eq("coupon_id",couponId);
-        List<CouponGoods> couponGoodsList = couponGoodsMapper.selectList(objectQueryWrapperCoupon);
-        if(CollUtil.isNotEmpty(couponGoodsList)){
-            for(CouponGoods couponGoods : couponGoodsList){
-                couponGoodsMapper.deleteById(couponGoods);
-            }
+        // 先判断是否存在关联商品,再进行查询和删除
+        if (CollUtil.isNotEmpty(couponGoodsMapper.selectList(
+                new LambdaQueryWrapper<CouponGoods>()
+                        .select(CouponGoods::getId)
+                        .eq(CouponGoods::getCouponId, couponId)))) {
+            couponGoodsMapper.delete(new LambdaQueryWrapper<CouponGoods>().eq(CouponGoods::getCouponId, couponId));
         }
-        if(CollUtil.isNotEmpty(couponRuleAddDto.getGoodsIds())){
-            List<Long> goodsIds = couponRuleAddDto.getGoodsIds();
-            for(Long goodsId : goodsIds){
+
+        // 处理 goodsIds 为 null 或空的情况
+        List<Long> goodsIds = couponRuleAddDto.getGoodsIds();
+        if (CollUtil.isNotEmpty(goodsIds)) {
+            for (Long goodsId : goodsIds) {
                 CouponGoods couponGoods = new CouponGoods();
                 couponGoods.setGoodsId(goodsId);
                 couponGoods.setCouponId(couponId);
@@ -945,21 +951,23 @@
         mallGoodsCoupon.setName(adminMallGoodsCouponVo.getName());
         mallGoodsCoupon.setExpireDay(adminMallGoodsCouponVo.getExpireDay());
         mallGoodsCoupon.setCostAmount(adminMallGoodsCouponVo.getCostAmount());
+        mallGoodsCoupon.setType(adminMallGoodsCouponVo.getType());
         mallGoodsCoupon.setRealAmount(adminMallGoodsCouponVo.getRealAmount());
         mallGoodsCouponMapper.updateById(mallGoodsCoupon);
 
         Long couponId = mallGoodsCoupon.getId();
-        QueryWrapper<CouponGoods> objectQueryWrapperCoupon = new QueryWrapper<>();
-        objectQueryWrapperCoupon.eq("coupon_id",couponId);
-        List<CouponGoods> couponGoodsList = couponGoodsMapper.selectList(objectQueryWrapperCoupon);
-        if(CollUtil.isNotEmpty(couponGoodsList)){
-            for(CouponGoods couponGoods : couponGoodsList){
-                couponGoodsMapper.deleteById(couponGoods);
-            }
+        // 先判断是否存在关联商品,再进行查询和删除
+        if (CollUtil.isNotEmpty(couponGoodsMapper.selectList(
+                new LambdaQueryWrapper<CouponGoods>()
+                        .select(CouponGoods::getId)
+                        .eq(CouponGoods::getCouponId, couponId)))) {
+            couponGoodsMapper.delete(new LambdaQueryWrapper<CouponGoods>().eq(CouponGoods::getCouponId, couponId));
         }
-        if(CollUtil.isNotEmpty(adminMallGoodsCouponVo.getGoodsIds())){
-            List<Long> goodsIds = adminMallGoodsCouponVo.getGoodsIds();
-            for(Long goodsId : goodsIds){
+
+        // 处理 goodsIds 为 null 或空的情况
+        List<Long> goodsIds = adminMallGoodsCouponVo.getGoodsIds();
+        if (CollUtil.isNotEmpty(goodsIds)) {
+            for (Long goodsId : goodsIds) {
                 CouponGoods couponGoods = new CouponGoods();
                 couponGoods.setGoodsId(goodsId);
                 couponGoods.setCouponId(couponId);
@@ -1007,9 +1015,13 @@
 
     @Override
     public List<AdminMallGoodsCouponTreeListVo> findAdminMallGoodsVoTreeList() {
-        QueryWrapper<MallGoods> objectQueryWrapper = new QueryWrapper<>();
-        objectQueryWrapper.eq("is_sale",1);
-        List<MallGoods> mallGoodsList = mallGoodsMapper.selectList(objectQueryWrapper);
+        List<MallGoods> mallGoodsList = mallGoodsMapper.selectList(
+                new LambdaQueryWrapper<MallGoods>()
+                        .select(MallGoods::getId, MallGoods::getGoodsName)
+                        .eq(MallGoods::getIsSale, MallGoods.ISSALE_STATUS_ENABLE)
+                        .eq(MallGoods::getGoodsType, MallGoods.ISSALE_STATUS_ENABLE)
+                        .eq(MallGoods::getIsNormal, MallGoods.ISSALE_STATUS_ENABLE)
+        );
 
         List<AdminMallGoodsCouponTreeListVo> objects = new ArrayList<>();
         if(CollUtil.isNotEmpty(mallGoodsList)){

--
Gitblit v1.9.1