Commit eac36ce3 authored by Junling Bu's avatar Junling Bu
Browse files

Merge branch 'master' of https://github.com/linlinjava/litemall

parents 9c387395 d611977c
...@@ -135,10 +135,76 @@ ...@@ -135,10 +135,76 @@
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item v-show="dataForm.goodsType === 1"> <el-form-item v-show="dataForm.goodsType === 1">
目前不支持 <el-cascader
v-model="selectGoodsCategory"
clearable
placeholder="请选择分类名称"
:options="goodsCategoryOptions"
/>
<el-button @click="handleAddGoodsCategory()">添加</el-button>
<el-table
ref="goodsCateRelationTable"
:data="couponCategoryList"
style="width: 100%;margin-top: 20px"
border
>
<el-table-column label="分类名称" align="center">
<template slot-scope="scope">{{ scope.row.parentCategoryName }}>{{ scope.row.goodsCategoryName }}</template>
</el-table-column>
<el-table-column label="操作" align="center" width="100">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
@click="handleDeleteGoodsCategory(scope.$index, scope.row)"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item> </el-form-item>
<el-form-item v-show="dataForm.goodsType === 2"> <el-form-item v-show="dataForm.goodsType === 2">
目前不支持 <el-select
v-model="selectGoods"
filterable
remote
reserve-keyword
placeholder="商品名称/商品货号"
>
<el-option
v-for="item in goodsOptions"
:key="item.goodsId"
:label="item.goodsName"
:value="item.goodsId"
>
<span style="float: left">{{ item.goodsName }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">NO.{{ item.goodsSn }}</span>
</el-option>
</el-select>
<el-button @click="handleAddGoods()">添加</el-button>
<el-table
ref="goodsRelationTable"
:data="couponGoodsList"
style="width: 100%;margin-top: 20px"
border
>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{ scope.row.goodsName }}</template>
</el-table-column>
<el-table-column label="商品编号" align="center" width="80">
<template slot-scope="scope">{{ scope.row.goodsSn }}</template>
</el-table-column>
<el-table-column label="操作" align="center" width="60">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
@click="handleDeleteGoods(scope.$index, scope.row)"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
...@@ -179,6 +245,8 @@ ...@@ -179,6 +245,8 @@
<script> <script>
import { listCoupon, createCoupon, updateCoupon, deleteCoupon } from '@/api/coupon' import { listCoupon, createCoupon, updateCoupon, deleteCoupon } from '@/api/coupon'
import { listCategory } from '@/api/category.js'
import { listGoods } from '@/api/goods.js'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
const defaultTypeOptions = [ const defaultTypeOptions = [
...@@ -287,11 +355,19 @@ export default { ...@@ -287,11 +355,19 @@ export default {
{ required: true, message: '优惠券标题不能为空', trigger: 'blur' } { required: true, message: '优惠券标题不能为空', trigger: 'blur' }
] ]
}, },
downloadLoading: false downloadLoading: false,
selectGoods: null,
goodsOptions: [],
selectGoodsCategory: null,
goodsCategoryOptions: [],
couponGoodsList: [],
couponCategoryList: []
} }
}, },
created() { created() {
this.getList() this.getList()
this.getCategoryList()
this.getGoodsList()
}, },
methods: { methods: {
getList() { getList() {
...@@ -331,6 +407,8 @@ export default { ...@@ -331,6 +407,8 @@ export default {
startTime: null, startTime: null,
endTime: null endTime: null
} }
this.couponCategoryList = []
this.couponGoodsList = []
}, },
handleCreate() { handleCreate() {
this.resetForm() this.resetForm()
...@@ -343,6 +421,12 @@ export default { ...@@ -343,6 +421,12 @@ export default {
createData() { createData() {
this.$refs['dataForm'].validate(valid => { this.$refs['dataForm'].validate(valid => {
if (valid) { if (valid) {
if (this.dataForm.goodsType === 1) {
this.dataForm.goodsValue = this.couponCategoryList.map(item => (item.goodsCategoryId))
}
if (this.dataForm.goodsType === 2) {
this.dataForm.goodsValue = this.couponGoodsList.map(item => (item.goodsId))
}
createCoupon(this.dataForm) createCoupon(this.dataForm)
.then(response => { .then(response => {
this.list.unshift(response.data.data) this.list.unshift(response.data.data)
...@@ -447,6 +531,84 @@ export default { ...@@ -447,6 +531,84 @@ export default {
excel.export_json_to_excel2(tHeader, this.list, filterVal, '优惠券信息') excel.export_json_to_excel2(tHeader, this.list, filterVal, '优惠券信息')
this.downloadLoading = false this.downloadLoading = false
}) })
},
getGoodsList() {
listGoods({ limit: 0 }).then(response => {
const goodsList = response.data.data.list
this.goodsOptions = []
for (let i = 0; i < goodsList.length; i++) {
const item = goodsList[i]
this.goodsOptions.push({ goodsId: item.id, goodsName: item.name, goodsSn: item.goodsSn })
}
}).catch(() => {
this.goodsOptions = []
})
},
handleAddGoods() {
if (this.selectGoods === null) {
this.$message({
message: '请先选择商品',
type: 'warning'
})
return
}
this.couponGoodsList.push(this.getGoodsById(this.selectGoods))
this.selectGoods = null
},
handleDeleteGoods(index, row) {
this.couponGoodsList.splice(index, 1)
},
handleAddGoodsCategory() {
if (this.selectGoodsCategory === null || this.selectGoodsCategory.length === 0) {
this.$message({
message: '请先选择商品分类',
type: 'warning'
})
return
}
this.couponCategoryList.push(this.getGoodsCategoryByIds(this.selectGoodsCategory))
this.selectGoodsCategory = []
},
handleDeleteGoodsCategory(index, row) {
this.couponCategoryList.splice(index, 1)
},
getGoodsById(id) {
for (let i = 0; i < this.goodsOptions.length; i++) {
if (id === this.goodsOptions[i].goodsId) {
return this.goodsOptions[i]
}
}
return null
},
getCategoryList() {
listCategory().then(response => {
const list = response.data.data.list
this.goodsCategoryOptions = []
for (let i = 0; i < list.length; i++) {
const children = []
if (list[i].children != null && list[i].children.length > 0) {
for (let j = 0; j < list[i].children.length; j++) {
children.push({ label: list[i].children[j].name, value: list[i].children[j].id })
}
}
this.goodsCategoryOptions.push({ label: list[i].name, value: list[i].id, children: children })
}
})
},
getGoodsCategoryByIds(ids) {
let name
let parentName
for (let i = 0; i < this.goodsCategoryOptions.length; i++) {
if (this.goodsCategoryOptions[i].value === ids[0]) {
parentName = this.goodsCategoryOptions[i].label
for (let j = 0; j < this.goodsCategoryOptions[i].children.length; j++) {
if (this.goodsCategoryOptions[i].children[j].value === ids[1]) {
name = this.goodsCategoryOptions[i].children[j].label
}
}
}
}
return { goodsCategoryId: ids[1], goodsCategoryName: name, parentCategoryName: parentName }
} }
} }
} }
......
package org.linlinjava.litemall.db.service; package org.linlinjava.litemall.db.service;
import org.linlinjava.litemall.db.domain.LitemallCart;
import org.linlinjava.litemall.db.domain.LitemallCoupon; import org.linlinjava.litemall.db.domain.LitemallCoupon;
import org.linlinjava.litemall.db.domain.LitemallCouponUser; import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.util.CouponConstant; import org.linlinjava.litemall.db.util.CouponConstant;
...@@ -8,6 +9,10 @@ import org.springframework.stereotype.Service; ...@@ -8,6 +9,10 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class CouponVerifyService { public class CouponVerifyService {
...@@ -16,6 +21,8 @@ public class CouponVerifyService { ...@@ -16,6 +21,8 @@ public class CouponVerifyService {
private LitemallCouponUserService couponUserService; private LitemallCouponUserService couponUserService;
@Autowired @Autowired
private LitemallCouponService couponService; private LitemallCouponService couponService;
@Autowired
private LitemallGoodsService goodsService;
/** /**
* 检测优惠券是否适合 * 检测优惠券是否适合
...@@ -25,7 +32,7 @@ public class CouponVerifyService { ...@@ -25,7 +32,7 @@ public class CouponVerifyService {
* @param checkedGoodsPrice * @param checkedGoodsPrice
* @return * @return
*/ */
public LitemallCoupon checkCoupon(Integer userId, Integer couponId, Integer userCouponId, BigDecimal checkedGoodsPrice) { public LitemallCoupon checkCoupon(Integer userId, Integer couponId, Integer userCouponId, BigDecimal checkedGoodsPrice, List<LitemallCart> cartList) {
LitemallCoupon coupon = couponService.findById(couponId); LitemallCoupon coupon = couponService.findById(couponId);
if (coupon == null) { if (coupon == null) {
return null; return null;
...@@ -62,10 +69,25 @@ public class CouponVerifyService { ...@@ -62,10 +69,25 @@ public class CouponVerifyService {
} }
// 检测商品是否符合 // 检测商品是否符合
// TODO 目前仅支持全平台商品,所以不需要检测 List<Integer> goodsList = cartList.stream().map(item -> item.getGoodsId()).collect(Collectors.toList());
for (LitemallCart cart : cartList) {
goodsList.add(cart.getGoodsId());
}
List<Integer> goodsValueList = new ArrayList<>(Arrays.asList(coupon.getGoodsValue()));
Short goodType = coupon.getGoodsType(); Short goodType = coupon.getGoodsType();
if (!goodType.equals(CouponConstant.GOODS_TYPE_ALL)) { if (goodType.equals(CouponConstant.GOODS_TYPE_ARRAY)) {
return null; goodsValueList.retainAll(goodsList);
if (goodsValueList.size() <= 0) {
return null;
}
} else if (goodType.equals(CouponConstant.GOODS_TYPE_CATEGORY)) {
List<Integer> categoryList = cartList.stream()
.map(item -> goodsService.findById(item.getGoodsId())
.getCategoryId()).collect(Collectors.toList());
goodsValueList.retainAll(categoryList);
if (goodsValueList.size() <= 0) {
return null;
}
} }
// 检测订单状态 // 检测订单状态
......
...@@ -340,7 +340,7 @@ public class WxOrderService { ...@@ -340,7 +340,7 @@ public class WxOrderService {
BigDecimal couponPrice = new BigDecimal(0); BigDecimal couponPrice = new BigDecimal(0);
// 如果couponId=0则没有优惠券,couponId=-1则不使用优惠券 // 如果couponId=0则没有优惠券,couponId=-1则不使用优惠券
if (couponId != 0 && couponId != -1) { if (couponId != 0 && couponId != -1) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice); LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice, checkedGoodsList);
if (coupon == null) { if (coupon == null) {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
...@@ -485,7 +485,7 @@ public class WxOrderService { ...@@ -485,7 +485,7 @@ public class WxOrderService {
* 1. 检测当前订单是否能够取消; * 1. 检测当前订单是否能够取消;
* 2. 设置订单取消状态; * 2. 设置订单取消状态;
* 3. 商品货品库存恢复; * 3. 商品货品库存恢复;
* 4. TODO 优惠券; * 4. 返还优惠券;
* *
* @param userId 用户ID * @param userId 用户ID
* @param body 订单信息,{ orderId:xxx } * @param body 订单信息,{ orderId:xxx }
......
...@@ -469,7 +469,7 @@ public class WxCartController { ...@@ -469,7 +469,7 @@ public class WxCartController {
int tmpCouponLength = 0; int tmpCouponLength = 0;
List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId); List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId);
for(LitemallCouponUser couponUser : couponUserList){ for(LitemallCouponUser couponUser : couponUserList){
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), couponUser.getId(), checkedGoodsPrice); LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), couponUser.getId(), checkedGoodsPrice, checkedGoodsList);
if(coupon == null){ if(coupon == null){
continue; continue;
} }
...@@ -498,7 +498,7 @@ public class WxCartController { ...@@ -498,7 +498,7 @@ public class WxCartController {
userCouponId = tmpUserCouponId; userCouponId = tmpUserCouponId;
} }
else { else {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice); LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice, checkedGoodsList);
// 用户选择的优惠券有问题,则选择合适优惠券,否则使用用户选择的优惠券 // 用户选择的优惠券有问题,则选择合适优惠券,否则使用用户选择的优惠券
if(coupon == null){ if(coupon == null){
couponPrice = tmpCouponPrice; couponPrice = tmpCouponPrice;
......
...@@ -155,12 +155,11 @@ public class WxCouponController { ...@@ -155,12 +155,11 @@ public class WxCouponController {
checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().multiply(new BigDecimal(cart.getNumber()))); checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().multiply(new BigDecimal(cart.getNumber())));
} }
} }
// 计算优惠券可用情况 // 计算优惠券可用情况
List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId); List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId);
List<CouponVo> couponVoList = change(couponUserList); List<CouponVo> couponVoList = change(couponUserList);
for (CouponVo cv : couponVoList) { for (CouponVo cv : couponVoList) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, cv.getCid(), cv.getId(), checkedGoodsPrice); LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, cv.getCid(), cv.getId(), checkedGoodsPrice, checkedGoodsList);
cv.setAvailable(coupon != null); cv.setAvailable(coupon != null);
} }
......
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