Ver Fonte

后台下单支持促销活动叠加赠品/满减

zhijiezhao há 3 anos atrás
pai
commit
0dcad39587

+ 11 - 0
src/main/java/com/caimei/modules/bulkpurchase/entity/PurchaseProduct.java

@@ -16,6 +16,7 @@ import java.util.List;
 public class PurchaseProduct extends DataEntity<PurchaseProduct> {
 
     private static final long serialVersionUID = 1L;
+    private String discounts; //是否支持叠加优惠,0支持,1不支持
     private String purchaseProductName;        // 商品名称
     private String name;        // 商品名称
     private String image;//商品图片
@@ -64,6 +65,8 @@ public class PurchaseProduct extends DataEntity<PurchaseProduct> {
     private String oldProductFlag;//是否是旧商品 0否 1是
     private String commodityType; //商品属性:1产品,2仪器
     private Integer couponsLogo;    //显示优惠券查看: 1不显示 2显示
+
+
     /**
      * 超级会员优惠价格标识:0不是,1是
      */
@@ -89,6 +92,14 @@ public class PurchaseProduct extends DataEntity<PurchaseProduct> {
      */
     private Double svipTaxReduction;
 
+    public String getDiscounts() {
+        return discounts;
+    }
+
+    public void setDiscounts(String discounts) {
+        this.discounts = discounts;
+    }
+
     public Integer getLadderPriceFlag() {
         return ladderPriceFlag;
     }

+ 1 - 0
src/main/java/com/caimei/modules/order/service/NewOrderService.java

@@ -207,6 +207,7 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
                 o.setCostPrice(copCostPrice);
                 //o.setShopProductAmount(copCostPrice * (o.getNum() + o.getPresentNum()));//商品费  =  成本价快照
                 // 赠送数单独列出来
+                //todo 叠加满减满赠修改
                 o.setShopProductAmount(copCostPrice * o.getNum());
                 discountFee += (o.getDiscountFee() == null ? 0 : o.getDiscountFee()); //主订单统计经理折扣
                 preferential += (o.getPreferential() == null ? 0 : o.getPreferential()); //主订单统计优惠

+ 2 - 0
src/main/java/com/caimei/modules/order/web/NewOrderController.java

@@ -337,6 +337,8 @@ public class NewOrderController extends BaseController {
     @RequiresPermissions("order:order:edit")
     @RequestMapping(value = "save")
     public String save(NewOrder newOrder, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
+        //todo 后台下单判断叠加优惠
+
         // 是否为二手订单(二手订单只存在一个商品)
         boolean isSecondHandOrder = false;
         if (!beanValidator(model, newOrder)) {

+ 158 - 159
src/main/resources/mappings/modules/product/CmPromotionMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="com.caimei.modules.product.dao.CmPromotionDao">
 
     <sql id="cmPromotionColumns">
-		cp.id AS "id",
+        cp.id AS "id",
 		cp.name AS "name",
 		cp.description AS "description",
 		cp.type AS "type",
@@ -16,7 +16,7 @@
 		cp.updateTime AS "updateTime",
 		cp.status AS "status",
 		cp.delFlag AS "delFlag1"
-	</sql>
+    </sql>
 
     <select id="get" resultType="CmPromotion">
         SELECT
@@ -94,58 +94,58 @@
     </select>
 
     <select id="findPromotionProduct" resultType="com.caimei.modules.product.entity.Product">
-        SELECT
-        p.*,
-        cp.reducedPrice AS "reducedPrice",
-        s.name AS "shopName"
-        FROM
-        cm_promotions cp
-        LEFT JOIN cm_promotions_product cpp ON cp.id = cpp.promotionsId
-        LEFT JOIN product p ON cpp.productId = p.productID
-        LEFT JOIN shop s ON s.shopID = p.shopID
-        WHERE
-            cp.id = #{id}
-        and p.productCategory = 1
+        SELECT p.*,
+               cp.reducedPrice AS "reducedPrice",
+               s.name          AS "shopName"
+        FROM cm_promotions cp
+                 LEFT JOIN cm_promotions_product cpp ON cp.id = cpp.promotionsId
+                 LEFT JOIN product p ON cpp.productId = p.productID
+                 LEFT JOIN shop s ON s.shopID = p.shopID
+        WHERE cp.id = #{id}
+          and p.productCategory = 1
     </select>
 
     <select id="findGiftProduct" resultType="com.caimei.modules.product.entity.Product">
-           SELECT
-             p.*,
-             s.name AS "shopName",
-             cpg.number AS "giftNumber"
-           FROM
-             cm_promotions cp
-             LEFT JOIN cm_promotions_gift cpg ON cp.id = cpg.promotionsId
-             LEFT JOIN product p ON cpg.productId = p.productID
-             LEFT JOIN shop s ON s.shopID = p.shopID
-           WHERE
-             cp.id = #{id}
-             and p.productCategory = 1
+        SELECT p.*,
+               s.name     AS "shopName",
+               cpg.number AS "giftNumber"
+        FROM cm_promotions cp
+                 LEFT JOIN cm_promotions_gift cpg ON cp.id = cpg.promotionsId
+                 LEFT JOIN product p ON cpg.productId = p.productID
+                 LEFT JOIN shop s ON s.shopID = p.shopID
+        WHERE cp.id = #{id}
+          and p.productCategory = 1
     </select>
 
     <select id="findGiftPurchaseProduct" resultType="com.caimei.modules.bulkpurchase.entity.PurchaseProduct">
-		SELECT p.name name,s.name shopName ,s.`shopID` shopId,p.name purchaseProductName,
-		p.`price1` price,p.`productID` productId,p.productCode productNo,p.mainImage image
-		,p.costCheckFlag costCheckFlag,p.costPrice costPrice,p.costProportional costProportional, p.price0 AS normalPrice,
-        cpg.number AS num
-           FROM
-             cm_promotions cp
-             LEFT JOIN cm_promotions_gift cpg ON cp.id = cpg.promotionsId
-             LEFT JOIN product p ON cpg.productId = p.productID
-             LEFT JOIN shop s ON s.shopID = p.shopID
-           WHERE
-             cp.id = #{id}
-             and p.productCategory = 1
+        SELECT p.name             name,
+               s.name             shopName,
+               s.`shopID`         shopId,
+               p.name             purchaseProductName,
+               p.`price1`         price,
+               p.`productID`      productId,
+               p.productCode      productNo,
+               p.mainImage        image
+                ,
+               p.costCheckFlag    costCheckFlag,
+               p.costPrice        costPrice,
+               p.costProportional costProportional,
+               p.price0    AS     normalPrice,
+               cpg.number  AS     num,
+               cp.discount as     discounts
+        FROM cm_promotions cp
+                 LEFT JOIN cm_promotions_gift cpg ON cp.id = cpg.promotionsId
+                 LEFT JOIN product p ON cpg.productId = p.productID
+                 LEFT JOIN shop s ON s.shopID = p.shopID
+        WHERE cp.id = #{id}
+          and p.productCategory = 1
     </select>
 
     <select id="findPromotionShops" resultType="com.caimei.modules.cibe.entity.Shop">
-        SELECT
-        s.*
-        FROM
-        cm_promotions_product cpp
-        LEFT JOIN shop s ON cpp.supplierId = s.shopID
-        WHERE
-            cpp.promotionsId = #{id}
+        SELECT s.*
+        FROM cm_promotions_product cpp
+                 LEFT JOIN shop s ON cpp.supplierId = s.shopID
+        WHERE cpp.promotionsId = #{id}
     </select>
 
     <select id="findAllProduct" resultType="com.caimei.modules.product.entity.Product">
@@ -239,154 +239,151 @@
     </select>
 
     <delete id="deleteAllPromotionProductsAndShops">
-		DELETE FROM cm_promotions_product
-		WHERE promotionsId = #{id}
-	</delete>
+        DELETE
+        FROM cm_promotions_product
+        WHERE promotionsId = #{id}
+    </delete>
 
     <delete id="deleteAllPromotionGifts">
-		DELETE FROM cm_promotions_gift
-		WHERE promotionsId = #{id}
-	</delete>
+        DELETE
+        FROM cm_promotions_gift
+        WHERE promotionsId = #{id}
+    </delete>
 
     <insert id="insertPromotionProduct">
-		INSERT INTO cm_promotions_product(
-			promotionsId,
-            productId,
-            addTime
-		) VALUES (
-			#{promotionId},
-			#{productId},
-			now()
-		)
-	</insert>
+        INSERT INTO cm_promotions_product(promotionsId,
+                                          productId,
+                                          addTime)
+        VALUES (#{promotionId},
+                #{productId},
+                now())
+    </insert>
 
     <insert id="insertGiftProduct">
-		INSERT INTO cm_promotions_gift(
-			promotionsId,
-            productId,
-            number,
-            addTime
-		) VALUES (
-			#{promotionId},
-			#{giftId},
-			#{number},
-			now()
-		)
-	</insert>
+        INSERT INTO cm_promotions_gift(promotionsId,
+                                       productId,
+                                       number,
+                                       addTime)
+        VALUES (#{promotionId},
+                #{giftId},
+                #{number},
+                now())
+    </insert>
 
     <insert id="insertPromotionShop">
-		INSERT INTO cm_promotions_product(
-			promotionsId,
-            supplierId,
-            productId,
-            addTime
-		) VALUES (
-			#{promotionId},
-			#{shopId},
-			0,
-			now()
-		)
-	</insert>
+        INSERT INTO cm_promotions_product(promotionsId,
+                                          supplierId,
+                                          productId,
+                                          addTime)
+        VALUES (#{promotionId},
+                #{shopId},
+                0,
+                now())
+    </insert>
 
     <insert id="insert" parameterType="CmPromotion" keyProperty="id" useGeneratedKeys="true">
-        INSERT INTO cm_promotions(
-            name,
-            description,
-            type,
-            mode,
-            touchPrice,
-            reducedPrice,
-            beginTime,
-            endTime,
-            addTime,
-            updateTime,
-            status,
-            delFlag,
-            discount,
-            seen
-        ) VALUES (
-            #{name},
-            #{description},
-            #{type},
-            #{mode},
-            #{touchPrice},
-            #{reducedPrice},
-            #{beginTime},
-            #{endTime},
-            #{addTime},
-            #{updateTime},
-            #{status},
-            #{delFlag1},
-            #{discount},
-            #{seen}
-        )
+        INSERT INTO cm_promotions(name,
+                                  description,
+                                  type,
+                                  mode,
+                                  touchPrice,
+                                  reducedPrice,
+                                  beginTime,
+                                  endTime,
+                                  addTime,
+                                  updateTime,
+                                  status,
+                                  delFlag,
+                                  discount,
+                                  seen)
+        VALUES (#{name},
+                #{description},
+                #{type},
+                #{mode},
+                #{touchPrice},
+                #{reducedPrice},
+                #{beginTime},
+                #{endTime},
+                #{addTime},
+                #{updateTime},
+                #{status},
+                #{delFlag1},
+                #{discount},
+                #{seen})
     </insert>
 
 
     <update id="update">
         UPDATE cm_promotions
-        SET name = #{name},
-        description = #{description},
-        type = #{type},
-        mode = #{mode},
-        touchPrice = #{touchPrice},
-        reducedPrice = #{reducedPrice},
-        beginTime = #{beginTime},
-        endTime = #{endTime},
-        updateTime = #{updateTime},
-        status = #{status},
-        delFlag = #{delFlag1}
+        SET name         = #{name},
+            description  = #{description},
+            type         = #{type},
+            mode         = #{mode},
+            touchPrice   = #{touchPrice},
+            reducedPrice = #{reducedPrice},
+            beginTime    = #{beginTime},
+            endTime      = #{endTime},
+            updateTime   = #{updateTime},
+            status       = #{status},
+            delFlag      = #{delFlag1},
+            discount     = #{discount},
+            seen         = #{seen}
         WHERE id = #{id}
     </update>
 
     <select id="findShop" resultType="com.caimei.modules.cibe.entity.Shop">
-        SELECT * from shop where shopID = #{id}
+        SELECT *
+        from shop
+        where shopID = #{id}
     </select>
 
     <select id="findProductPromotion" resultType="com.caimei.modules.product.entity.CmPromotion">
-        select  pr.id,
-                pr.name,
-                pr.type,
-                pr.mode,
-                pr.touchPrice,
-                pr.reducedPrice,
-                pr.beginTime,
-                pr.endTime,
-                pr.status,
-                prp.productId,
-                prp.supplierId
+        select pr.id,
+               pr.name,
+               pr.type,
+               pr.mode,
+               pr.touchPrice,
+               pr.reducedPrice,
+               pr.beginTime,
+               pr.endTime,
+               pr.status,
+               prp.productId,
+               prp.supplierId,
+               pr.discount
         from cm_promotions pr
-        left join cm_promotions_product prp on pr.id = prp.promotionsId
+                 left join cm_promotions_product prp on pr.id = prp.promotionsId
         where (prp.productId = #{productId}
-        or prp.supplierId = #{shopId})
-        and (pr.status = 1 or ( pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
-        and pr.delFlag not in ('1','2')
+            or prp.supplierId = #{shopId})
+          and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
+          and pr.delFlag not in ('1', '2')
         order by pr.type desc
         limit 1
     </select>
 
     <select id="findProductPromotionsGift" resultType="com.caimei.modules.product.entity.CmPromotion">
-        SELECT DISTINCT  pr.id,
-        pr.name,
-        pr.type,
-        pr.mode,
-        pr.touchPrice,
-        pr.reducedPrice,
-        pr.beginTime,
-        pr.endTime,
-        pr.status
+        SELECT DISTINCT pr.id,
+                        pr.name,
+                        pr.type,
+                        pr.mode,
+                        pr.touchPrice,
+                        pr.reducedPrice,
+                        pr.beginTime,
+                        pr.endTime,
+                        pr.status
         FROM cm_promotions_gift cpg
-        LEFT JOIN cm_promotions pr ON pr.id = cpg.promotionsId
+                 LEFT JOIN cm_promotions pr ON pr.id = cpg.promotionsId
         WHERE cpg.productId = #{productId}
-        AND (pr.status = 1 OR ( pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
-        AND pr.mode = 3
-        AND pr.delFlag not in ('1','2')
+          AND (pr.status = 1 OR (pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
+          AND pr.mode = 3
+          AND pr.delFlag not in ('1', '2')
         ORDER BY pr.type DESC
         LIMIT 1
     </select>
 
     <select id="findOrderPromotions" resultType="com.caimei.modules.product.entity.CmPromotion">
-        SELECT * FROM cm_promotions_order WHERE id = #{orderPromotionsId}
+        SELECT *
+        FROM cm_promotions_order
+        WHERE id = #{orderPromotionsId}
     </select>
 
     <select id="findPromotionsByProductId" resultType="com.caimei.modules.product.entity.CmPromotion">
@@ -408,11 +405,13 @@
                prp.supplierId = (select p.shopID from product p where p.productID = #{productId})
             )
           and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
-          and pr.delFlag not in (1,2)
+          and pr.delFlag not in (1, 2)
         order by pr.type desc
         limit 1
     </select>
     <select id="getPresentPriceById" resultType="java.lang.Double">
-        select price1 from product where productID=#{productId}
+        select price1
+        from product
+        where productID = #{productId}
     </select>
 </mapper>

+ 0 - 1
src/main/webapp/WEB-INF/views/modules/order/orderForm.jsp

@@ -30,7 +30,6 @@
         ul.couponContent span{display:inline-block;width:100%;padding:2px}
         ul.couponContent span.couponDesc{min-height:72px;}
         ul.couponContent span.couponDesc.none{height:72px;line-height:72px;vertical-align:middle;}
-    }
     </style>
 </head>
 <body>

+ 37 - 6
src/main/webapp/static/modules/bulkpurchase/orderForm.js

@@ -1049,6 +1049,7 @@ function setGiftHtmlList(data, cmPromotion) {
                 });
             }
         });
+        //本单总价>=满赠条件金额
         if (thisTouchPrice >= data.cmPromotion.touchPrice) {
             if (giftPromotionsIds.indexOf(data.cmPromotion.id) < 0) {
                 // 已经添加的,重新添加
@@ -1073,9 +1074,24 @@ function setGiftHtmlList(data, cmPromotion) {
                             if ($("#product_promotion_" + gift.productId).length > 0) {
                                 var pageGift = JSON.parse($("#product_promotion_" + gift.productId)
                                     .attr("data-value"));
-                                gift.num = gift.num * 1 + pageGift.num * 1;
+                                console.log(thisTouchPrice);
+                                console.log(data.cmPromotion.touchPrice);
+                                if (gift.discounts * 1 === 0) {
+                                    // var totalfee = $(".totalFee").val();
+                                    var b = Math.floor(thisTouchPrice / data.cmPromotion.touchPrice);
+                                    gift.num = gift.num * 1 * b + pageGift.num * 1;
+                                } else {
+                                    gift.num = gift.num * 1 + pageGift.num * 1;
+                                }
                                 $("#product_promotion_" + gift.productId).remove();
                             }
+                            if (gift.discounts * 1 === 0) {
+                                // var totalfee = $(".totalFee").val();
+                                var b = Math.floor(thisTouchPrice / data.cmPromotion.touchPrice);
+                                gift.num = gift.num * 1 * b;
+                            } else {
+                                gift.num = gift.num * 1;
+                            }
                             var giftStr = "<tr id='product_promotion_" + gift.productId +
                                 "' class='gift promotions promotion_" + data.cmPromotion.id +
                                 "' data-value='" + JSON.stringify(gift) + "' gift-index='" +
@@ -1085,8 +1101,8 @@ function setGiftHtmlList(data, cmPromotion) {
                                 "].enabledStatus' id='orderProduct" + product_index +
                                 ".enabledStatus' value='" + JSON.stringify(gift) + "'/>" + gift.shopId +
                                 "</td>" +
-                                "<td hidden>" + gift.shopName + "</td>" +
                                 "<td class='fix-width'><i class='red'>促销赠品:</i>" + gift.name +
+                                "<td>" + gift.shopName + "</td>" +
                                 "</td><td hidden></td>" +
                                 "<td>" + gift.num + "</td>" +
                                 "<td>0</td>" +
@@ -1252,14 +1268,21 @@ function setOrderFee() { //不考虑经理折扣、运费,此时 商品总金
     });
     // 计算促销折扣
     totalPromotions.forEach(function (item) {
+        console.log(totalPromotions);
         if (item.mode == 2) {
             var touchPrice = 0;
             item.promotionProducts.forEach(function (product) {
                 touchPrice += (product.number * product.price + product.totalTax * 1);
             });
             if (touchPrice >= item.touchPrice) {
-                reducedPrice += item.reducedPrice;
-                payTotalFee -= item.reducedPrice;
+                if (item.discount * 1 === 0) {
+                    var b = Math.floor(touchPrice/item.touchPrice);
+                    reducedPrice = b * item.reducedPrice;
+                    payTotalFee -= reducedPrice;
+                } else {
+                    reducedPrice += item.reducedPrice;
+                    payTotalFee -= item.reducedPrice;
+                }
             }
         }
     });
@@ -2036,8 +2059,14 @@ function setProductTotalFee() {
                 touchPrice += (product.number * product.price + product.totalTax * 1);
             });
             if (touchPrice >= item.touchPrice) {
-                reducedPrice += item.reducedPrice;
-                payTotalFee -= item.reducedPrice;
+                if (item.discount * 1 === 0) {
+                    var b = Math.floor(touchPrice/item.touchPrice);
+                    reducedPrice = b * item.reducedPrice;
+                    payTotalFee -= reducedPrice;
+                } else {
+                    reducedPrice += item.reducedPrice;
+                    payTotalFee -= item.reducedPrice;
+                }
             }
         }
     });
@@ -2195,6 +2224,7 @@ function updateRebateFlag() {
         //选中返佣订单后不可用优惠券
         // $("#couponBox").find("input[name=clubCouponId]").prop('checked', 'checked');
         $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
+        $("#couponBox").find("input[name=clubCouponId]").attr("disabled", true);
         $("#couponBox").find("#bsy").prop('checked', 'checked');
         $("#freePostFlag").attr("value", "-1");
         $("#freeDesc").find(".select2-chosen").text("到付");
@@ -2208,6 +2238,7 @@ function updateRebateFlag() {
         $("#rebateFlag").val(0);
         // $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
         $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
+        $("#couponBox").find("input[name=clubCouponId]").attr("disabled", false);
         $("#freePostFlag").attr("value", "0");
         $("#freeDesc").find(".select2-chosen").text("包邮");
         $("#useBalancePayFee").prop('checked', '');