|
@@ -73,6 +73,12 @@ public class CouponLogic {
|
|
|
@Autowired
|
|
|
CouponUserService couponUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ CouponCompanyService couponCompanyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CouponWebsitService couponWebsitService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 统计 未使用 ,已使用,已过期优惠券
|
|
@@ -614,6 +620,7 @@ public class CouponLogic {
|
|
|
|
|
|
public List<Coupon> listAll(HttpServletRequest request) {
|
|
|
CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
|
|
|
+ this.getCouponUser(currentCompanyWechat.getUserId());
|
|
|
List<CouponUser> list = couponUserService.lambdaQuery().eq(CouponUser::getUserId, currentCompanyWechat.getUserId()).list();
|
|
|
if (CollectionUtils.isEmpty(list))
|
|
|
return new ArrayList<>();
|
|
@@ -640,6 +647,80 @@ public class CouponLogic {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void getCouponUser(String userId) {
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ List<Coupon> couponList = couponService.lambdaQuery()
|
|
|
+ .eq(Coupon::getBuyType, "COMPANY")
|
|
|
+ .gt(Coupon::getLeftAmount, 0)
|
|
|
+ .lt(Coupon::getObtainStartTime, new Date())
|
|
|
+ .gt(Coupon::getObtainEndTime, new Date())
|
|
|
+ .list();
|
|
|
+
|
|
|
+ for (Coupon coupon : couponList) {
|
|
|
+
|
|
|
+ if (coupon.getReceiveCrowd().equals(2))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (coupon.getReceiveCrowd().equals(3) && !user.getType().equals("SERVICE"))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (coupon.getReceiveCrowd().equals(4) && !user.getType().equals("GENERAL"))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (couponCompanyService.lambdaQuery().eq(CouponCompany::getCouponId,coupon.getCouponId())
|
|
|
+ .eq(CouponCompany::getCompanyId,user.getCompanyId()).count() > 0
|
|
|
+ &&
|
|
|
+ couponUserService.lambdaQuery().eq(CouponUser::getCouponId,coupon.getCouponId())
|
|
|
+ .eq(CouponUser::getUserId,user.getUserId()).count() < 1
|
|
|
+ ) {
|
|
|
+ CouponUser couponUser = new CouponUser();
|
|
|
+ couponUser.setCouponId(coupon.getCouponId());
|
|
|
+ couponUser.setUserId(user.getUserId());
|
|
|
+ couponUser.setUserName(user.getNickName());
|
|
|
+ couponUser.setCreateTime(new Date());
|
|
|
+ couponUser.insert();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<Coupon> couponListWebsit = couponService.lambdaQuery()
|
|
|
+ .eq(Coupon::getBuyType, "WEBSIT")
|
|
|
+ .gt(Coupon::getLeftAmount, 0)
|
|
|
+ .lt(Coupon::getObtainStartTime, new Date())
|
|
|
+ .gt(Coupon::getObtainEndTime, new Date())
|
|
|
+ .list();
|
|
|
+
|
|
|
+
|
|
|
+ for (Coupon coupon : couponListWebsit) {
|
|
|
+
|
|
|
+ if (coupon.getReceiveCrowd().equals(2))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (coupon.getReceiveCrowd().equals(3) && !user.getType().equals("SERVICE"))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (coupon.getReceiveCrowd().equals(4) && !user.getType().equals("GENERAL"))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (couponWebsitService.lambdaQuery().eq(CouponWebsit::getCouponId,coupon.getCouponId())
|
|
|
+ .eq(CouponWebsit::getWebsitId,user.getWebsitId()).count() > 0
|
|
|
+ &&
|
|
|
+ couponUserService.lambdaQuery().eq(CouponUser::getCouponId,coupon.getCouponId())
|
|
|
+ .eq(CouponUser::getUserId,user.getUserId()).count() < 1
|
|
|
+ ) {
|
|
|
+ CouponUser couponUser = new CouponUser();
|
|
|
+ couponUser.setCouponId(coupon.getCouponId());
|
|
|
+ couponUser.setUserId(user.getUserId());
|
|
|
+ couponUser.setUserName(user.getNickName());
|
|
|
+ couponUser.setCreateTime(new Date());
|
|
|
+ couponUser.insert();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void getCoupon(HttpServletRequest request, String userId, List<String> couponIds) {
|
|
|
|