提交 d672976b authored 作者: YunaiV's avatar YunaiV

后端:商品价格计算,接入促销活动

H5 前端:购物车接入促销
上级 355c53df
##################### 业务模块 #####################
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 使用驼峰命名法转换字段。 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="Integer" type="java.lang.Integer"/>
<typeAlias alias="Long" type="java.lang.Long"/>
<typeAlias alias="HashMap" type="java.util.HashMap"/>
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap"/>
<typeAlias alias="ArrayList" type="java.util.ArrayList"/>
<typeAlias alias="LinkedList" type="java.util.LinkedList"/>
</typeAliases>
</configuration>
\ No newline at end of file
...@@ -14,20 +14,19 @@ ...@@ -14,20 +14,19 @@
<!-- <van-checkbox :name="item.id" />--> <!-- <van-checkbox :name="item.id" />-->
<!-- <product-card :product='item' :iscard='false' >--> <!-- <product-card :product='item' :iscard='false' >-->
<!-- <template slot>-->
<!-- <van-cell value="修改" >-->
<!-- <template slot="title">-->
<!-- <van-tag type="danger">促销</van-tag>-->
<!-- <span class="van-cell-text" >满60元减5元</span>-->
<!-- </template>-->
<!-- </van-cell>-->
<!-- </template>-->
<!-- </product-card>--> <!-- </product-card>-->
<!-- </div>--> <!-- </div>-->
<div v-for="(itemGroup, i) in itemGroups" class="card-goods__item"> <div v-for="(itemGroup, i) in itemGroups" class="card-goods__item">
<van-cell >
<template v-if="itemGroup.activity" slot="title">
<van-tag type="danger">满减送</van-tag>
<span class="van-cell-text" > {{ formatFullPrivilegeText(itemGroup.activity) }} </span>
</template>
</van-cell>
<div class="card" v-for="(item, j) in itemGroup.items" :key="j"> <div class="card" v-for="(item, j) in itemGroup.items" :key="j">
<van-checkbox :key="item.id" :name="item.id" v-model="item.selected" style="position: relative;" /> <van-checkbox :key="item.id" :name="item.id" v-model="item.selected" style="position: relative;top: 40px;" />
<product-card :product='convertProduct(item)'/> <product-card :product='convertProduct(item)'/>
</div> </div>
<div style="height:15px;"></div> <div style="height:15px;"></div>
...@@ -47,13 +46,14 @@ ...@@ -47,13 +46,14 @@
<div style="height:50px;"></div> <div style="height:50px;"></div>
<van-submit-bar <van-submit-bar
:tip="this.formatItemGroupDiscountPriceText()"
:price="fee.presentTotal" :price="fee.presentTotal"
:disabled="!checkedItemIds || !checkedItemIds.length" :disabled="!checkedItemIds || !checkedItemIds.length"
:button-text="submitBarText" :button-text="submitBarText"
@submit="onSubmit" @submit="onSubmit"
> >
<template slot> <template slot>
<van-checkbox v-model="checkedAll" @change="onSelectAll">全选</van-checkbox> <van-checkbox v-model="checkedAll" @click="onSelectAll">全选</van-checkbox>
</template> </template>
</van-submit-bar> </van-submit-bar>
</div> </div>
...@@ -87,6 +87,39 @@ export default { ...@@ -87,6 +87,39 @@ export default {
}, },
}, },
methods: { methods: {
formatFullPrivilegeText(activity) {
let text = '';
let fullPrivilege = activity.fullPrivilege;
for (let i in fullPrivilege.privileges) {
let privilege = fullPrivilege.privileges[i];
if (i > 0) {
text += ';';
}
if (fullPrivilege.cycled) {
text += '每';
}
if (privilege.meetType === 1) {
text += '满 ' + privilege.meetValue / 100.0 + ' 元,';
} else if (privilege.meetType === 2) {
text += '满 ' + privilege.meetValue + ' 件,';
}
if (privilege.preferentialType === 1) {
text += '减 ' + privilege.preferentialValue / 100.0 + ' 元';
} else if (privilege.preferentialType === 2) {
text += '打 ' + privilege.preferentialValue / 10.0 + ' 折';
}
}
return text;
},
formatItemGroupDiscountPriceText() {
let price = 0;
for (let i in this.itemGroups) {
let itemGroup = this.itemGroups[i];
price += itemGroup.fee.discountTotal;
}
return price > 0 ? '立减 ' + price / 100.0 + ' 元' : '';
},
calCheckedItemIds() { calCheckedItemIds() {
// debugger; // debugger;
let itemIds = []; let itemIds = [];
...@@ -122,11 +155,10 @@ export default { ...@@ -122,11 +155,10 @@ export default {
// 计算 checkedItemIds + checkedAll // 计算 checkedItemIds + checkedAll
this.calCheckedItemIds(); this.calCheckedItemIds();
}, },
onItemSelectedChange(newVal) { onItemSelectedChange(newVal) { // TODO 芋艿,后续研究下。这样的处理方式,很奇怪。
if (!this.checkedItemIds) { if (!this.checkedItemIds) {
return; return;
} }
// debugger;
let selected; let selected;
let diffItemIds; let diffItemIds;
if (newVal.length > this.oldCheckedItemIds.length) { // 新增 if (newVal.length > this.oldCheckedItemIds.length) { // 新增
...@@ -152,9 +184,17 @@ export default { ...@@ -152,9 +184,17 @@ export default {
if (this.checkedAll === undefined) { if (this.checkedAll === undefined) {
return; return;
} }
updateCartSelected(this.getItemIds(), newVal).then(data => { // debugger;
this.handleData(data); // updateCartSelected(this.getItemIds(), newVal).then(data => {
}) // this.handleData(data);
// })
if (newVal) {
this.onItemSelectedChange(this.getItemIds());
} else {
// alert('有 bug ,后续修复');
// this.onItemSelectedChange(this.getItemIds());
// TODO 芋艿,暂时有 bug 。后续修复
}
}, },
onSubmit() { onSubmit() {
this.$router.push('/order?from=cart') this.$router.push('/order?from=cart')
...@@ -164,7 +204,7 @@ export default { ...@@ -164,7 +204,7 @@ export default {
return { return {
...item.spu, ...item.spu,
quantity: item.buyQuantity, quantity: item.buyQuantity,
price: item.price, price: item.discountPrice || item.price,
sku: { sku: {
...item, ...item,
spu: undefined, spu: undefined,
......
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
text += '每'; text += '每';
} }
if (privilege.meetType === 1) { if (privilege.meetType === 1) {
text += '满 ' + privilege.meetValue + ' 元,'; text += '满 ' + privilege.meetValue / 100.0 + ' 元,';
} else if (privilege.meetType === 2) { } else if (privilege.meetType === 2) {
text += '满 ' + privilege.meetValue + ' 件,'; text += '满 ' + privilege.meetValue + ' 件,';
} }
......
package cn.iocoder.mall.order.application.vo; package cn.iocoder.mall.order.application.vo;
import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO; import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO;
import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
...@@ -30,12 +31,30 @@ public class UsersCartDetailVO { ...@@ -30,12 +31,30 @@ public class UsersCartDetailVO {
@Accessors(chain = true) @Accessors(chain = true)
public static class ItemGroup { public static class ItemGroup {
// TODO 优惠活动 /**
private Object activity; * 优惠活动
*/
private PromotionActivityBO activity; // TODO 芋艿,偷懒
/**
* 优惠活动是否生效
*
* 多个商品,参与某个活动,因为并发达到条件,所以会存在未生效的情况。所以一共有三种情况
*
* 1. activity 非空,activityEffectEffective 为 true,参与活动,且生效
* 2. activity 非空,activityEffectEffective 为 false ,参与活动,并未生效
* 3. activity 为空,activityEffectEffective 为空,并未参与活动。
*/
private Boolean activityEffectEffective;
/** /**
* 商品数组 * 商品数组
*/ */
private List<Sku> items; private List<Sku> items;
/**
* 费用
*
* TODO 芋艿,这里先偷懒,postageTotal 字段用不到。
*/
private Fee fee;
} }
...@@ -79,6 +98,20 @@ public class UsersCartDetailVO { ...@@ -79,6 +98,20 @@ public class UsersCartDetailVO {
* 是否选中 * 是否选中
*/ */
private Boolean selected; private Boolean selected;
/**
* 优惠活动
*/
private PromotionActivityBO activity;
/**
* 折扣价
*/
private Integer discountPrice;
/**
* 费用
*
* TODO 芋艿,这里先偷懒,postageTotal 字段用不到。
*/
private Fee fee;
} }
...@@ -151,7 +184,7 @@ public class UsersCartDetailVO { ...@@ -151,7 +184,7 @@ public class UsersCartDetailVO {
} }
/** /**
* 邮费信息 * 邮费信息 TODO 芋艿,未完成
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
......
package cn.iocoder.mall.order.application.vo; package cn.iocoder.mall.order.application.vo;
import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO; import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO;
import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
...@@ -28,8 +29,12 @@ public class UsersOrderConfirmCreateVO { ...@@ -28,8 +29,12 @@ public class UsersOrderConfirmCreateVO {
@Accessors(chain = true) @Accessors(chain = true)
public static class ItemGroup { public static class ItemGroup {
// TODO 优惠活动 /**
private Object activity; * 优惠活动
*/
// TODO 芋艿,目前只会有【满减送】的情况,未来有新的促销方式,可能需要改成数组
// TODO 芋艿,后面改成 VO
private PromotionActivityBO activity;
/** /**
* 商品数组 * 商品数组
*/ */
...@@ -73,6 +78,10 @@ public class UsersOrderConfirmCreateVO { ...@@ -73,6 +78,10 @@ public class UsersOrderConfirmCreateVO {
* 购买数量 * 购买数量
*/ */
private Integer buyQuantity; private Integer buyQuantity;
/**
* 折扣价
*/
private Integer discountPrice;
} }
......
...@@ -41,10 +41,26 @@ public class CalcOrderPriceBO { ...@@ -41,10 +41,26 @@ public class CalcOrderPriceBO {
*/ */
// TODO 芋艿,目前只会有【满减送】的情况,未来有新的促销方式,可能需要改成数组 // TODO 芋艿,目前只会有【满减送】的情况,未来有新的促销方式,可能需要改成数组
private PromotionActivityBO activity; private PromotionActivityBO activity;
/**
* 优惠活动是否生效
*
* 多个商品,参与某个活动,因为并发达到条件,所以会存在未生效的情况。所以一共有三种情况
*
* 1. activity 非空,activityEffectEffective 为 true,参与活动,且生效
* 2. activity 非空,activityEffectEffective 为 false ,参与活动,并未生效
* 3. activity 为空,activityEffectEffective 为空,并未参与活动。
*/
private Boolean activityEffectEffective;
/** /**
* 商品数组 * 商品数组
*/ */
private List<Item> items; private List<Item> items;
/**
* 费用
*
* TODO 芋艿,这里先偷懒,postageTotal 字段用不到。
*/
private Fee fee;
} }
...@@ -70,6 +86,10 @@ public class CalcOrderPriceBO { ...@@ -70,6 +86,10 @@ public class CalcOrderPriceBO {
* TODO 芋艿,这里先偷懒,postageTotal 字段用不到。 * TODO 芋艿,这里先偷懒,postageTotal 字段用不到。
*/ */
private Fee fee; private Fee fee;
/**
* 折扣价
*/
private Integer discountPrice;
} }
......
package cn.iocoder.mall.order.api.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
/**
* 购物车明细 BO
*/
@Data
@Accessors(chain = true)
public class CartBO {
/**
* 商品分组数组
*/
private List<CartItemGroupBO> itemGroups;
/**
* 费用
*/
private FeeMessageBO fee;
}
package cn.iocoder.mall.order.api.bo;
public class FeeDetailBO {
}
package cn.iocoder.mall.order.api.bo;
import java.util.List;
/**
* 商家商品分组
*/
public class MerchantItemGroup {
/**
* 商品分组数组
*/
private List<CartItemGroupBO> itemGroups;
/**
* 运费详情
*/
private PostageDetailBO postageDetail;
}
...@@ -128,6 +128,10 @@ public class PromotionActivityBO implements Serializable { ...@@ -128,6 +128,10 @@ public class PromotionActivityBO implements Serializable {
* 指定可用商品列表 * 指定可用商品列表
*/ */
private List<Integer> rangeValues; private List<Integer> rangeValues;
/**
* 是否循环
*/
private Boolean cycled;
/** /**
* 优惠数组 * 优惠数组
*/ */
......
package cn.iocoder.mall.promotion.api.constant;
/**
* 匹配类型枚举
*/
public enum MeetTypeEnum {
PRICE(1, "金额"),
QUANTITY(2, "数量"),;
/**
* 值
*/
private final Integer value;
/**
* 名字
*/
private final String name;
MeetTypeEnum(Integer value, String name) {
this.value = value;
this.name = name;
}
public Integer getValue() {
return value;
}
public String getName() {
return name;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论