修改3-18问题
This commit is contained in:
@@ -120,7 +120,7 @@ public class SingeMarkingController extends ApiBaseAction {
|
||||
|
||||
@ApiOperation("领取指定优惠券")
|
||||
@PostMapping(value = "/add")
|
||||
public Object add(@RequestParam(value = "couponId", required = true) Long couponId) {
|
||||
public Object add(@RequestParam(value = "couponId", required = false) Long couponId) {
|
||||
|
||||
try {
|
||||
return couponService.add(couponId);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.zscat.mallplus.sms.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zscat.mallplus.oms.entity.OmsCartItem;
|
||||
import com.zscat.mallplus.pay.utils.StringUtils;
|
||||
import com.zscat.mallplus.sms.entity.*;
|
||||
import com.zscat.mallplus.sms.mapper.*;
|
||||
import com.zscat.mallplus.sms.service.ISmsCouponService;
|
||||
@@ -16,10 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -178,7 +176,104 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
|
||||
if (currentMember == null) {
|
||||
return new CommonResult().failed("优惠券不存在");
|
||||
}
|
||||
//获取优惠券信息,判断数量
|
||||
if(couponId != null){
|
||||
//获取优惠券信息,判断数量
|
||||
SmsCoupon coupon = couponMapper.selectById(couponId);
|
||||
if (coupon == null) {
|
||||
return new CommonResult().failed("优惠券不存在");
|
||||
}
|
||||
if (coupon.getCount() <= 0) {
|
||||
return new CommonResult().failed("优惠券已经领完了");
|
||||
}
|
||||
Date now = new Date();
|
||||
if (now.after(coupon.getEndTime())) {
|
||||
return new CommonResult().failed("优惠券已过期");
|
||||
}
|
||||
//判断用户领取的优惠券数量是否超过限制
|
||||
SmsCouponHistory queryH = new SmsCouponHistory();
|
||||
queryH.setMemberId(currentMember.getId());
|
||||
queryH.setCouponId(couponId);
|
||||
|
||||
int count = couponHistoryMapper.selectCount(new QueryWrapper<>(queryH));
|
||||
if (count >= coupon.getPerLimit()) {
|
||||
return new CommonResult().failed("您已经领取过该优惠券");
|
||||
}
|
||||
//生成领取优惠券历史
|
||||
SmsCouponHistory couponHistory = new SmsCouponHistory();
|
||||
couponHistory.setCouponId(couponId);
|
||||
couponHistory.setCouponCode(generateCouponCode(currentMember.getId()));
|
||||
couponHistory.setCreateTime(now);
|
||||
couponHistory.setMemberId(currentMember.getId());
|
||||
couponHistory.setMemberNickname(currentMember.getNickname());
|
||||
//主动领取
|
||||
couponHistory.setGetType(1);
|
||||
//未使用
|
||||
couponHistory.setUseStatus(0);
|
||||
couponHistory.setStartTime(coupon.getStartTime());
|
||||
couponHistory.setEndTime(coupon.getEndTime());
|
||||
couponHistory.setNote(coupon.getName() + ":满" + coupon.getMinPoint() + "减" + coupon.getAmount());
|
||||
couponHistory.setAmount(coupon.getAmount());
|
||||
couponHistory.setMinPoint(coupon.getMinPoint());
|
||||
couponHistoryMapper.insert(couponHistory);
|
||||
//修改优惠券表的数量、领取数量
|
||||
coupon.setCount(coupon.getCount() - 1);
|
||||
coupon.setReceiveCount(coupon.getReceiveCount() == null ? 1 : coupon.getReceiveCount() + 1);
|
||||
couponMapper.updateById(coupon);
|
||||
}else{
|
||||
//一键领取
|
||||
//查询未过期的以及未领取的数量
|
||||
List<SmsCoupon> smsCouponList = baseMapper.selectAll();
|
||||
smsCouponList.removeAll(Collections.singleton(null));
|
||||
if(!smsCouponList.isEmpty()){
|
||||
for (int i = 0;i<smsCouponList.size();i++){
|
||||
//优惠券是否已领完
|
||||
SmsCoupon smsCoupon = smsCouponList.get(i);
|
||||
if(smsCoupon.getCount()<=0){
|
||||
continue;
|
||||
}else{
|
||||
//判断用户领取的优惠券数量是否超过限制
|
||||
SmsCouponHistory queryH = new SmsCouponHistory();
|
||||
queryH.setMemberId(currentMember.getId());
|
||||
queryH.setCouponId(smsCoupon.getId());
|
||||
int count = couponHistoryMapper.selectCount(new QueryWrapper<>(queryH));
|
||||
if (count >= smsCoupon.getPerLimit()) {
|
||||
continue;
|
||||
}else{
|
||||
int counts = smsCoupon.getPerLimit()-count;
|
||||
for(int j = 0;j<counts;j++){
|
||||
//生成领取优惠券历史
|
||||
Date now = new Date();
|
||||
SmsCouponHistory couponHistory = new SmsCouponHistory();
|
||||
couponHistory.setCouponId(smsCoupon.getId());
|
||||
couponHistory.setCouponCode(generateCouponCode(currentMember.getId()));
|
||||
couponHistory.setCreateTime(now);
|
||||
couponHistory.setMemberId(currentMember.getId());
|
||||
couponHistory.setMemberNickname(currentMember.getNickname());
|
||||
//主动领取
|
||||
couponHistory.setGetType(1);
|
||||
//未使用
|
||||
couponHistory.setUseStatus(0);
|
||||
couponHistory.setStartTime(smsCoupon.getStartTime());
|
||||
couponHistory.setEndTime(smsCoupon.getEndTime());
|
||||
couponHistory.setNote(smsCoupon.getName() + ":满" + smsCoupon.getMinPoint() + "减" + smsCoupon.getAmount());
|
||||
couponHistory.setAmount(smsCoupon.getAmount());
|
||||
couponHistory.setMinPoint(smsCoupon.getMinPoint());
|
||||
couponHistoryMapper.insert(couponHistory);
|
||||
//修改优惠券表的数量、领取数量
|
||||
smsCoupon.setCount(smsCoupon.getCount() - 1);
|
||||
smsCoupon.setReceiveCount(smsCoupon.getReceiveCount() == null ? 1 : smsCoupon.getReceiveCount() + 1);
|
||||
couponMapper.updateById(smsCoupon);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*//获取优惠券信息,判断数量
|
||||
SmsCoupon coupon = couponMapper.selectById(couponId);
|
||||
if (coupon == null) {
|
||||
return new CommonResult().failed("优惠券不存在");
|
||||
@@ -219,7 +314,7 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
|
||||
//修改优惠券表的数量、领取数量
|
||||
coupon.setCount(coupon.getCount() - 1);
|
||||
coupon.setReceiveCount(coupon.getReceiveCount() == null ? 1 : coupon.getReceiveCount() + 1);
|
||||
couponMapper.updateById(coupon);
|
||||
couponMapper.updateById(coupon);*/
|
||||
return new CommonResult().success("领取成功", "领取成功");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user