奖品兑换需求
This commit is contained in:
@@ -25,11 +25,14 @@ public class UserPrizeExchange implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@TableId(type = IdType.ID_WORKER)
|
@TableId(type = IdType.ID_WORKER)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 奖品记录id
|
* 奖品引用id
|
||||||
*/
|
*/
|
||||||
private Long discSpinningRecordId;
|
private Long foreignId;
|
||||||
|
/**
|
||||||
|
* 活动类型 task-任务奖励 spinning-大转盘
|
||||||
|
*/
|
||||||
|
private String foreignType;
|
||||||
/**
|
/**
|
||||||
* 奖品名称
|
* 奖品名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.sqx.modules.app.service.impl;
|
package com.sqx.modules.app.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Dict;
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
import cn.hutool.core.map.MapProxy;
|
import cn.hutool.core.map.MapProxy;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
@@ -20,6 +21,10 @@ import com.sqx.modules.app.entity.UserPrizeExchange;
|
|||||||
import com.sqx.modules.app.service.UserPrizeExchangeService;
|
import com.sqx.modules.app.service.UserPrizeExchangeService;
|
||||||
import com.sqx.modules.discSpinning.dao.DiscSpinningRecordDao;
|
import com.sqx.modules.discSpinning.dao.DiscSpinningRecordDao;
|
||||||
import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
||||||
|
import com.sqx.modules.taskCenter.dao.TaskCenterRecordDao;
|
||||||
|
import com.sqx.modules.taskCenter.dao.TaskCenterRewardDao;
|
||||||
|
import com.sqx.modules.taskCenter.entity.TaskCenterRecord;
|
||||||
|
import com.sqx.modules.taskCenter.entity.TaskCenterReward;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -38,6 +43,10 @@ public class UserPrizeExchangeServiceImpl extends ServiceImpl<UserPrizeExchangeD
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DiscSpinningRecordDao discSpinningRecordDao;
|
private DiscSpinningRecordDao discSpinningRecordDao;
|
||||||
|
@Resource
|
||||||
|
private TaskCenterRecordDao taskCenterRecordDao;
|
||||||
|
@Resource
|
||||||
|
private TaskCenterRewardDao taskCenterRewardDao;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserDao userDao;
|
private UserDao userDao;
|
||||||
@@ -45,7 +54,8 @@ public class UserPrizeExchangeServiceImpl extends ServiceImpl<UserPrizeExchangeD
|
|||||||
@Override
|
@Override
|
||||||
public PageUtils page(Map<String, Object> params) {
|
public PageUtils page(Map<String, Object> params) {
|
||||||
MapProxy proxy = MapProxy.create(params);
|
MapProxy proxy = MapProxy.create(params);
|
||||||
Long discSpinningRecordId = proxy.getLong("discSpinningRecordId");
|
Long foreignId = proxy.getLong("foreignId");
|
||||||
|
String foreignType = proxy.getStr("foreignType");
|
||||||
Long userId = proxy.getLong("userId");
|
Long userId = proxy.getLong("userId");
|
||||||
String userName = proxy.getStr("userName");
|
String userName = proxy.getStr("userName");
|
||||||
String prizeName = proxy.getStr("prizeName");
|
String prizeName = proxy.getStr("prizeName");
|
||||||
@@ -55,7 +65,8 @@ public class UserPrizeExchangeServiceImpl extends ServiceImpl<UserPrizeExchangeD
|
|||||||
String beginDate = proxy.getStr("beginDate");
|
String beginDate = proxy.getStr("beginDate");
|
||||||
String endDate = proxy.getStr("endDate");
|
String endDate = proxy.getStr("endDate");
|
||||||
LambdaQueryWrapper<UserPrizeExchange> wrapper = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<UserPrizeExchange> wrapper = Wrappers.lambdaQuery();
|
||||||
wrapper.eq(discSpinningRecordId != null, UserPrizeExchange::getDiscSpinningRecordId, discSpinningRecordId);
|
wrapper.eq(foreignId != null, UserPrizeExchange::getForeignId, foreignId);
|
||||||
|
wrapper.eq(StrUtil.isNotEmpty(foreignType), UserPrizeExchange::getForeignType, foreignType);
|
||||||
wrapper.eq(userId != null, UserPrizeExchange::getUserId, userId);
|
wrapper.eq(userId != null, UserPrizeExchange::getUserId, userId);
|
||||||
wrapper.like(StrUtil.isNotEmpty(userName), UserPrizeExchange::getUserName, userName);
|
wrapper.like(StrUtil.isNotEmpty(userName), UserPrizeExchange::getUserName, userName);
|
||||||
wrapper.like(StrUtil.isNotEmpty(prizeName), UserPrizeExchange::getPrizeName, prizeName);
|
wrapper.like(StrUtil.isNotEmpty(prizeName), UserPrizeExchange::getPrizeName, prizeName);
|
||||||
@@ -78,9 +89,15 @@ public class UserPrizeExchangeServiceImpl extends ServiceImpl<UserPrizeExchangeD
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void exchange(Long currentUserId, UserPrizeExchange dto) {
|
public void exchange(Long currentUserId, UserPrizeExchange dto) {
|
||||||
if (dto.getDiscSpinningRecordId() == null) {
|
if (dto.getForeignId() == null) {
|
||||||
throw new SqxException("中奖记录ID不能为空");
|
throw new SqxException("中奖记录ID不能为空");
|
||||||
}
|
}
|
||||||
|
if (StrUtil.isEmpty(dto.getForeignType())) {
|
||||||
|
throw new SqxException("活动类型不能为空");
|
||||||
|
}
|
||||||
|
if (!ArrayUtil.contains(new String[]{"spinning", "task"}, dto.getForeignType())) {
|
||||||
|
throw new SqxException("仅限大转盘、任务活动兑换奖品");
|
||||||
|
}
|
||||||
if (StrUtil.isBlank(dto.getPhone())) {
|
if (StrUtil.isBlank(dto.getPhone())) {
|
||||||
throw new SqxException("用户手机号码不能为空");
|
throw new SqxException("用户手机号码不能为空");
|
||||||
}
|
}
|
||||||
@@ -89,43 +106,81 @@ public class UserPrizeExchangeServiceImpl extends ServiceImpl<UserPrizeExchangeD
|
|||||||
} catch (ValidateException e) {
|
} catch (ValidateException e) {
|
||||||
throw new SqxException("用户手机号码不合法");
|
throw new SqxException("用户手机号码不合法");
|
||||||
}
|
}
|
||||||
DiscSpinningRecord record = discSpinningRecordDao.selectById(dto.getDiscSpinningRecordId());
|
Dict dict = Dict.create();
|
||||||
if (record == null) {
|
if ("spinning".equals(dto.getForeignType())) {
|
||||||
throw new SqxException("中奖记录不存在");
|
DiscSpinningRecord record = discSpinningRecordDao.selectById(dto.getForeignId());
|
||||||
|
if (record == null) {
|
||||||
|
throw new SqxException("中奖记录不存在");
|
||||||
|
}
|
||||||
|
dict.put("userId", record.getUserId());
|
||||||
|
dict.put("name", record.getName());
|
||||||
|
dict.put("imgUrl", record.getImgUrl());
|
||||||
|
dict.put("type", record.getType());
|
||||||
|
} else if ("task".equals(dto.getForeignType())) {
|
||||||
|
TaskCenterRecord record = taskCenterRecordDao.selectById(dto.getForeignId());
|
||||||
|
if (record == null) {
|
||||||
|
throw new SqxException("中奖记录不存在");
|
||||||
|
}
|
||||||
|
if (record.getSourceId() == null) {
|
||||||
|
throw new SqxException("中奖记录未关联奖品");
|
||||||
|
}
|
||||||
|
TaskCenterReward reward = taskCenterRewardDao.selectById(record.getSourceId());
|
||||||
|
if (reward == null) {
|
||||||
|
throw new SqxException("对应的奖品信息不存在");
|
||||||
|
}
|
||||||
|
dict.put("userId", record.getUserId());
|
||||||
|
dict.put("name", record.getName());
|
||||||
|
dict.put("imgUrl", reward.getImg());
|
||||||
|
dict.put("type", reward.getType());
|
||||||
}
|
}
|
||||||
if (record.getUserId() == null) {
|
Long userId = dict.getLong("userId");
|
||||||
|
String name = dict.getStr("name");
|
||||||
|
String imgUrl = dict.getStr("imgUrl");
|
||||||
|
Integer type = dict.getInt("type");
|
||||||
|
if (userId == null) {
|
||||||
throw new SqxException("中奖用户数据不完整");
|
throw new SqxException("中奖用户数据不完整");
|
||||||
}
|
}
|
||||||
if (currentUserId == null) {
|
if (currentUserId == null) {
|
||||||
throw new SqxException("未获取当前登录用户id");
|
throw new SqxException("未获取当前登录用户id");
|
||||||
}
|
}
|
||||||
Long userId = record.getUserId();
|
|
||||||
if (!currentUserId.equals(userId)) {
|
if (!currentUserId.equals(userId)) {
|
||||||
throw new SqxException("兑奖用户和获奖用户不一致");
|
throw new SqxException("兑奖用户和获奖用户不一致");
|
||||||
}
|
}
|
||||||
UserEntity user = userDao.selectById(record.getUserId());
|
UserEntity user = userDao.selectById(userId);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new SqxException("兑奖用户不存在");
|
throw new SqxException("兑奖用户不存在");
|
||||||
}
|
}
|
||||||
if (ArrayUtil.contains(new int[]{1, 2}, record.getType())) {
|
if (ArrayUtil.contains(new int[]{1, 2}, type)) {
|
||||||
throw new SqxException("仅限兑换实物、会员卡等奖项");
|
throw new SqxException("仅限兑换实物、会员卡等奖项");
|
||||||
}
|
}
|
||||||
Integer count = baseMapper.selectCount(Wrappers.<UserPrizeExchange>lambdaQuery()
|
Integer count = baseMapper.selectCount(Wrappers.<UserPrizeExchange>lambdaQuery()
|
||||||
.eq(UserPrizeExchange::getDiscSpinningRecordId, record.getId())
|
.eq(UserPrizeExchange::getForeignId, dto.getForeignId())
|
||||||
|
.eq(UserPrizeExchange::getForeignType, dto.getForeignType())
|
||||||
);
|
);
|
||||||
if (count != null && count > 0) {
|
if (count != null && count > 0) {
|
||||||
throw new SqxException("奖品已兑换,请勿重复操作");
|
throw new SqxException("奖品已兑换,请勿重复操作");
|
||||||
}
|
}
|
||||||
dto.setPrizeName(record.getName());
|
dto.setPrizeName(name);
|
||||||
dto.setUserId(record.getUserId());
|
dto.setUserId(userId);
|
||||||
dto.setUserName(user.getUserName());
|
dto.setUserName(user.getUserName());
|
||||||
dto.setStatus(0);
|
dto.setStatus(0);
|
||||||
dto.setCreateTime(new Date());
|
dto.setCreateTime(new Date());
|
||||||
dto.setImgUrl(record.getImgUrl());
|
dto.setImgUrl(imgUrl);
|
||||||
baseMapper.insert(dto);
|
baseMapper.insert(dto);
|
||||||
record.setTarget("3");
|
if ("spinning".equals(dto.getForeignType())) {
|
||||||
record.setTargetId(dto.getId());
|
discSpinningRecordDao.update(null,
|
||||||
discSpinningRecordDao.updateById(record);
|
Wrappers.<DiscSpinningRecord>lambdaUpdate()
|
||||||
|
.set(DiscSpinningRecord::getTarget, "3")
|
||||||
|
.set(DiscSpinningRecord::getTargetId, dto.getId())
|
||||||
|
.eq(DiscSpinningRecord::getId, dto.getForeignId())
|
||||||
|
);
|
||||||
|
} else if ("task".equals(dto.getForeignType())) {
|
||||||
|
taskCenterRecordDao.update(null,
|
||||||
|
Wrappers.<TaskCenterRecord>lambdaUpdate()
|
||||||
|
.set(TaskCenterRecord::getTargetId, dto.getId())
|
||||||
|
.eq(TaskCenterRecord::getId, dto.getForeignId())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user