|
@@ -15,10 +15,12 @@ import org.jeecg.modules.business.dto.MobileDto;
|
|
|
import org.jeecg.modules.business.dto.ProvideCouponsUsedDto;
|
|
import org.jeecg.modules.business.dto.ProvideCouponsUsedDto;
|
|
|
import org.jeecg.modules.business.entity.BusMarketCoupons;
|
|
import org.jeecg.modules.business.entity.BusMarketCoupons;
|
|
|
import org.jeecg.modules.business.entity.BusMarketCouponsUsed;
|
|
import org.jeecg.modules.business.entity.BusMarketCouponsUsed;
|
|
|
|
|
+import org.jeecg.modules.business.entity.BusMemberCard;
|
|
|
import org.jeecg.modules.business.enums.CouponsStatusEnum;
|
|
import org.jeecg.modules.business.enums.CouponsStatusEnum;
|
|
|
import org.jeecg.modules.business.mapper.BusMarketCouponsMapper;
|
|
import org.jeecg.modules.business.mapper.BusMarketCouponsMapper;
|
|
|
import org.jeecg.modules.business.mapper.BusMarketCouponsUsedMapper;
|
|
import org.jeecg.modules.business.mapper.BusMarketCouponsUsedMapper;
|
|
|
import org.jeecg.modules.business.service.IBusMarketCouponsUsedService;
|
|
import org.jeecg.modules.business.service.IBusMarketCouponsUsedService;
|
|
|
|
|
+import org.jeecg.modules.system.entity.SysUser;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -46,6 +48,8 @@ public class BusMarketCouponsUsedServiceImpl extends ServiceImpl<BusMarketCoupon
|
|
|
private BusMarketCouponsMapper busMarketCouponsMapper;
|
|
private BusMarketCouponsMapper busMarketCouponsMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
private RedisUtil redisUtil;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private BusMemberCardServiceImpl busMemberCardService;
|
|
|
/**
|
|
/**
|
|
|
* 生成16位数字+prefix
|
|
* 生成16位数字+prefix
|
|
|
* @param prefix
|
|
* @param prefix
|
|
@@ -127,12 +131,16 @@ public class BusMarketCouponsUsedServiceImpl extends ServiceImpl<BusMarketCoupon
|
|
|
// for (int i = 0; i < dto.getMobiles().size(); i++) {
|
|
// for (int i = 0; i < dto.getMobiles().size(); i++) {
|
|
|
// int num = dto.getNum();
|
|
// int num = dto.getNum();
|
|
|
//以防手机号相同用分组实现
|
|
//以防手机号相同用分组实现
|
|
|
- Map<String, List<MobileDto>> map= dto.getMobiles().stream().collect(Collectors.groupingBy(t->t.getValue()));
|
|
|
|
|
- for (String key:map.keySet()) {
|
|
|
|
|
- int num = dto.getNum()*map.get(key).size();
|
|
|
|
|
- if (num> coupons.getKlqzs()) {
|
|
|
|
|
|
|
+ Map<String, List<MobileDto>> map = dto.getMobiles().stream().collect(Collectors.groupingBy(t -> t.getValue()));
|
|
|
|
|
+ for (String key : map.keySet()) {
|
|
|
|
|
+ int num = dto.getNum() * map.get(key).size();
|
|
|
|
|
+ if (num > coupons.getKlqzs()) {
|
|
|
throw new JeecgBootException("每人最多可领取" + coupons.getKlqzs());
|
|
throw new JeecgBootException("每人最多可领取" + coupons.getKlqzs());
|
|
|
}
|
|
}
|
|
|
|
|
+ LambdaQueryWrapper<BusMemberCard> queryWrapper3 = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper3.eq(BusMemberCard::getMobile, key);
|
|
|
|
|
+ //查询手机号是否是会员
|
|
|
|
|
+ BusMemberCard memeberCard = busMemberCardService.getOne(queryWrapper3);
|
|
|
while (num > 0) {
|
|
while (num > 0) {
|
|
|
LambdaQueryWrapper<BusMarketCouponsUsed> queryWrapper2 = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<BusMarketCouponsUsed> queryWrapper2 = new LambdaQueryWrapper<>();
|
|
|
queryWrapper2.eq(BusMarketCouponsUsed::getCouponsId, dto.getCouponsId());
|
|
queryWrapper2.eq(BusMarketCouponsUsed::getCouponsId, dto.getCouponsId());
|
|
@@ -154,6 +162,10 @@ public class BusMarketCouponsUsedServiceImpl extends ServiceImpl<BusMarketCoupon
|
|
|
//这里到时候要根据会员表查询一下是否存在会员信息,现在没有会员表
|
|
//这里到时候要根据会员表查询一下是否存在会员信息,现在没有会员表
|
|
|
// model.setMobile(dto.getMobiles().get(i).getValue());
|
|
// model.setMobile(dto.getMobiles().get(i).getValue());
|
|
|
model.setMobile(key);
|
|
model.setMobile(key);
|
|
|
|
|
+ if (memeberCard != null) {
|
|
|
|
|
+ model.setUserName(memeberCard.getName());
|
|
|
|
|
+ model.setUserid(memeberCard.getId());
|
|
|
|
|
+ }
|
|
|
model.setGainTime(DateTime.now());
|
|
model.setGainTime(DateTime.now());
|
|
|
model.setStatus(CouponsStatusEnum.received.getKey());
|
|
model.setStatus(CouponsStatusEnum.received.getKey());
|
|
|
index++;
|
|
index++;
|
|
@@ -175,7 +187,7 @@ public class BusMarketCouponsUsedServiceImpl extends ServiceImpl<BusMarketCoupon
|
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
|
message = "创建失败";
|
|
message = "创建失败";
|
|
|
} finally {
|
|
} finally {
|
|
|
- //删除redis缓存
|
|
|
|
|
|
|
+ //删除redis缓存,添加成功后也可不删除
|
|
|
list.forEach(item -> {
|
|
list.forEach(item -> {
|
|
|
String keyString = String.format("sys:cache:couponsused::%s", item.getId());
|
|
String keyString = String.format("sys:cache:couponsused::%s", item.getId());
|
|
|
redisUtil.del(keyString);
|
|
redisUtil.del(keyString);
|
|
@@ -184,4 +196,85 @@ public class BusMarketCouponsUsedServiceImpl extends ServiceImpl<BusMarketCoupon
|
|
|
return message == "创建成功" ? Result.ok(message) : Result.error(message);
|
|
return message == "创建成功" ? Result.ok(message) : Result.error(message);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发放免房券给会员
|
|
|
|
|
+ * @param dto
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result gainCouponsUsedToMember(ProvideCouponsUsedDto dto) {
|
|
|
|
|
+ if (ObjectUtils.isEmpty(dto.getCouponsId())) return Result.error("免房券id不能为空");
|
|
|
|
|
+ if (dto.getNum() <= 0) return Result.error("每人发放张数不能小于1!");
|
|
|
|
|
+ if (dto.getMemberIds() == null || dto.getMemberIds().size() <= 0) return Result.error("会员不能为空!");
|
|
|
|
|
+ BusMarketCoupons coupons = busMarketCouponsMapper.selectById(dto.getCouponsId());
|
|
|
|
|
+ if (ObjectUtils.isEmpty(coupons)) {
|
|
|
|
|
+ return Result.error("免房券活动不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getNum() > coupons.getKlqzs()) {
|
|
|
|
|
+ return Result.error("每人最多可领取" + coupons.getKlqzs());
|
|
|
|
|
+ }
|
|
|
|
|
+ int totalNum = dto.getMemberIds().size() * dto.getNum();
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<BusMarketCouponsUsed> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(BusMarketCouponsUsed::getStatus, CouponsStatusEnum.notClaimed.getKey());
|
|
|
|
|
+ queryWrapper.eq(BusMarketCouponsUsed::getCouponsId, dto.getCouponsId());
|
|
|
|
|
+
|
|
|
|
|
+ Page<BusMarketCouponsUsed> page = new Page<BusMarketCouponsUsed>(1, totalNum);
|
|
|
|
|
+ IPage<BusMarketCouponsUsed> pageList = this.page(page, queryWrapper);
|
|
|
|
|
+ int count = pageList.getRecords().size();
|
|
|
|
|
+ if (totalNum > count) {
|
|
|
|
|
+ return Result.error("待领取数量" + count + ",不够发放");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<BusMarketCouponsUsed> list = pageList.getRecords();
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+ String message = "创建成功";
|
|
|
|
|
+ try {
|
|
|
|
|
+ //以防会员相同用分组实现
|
|
|
|
|
+ Map<String, List<String>> map= dto.getMemberIds().stream().collect(Collectors.groupingBy(t->t));
|
|
|
|
|
+ for (String key:map.keySet()) {
|
|
|
|
|
+ int num = dto.getNum()*map.get(key).size();
|
|
|
|
|
+ if (num> coupons.getKlqzs()) {
|
|
|
|
|
+ throw new JeecgBootException("每人最多可领取" + coupons.getKlqzs());
|
|
|
|
|
+ }
|
|
|
|
|
+ BusMemberCard memeberCard=busMemberCardService.getById(key);
|
|
|
|
|
+ while (num > 0) {
|
|
|
|
|
+ LambdaQueryWrapper<BusMarketCouponsUsed> queryWrapper2 = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper2.eq(BusMarketCouponsUsed::getCouponsId, dto.getCouponsId());
|
|
|
|
|
+ queryWrapper2.and(i -> i.eq(BusMarketCouponsUsed::getUserid, key).or().eq(BusMarketCouponsUsed::getMobile, memeberCard.getMobile()));
|
|
|
|
|
+ Long gainCount = this.count(queryWrapper2);
|
|
|
|
|
+ if (gainCount > coupons.getKlqzs()) {
|
|
|
|
|
+ throw new JeecgBootException("每人限领数量" + coupons.getKlqzs());
|
|
|
|
|
+ }
|
|
|
|
|
+ BusMarketCouponsUsed model = list.get(index);
|
|
|
|
|
+ String keyString = String.format("sys:cache:couponsused::%s", model.getId());
|
|
|
|
|
+ if (redisUtil.hasKey(keyString)) {
|
|
|
|
|
+ throw new JeecgBootException("该免房券已被领取,请勿同时操作该功能");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ redisUtil.set(keyString, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ model.setUserid(memeberCard.getId());
|
|
|
|
|
+ model.setUserName(memeberCard.getName());
|
|
|
|
|
+ model.setMobile(memeberCard.getMobile());
|
|
|
|
|
+ model.setGainTime(DateTime.now());
|
|
|
|
|
+ model.setStatus(CouponsStatusEnum.received.getKey());
|
|
|
|
|
+ index++;
|
|
|
|
|
+ num--;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.updateBatchById(list);
|
|
|
|
|
+ } catch (JeecgBootException ex) {
|
|
|
|
|
+ message = ex.getMessage();
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ message = "创建失败";
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ //删除redis缓存,添加成功后也可不删除
|
|
|
|
|
+ list.forEach(item -> {
|
|
|
|
|
+ String keyString = String.format("sys:cache:couponsused::%s", item.getId());
|
|
|
|
|
+ redisUtil.del(keyString);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return message == "创建成功" ? Result.ok(message) : Result.error(message);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|