支付回调
获取数据列表接口问题 token有效期 及 续期 订单详情 为null的情况 根据桌码获取shopid接口调整 首页 默认值
This commit is contained in:
@@ -4,11 +4,12 @@ import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.DistrictVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
import com.chaozhanggui.system.cashierservice.service.FileService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.LocationUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.StringUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.ValidateCodeUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@@ -16,12 +17,13 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 通用接口
|
||||
@@ -34,8 +36,9 @@ import java.util.concurrent.TimeUnit;
|
||||
public class CommonController {
|
||||
|
||||
private final ValidateCodeUtil validateCodeUtil;
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private TbPlatformDictMapper platformDictMapper;
|
||||
@Resource
|
||||
@@ -52,15 +55,24 @@ public class CommonController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/phoneValidateCode")
|
||||
public Result verifyPhoneIsExist(@RequestParam String phone) {
|
||||
public Result phoneValidateCode(@RequestParam String phone) {
|
||||
if (StringUtils.isBlank(phone)) {
|
||||
return Result.fail("手机号不可为空!");
|
||||
}
|
||||
// 检查手机号格式是否正确
|
||||
if (!isValidPhoneNumber(phone)) {
|
||||
return Result.fail("手机号格式不正确!");
|
||||
}
|
||||
// 检查手机号请求次数是否超出限制
|
||||
Result isOk = isRequestLimit(phone);
|
||||
if (!isOk.getCode().equals("0")) {
|
||||
return isOk;
|
||||
}
|
||||
String random = StringUtil.random(6);
|
||||
validateCodeUtil.requestValidateCodeAli(phone, random);
|
||||
//存入缓存
|
||||
try {
|
||||
redisUtils.set(phone, random, ONE_MINUTE, TimeUnit.SECONDS);
|
||||
redisUtil.saveMessage(phone, random, 60L);
|
||||
} catch (Exception e) {
|
||||
throw new MsgException("验证码发送失败");
|
||||
}
|
||||
@@ -119,4 +131,50 @@ public class CommonController {
|
||||
public Result upload(MultipartFile file) throws Exception {
|
||||
return new Result(CodeEnum.SUCCESS, fileService.uploadFile(file));
|
||||
}
|
||||
|
||||
// 检查手机号格式是否正确的方法
|
||||
private boolean isValidPhoneNumber(String phone) {
|
||||
return phone.matches("^1[3-9]\\d{9}$");
|
||||
}
|
||||
|
||||
// 检查手机号请求次数是否超出限制的方法
|
||||
public Result isRequestLimit(String phone) {
|
||||
Object count = redisUtil.getMessage(RedisCst.PHONE_LIMIT + phone);
|
||||
if (count != null && Integer.valueOf(count.toString()) >= 5) {
|
||||
return Result.fail("请求次数超出限制!,请半小时后重试");
|
||||
}
|
||||
long time = redisUtil.getRemainingTime(phone);
|
||||
if (time > 0) {
|
||||
return Result.fail("请" + time + "秒后重试");
|
||||
}
|
||||
refreshPhoneLimit(phone,count != null);
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
// 从 Redis 中获取手机号码的请求次数的方法
|
||||
@Async
|
||||
public void refreshPhoneLimit(String phone,boolean isExist) {
|
||||
if (isExist) {
|
||||
phoneRequestrinc(RedisCst.PHONE_LIMIT + phone);
|
||||
} else {
|
||||
phoneRequestset(RedisCst.PHONE_LIMIT + phone);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储手机号和请求次数的对应关系 时间 半小时
|
||||
*/
|
||||
public void phoneRequestset(String key) {
|
||||
// 使用 Hash 结构存储手机号和请求次数的对应关系 时间 半小时
|
||||
redisUtil.saveMessage(key, "1", 60*30L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将手机号码的请求次数加1
|
||||
*/
|
||||
public void phoneRequestrinc(String key) {
|
||||
// 将手机号码的请求次数加1
|
||||
redisUtil.getIncrNum(key, "2");
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,10 @@ public class OrderController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping ("/orderInfo")
|
||||
private Result orderInfo(@RequestParam Integer orderId){
|
||||
private Result orderInfo(@RequestParam(required = false) Integer orderId){
|
||||
if (orderId==null) {
|
||||
return Result.fail("请返回首页订单列表查看");
|
||||
}
|
||||
return orderService.orderInfo(orderId);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ public class ProductController {
|
||||
* @return shopid
|
||||
*/
|
||||
@RequestMapping("queryShopIdByTableCode")
|
||||
public Result queryShopIdByTableCode(@RequestHeader String token, @RequestParam("code") String code) {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userId = jsonObject.getString("userId");
|
||||
String openId = jsonObject.getString("openId");
|
||||
public Result queryShopIdByTableCode(
|
||||
@RequestHeader("openId") String openId,
|
||||
@RequestHeader("id") String userId,
|
||||
@RequestParam("code") String code) {
|
||||
return productService.queryShopIdByTableCode(userId, openId, code);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user