Commit 02a41fd4 authored by Menethil's avatar Menethil
Browse files

优化团购

parent eec5e222
......@@ -53,41 +53,8 @@
<el-table-column align="center" label="结束时间" prop="rules.expireTime">
</el-table-column>
<!--<el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">-->
<!--<template slot-scope="scope">-->
<!--<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>-->
<!--<el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>-->
<!--</template>-->
<!--</el-table-column>-->
</el-table>
<!-- 添加或修改对话框 -->
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
<el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="100px"
style='width: 400px; margin-left:50px;'>
<el-form-item label="商品ID" prop="goodsId">
<el-input v-model="dataForm.goodsId"></el-input>
</el-form-item>
<el-form-item label="团购折扣" prop="discount">
<el-input v-model="dataForm.discount"></el-input>
</el-form-item>
<el-form-item label="团购人数要求" prop="discountMember">
<el-input v-model="dataForm.discountMember"></el-input>
</el-form-item>
<el-form-item label="过期时间" prop="expireTime">
<el-date-picker v-model="dataForm.expireTime" type="datetime" placeholder="选择日期"
value-format="yyyy-MM-dd HH:mm:ss">
</el-date-picker>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取消</el-button>
<el-button v-if="dialogStatus=='create'" type="primary" @click="createData">确定</el-button>
<el-button v-else type="primary" @click="updateData">确定</el-button>
</div>
</el-dialog>
<!-- 分页 -->
<div class="pagination-container">
<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
......@@ -147,19 +114,6 @@
goodsDetail: '',
detailDialogVisible: false,
downloadLoading: false,
dataForm: {
id: undefined,
goodsId: '',
discount: '',
discountMember: '',
expireTime: undefined,
},
dialogFormVisible: false,
dialogStatus: '',
textMap: {
update: '编辑',
create: '创建'
},
}
},
created() {
......@@ -190,81 +144,6 @@
this.listQuery.page = val
this.getList()
},
resetForm() {
this.dataForm = {
id: undefined,
goodsId: '',
discount: '',
discountMember: '',
expireTime: undefined,
}
},
handleCreate() {
this.resetForm()
this.dialogStatus = 'create'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
createData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
publishGroupon(this.dataForm).then(response => {
this.list.unshift(response.data.data)
this.dialogFormVisible = false
this.$notify({
title: '成功',
message: '创建成功',
type: 'success',
duration: 2000
})
})
}
})
},
handleUpdate(row) {
this.dataForm = Object.assign({}, row)
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
updateData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
editGroupon(this.dataForm).then(() => {
for (const v of this.list) {
if (v.id === this.dataForm.id) {
const index = this.list.indexOf(v)
this.list.splice(index, 1, this.dataForm)
break
}
}
this.dialogFormVisible = false
this.$notify({
title: '成功',
message: '更新成功',
type: 'success',
duration: 2000
})
})
}
})
},
handleDelete(row) {
deleteGroupon(row).then(response => {
this.$notify({
title: '成功',
message: '删除成功',
type: 'success',
duration: 2000
})
const index = this.list.indexOf(row)
this.list.splice(index, 1)
})
},
handleDownload() {
this.downloadLoading = true
import('@/vendor/Export2Excel').then(excel => {
......
......@@ -52,6 +52,7 @@ class SystemInistService {
infos.put("本地对象访问地址", environment.getProperty("litemall.storage.local.address"));
infos.put("本地对象访问端口", environment.getProperty("litemall.storage.local.port"));
// 微信相关信息
infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 2, "微信相关");
infos.put("微信APP KEY", environment.getProperty("litemall.wx.app-id"));
infos.put("微信APP-SECRET", environment.getProperty("litemall.wx.app-secret"));
......
......@@ -417,7 +417,7 @@ public class WxCartController {
* 失败则 { errno: XXX, errmsg: XXX }
*/
@GetMapping("checkout")
public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addressId, Integer couponId, Integer grouponId) {
public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addressId, Integer couponId, Integer grouponRulesId) {
if (userId == null) {
return ResponseUtil.unlogin();
}
......@@ -448,6 +448,13 @@ public class WxCartController {
// 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00);
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId);
if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount();
}
// 商品价格
List<LitemallCart> checkedGoodsList = null;
if (cartId == null || cartId.equals(0)) {
......@@ -462,7 +469,12 @@ public class WxCartController {
}
BigDecimal checkedGoodsPrice = new BigDecimal(0.00);
for (LitemallCart cart : checkedGoodsList) {
checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().multiply(new BigDecimal(cart.getNumber())));
// 只有当团购规格商品ID符合才进行团购优惠
if (grouponRules != null && grouponRules.getGoodsId().equals(cart.getGoodsId())) {
checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().subtract(grouponPrice).multiply(new BigDecimal(cart.getNumber())));
} else {
checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().multiply(new BigDecimal(cart.getNumber())));
}
}
// 根据订单商品总价计算运费,满88则免运费,否则8元;
......@@ -474,20 +486,13 @@ public class WxCartController {
// 可以使用的其他钱,例如用户积分
BigDecimal integralPrice = new BigDecimal(0.00);
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponId);
if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount();
}
// 订单费用
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice).subtract(grouponPrice);
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice);
BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice);
Map<String, Object> data = new HashMap<>();
data.put("addressId", addressId);
data.put("grouponId", grouponId);
data.put("grouponRulesId", grouponRulesId);
data.put("checkedAddress", checkedAddress);
data.put("couponId", couponId);
data.put("checkedCoupon", 0);
......@@ -495,7 +500,6 @@ public class WxCartController {
data.put("goodsTotalPrice", checkedGoodsPrice);
data.put("freightPrice", freightPrice);
data.put("couponPrice", couponPrice);
data.put("grouponPrice", grouponPrice);
data.put("orderTotalPrice", orderTotalPrice);
data.put("actualPrice", actualPrice);
data.put("checkedGoodsList", checkedGoodsList);
......
......@@ -101,13 +101,22 @@ public class WxHomeController {
//优惠专区
List<LitemallGrouponRules> grouponRules = grouponRulesService.queryByIndex(0, 4);
List<LitemallGoods> grouponGoods = new ArrayList<>();
List<Map<String, Object>> grouponList = new ArrayList<>();
for (LitemallGrouponRules rule : grouponRules) {
LitemallGoods goods = goodsService.findById(rule.getGoodsId());
if (goods == null)
continue;
if (!grouponGoods.contains(goods)) {
Map<String, Object> item = new HashMap<>();
item.put("goods", goods);
item.put("groupon_price", goods.getRetailPrice().subtract(rule.getDiscount()));
item.put("groupon_member", rule.getDiscountMember());
grouponList.add(item);
grouponGoods.add(goods);
}
}
data.put("grouponList", grouponGoods);
data.put("grouponList", grouponList);
List<Map> categoryList = new ArrayList<>();
List<LitemallCategory> catL1List = categoryService.queryL1WithoutRecommend(0, SystemConfig.getCatlogListLimit());
......
......@@ -279,7 +279,7 @@ public class WxOrderController {
Integer cartId = JacksonUtil.parseInteger(body, "cartId");
Integer addressId = JacksonUtil.parseInteger(body, "addressId");
Integer couponId = JacksonUtil.parseInteger(body, "couponId");
Integer grouponId = JacksonUtil.parseInteger(body, "grouponId");
Integer grouponRulesId = JacksonUtil.parseInteger(body, "grouponRulesId");
Integer grouponLinkId = JacksonUtil.parseInteger(body, "grouponLinkId");
if (cartId == null || addressId == null || couponId == null) {
......@@ -293,6 +293,13 @@ public class WxOrderController {
// 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00);
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId);
if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount();
}
// 货品价格
List<LitemallCart> checkedGoodsList = null;
if (cartId.equals(0)) {
......@@ -307,7 +314,12 @@ public class WxOrderController {
}
BigDecimal checkedGoodsPrice = new BigDecimal(0.00);
for (LitemallCart checkGoods : checkedGoodsList) {
checkedGoodsPrice = checkedGoodsPrice.add(checkGoods.getPrice().multiply(new BigDecimal(checkGoods.getNumber())));
// 只有当团购规格商品ID符合才进行团购优惠
if (grouponRules != null && grouponRules.getGoodsId().equals(checkGoods.getGoodsId())) {
checkedGoodsPrice = checkedGoodsPrice.add(checkGoods.getPrice().subtract(grouponPrice).multiply(new BigDecimal(checkGoods.getNumber())));
} else {
checkedGoodsPrice = checkedGoodsPrice.add(checkGoods.getPrice().multiply(new BigDecimal(checkGoods.getNumber())));
}
}
// 根据订单商品总价计算运费,满88则免运费,否则8元;
......@@ -319,15 +331,8 @@ public class WxOrderController {
// 可以使用的其他钱,例如用户积分
BigDecimal integralPrice = new BigDecimal(0.00);
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponId);
if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount();
}
// 订单费用
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice).subtract(grouponPrice);
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice);
BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice);
// 开启事务管理
......@@ -400,18 +405,19 @@ public class WxOrderController {
}
//如果是团购项目,添加团购信息
if (grouponId != null && grouponId > 0) {
if (grouponRulesId != null && grouponRulesId > 0) {
LitemallGroupon groupon = new LitemallGroupon();
groupon.setOrderId(orderId);
groupon.setPayed(false);
groupon.setUserId(userId);
groupon.setRulesId(grouponId);
groupon.setRulesId(grouponRulesId);
//参与者
if (grouponLinkId != null && grouponLinkId > 0) {
LitemallGroupon baseGroupon = grouponService.queryById(grouponLinkId);
groupon.setCreatorUserId(baseGroupon.getCreatorUserId());
groupon.setGrouponId(grouponLinkId);
groupon.setShareUrl(baseGroupon.getShareUrl());
} else {
groupon.setCreatorUserId(userId);
groupon.setGrouponId(0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment