|
@@ -1,19 +1,24 @@
|
|
package com.ylx.massage.service.impl;
|
|
package com.ylx.massage.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.ylx.massage.domain.Coupon;
|
|
import com.ylx.massage.domain.Coupon;
|
|
import com.ylx.massage.domain.vo.CouponReceiveVo;
|
|
import com.ylx.massage.domain.vo.CouponReceiveVo;
|
|
|
|
+import com.ylx.massage.domain.vo.CouponReceivesVO;
|
|
import com.ylx.massage.mapper.CouponReceiveMapper;
|
|
import com.ylx.massage.mapper.CouponReceiveMapper;
|
|
import com.ylx.massage.domain.CouponReceive;
|
|
import com.ylx.massage.domain.CouponReceive;
|
|
import com.ylx.massage.service.CouponReceiveService;
|
|
import com.ylx.massage.service.CouponReceiveService;
|
|
import com.ylx.massage.service.CouponService;
|
|
import com.ylx.massage.service.CouponService;
|
|
import com.ylx.massage.utils.DateTimeUtils;
|
|
import com.ylx.massage.utils.DateTimeUtils;
|
|
|
|
+import org.apache.commons.compress.utils.Lists;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -51,6 +56,31 @@ public class CouponReceiveServiceImpl extends ServiceImpl<CouponReceiveMapper, C
|
|
return coupon;
|
|
return coupon;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Integer submits(CouponReceivesVO couponReceive) {
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<Coupon> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.in(Coupon::getId, couponReceive.getCouponIds());
|
|
|
|
+
|
|
|
|
+ List<Coupon> list = couponService.list(queryWrapper);
|
|
|
|
+ if (CollectionUtil.isEmpty(list)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ ArrayList<CouponReceive> couponReceives = Lists.newArrayList();
|
|
|
|
+ list.forEach(coupon -> {
|
|
|
|
+ CouponReceive couponRec= new CouponReceive();
|
|
|
|
+ couponRec.setCouponId(coupon.getId());
|
|
|
|
+ couponRec.setOpenid(couponReceive.getOpenId());
|
|
|
|
+ couponRec.setDeptId(coupon.getDeptId());
|
|
|
|
+ couponRec.setDeptName(coupon.getDeptName());
|
|
|
|
+ couponRec.setUseState(0);
|
|
|
|
+ couponRec.setExpirationTime(DateTimeUtils.addDays(new Date(), coupon.getTermDays()));
|
|
|
|
+ couponReceives.add(couponRec);
|
|
|
|
+ });
|
|
|
|
+ return couponReceiveMapper.insertBatch(couponReceives);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<CouponReceiveVo> getByOpenId(String openid) {
|
|
public List<CouponReceiveVo> getByOpenId(String openid) {
|
|
List<CouponReceiveVo> CouponReceiveVos = couponReceiveMapper.getByOpenId(openid);
|
|
List<CouponReceiveVo> CouponReceiveVos = couponReceiveMapper.getByOpenId(openid);
|
|
@@ -74,5 +104,23 @@ public class CouponReceiveServiceImpl extends ServiceImpl<CouponReceiveMapper, C
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<Coupon> couponWindows(CouponReceive couponReceive) {
|
|
|
|
+ //判断是否领过优惠卷
|
|
|
|
+ //查询领取优惠卷
|
|
|
|
+ List<CouponReceiveVo> CouponReceiveVos = couponReceiveMapper.getByOpenId(couponReceive.getOpenid());
|
|
|
|
+ //如果没有领取优惠卷
|
|
|
|
+ if (CollectionUtil.isEmpty(CouponReceiveVos)) {
|
|
|
|
+ //查询优惠卷
|
|
|
|
+ LambdaQueryWrapper<Coupon> couponLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ couponLambdaQueryWrapper.eq(Coupon::getStatus, 1).like(Coupon::getDeptName, couponReceive.getDeptName());
|
|
|
|
+ //返回新人优惠卷列表
|
|
|
|
+ return couponService.list(couponLambdaQueryWrapper);
|
|
|
|
+ } else {
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|