diff --git a/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java b/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java index ce85dd7..86bf867 100644 --- a/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java +++ b/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java @@ -67,23 +67,32 @@ public class ShopController { } @GetMapping("/wechatAuth") - public RedirectView wechatAuthRedirect(HttpServletRequest request, @RequestParam String token) { + public RedirectView wechatAuthRedirect(HttpServletRequest request) { /*java.util.StringJoiner joiner = new java.util.StringJoiner("&"); request.getParameterMap().forEach((key, values) -> { joiner.add(key + "=" + String.join(",", values)); + log.info("wechatAuth key: {} value: {}", key, values[0]); }); log.info("wechatAuth 参数:{}", joiner.toString());*/ - String state = ""; - if (StringUtils.isNoneBlank(token)) { - state = "token_" + token; - } - /*try { - state = URLEncoder.encode(state, StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - log.error("wechatAuth 编码失败", e); - }*/ + // 从请求参数中提取包含token的参数名(参数名本身可能包含"token=") + String token = request.getParameterMap().keySet().stream() + .filter(key -> key.contains("token=")) + .findFirst().orElse(""); + log.info("wechatAuth token:{}", token); + String state = ""; + if (StringUtils.isNotBlank(token)) { + // 清洗token参数值(原参数名格式为"token=xxx") + token = token.replace("token=", ""); + // 构造带有token标识的state参数,用于授权后回传 + state = "token_" + token; + } else { + // 默认state参数,保持微信要求的标准格式 + state = "state"; + } + + // 构造微信网页授权URL String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize" + "?appid=" + WeixinConstants.appid + "&redirect_uri=http%3A%2F%2Fwxshop.ab98.cn%2Fshop" diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java index d1b5577..e62b9e7 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java @@ -73,6 +73,7 @@ public class OrderApplicationService { throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "订单状态不允许操作"); } + // 获取并验证订单商品信息 ShopOrderGoodsEntity goodsEntity = orderGoodsService.getById(orderGoodsId); if (null == goodsEntity || !orderId.equals(goodsEntity.getOrderId())) { throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "订单商品不存在"); @@ -80,19 +81,19 @@ public class OrderApplicationService { if (goodsEntity.getStatus() != 1 && goodsEntity.getStatus()!= 5) { throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "订单商品状态不允许操作"); } - - List<CabinetCellEntity> cabinetCellEntityList = cabinetCellService.selectByGoodsId(goodsEntity.getGoodsId()); - if (null == cabinetCellEntityList || cabinetCellEntityList.isEmpty()) { - throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "商品未绑定柜子"); + if (goodsEntity.getCellId() == null) { + throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "订单商品未绑定柜子"); } - CabinetCellEntity cabinetCellEntity = cabinetCellEntityList.get(0); + // 获取柜子单元和智能柜信息 + CabinetCellEntity cabinetCellEntity = cabinetCellService.getById(goodsEntity.getCellId()); SmartCabinetEntity smartCabinet = smartCabinetService.getById(cabinetCellEntity.getCabinetId()); if (null == smartCabinet) { throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "柜子不存在"); } - // 发送指令 + // 构造MQTT开柜指令: + // 指令格式:8A + 锁控编号(2位HEX) + 引脚号(2位HEX) + 操作码11 String mqttDate = "8A"; mqttDate += String.format("%02X", smartCabinet.getLockControlNo()); mqttDate += String.format("%02X", cabinetCellEntity.getPinNo()); diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsEntity.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsEntity.java index b580afd..e4c0f23 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsEntity.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsEntity.java @@ -40,6 +40,10 @@ public class ShopOrderGoodsEntity extends BaseEntity<ShopOrderGoodsEntity> { @TableField("goods_id") private Long goodsId; + @ApiModelProperty("关联格口ID") + @TableField("cell_id") + private Long cellId; + @ApiModelProperty("购买数量") @TableField("quantity") private Integer quantity; diff --git a/sql/20250328_return_approval.sql b/sql/20250328_return_approval.sql index 4992aa6..edfa6ca 100644 --- a/sql/20250328_return_approval.sql +++ b/sql/20250328_return_approval.sql @@ -69,3 +69,6 @@ ADD COLUMN `userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_c ALTER TABLE `shop_order` ADD COLUMN `name` varchar(30) DEFAULT NULL COMMENT '成员名称' AFTER `mobile`; + +ALTER TABLE `shop_order_goods` +ADD COLUMN `cell_id` BIGINT NULL COMMENT '格口ID' AFTER `goods_id`; \ No newline at end of file