|
@@ -1,10 +1,21 @@
|
|
|
package com.qs.mp.admin.service.impl;
|
|
|
|
|
|
-import com.qs.mp.admin.domain.Marketing;
|
|
|
+import com.qs.mp.admin.domain.*;
|
|
|
+import com.qs.mp.admin.domain.param.*;
|
|
|
import com.qs.mp.admin.mapper.MarketingMapper;
|
|
|
-import com.qs.mp.admin.service.IMarketingService;
|
|
|
+import com.qs.mp.admin.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qs.mp.common.enums.TicketPrizeTypeEnum;
|
|
|
+import com.qs.mp.common.exception.ServiceException;
|
|
|
+import com.qs.mp.common.utils.bean.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +28,84 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class MarketingServiceImpl extends ServiceImpl<MarketingMapper, Marketing> implements IMarketingService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGoodsService goodsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICouponService couponService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICouponPkgService couponPkgService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IMarketingAwardsService marketingAwardsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IMarketingAwardsPrizeService marketingAwardsPrizeService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void createMarketing(MarketingCreateParam marketingCreateParam) {
|
|
|
+ // 保存营销活动
|
|
|
+ Marketing marketing = new Marketing();
|
|
|
+ BeanUtils.copyProperties(marketingCreateParam, marketing);
|
|
|
+ this.save(marketing);
|
|
|
+
|
|
|
+ // 创建奖级
|
|
|
+ List<MarketingAwardsPrize> marketingAwardsPrizeList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < marketingCreateParam.getAwardsList().size(); i ++) {
|
|
|
+ MarketingAwardsParam awardsParam = marketingCreateParam.getAwardsList().get(i);
|
|
|
+
|
|
|
+ if (awardsParam.getInsideNum() > awardsParam.getQuantity()) {
|
|
|
+ throw new ServiceException("内定数量不能大于奖品数量");
|
|
|
+ }
|
|
|
+
|
|
|
+ MarketingAwards marketingAwards = new MarketingAwards();
|
|
|
+ BeanUtils.copyProperties(awardsParam, marketingAwards);
|
|
|
+ marketingAwards.setId(null);
|
|
|
+ // 设置活动id
|
|
|
+ marketingAwards.setMarketingId(marketing.getId());
|
|
|
+ marketingAwardsService.save(marketingAwards);
|
|
|
+
|
|
|
+ if (awardsParam.getPrizeList().size() > 1) {
|
|
|
+ throw new ServiceException("奖品目前暂时不能超过1个");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (MarketingAwardsPrizeParam prizeParam : awardsParam.getPrizeList()) {
|
|
|
+ MarketingAwardsPrize awardsPrize = new MarketingAwardsPrize();
|
|
|
+ BeanUtils.copyProperties(prizeParam, awardsPrize);
|
|
|
+ awardsPrize.setId(null);
|
|
|
+ awardsPrize.setMarketingId(marketing.getId());
|
|
|
+ awardsPrize.setAwardsId(marketingAwards.getId());
|
|
|
+ if (null == awardsPrize.getQuantity() || 0 == awardsPrize.getQuantity()) {
|
|
|
+ // 页面没设置奖品的具体数量,则默认为整个奖项的数量
|
|
|
+ awardsPrize.setQuantity(marketingAwards.getQuantity());
|
|
|
+ }
|
|
|
+ if (prizeParam.getPrizeType() == TicketPrizeTypeEnum.GOODS) {
|
|
|
+ Goods goods = goodsService.getById(awardsPrize.getRefId());
|
|
|
+ awardsPrize.setTitle(goods.getTitle());
|
|
|
+ awardsPrize.setPicUrl(goods.getPicUrl());
|
|
|
+ awardsPrize.setValue(goods.getValue());
|
|
|
+ } else if (prizeParam.getPrizeType() == TicketPrizeTypeEnum.COUPON) {
|
|
|
+ Coupon coupon = couponService.getById(awardsPrize.getRefId());
|
|
|
+ awardsPrize.setTitle(coupon.getTitle());
|
|
|
+ awardsPrize.setPicUrl(coupon.getPicUrl());
|
|
|
+ awardsPrize.setValue(coupon.getDiscount());
|
|
|
+ } else if (prizeParam.getPrizeType() == TicketPrizeTypeEnum.COUPON_PKG) {
|
|
|
+ CouponPkg couponPkg = couponPkgService.getById(awardsPrize.getRefId());
|
|
|
+ awardsPrize.setTitle(couponPkg.getTitle());
|
|
|
+ awardsPrize.setValue(couponPkg.getFacePrice());
|
|
|
+ awardsPrize.setPicUrl(couponPkg.getPicUrl());
|
|
|
+ } else {
|
|
|
+ awardsPrize.setTitle("盲豆");
|
|
|
+ awardsPrize.setPicUrl("md.jpeg");
|
|
|
+ }
|
|
|
+ marketingAwardsPrizeList.add(awardsPrize);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ marketingAwardsPrizeService.saveBatch(marketingAwardsPrizeList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|