提交 e6c775e1 authored 作者: 窦馨雨's avatar 窦馨雨

合并分支 'dxy' 到 'qa'

重客抽奖小程序,添加前段代码适配 查看合并请求 !107
...@@ -20,7 +20,7 @@ public class LotteryController { ...@@ -20,7 +20,7 @@ public class LotteryController {
*/ */
@PostMapping("/init") @PostMapping("/init")
public LotteryRecordDto init(@RequestBody LotteryRecordVo lotteryRecordVo) { public LotteryRecordDto init(@RequestBody LotteryRecordVo lotteryRecordVo) {
return lotteryService.initLottery(lotteryRecordVo.getLongitude(), lotteryRecordVo.getLatitude(), lotteryRecordVo.getReceiptImageUrl(), lotteryRecordVo.getUserInfo()); return lotteryService.initLottery(lotteryRecordVo.getLongitude(), lotteryRecordVo.getLatitude(), lotteryRecordVo.getReceiptImageUrl(), lotteryRecordVo.getWxOpenId());
} }
/** /**
...@@ -28,7 +28,7 @@ public class LotteryController { ...@@ -28,7 +28,7 @@ public class LotteryController {
*/ */
@PostMapping("/draw") @PostMapping("/draw")
public LotteryRecordDto draw(@RequestBody LotteryRecordVo lotteryRecordVo) { public LotteryRecordDto draw(@RequestBody LotteryRecordVo lotteryRecordVo) {
return lotteryService.doDraw(lotteryRecordVo.getId()); return lotteryService.doDraw(lotteryRecordVo.getId(), lotteryRecordVo.getUserInfo());
} }
@PostMapping("/upload-receipt") @PostMapping("/upload-receipt")
......
...@@ -2,6 +2,7 @@ package com.wangxiaolu.promotion.domain.lottery.dao; ...@@ -2,6 +2,7 @@ package com.wangxiaolu.promotion.domain.lottery.dao;
import com.wangxiaolu.promotion.domain.lottery.entity.LotteryUserInfo; import com.wangxiaolu.promotion.domain.lottery.entity.LotteryUserInfo;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto; import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryUserInfoDto;
/** /**
* @Author: DouXinYu * @Author: DouXinYu
...@@ -9,7 +10,7 @@ import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto; ...@@ -9,7 +10,7 @@ import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto;
* @Description: * @Description:
*/ */
public interface LotteryCoreDao { public interface LotteryCoreDao {
LotteryRecordDto doDraw(Long recordId); LotteryRecordDto doDraw(Long recordId, LotteryUserInfoDto userInfo);
LotteryRecordDto initLottery(Double longitude, Double latitude, String receiptImage, LotteryUserInfo userInfo); LotteryRecordDto initLottery(Double longitude, Double latitude, String receiptImage, String wxOpenId);
} }
...@@ -10,6 +10,7 @@ import com.wangxiaolu.promotion.domain.lottery.mapper.LotteryMapper; ...@@ -10,6 +10,7 @@ import com.wangxiaolu.promotion.domain.lottery.mapper.LotteryMapper;
import com.wangxiaolu.promotion.domain.lottery.mapper.LotteryUserInfoMapper; import com.wangxiaolu.promotion.domain.lottery.mapper.LotteryUserInfoMapper;
import com.wangxiaolu.promotion.exception.ParamException; import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto; import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryUserInfoDto;
import com.wangxiaolu.promotion.result.basedata.RCode; import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.utils.TencentMapUtil; import com.wangxiaolu.promotion.utils.TencentMapUtil;
import org.apache.poi.ss.formula.functions.Now; import org.apache.poi.ss.formula.functions.Now;
...@@ -42,7 +43,7 @@ public class LotteryCoreDaoImpl implements LotteryCoreDao { ...@@ -42,7 +43,7 @@ public class LotteryCoreDaoImpl implements LotteryCoreDao {
* 初始化抽奖记录 * 初始化抽奖记录
*/ */
@Override @Override
public LotteryRecordDto initLottery(Double longitude, Double latitude, String receiptImage, LotteryUserInfo userInfo) { public LotteryRecordDto initLottery(Double longitude, Double latitude, String receiptImage, String wxOpenId) {
// 腾讯地图逆地址解析 // 腾讯地图逆地址解析
Map<String, String> location = tencentMapUtil.getAddressMapByLngLat(longitude, latitude); Map<String, String> location = tencentMapUtil.getAddressMapByLngLat(longitude, latitude);
...@@ -56,22 +57,11 @@ public class LotteryCoreDaoImpl implements LotteryCoreDao { ...@@ -56,22 +57,11 @@ public class LotteryCoreDaoImpl implements LotteryCoreDao {
record.setDistrict(location.get("district")); record.setDistrict(location.get("district"));
record.setAddress(location.get("address")); record.setAddress(location.get("address"));
record.setReceiptImageUrl(receiptImage); record.setReceiptImageUrl(receiptImage);
record.setStatus("pending");
if (Objects.nonNull(userInfo) && userInfo.getOpenId() != null) { record.setWxOpenId(wxOpenId);
LambdaQueryWrapper<LotteryUserInfo> eq = new LambdaQueryWrapper<LotteryUserInfo>()
.eq(LotteryUserInfo::getOpenId, userInfo.getOpenId());
LotteryUserInfo lotteryUserInfo = lotteryUserInfoMapper.selectOne(eq);
if (lotteryUserInfo == null) {
// 保存用户信息
lotteryUserInfoMapper.insert(userInfo);
record.setWxOpenId(userInfo.getOpenId());
}else {
record.setWxOpenId(userInfo.getOpenId());
}
}
lotteryMapper.insert(record); lotteryMapper.insert(record);
LotteryRecordDto result = BeanUtils.transitionDto(record, LotteryRecordDto.class); LotteryRecordDto result = BeanUtils.transitionDto(record, LotteryRecordDto.class);
ArrayList<String> prizeList = new ArrayList<>(); ArrayList<String> prizeList = new ArrayList<>();
prizeList.add("三等奖"); prizeList.add("三等奖");
prizeList.add("一等奖"); prizeList.add("一等奖");
...@@ -90,7 +80,7 @@ public class LotteryCoreDaoImpl implements LotteryCoreDao { ...@@ -90,7 +80,7 @@ public class LotteryCoreDaoImpl implements LotteryCoreDao {
* 执行抽奖(动态概率核心) * 执行抽奖(动态概率核心)
*/ */
@Override @Override
public LotteryRecordDto doDraw(Long recordId) { public LotteryRecordDto doDraw(Long recordId, LotteryUserInfoDto userInfo) {
LotteryRecord record = lotteryMapper.selectById(recordId); LotteryRecord record = lotteryMapper.selectById(recordId);
if (record == null) { if (record == null) {
throw new ParamException(RCode.LOTTERY_RECORD_NOT_EXIST); throw new ParamException(RCode.LOTTERY_RECORD_NOT_EXIST);
...@@ -100,11 +90,17 @@ public class LotteryCoreDaoImpl implements LotteryCoreDao { ...@@ -100,11 +90,17 @@ public class LotteryCoreDaoImpl implements LotteryCoreDao {
throw new ParamException(RCode.LOTTERY_RECORD_ERROR); throw new ParamException(RCode.LOTTERY_RECORD_ERROR);
} }
LotteryUserInfo lotteryUserInfo = new LotteryUserInfo();
lotteryUserInfo = BeanUtils.transitionDto(userInfo, LotteryUserInfo.class);
lotteryUserInfoMapper.insert(lotteryUserInfo);
// 动态概率 // 动态概率
int prizeLevel = simpleDynamicPrize(); int prizeLevel = simpleDynamicPrize();
record.setPrizeLevel(prizeLevel); record.setPrizeLevel(prizeLevel);
lotteryMapper.updateById(record); lotteryMapper.updateById(record);
return BeanUtils.transitionDto(record, LotteryRecordDto.class); LotteryRecordDto result = new LotteryRecordDto();
result = BeanUtils.transitionDto(record, LotteryRecordDto.class);
result.setUserInfo(userInfo);
return result ;
} }
/** /**
......
...@@ -18,6 +18,7 @@ public class LotteryUserInfo { ...@@ -18,6 +18,7 @@ public class LotteryUserInfo {
private String country; private String country;
private String province; private String province;
private String city; private String city;
private String phone;
private Date createTime; private Date createTime;
private Date updateTime; private Date updateTime;
private Integer isDeleted; private Integer isDeleted;
......
...@@ -59,4 +59,10 @@ public class LotteryRecordDto { ...@@ -59,4 +59,10 @@ public class LotteryRecordDto {
*/ */
private String wxOpenId; private String wxOpenId;
/**
* 用户信息
*/
private LotteryUserInfoDto userInfo;
} }
\ No newline at end of file
package com.wangxiaolu.promotion.pojo.lottery.dto;
import lombok.Data;
/**
* @Author: DouXinYu
* @Date: 2026-04-27 17:25
* @Description:
*/
@Data
public class LotteryUserInfoDto {
private Long id;
private String openId;
private String nickName;
private String avatarUrl;
private String gender;
private String language;
private String country;
private String province;
private String city;
private String phone;
}
...@@ -3,6 +3,7 @@ package com.wangxiaolu.promotion.pojo.lottery.vo; ...@@ -3,6 +3,7 @@ package com.wangxiaolu.promotion.pojo.lottery.vo;
import cn.hutool.system.UserInfo; import cn.hutool.system.UserInfo;
import com.wangxiaolu.promotion.domain.lottery.entity.LotteryUserInfo; import com.wangxiaolu.promotion.domain.lottery.entity.LotteryUserInfo;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryUserInfoDto;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
...@@ -47,9 +48,14 @@ public class LotteryRecordVo { ...@@ -47,9 +48,14 @@ public class LotteryRecordVo {
*/ */
private String receiptImageUrl; private String receiptImageUrl;
/**
* 微信OpenId
*/
private String wxOpenId;
/** /**
* 用户信息 * 用户信息
*/ */
private LotteryUserInfo userInfo; private LotteryUserInfoDto userInfo;
} }
\ No newline at end of file
package com.wangxiaolu.promotion.service.lottery; package com.wangxiaolu.promotion.service.lottery;
import com.wangxiaolu.promotion.domain.lottery.entity.LotteryUserInfo;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto; import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryUserInfoDto;
/** /**
* @Author: DouXinYu * @Author: DouXinYu
...@@ -9,7 +9,7 @@ import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto; ...@@ -9,7 +9,7 @@ import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto;
* @Description: * @Description:
*/ */
public interface LotteryCoreService { public interface LotteryCoreService {
LotteryRecordDto initLottery(Double longitude, Double latitude, String receiptImage, LotteryUserInfo userInfo); LotteryRecordDto initLottery(Double longitude, Double latitude, String receiptImage, String wxOpenId);
LotteryRecordDto doDraw(Long recordId); LotteryRecordDto doDraw(Long recordId, LotteryUserInfoDto userInfo);
} }
...@@ -7,6 +7,7 @@ import com.wangxiaolu.promotion.domain.lottery.entity.LotteryUserInfo; ...@@ -7,6 +7,7 @@ import com.wangxiaolu.promotion.domain.lottery.entity.LotteryUserInfo;
import com.wangxiaolu.promotion.domain.lottery.mapper.LotteryMapper; import com.wangxiaolu.promotion.domain.lottery.mapper.LotteryMapper;
import com.wangxiaolu.promotion.exception.ParamException; import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto; import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryRecordDto;
import com.wangxiaolu.promotion.pojo.lottery.dto.LotteryUserInfoDto;
import com.wangxiaolu.promotion.result.basedata.RCode; import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.lottery.LotteryCoreService; import com.wangxiaolu.promotion.service.lottery.LotteryCoreService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -42,16 +43,15 @@ public class LotteryCoreServiceImpl implements LotteryCoreService { ...@@ -42,16 +43,15 @@ public class LotteryCoreServiceImpl implements LotteryCoreService {
* 1. 初始化:保存位置信息 * 1. 初始化:保存位置信息
*/ */
@Override @Override
public LotteryRecordDto initLottery(Double longitude, Double latitude, String receiptImage, LotteryUserInfo userInfo) { public LotteryRecordDto initLottery(Double longitude, Double latitude, String receiptImage, String wxOpenId) {
return lotteryCoreDao.initLottery(longitude, latitude, receiptImage, userInfo); return lotteryCoreDao.initLottery(longitude, latitude, receiptImage, wxOpenId);
} }
/** /**
* 2. 抽奖:根据地址动态计算概率 * 2. 抽奖:根据地址动态计算概率
*/ */
@Override @Override
public LotteryRecordDto doDraw(Long recordId) { public LotteryRecordDto doDraw(Long recordId, LotteryUserInfoDto userInfo) {
return lotteryCoreDao.doDraw(recordId,userInfo);
return lotteryCoreDao.doDraw(recordId);
} }
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论