Commit e688a1d4 authored by zhangfeng's avatar zhangfeng

客户端兑换礼品短信验证码

parent df1a30a9
...@@ -15,4 +15,5 @@ public interface RedeemRewardApi { ...@@ -15,4 +15,5 @@ public interface RedeemRewardApi {
List<RedeemRewardRespDTO> redeemRewards(List<RedeemRewardReqVO> redeemRewardReqVOList); List<RedeemRewardRespDTO> redeemRewards(List<RedeemRewardReqVO> redeemRewardReqVOList);
RedeemDetailForUserDTO getRedeemDetailForUser(Long redeemId); RedeemDetailForUserDTO getRedeemDetailForUser(Long redeemId);
void sendSmsCode(Long memberId);
} }
...@@ -13,19 +13,19 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ ...@@ -13,19 +13,19 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data @Data
@ApiModel("管理后台 - 礼品兑换 Request VO") @ApiModel("管理后台 - 礼品兑换 Request VO")
public class RedeemRewardReqVO { public class RedeemRewardReqVO {
@ApiModelProperty(value = "会员id") @ApiModelProperty(value = "会员id", required = true)
private Long memberId; private Long memberId;
@ApiModelProperty(value = "礼品id") @ApiModelProperty(value = "礼品id", required = true)
private Long rewardId; private Long rewardId;
@ApiModelProperty(value = "兑换数量") @ApiModelProperty(value = "兑换数量", required = true)
private Integer rewardCount; private Integer rewardCount;
@ApiModelProperty(value = "兑换方式,同领取方式(1上门领取,2包邮到家,3邮寄到付)") @ApiModelProperty(value = "兑换方式,同领取方式(1上门领取,2包邮到家,3邮寄到付)", required = true)
private Integer redeemType; private Integer redeemType;
@ApiModelProperty(value = "兑换入口(后台,app,web)") @ApiModelProperty(value = "兑换入口(后台,app,web)", required = true)
private Integer entrance; private Integer entrance;
@ApiModelProperty(value = "费用数字(两位小数)") @ApiModelProperty(value = "费用数字(两位小数)")
...@@ -34,13 +34,13 @@ public class RedeemRewardReqVO { ...@@ -34,13 +34,13 @@ public class RedeemRewardReqVO {
@ApiModelProperty(value = "费用币种(字典配置)") @ApiModelProperty(value = "费用币种(字典配置)")
private Integer currency; private Integer currency;
@ApiModelProperty(value = "收件人姓名") @ApiModelProperty(value = "收件人姓名", required = true)
private String recipientName; private String recipientName;
@ApiModelProperty(value = "收件人电话") @ApiModelProperty(value = "收件人电话", required = true)
private String recipientPhoneNum; private String recipientPhoneNum;
@ApiModelProperty(value = "收件人地址") @ApiModelProperty(value = "收件人地址", required = true)
private String recipientAddress; private String recipientAddress;
@ApiModelProperty(value = "兑换人") @ApiModelProperty(value = "兑换人")
...@@ -68,5 +68,4 @@ public class RedeemRewardReqVO { ...@@ -68,5 +68,4 @@ public class RedeemRewardReqVO {
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private String remark; private String remark;
} }
...@@ -12,11 +12,16 @@ import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum; ...@@ -12,11 +12,16 @@ import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemDetailForUserDTO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemDetailForUserDTO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO;
import cn.iocoder.yudao.module.reward.controller.app.redeem.vo.AppRedeemRewardReqVO;
import cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO; import cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO;
import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO; import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper; import cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper;
import cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper; import cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper;
import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum; import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum;
import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock; import org.redisson.api.RLock;
...@@ -33,6 +38,7 @@ import java.util.Map; ...@@ -33,6 +38,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.GET_LOCK_FAILED; import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.GET_LOCK_FAILED;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.USER_NOT_EXISTS; import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.USER_NOT_EXISTS;
import static cn.iocoder.yudao.module.reward.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.reward.enums.ErrorCodeConstants.*;
...@@ -54,10 +60,25 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -54,10 +60,25 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
private MemberUserScoreApi memberUserScoreApi; private MemberUserScoreApi memberUserScoreApi;
@Resource @Resource
private SnowflakeGenerator snowflakeGenerator; private SnowflakeGenerator snowflakeGenerator;
@Resource
private SmsCodeApi smsCodeApi;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public RedeemRewardRespDTO redeemReward(RedeemRewardReqVO redeemRewardReqVO) { public RedeemRewardRespDTO redeemReward(RedeemRewardReqVO redeemRewardReqVO) {
if (redeemRewardReqVO.getEntrance() != PlatformTypeEnum.BACKEND.getValue() && redeemRewardReqVO instanceof AppRedeemRewardReqVO){
AppRedeemRewardReqVO appRedeemRewardReqVO = (AppRedeemRewardReqVO) redeemRewardReqVO;
SmsCodeUseReqDTO smsCodeUseReqDTO = new SmsCodeUseReqDTO();
UserRespDTO memberUserApiUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId());
if (memberUserApiUser == null) {
throw exception(USER_NOT_EXISTS);
}
smsCodeUseReqDTO.setMobile(memberUserApiUser.getMobile());
smsCodeUseReqDTO.setCode(appRedeemRewardReqVO.getCode());
smsCodeUseReqDTO.setUsedIp(getClientIP());
smsCodeUseReqDTO.setScene(SmsSceneEnum.MEMBER_REDEEM_REWARD.getScene());
smsCodeApi.useSmsCode(smsCodeUseReqDTO);
}
// 查询礼品 // 查询礼品
RewardDO rewardDO = rewardMapper.selectById(redeemRewardReqVO.getRewardId()); RewardDO rewardDO = rewardMapper.selectById(redeemRewardReqVO.getRewardId());
if (rewardDO == null) { if (rewardDO == null) {
...@@ -211,6 +232,21 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -211,6 +232,21 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
return null; return null;
} }
@Override
public void sendSmsCode(Long memberId) {
UserRespDTO memberUserApiUser = memberUserApi.getUser(memberId);
if (memberUserApiUser == null) {
throw exception(USER_NOT_EXISTS);
}
SmsCodeSendReqDTO smsCodeSendReqDTO = new SmsCodeSendReqDTO();
smsCodeSendReqDTO.setMobile(memberUserApiUser.getMobile());
smsCodeSendReqDTO.setAreaCode(memberUserApiUser.getAreaCode());
smsCodeSendReqDTO.setCreateIp(getClientIP());
smsCodeSendReqDTO.setScene(SmsSceneEnum.MEMBER_REDEEM_REWARD.getScene());
smsCodeApi.sendSmsCode(smsCodeSendReqDTO);
}
private void verifyMemberUser(RedeemRewardReqVO redeemRewardReqVO, RewardDO rewardDO) { private void verifyMemberUser(RedeemRewardReqVO redeemRewardReqVO, RewardDO rewardDO) {
// 查询会员积分 // 查询会员积分
UserRespDTO memberUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId()); UserRespDTO memberUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId());
......
package cn.iocoder.yudao.module.reward.controller.app.redeem; package cn.iocoder.yudao.module.reward.controller.app.redeem;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.idempotent.core.annotation.Idempotent;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.reward.api.reward.RedeemRewardApi; import cn.iocoder.yudao.module.reward.api.reward.RedeemRewardApi;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO;
import cn.iocoder.yudao.module.reward.controller.app.redeem.vo.AppRewardRedeemDetailReqVO; import cn.iocoder.yudao.module.reward.controller.app.redeem.vo.*;
import cn.iocoder.yudao.module.reward.controller.app.redeem.vo.AppRewardRedeemDetailRespVO;
import cn.iocoder.yudao.module.reward.controller.app.redeem.vo.AppRewardRedeemListRespVO;
import cn.iocoder.yudao.module.reward.controller.app.redeem.vo.AppRewardRedeemReqVO;
import cn.iocoder.yudao.module.reward.service.redeem.RewardRedeemService; import cn.iocoder.yudao.module.reward.service.redeem.RewardRedeemService;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO; import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -58,8 +56,17 @@ public class AppRedeemRewardController { ...@@ -58,8 +56,17 @@ public class AppRedeemRewardController {
@PostMapping("/single") @PostMapping("/single")
@ApiOperation("兑换礼品") @ApiOperation("兑换礼品")
@Idempotent(timeout = 5)
//@PreAuthenticated //@PreAuthenticated
public CommonResult<RedeemRewardRespDTO> redeemReward(@Valid @RequestBody RedeemRewardReqVO redeemRewardReqVO) { public CommonResult<RedeemRewardRespDTO> redeemReward(@Valid @RequestBody AppRedeemRewardReqVO redeemRewardReqVO) {
return success(redeemRewardApi.redeemReward(redeemRewardReqVO)); return success(redeemRewardApi.redeemReward(redeemRewardReqVO));
} }
@PostMapping("/send-sms-code")
@ApiOperation(value = "兑换礼品发送手机验证码")
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
@Idempotent(timeout = 5)
public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid AppRewardRedeemReqVO reqVO) {
redeemRewardApi.sendSmsCode(reqVO.getMemberId());
return success(true);
}
} }
package cn.iocoder.yudao.module.reward.controller.app.redeem.vo;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
@Data
@ApiModel("客户端 - 礼品兑换 req VO")
@EqualsAndHashCode(callSuper = true)
public class AppRedeemRewardReqVO extends RedeemRewardReqVO {
@ApiModelProperty(value = "手机验证码", required = true, example = "1024")
@NotBlank(message = "{app.auth.captcha.not.blank}")
@Length(min = 4, max = 4, message = "{app.auth.captcha.len.err}")
@Pattern(regexp = "^[0-9]+$", message = "{app.auth.captcha.pattern}")
private String code;
}
...@@ -7,7 +7,7 @@ import lombok.Data; ...@@ -7,7 +7,7 @@ import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@Data @Data
@ApiModel("客户端 - 礼品兑换记录列表 req VO") @ApiModel("客户端 - 礼品兑换 req VO")
public class AppRewardRedeemReqVO { public class AppRewardRedeemReqVO {
@ApiModelProperty(value = "会员id") @ApiModelProperty(value = "会员id")
@NotNull(message = "会员id不能为空") @NotNull(message = "会员id不能为空")
......
...@@ -28,6 +28,8 @@ public enum SmsSceneEnum implements IntArrayValuable { ...@@ -28,6 +28,8 @@ public enum SmsSceneEnum implements IntArrayValuable {
NOTIFICATION_SUCCESS_CANCEL_DELIVERY(7, "notification-successful-cancel-delivery", "订单 - 取消放货通知"), NOTIFICATION_SUCCESS_CANCEL_DELIVERY(7, "notification-successful-cancel-delivery", "订单 - 取消放货通知"),
NOTIFICATION_SUCCESS_SEASONING_CONDIMENTS(8, "notification-successful-seasoning-condiments", "订单 - 调货通知"), NOTIFICATION_SUCCESS_SEASONING_CONDIMENTS(8, "notification-successful-seasoning-condiments", "订单 - 调货通知"),
MEMBER_REDEEM_REWARD(9, "user-sms-redeem-reward", "会员用户 - 兑换礼品"),
SHIPMENT_ARRIVALS(20, "shipment-arrivals", "出货 - 到港通知(多订单)"), SHIPMENT_ARRIVALS(20, "shipment-arrivals", "出货 - 到港通知(多订单)"),
SHIPMENT_CUSTOMS_CLEARANCES(21, "shipment-customs-clearances", "出货 - 清关通知(多订单)"), SHIPMENT_CUSTOMS_CLEARANCES(21, "shipment-customs-clearances", "出货 - 清关通知(多订单)"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment