|
@@ -0,0 +1,212 @@
|
|
|
+package com.iamberry.wechat.service.activity;
|
|
|
+
|
|
|
+import com.iamberry.wechat.core.entity.activity.Festival;
|
|
|
+import com.iamberry.wechat.core.entity.activity.FestivalHelp;
|
|
|
+import com.iamberry.wechat.core.entity.coupon.CouponItem;
|
|
|
+import com.iamberry.wechat.core.entity.coupon.CouponType;
|
|
|
+import com.iamberry.wechat.core.entity.member.Member;
|
|
|
+import com.iamberry.wechat.face.activity.FestivalService;
|
|
|
+import com.iamberry.wechat.face.coupon.CouponTypeService;
|
|
|
+import com.iamberry.wechat.service.mapper.*;
|
|
|
+import com.iamberry.wechat.tools.StrUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 年货节-分享活动接口
|
|
|
+ * @author Administrator
|
|
|
+ * @Date 2020-01-02
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FestivalServiceImpl implements FestivalService {
|
|
|
+ @Autowired
|
|
|
+ private FestivalMapper festivalMapper;
|
|
|
+ @Autowired
|
|
|
+ private FestivalHelpMapper festivalHelpMapper;
|
|
|
+ @Autowired
|
|
|
+ private MemberMapper memberMapper;
|
|
|
+ @Autowired
|
|
|
+ private CouponItemMapper couponItemMapper;
|
|
|
+ @Autowired
|
|
|
+ private CouponTypeMapper couponTypeMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取集合
|
|
|
+ * @param festival
|
|
|
+ * @return List
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Festival> getFestivalList(Festival festival){
|
|
|
+ return festivalMapper.getFestivalList(festival);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询单条数据
|
|
|
+ * @param id
|
|
|
+ * @return festival
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Festival getFestivalById(Integer id){
|
|
|
+ return festivalMapper.getFestivalById(id);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 增加数据
|
|
|
+ * @param festival
|
|
|
+ * @return Integer
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Integer save(Festival festival){
|
|
|
+ Integer flag = 0;
|
|
|
+ flag = festivalMapper.save(festival);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("参与活动失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //1;为被助力的用户增加一个助力,并判断人数和优惠券,
|
|
|
+ Festival oldFestival = new Festival();
|
|
|
+ oldFestival.setFestivalOpenId(festival.getSharerOpenId());
|
|
|
+ List<Festival> festivalList = festivalMapper.getFestivalList(oldFestival);
|
|
|
+ if(festivalList!=null && festivalList.size()>0){
|
|
|
+ oldFestival = festivalList.get(0);
|
|
|
+ FestivalHelp oldFestivalHelp = new FestivalHelp();
|
|
|
+ oldFestivalHelp.setFestivalId(oldFestival.getFestivalId());
|
|
|
+ Integer num = festivalHelpMapper.getFestivalHelpCount(oldFestivalHelp);
|
|
|
+ num++;
|
|
|
+
|
|
|
+ //增加分享者的助力人数
|
|
|
+ FestivalHelp newAddFestivalHelp = new FestivalHelp();
|
|
|
+ newAddFestivalHelp.setFestivalHelpOpenId(festival.getFestivalOpenId());
|
|
|
+ StringBuffer remake = new StringBuffer( "当前第"+num+"朋友助力,");
|
|
|
+ switch (num){
|
|
|
+ case 1: //分享给1位朋友并且打开刷头优惠券链接,即可获得电动牙刷8折优惠券
|
|
|
+ remake.append("获得电动牙刷8折优惠券");
|
|
|
+ break;
|
|
|
+ case 3: //分享给3位朋友并且打开刷头优惠券链接,则刷头优惠券变为8.5折
|
|
|
+ remake.append("刷头优惠券变为8.5折");
|
|
|
+ break;
|
|
|
+ case 5: //分享给5位朋友并且打开刷头优惠券链接,则刷头优惠券变为8折
|
|
|
+ remake.append("刷头优惠券变为8折");
|
|
|
+ break;
|
|
|
+ case 10: // 分享给10位朋友并且打开刷头优惠券链接,则刷头优惠券变为7.5折
|
|
|
+ remake.append("刷头优惠券变为7.5折");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ newAddFestivalHelp.setFestivalHelpRemake(remake.toString());
|
|
|
+ newAddFestivalHelp.setFestivalId(oldFestival.getFestivalId());
|
|
|
+ flag = festivalHelpMapper.save(newAddFestivalHelp);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("助力失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!"X".equals(festival.getSharerOpenId())){
|
|
|
+ switch (num){
|
|
|
+ case 1: //分享给1位朋友并且打开刷头优惠券链接,即可获得电动牙刷8折优惠券 110000 上朵年货节-电动牙刷8折券
|
|
|
+ CouponType couponType = couponTypeMapper.getCouponTypeById(110000);
|
|
|
+ String uuidStr = StrUtils.getUUID();
|
|
|
+ CouponItem ci = new CouponItem();
|
|
|
+ ci.setCouponItemId(uuidStr);
|
|
|
+ ci.setCouponId(couponType.getCouponId());
|
|
|
+ if(couponType.getCouponIsUseEnd() == 2){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.add(Calendar.DATE,couponType.getCouponGetDays()); //增加X天
|
|
|
+ ci.setCouponUseEndDate(calendar.getTime());
|
|
|
+ }else{
|
|
|
+ ci.setCouponUseEndDate(couponType.getCouponUseEndDate());
|
|
|
+ }
|
|
|
+ ci.setCouponReceiveDate(new Date());
|
|
|
+ ci.setCouponItemUseropenid(festival.getSharerOpenId());
|
|
|
+ ci.setCouponUseStatus(1);
|
|
|
+ ci.setCouponIsDonation(2);
|
|
|
+ ci.setCouponItemRemark(couponType.getCouponRemark());
|
|
|
+ flag = couponItemMapper.insertCouponItem(ci);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("助力失败,请重试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //将优惠券id 修改到分享者的牙刷抵扣券上
|
|
|
+ Festival itemFestival = new Festival();
|
|
|
+ itemFestival.setFestivalId(oldFestival.getFestivalId());
|
|
|
+ itemFestival.setFestivalBrushCouponItemId(uuidStr);
|
|
|
+ flag = festivalMapper.update(itemFestival);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("助力失败,请重试!");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3: //分享给3位朋友并且打开刷头优惠券链接,则刷头优惠券变为8.5折 110002 上朵年货节-刷头8.5折券
|
|
|
+ CouponItem couponItem_110002 = new CouponItem();
|
|
|
+ couponItem_110002.setCouponItemId(oldFestival.getFestivalHeadCouponItemId());
|
|
|
+ couponItem_110002.setCouponId(110002);
|
|
|
+ flag = couponItemMapper.updateCouponTypeId(couponItem_110002);
|
|
|
+ break;
|
|
|
+ case 5: //分享给5位朋友并且打开刷头优惠券链接,则刷头优惠券变为8折 110003 上朵年货节-刷头8折券
|
|
|
+ CouponItem couponItem_110003 = new CouponItem();
|
|
|
+ couponItem_110003.setCouponItemId(oldFestival.getFestivalHeadCouponItemId());
|
|
|
+ couponItem_110003.setCouponId(110003);
|
|
|
+ flag = couponItemMapper.updateCouponTypeId(couponItem_110003);
|
|
|
+ break;
|
|
|
+ case 10: // 分享给10位朋友并且打开刷头优惠券链接,则刷头优惠券变为7.5折 110004 上朵年货节-刷头7.5折券
|
|
|
+ CouponItem couponItem_110004 = new CouponItem();
|
|
|
+ couponItem_110004.setCouponItemId(oldFestival.getFestivalHeadCouponItemId());
|
|
|
+ couponItem_110004.setCouponId(110004);
|
|
|
+ flag = couponItemMapper.updateCouponTypeId(couponItem_110004);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("助力失败,请重试!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2:添加优惠券
|
|
|
+ CouponType couponType = couponTypeMapper.getCouponTypeById(110001); //110001 上朵年货节-刷头9折券
|
|
|
+ String uuidStr = StrUtils.getUUID();
|
|
|
+ CouponItem ci = new CouponItem();
|
|
|
+ ci.setCouponItemId(uuidStr);
|
|
|
+ ci.setCouponId(couponType.getCouponId());
|
|
|
+ if(couponType.getCouponIsUseEnd() == 2){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.add(Calendar.DATE,couponType.getCouponGetDays()); //增加X天
|
|
|
+ ci.setCouponUseEndDate(calendar.getTime());
|
|
|
+ }else{
|
|
|
+ ci.setCouponUseEndDate(couponType.getCouponUseEndDate());
|
|
|
+ }
|
|
|
+ ci.setCouponReceiveDate(new Date());
|
|
|
+ ci.setCouponItemUseropenid(festival.getFestivalOpenId());
|
|
|
+ ci.setCouponUseStatus(1);
|
|
|
+ ci.setCouponIsDonation(2);
|
|
|
+ ci.setCouponItemRemark(couponType.getCouponRemark());
|
|
|
+ flag = couponItemMapper.insertCouponItem(ci);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("助力失败,请重试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ festival.setFestivalHeadCouponItemId(uuidStr);
|
|
|
+ flag = festivalMapper.update(festival);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("参与活动失败");
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改数据
|
|
|
+ * @param festival
|
|
|
+ * @return Integer
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer update(Festival festival){
|
|
|
+ return festivalMapper.update(festival);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|