"eladmin-common/src/main/vscode:/vscode.git/clone" did not exist on "189f671e88c207a06e767f72d0807f5a47e304ea"
Commit 898942fa authored by beaver383's avatar beaver383
Browse files

修复订单确认页优惠券问题

parent 6fec6b58
...@@ -25,10 +25,20 @@ public class CouponVerifyService { ...@@ -25,10 +25,20 @@ public class CouponVerifyService {
* @param checkedGoodsPrice * @param checkedGoodsPrice
* @return * @return
*/ */
public LitemallCoupon checkCoupon(Integer userId, Integer couponId, BigDecimal checkedGoodsPrice) { public LitemallCoupon checkCoupon(Integer userId, Integer couponId, Integer userCouponId, BigDecimal checkedGoodsPrice) {
LitemallCoupon coupon = couponService.findById(couponId); LitemallCoupon coupon = couponService.findById(couponId);
LitemallCouponUser couponUser = couponUserService.queryOne(userId, couponId); if (coupon == null) {
if (coupon == null || couponUser == null) { return null;
}
LitemallCouponUser couponUser = couponUserService.findById(userCouponId);
if (couponUser == null) {
couponUser = couponUserService.queryOne(userId, couponId);
} else if (!couponId.equals(couponUser.getCouponId())) {
return null;
}
if (couponUser == null) {
return null; return null;
} }
......
...@@ -105,7 +105,7 @@ export default { ...@@ -105,7 +105,7 @@ export default {
methods: { methods: {
onSubmit() { onSubmit() {
const {AddressId, CartId, CouponId} = getLocalStorage('AddressId', 'CartId', 'CouponId'); const {AddressId, CartId, CouponId, UserCouponId} = getLocalStorage('AddressId', 'CartId', 'CouponId', 'UserCouponId');
if (AddressId === null) { if (AddressId === null) {
Toast.fail('请设置收货地址'); Toast.fail('请设置收货地址');
...@@ -119,6 +119,7 @@ export default { ...@@ -119,6 +119,7 @@ export default {
addressId: AddressId, addressId: AddressId,
cartId: CartId, cartId: CartId,
couponId: CouponId, couponId: CouponId,
userCouponId: UserCouponId,
grouponLinkId: 0, grouponLinkId: 0,
grouponRulesId: 0, grouponRulesId: 0,
message: this.message message: this.message
...@@ -155,15 +156,17 @@ export default { ...@@ -155,15 +156,17 @@ export default {
getCoupons() { getCoupons() {
const {AddressId, CartId, CouponId} = getLocalStorage('AddressId', 'CartId', 'CouponId'); const {AddressId, CartId, CouponId} = getLocalStorage('AddressId', 'CartId', 'CouponId');
couponSelectList({cartId: CartId, grouponRulesId: 0}).then(res => { couponSelectList({cartId: CartId, grouponRulesId: 0}).then(res => {
var cList = res.data.data var cList = res.data.data.list;
this.coupons = [] this.coupons = []
this.disabledCoupons = [];
for(var i = 0; i < cList.length; i++){ for(var i = 0; i < cList.length; i++){
var c = cList[i] var c = cList[i]
var coupon = { var coupon = {
id: c.id, id: c.id,
cid: c.cid,
name: c.name, name: c.name,
condition: c.min, condition: '' + c.min + '元可用',
value: c.discount * 100, value: c.discount * 100,
description: c.desc, description: c.desc,
startAt: new Date(c.startTime).getTime()/1000, startAt: new Date(c.startTime).getTime()/1000,
...@@ -171,11 +174,10 @@ export default { ...@@ -171,11 +174,10 @@ export default {
valueDesc: c.discount, valueDesc: c.discount,
unitDesc: '' unitDesc: ''
} }
this.coupons.push(coupon) if (c.available) {
this.coupons.push(coupon);
if(c.id === this.couponId){ } else {
this.chosenCoupon = i; this.disabledCoupons.push(coupon);
break;
} }
} }
...@@ -183,9 +185,9 @@ export default { ...@@ -183,9 +185,9 @@ export default {
}) })
}, },
init() { init() {
const {AddressId, CartId, CouponId} = getLocalStorage('AddressId', 'CartId', 'CouponId'); const {AddressId, CartId, CouponId, UserCouponId} = getLocalStorage('AddressId', 'CartId', 'CouponId', 'UserCouponId');
cartCheckout({cartId: CartId, addressId: AddressId, couponId: CouponId, grouponRulesId: 0}).then(res => { cartCheckout({cartId: CartId, addressId: AddressId, couponId: CouponId, userCouponId: UserCouponId, grouponRulesId: 0}).then(res => {
var data = res.data.data var data = res.data.data
this.checkedGoodsList = data.checkedGoodsList; this.checkedGoodsList = data.checkedGoodsList;
...@@ -198,7 +200,7 @@ export default { ...@@ -198,7 +200,7 @@ export default {
this.goodsTotalPrice= data.goodsTotalPrice; this.goodsTotalPrice= data.goodsTotalPrice;
this.orderTotalPrice= data.orderTotalPrice; this.orderTotalPrice= data.orderTotalPrice;
setLocalStorage({AddressId: data.addressId, CartId: data.cartId, CouponId: data.couponId}); setLocalStorage({AddressId: data.addressId, CartId: data.cartId, CouponId: data.couponId, UserCouponId: data.userCouponId});
}); });
}, },
...@@ -207,11 +209,12 @@ export default { ...@@ -207,11 +209,12 @@ export default {
this.chosenCoupon = index; this.chosenCoupon = index;
if(index === -1 ){ if(index === -1 ){
setLocalStorage({CouponId: -1}); setLocalStorage({CouponId: -1, UserCouponId: -1});
} }
else{ else{
const couponId = this.coupons[index].id; const couponId = this.coupons[index].cid;
setLocalStorage({CouponId: couponId}); const userCouponId = this.coupons[index].id;
setLocalStorage({CouponId: couponId, UserCouponId: userCouponId});
} }
this.init() this.init()
...@@ -226,7 +229,7 @@ export default { ...@@ -226,7 +229,7 @@ export default {
[SubmitBar.name]: SubmitBar, [SubmitBar.name]: SubmitBar,
[Card.name]: Card, [Card.name]: Card,
[Field.name]: Field, [Field.name]: Field,
[Tag.name]: Field, [Tag.name]: Tag,
[CouponCell.name]: CouponCell, [CouponCell.name]: CouponCell,
[CouponList.name]: CouponList, [CouponList.name]: CouponList,
[Popup.name]: Popup [Popup.name]: Popup
......
...@@ -240,6 +240,7 @@ public class WxOrderService { ...@@ -240,6 +240,7 @@ public class WxOrderService {
Integer cartId = JacksonUtil.parseInteger(body, "cartId"); Integer cartId = JacksonUtil.parseInteger(body, "cartId");
Integer addressId = JacksonUtil.parseInteger(body, "addressId"); Integer addressId = JacksonUtil.parseInteger(body, "addressId");
Integer couponId = JacksonUtil.parseInteger(body, "couponId"); Integer couponId = JacksonUtil.parseInteger(body, "couponId");
Integer userCouponId = JacksonUtil.parseInteger(body, "userCouponId");
String message = JacksonUtil.parseString(body, "message"); String message = JacksonUtil.parseString(body, "message");
Integer grouponRulesId = JacksonUtil.parseInteger(body, "grouponRulesId"); Integer grouponRulesId = JacksonUtil.parseInteger(body, "grouponRulesId");
Integer grouponLinkId = JacksonUtil.parseInteger(body, "grouponLinkId"); Integer grouponLinkId = JacksonUtil.parseInteger(body, "grouponLinkId");
...@@ -301,7 +302,7 @@ public class WxOrderService { ...@@ -301,7 +302,7 @@ public class WxOrderService {
BigDecimal couponPrice = new BigDecimal(0.00); BigDecimal couponPrice = new BigDecimal(0.00);
// 如果couponId=0则没有优惠券,couponId=-1则不使用优惠券 // 如果couponId=0则没有优惠券,couponId=-1则不使用优惠券
if (couponId != 0 && couponId != -1) { if (couponId != 0 && couponId != -1) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, checkedGoodsPrice); LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice);
if (coupon == null) { if (coupon == null) {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
...@@ -390,7 +391,7 @@ public class WxOrderService { ...@@ -390,7 +391,7 @@ public class WxOrderService {
// 如果使用了优惠券,设置优惠券使用状态 // 如果使用了优惠券,设置优惠券使用状态
if (couponId != 0 && couponId != -1) { if (couponId != 0 && couponId != -1) {
LitemallCouponUser couponUser = couponUserService.queryOne(userId, couponId); LitemallCouponUser couponUser = couponUserService.findById(userCouponId);
couponUser.setStatus(CouponUserConstant.STATUS_USED); couponUser.setStatus(CouponUserConstant.STATUS_USED);
couponUser.setUsedTime(LocalDateTime.now()); couponUser.setUsedTime(LocalDateTime.now());
couponUser.setOrderId(orderId); couponUser.setOrderId(orderId);
......
...@@ -4,6 +4,7 @@ import java.time.LocalDateTime; ...@@ -4,6 +4,7 @@ import java.time.LocalDateTime;
public class CouponVo { public class CouponVo {
private Integer id; private Integer id;
private Integer cid;
private String name; private String name;
private String desc; private String desc;
private String tag; private String tag;
...@@ -11,6 +12,7 @@ public class CouponVo { ...@@ -11,6 +12,7 @@ public class CouponVo {
private String discount; private String discount;
private LocalDateTime startTime; private LocalDateTime startTime;
private LocalDateTime endTime; private LocalDateTime endTime;
private boolean available;
public Integer getId() { public Integer getId() {
return id; return id;
...@@ -20,6 +22,14 @@ public class CouponVo { ...@@ -20,6 +22,14 @@ public class CouponVo {
this.id = id; this.id = id;
} }
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getName() { public String getName() {
return name; return name;
} }
...@@ -75,4 +85,12 @@ public class CouponVo { ...@@ -75,4 +85,12 @@ public class CouponVo {
public void setEndTime(LocalDateTime endTime) { public void setEndTime(LocalDateTime endTime) {
this.endTime = endTime; this.endTime = endTime;
} }
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
} }
...@@ -386,7 +386,7 @@ public class WxCartController { ...@@ -386,7 +386,7 @@ public class WxCartController {
* @return 购物车操作结果 * @return 购物车操作结果
*/ */
@GetMapping("checkout") @GetMapping("checkout")
public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addressId, Integer couponId, Integer grouponRulesId) { public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addressId, Integer couponId, Integer userCouponId, Integer grouponRulesId) {
if (userId == null) { if (userId == null) {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
...@@ -445,10 +445,12 @@ public class WxCartController { ...@@ -445,10 +445,12 @@ public class WxCartController {
// 计算优惠券可用情况 // 计算优惠券可用情况
BigDecimal tmpCouponPrice = new BigDecimal(0.00); BigDecimal tmpCouponPrice = new BigDecimal(0.00);
Integer tmpCouponId = 0; Integer tmpCouponId = 0;
Integer tmpUserCouponId = 0;
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(), checkedGoodsPrice); tmpUserCouponId = couponUser.getId();
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), tmpUserCouponId, checkedGoodsPrice);
if(coupon == null){ if(coupon == null){
continue; continue;
} }
...@@ -468,17 +470,20 @@ public class WxCartController { ...@@ -468,17 +470,20 @@ public class WxCartController {
// 3. 用户已选择优惠券,则测试优惠券是否合适 // 3. 用户已选择优惠券,则测试优惠券是否合适
if (couponId == null || couponId.equals(-1)){ if (couponId == null || couponId.equals(-1)){
couponId = -1; couponId = -1;
userCouponId = -1;
} }
else if (couponId.equals(0)) { else if (couponId.equals(0)) {
couponPrice = tmpCouponPrice; couponPrice = tmpCouponPrice;
couponId = tmpCouponId; couponId = tmpCouponId;
userCouponId = tmpUserCouponId;
} }
else { else {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, checkedGoodsPrice); LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice);
// 用户选择的优惠券有问题,则选择合适优惠券,否则使用用户选择的优惠券 // 用户选择的优惠券有问题,则选择合适优惠券,否则使用用户选择的优惠券
if(coupon == null){ if(coupon == null){
couponPrice = tmpCouponPrice; couponPrice = tmpCouponPrice;
couponId = tmpCouponId; couponId = tmpCouponId;
userCouponId = tmpUserCouponId;
} }
else { else {
couponPrice = coupon.getDiscount(); couponPrice = coupon.getDiscount();
...@@ -502,6 +507,7 @@ public class WxCartController { ...@@ -502,6 +507,7 @@ public class WxCartController {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("addressId", addressId); data.put("addressId", addressId);
data.put("couponId", couponId); data.put("couponId", couponId);
data.put("userCouponId", userCouponId);
data.put("cartId", cartId); data.put("cartId", cartId);
data.put("grouponRulesId", grouponRulesId); data.put("grouponRulesId", grouponRulesId);
data.put("grouponPrice", grouponPrice); data.put("grouponPrice", grouponPrice);
......
...@@ -99,7 +99,8 @@ public class WxCouponController { ...@@ -99,7 +99,8 @@ public class WxCouponController {
Integer couponId = couponUser.getCouponId(); Integer couponId = couponUser.getCouponId();
LitemallCoupon coupon = couponService.findById(couponId); LitemallCoupon coupon = couponService.findById(couponId);
CouponVo couponVo = new CouponVo(); CouponVo couponVo = new CouponVo();
couponVo.setId(coupon.getId()); couponVo.setId(couponUser.getId());
couponVo.setCid(coupon.getId());
couponVo.setName(coupon.getName()); couponVo.setName(coupon.getName());
couponVo.setDesc(coupon.getDesc()); couponVo.setDesc(coupon.getDesc());
couponVo.setTag(coupon.getTag()); couponVo.setTag(coupon.getTag());
...@@ -160,17 +161,12 @@ public class WxCouponController { ...@@ -160,17 +161,12 @@ public class WxCouponController {
// 计算优惠券可用情况 // 计算优惠券可用情况
List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId); List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId);
List<LitemallCouponUser> availableCouponUserList = new ArrayList<>(couponUserList.size()); List<CouponVo> couponVoList = change(couponUserList);
for (LitemallCouponUser couponUser : couponUserList) { for (CouponVo cv : couponVoList) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), checkedGoodsPrice); LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, cv.getCid(), cv.getId(), checkedGoodsPrice);
if (coupon == null) { cv.setAvailable(coupon != null);
continue;
}
availableCouponUserList.add(couponUser);
} }
List<CouponVo> couponVoList = change(availableCouponUserList);
return ResponseUtil.okList(couponVoList); return ResponseUtil.okList(couponVoList);
} }
......
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