奖品兑换需求
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.sqx.modules.app.controller;
|
||||
|
||||
import com.sqx.common.utils.Constant;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.entity.UserPrizeExchange;
|
||||
import com.sqx.modules.app.service.UserPrizeExchangeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/app/userPrizeExchange")
|
||||
@AllArgsConstructor
|
||||
@Api(value = "用户奖品兑换", tags = {"用户奖品兑换"})
|
||||
public class AppUserPrizeExchangeController {
|
||||
private final UserPrizeExchangeService userPrizeExchangeService;
|
||||
|
||||
@Login
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType = "int"),
|
||||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
|
||||
})
|
||||
public Result page(@RequestAttribute("userId") Long userId, @ApiIgnore @RequestParam Map<String, Object> params) {
|
||||
params.put("userId", userId);
|
||||
PageUtils page = userPrizeExchangeService.page(params);
|
||||
return Result.success().put("page", page);
|
||||
}
|
||||
|
||||
@Login
|
||||
@PostMapping("/exchange")
|
||||
@ApiOperation("兑换")
|
||||
public Result exchange(@RequestAttribute("userId") Long userId, @RequestBody UserPrizeExchange entity) {
|
||||
userPrizeExchangeService.exchange(userId, entity);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,9 @@ public class AppController {
|
||||
@ApiOperation("用户修改个人信息")
|
||||
@ResponseBody
|
||||
public Result updateUserImageUrl(@RequestAttribute("userId") Long userId, String zhiFuBao, String zhiFuBaoName) {
|
||||
if(StrUtil.isEmpty(zhiFuBao) || StrUtil.isEmpty(zhiFuBaoName)){
|
||||
return Result.error("支付宝账户及姓名不能为空!");
|
||||
}
|
||||
int count = userService.count(new QueryWrapper<UserEntity>()
|
||||
.ne("user_id", userId)
|
||||
.eq("zhi_fu_bao_name", zhiFuBaoName)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sqx.modules.app.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.app.entity.UserPrizeExchange;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户奖品兑换
|
||||
*
|
||||
* @author tankaikai
|
||||
* @since 2024-12-20 18:11
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserPrizeExchangeDao extends BaseMapper<UserPrizeExchange> {
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.sqx.modules.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户奖品兑换
|
||||
* @author tankaikai
|
||||
* @since 2024-12-20 17:52
|
||||
*/
|
||||
@Data
|
||||
@TableName("user_prize_exchange")
|
||||
public class UserPrizeExchange implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 奖品记录
|
||||
*/
|
||||
@TableId(type = IdType.ID_WORKER)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 奖品记录id
|
||||
*/
|
||||
private Long discSpinningRecordId;
|
||||
/**
|
||||
* 奖品名称
|
||||
*/
|
||||
private String prizeName;
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 收货地址
|
||||
*/
|
||||
private String address;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 状态 0-待发放 1-已发放
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.sqx.modules.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.modules.app.entity.UserPrizeExchange;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户奖品兑换Service
|
||||
*
|
||||
* @author tankaikai
|
||||
* @since 2024-12-20 18:04
|
||||
*/
|
||||
public interface UserPrizeExchangeService extends IService<UserPrizeExchange> {
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
PageUtils page(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 兑换奖品
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
void exchange(Long currentUserId, UserPrizeExchange entity);
|
||||
|
||||
/**
|
||||
* 发放奖品
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
|
||||
void deliver(UserPrizeExchange dto);
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.sqx.modules.app.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.map.MapProxy;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aliyun.tea.ValidateException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.Constant;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.modules.app.dao.UserDao;
|
||||
import com.sqx.modules.app.dao.UserPrizeExchangeDao;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserPrizeExchange;
|
||||
import com.sqx.modules.app.service.UserPrizeExchangeService;
|
||||
import com.sqx.modules.discSpinning.dao.DiscSpinningRecordDao;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tankaikai
|
||||
* @since 2024-12-20 18:10
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserPrizeExchangeServiceImpl extends ServiceImpl<UserPrizeExchangeDao, UserPrizeExchange> implements UserPrizeExchangeService {
|
||||
|
||||
@Resource
|
||||
private DiscSpinningRecordDao discSpinningRecordDao;
|
||||
|
||||
@Resource
|
||||
private UserDao userDao;
|
||||
|
||||
@Override
|
||||
public PageUtils page(Map<String, Object> params) {
|
||||
MapProxy proxy = MapProxy.create(params);
|
||||
Long discSpinningRecordId = proxy.getLong("discSpinningRecordId");
|
||||
Long userId = proxy.getLong("userId");
|
||||
String userName = proxy.getStr("userName");
|
||||
String prizeName = proxy.getStr("prizeName");
|
||||
Integer status = proxy.getInt("status");
|
||||
String phone = proxy.getStr("phone");
|
||||
String remark = proxy.getStr("remark");
|
||||
String beginDate = proxy.getStr("beginDate");
|
||||
String endDate = proxy.getStr("endDate");
|
||||
LambdaQueryWrapper<UserPrizeExchange> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(discSpinningRecordId != null, UserPrizeExchange::getDiscSpinningRecordId, discSpinningRecordId);
|
||||
wrapper.eq(userId != null, UserPrizeExchange::getUserId, userId);
|
||||
wrapper.like(StrUtil.isNotEmpty(userName), UserPrizeExchange::getUserName, userName);
|
||||
wrapper.like(StrUtil.isNotEmpty(prizeName), UserPrizeExchange::getPrizeName, prizeName);
|
||||
wrapper.eq(status != null, UserPrizeExchange::getStatus, status);
|
||||
wrapper.like(StrUtil.isNotEmpty(phone), UserPrizeExchange::getPhone, phone);
|
||||
wrapper.like(StrUtil.isNotEmpty(remark), UserPrizeExchange::getRemark, remark);
|
||||
if (StrUtil.isNotEmpty(beginDate)) {
|
||||
wrapper.apply("create_time >= str_to_date({0}, '%Y-%m-%d %H:%i:%s')", beginDate + " 00:00:00");
|
||||
}
|
||||
if (StrUtil.isNotEmpty(endDate)) {
|
||||
wrapper.apply("create_time <= str_to_date({0}, '%Y-%m-%d %H:%i:%s')", endDate + " 23:59:59");
|
||||
}
|
||||
wrapper.orderByDesc(UserPrizeExchange::getId);
|
||||
long pageNum = proxy.getLong(Constant.PAGE, 1L);
|
||||
long pageSize = proxy.getLong(Constant.LIMIT, 10L);
|
||||
IPage<UserPrizeExchange> page = this.page(new Page<>(pageNum, pageSize), wrapper);
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exchange(Long currentUserId, UserPrizeExchange dto) {
|
||||
if (dto.getDiscSpinningRecordId() == null) {
|
||||
throw new SqxException("中奖记录ID不能为空");
|
||||
}
|
||||
if (StrUtil.isBlank(dto.getPhone())) {
|
||||
throw new SqxException("用户手机号码不能为空");
|
||||
}
|
||||
try {
|
||||
Validator.isMobile(dto.getPhone());
|
||||
} catch (ValidateException e) {
|
||||
throw new SqxException("用户手机号码不合法");
|
||||
}
|
||||
DiscSpinningRecord record = discSpinningRecordDao.selectById(dto.getDiscSpinningRecordId());
|
||||
if (record == null) {
|
||||
throw new SqxException("中奖记录不存在");
|
||||
}
|
||||
if (record.getUserId() == null) {
|
||||
throw new SqxException("中奖用户数据不完整");
|
||||
}
|
||||
if (currentUserId == null) {
|
||||
throw new SqxException("未获取当前登录用户id");
|
||||
}
|
||||
Long userId = record.getUserId();
|
||||
if (!currentUserId.equals(userId)) {
|
||||
throw new SqxException("兑奖用户和获奖用户不一致");
|
||||
}
|
||||
UserEntity user = userDao.selectById(record.getUserId());
|
||||
if (user == null) {
|
||||
throw new SqxException("兑奖用户不存在");
|
||||
}
|
||||
if (ArrayUtil.contains(new int[]{1, 2}, record.getType())) {
|
||||
throw new SqxException("仅限兑换实物、会员卡等奖项");
|
||||
}
|
||||
Integer count = baseMapper.selectCount(Wrappers.<UserPrizeExchange>lambdaQuery()
|
||||
.eq(UserPrizeExchange::getDiscSpinningRecordId, record.getId())
|
||||
);
|
||||
if (count != null && count > 0) {
|
||||
throw new SqxException("奖品已兑换,请勿重复操作");
|
||||
}
|
||||
dto.setPrizeName(record.getName());
|
||||
dto.setUserId(record.getUserId());
|
||||
dto.setUserName(user.getUserName());
|
||||
dto.setStatus(0);
|
||||
dto.setCreateTime(new Date());
|
||||
baseMapper.insert(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliver(UserPrizeExchange dto) {
|
||||
Long id = dto.getId();
|
||||
if (id == null) {
|
||||
throw new SqxException("兑奖id不能为空");
|
||||
}
|
||||
UserPrizeExchange entity = baseMapper.selectById(id);
|
||||
if (entity == null) {
|
||||
throw new SqxException("兑奖订单不存在");
|
||||
}
|
||||
entity.setStatus(1);
|
||||
if (StrUtil.isNotEmpty(dto.getAddress())) {
|
||||
entity.setAddress(dto.getAddress());
|
||||
}
|
||||
if (StrUtil.isNotEmpty(dto.getRemark())) {
|
||||
entity.setRemark(dto.getRemark());
|
||||
}
|
||||
entity.setUpdateTime(new Date());
|
||||
baseMapper.updateById(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.sqx.modules.discSpinning.controller;
|
||||
|
||||
import com.sqx.common.utils.Constant;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserPrizeExchange;
|
||||
import com.sqx.modules.app.service.UserPrizeExchangeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/userPrizeExchange")
|
||||
@AllArgsConstructor
|
||||
@Api(value = "用户奖品兑换", tags = {"用户奖品兑换"})
|
||||
public class UserPrizeExchangeController {
|
||||
private final UserPrizeExchangeService userPrizeExchangeService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType = "int"),
|
||||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
|
||||
})
|
||||
public Result page(@ApiIgnore @RequestParam Map<String, Object> params) {
|
||||
PageUtils page = userPrizeExchangeService.page(params);
|
||||
return Result.success().put("page", page);
|
||||
}
|
||||
|
||||
@PostMapping("/deliver")
|
||||
@ApiOperation("发放")
|
||||
public Result exchange(@RequestBody UserPrizeExchange entity) {
|
||||
userPrizeExchangeService.deliver(entity);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user