修改3-18问题
This commit is contained in:
@@ -22,4 +22,6 @@ public interface SmsCouponMapper extends BaseMapper<SmsCoupon> {
|
|||||||
List<SmsCoupon> selectRecive(@Param("memberId") Long memberId, @Param("limit") Integer limit);
|
List<SmsCoupon> selectRecive(@Param("memberId") Long memberId, @Param("limit") Integer limit);
|
||||||
|
|
||||||
SmsCouponParam getItem(@Param("id") Long id);
|
SmsCouponParam getItem(@Param("id") Long id);
|
||||||
|
|
||||||
|
List<SmsCoupon> selectAll();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
LEFT JOIN sms_coupon_product_category_relation cpcr ON cpcr.coupon_id = c.id
|
LEFT JOIN sms_coupon_product_category_relation cpcr ON cpcr.coupon_id = c.id
|
||||||
WHERE ch.member_id = #{memberId}
|
WHERE ch.member_id = #{memberId}
|
||||||
AND ch.use_status = 0 and now() >c.start_time and c.end_time>now()
|
AND ch.use_status = 0 and now() >c.start_time and c.end_time>now()
|
||||||
|
order by ch.amount desc
|
||||||
</select>
|
</select>
|
||||||
<!-- 通用查询结果列 -->
|
<!-- 通用查询结果列 -->
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
|
|||||||
@@ -59,12 +59,18 @@
|
|||||||
|
|
||||||
<select id="selectNotRecive" resultMap="BaseResultMap">
|
<select id="selectNotRecive" resultMap="BaseResultMap">
|
||||||
SELECT sms_coupon.* from sms_coupon where count>0 and now()>=start_time and end_time>=now() and (SELECT count(*) from sms_coupon_history where member_id =
|
SELECT sms_coupon.* from sms_coupon where count>0 and now()>=start_time and end_time>=now() and (SELECT count(*) from sms_coupon_history where member_id =
|
||||||
#{memberId} and sms_coupon.id = coupon_id) < per_limit limit #{limit}
|
#{memberId} and sms_coupon.id = coupon_id) < per_limit
|
||||||
|
<if test="limit != null and limit != ''">
|
||||||
|
limit #{limit}
|
||||||
|
</if>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
<select id="selectRecive" resultMap="BaseResultMap">
|
<select id="selectRecive" resultMap="BaseResultMap">
|
||||||
|
|
||||||
SELECT sms_coupon.* from sms_coupon where id in (SELECT coupon_id from sms_coupon_history where member_id =
|
SELECT sms_coupon.* from sms_coupon where id in (SELECT coupon_id from sms_coupon_history where member_id =
|
||||||
#{memberId}) limit #{limit}
|
#{memberId}) limit #{limit}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectAll" resultMap="BaseResultMap">
|
||||||
|
SELECT sms_coupon.* from sms_coupon where count>0 and now()>=start_time and end_time>=now()
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ public class SingeMarkingController extends ApiBaseAction {
|
|||||||
|
|
||||||
@ApiOperation("领取指定优惠券")
|
@ApiOperation("领取指定优惠券")
|
||||||
@PostMapping(value = "/add")
|
@PostMapping(value = "/add")
|
||||||
public Object add(@RequestParam(value = "couponId", required = true) Long couponId) {
|
public Object add(@RequestParam(value = "couponId", required = false) Long couponId) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return couponService.add(couponId);
|
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.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.zscat.mallplus.oms.entity.OmsCartItem;
|
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.entity.*;
|
||||||
import com.zscat.mallplus.sms.mapper.*;
|
import com.zscat.mallplus.sms.mapper.*;
|
||||||
import com.zscat.mallplus.sms.service.ISmsCouponService;
|
import com.zscat.mallplus.sms.service.ISmsCouponService;
|
||||||
@@ -16,10 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,7 +176,104 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
|
|||||||
if (currentMember == null) {
|
if (currentMember == null) {
|
||||||
return new CommonResult().failed("优惠券不存在");
|
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);
|
SmsCoupon coupon = couponMapper.selectById(couponId);
|
||||||
if (coupon == null) {
|
if (coupon == null) {
|
||||||
return new CommonResult().failed("优惠券不存在");
|
return new CommonResult().failed("优惠券不存在");
|
||||||
@@ -219,7 +314,7 @@ public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon
|
|||||||
//修改优惠券表的数量、领取数量
|
//修改优惠券表的数量、领取数量
|
||||||
coupon.setCount(coupon.getCount() - 1);
|
coupon.setCount(coupon.getCount() - 1);
|
||||||
coupon.setReceiveCount(coupon.getReceiveCount() == null ? 1 : coupon.getReceiveCount() + 1);
|
coupon.setReceiveCount(coupon.getReceiveCount() == null ? 1 : coupon.getReceiveCount() + 1);
|
||||||
couponMapper.updateById(coupon);
|
couponMapper.updateById(coupon);*/
|
||||||
return new CommonResult().success("领取成功", "领取成功");
|
return new CommonResult().success("领取成功", "领取成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user