Commit 3a137006 by 吕明尚

优惠卷赠送功能

parent 3dc7a59f
......@@ -121,4 +121,10 @@ public class SConsumerCouponController extends BaseController
{
return toAjax(sConsumerCouponService.deleteSConsumerCouponByIds(ids));
}
//赠送优惠卷
@PostMapping("/give")
public AjaxResult give(@RequestBody SConsumerCoupon sConsumerCoupon) {
return toAjax(sConsumerCouponService.give(sConsumerCoupon));
}
}
......@@ -64,4 +64,6 @@ public interface ISConsumerCouponService extends IService<SConsumerCoupon>
int selectSConsumerCouponConut(SConsumerCoupon sConsumerCoupon);
List<SConsumerCoupon> availableCouponList(CouponRequest couponRequest);
int give(SConsumerCoupon sConsumerCoupon);
}
......@@ -8,18 +8,17 @@ import java.util.*;
import cn.hutool.json.JSONArray;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import share.common.enums.*;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.system.domain.SConsumer;
import share.system.domain.SRoom;
import share.system.domain.SStore;
import share.system.domain.*;
import share.system.domain.vo.FrontTokenComponent;
import share.system.mapper.SConsumerCouponMapper;
import share.system.domain.SConsumerCoupon;
import share.system.request.CouponRequest;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISCouponService;
import share.system.service.ISRoomService;
import share.system.service.ISStoreService;
......@@ -40,6 +39,11 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
@Autowired
private ISStoreService sStoreService;
@Autowired
private ISCouponService sCouponService;
private static final Integer ZERO = 0;
/**
* 查询优惠券领取记录
*
......@@ -181,6 +185,42 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
return sConsumerCoupons;
}
@Override
public int give(SConsumerCoupon sConsumerCoupon) {
//根据优惠券id查询优惠券信息
SCoupon sCoupon = sCouponService.selectSCouponById(sConsumerCoupon.getCouponId());
if (ObjectUtils.isEmpty(sCoupon)) {
return 0;
}
if (sCoupon.getNumber().equals(ZERO)) {
throw new RuntimeException("优惠券数量为0");
}
//创建优惠卷领取记录
SConsumerCoupon newSConsumerCoupon = new SConsumerCoupon();
newSConsumerCoupon.setCouponId(sCoupon.getId());
newSConsumerCoupon.setConsumerId(sConsumerCoupon.getConsumerId());
newSConsumerCoupon.setName(sCoupon.getName());
newSConsumerCoupon.setStoreType(sCoupon.getStoreType());
newSConsumerCoupon.setRoomType(sCoupon.getRoomType());
newSConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime());
newSConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime());
newSConsumerCoupon.setCouponType(sCoupon.getCouponType());
newSConsumerCoupon.setMinDuration(sCoupon.getMinDuration());
newSConsumerCoupon.setMaxDuration(sCoupon.getMaxDuration());
newSConsumerCoupon.setDuration(sCoupon.getDuration());
newSConsumerCoupon.setSourceType(SourceTypeEnum.GIVE.getCode());
newSConsumerCoupon.setPlatformType(String.valueOf(sCoupon.getPlatformType()));
newSConsumerCoupon.setStartDate(sCoupon.getStartDate());
newSConsumerCoupon.setEndDate(sCoupon.getEndDate());
int insert = sConsumerCouponMapper.insert(newSConsumerCoupon);
if (insert > 0) {
//优惠券数量减一
sCoupon.setNumber(sCoupon.getNumber() - 1);
sCouponService.updateSCoupon(sCoupon);
}
return insert;
}
private void extracted(SConsumerCoupon item, BigDecimal bigDecimal, SRoom byId, BigDecimal subtract, SStore sStore) {
//计算价格
BigDecimal multiply = bigDecimal.multiply(byId.getPrice());
......
Markdown is supported
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