|
|
@@ -12,6 +12,8 @@ import com.haha.mapper.OrderGoodsMapper;
|
|
|
import com.haha.sdk.HahaClient;
|
|
|
import com.haha.service.HahaCallbackService;
|
|
|
import com.haha.service.OrderService;
|
|
|
+import com.haha.service.payment.payscore.PayScoreResult;
|
|
|
+import com.haha.service.payment.payscore.PayScoreService;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -45,6 +47,9 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
@Autowired
|
|
|
private HahaClient hahaClient;
|
|
|
|
|
|
+ @Autowired(required = false)
|
|
|
+ private PayScoreService payScoreService;
|
|
|
+
|
|
|
@Value("${haha.api.app-secret}")
|
|
|
private String appSecret;
|
|
|
|
|
|
@@ -214,6 +219,11 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理AI识别结果通知
|
|
|
+ *
|
|
|
+ * @param params 消息参数
|
|
|
+ */
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void handleOrcResult(Map<String, Object> params) {
|
|
|
@@ -236,6 +246,7 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 识别结果置信度
|
|
|
BigDecimal confidence = parseBigDecimal(params.get("confidence"));
|
|
|
|
|
|
Order existingOrder = orderService.getOrderByActivityId(activityId);
|
|
|
@@ -290,6 +301,10 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
updateOrderFromCallback(localOrder, orderId, activityId, orderMoney, orderDetail, orderName, orderGoodsStr);
|
|
|
saveOrderInfoToRedis(localOrder, activityId, orderId, orderMoney, orderDetail);
|
|
|
|
|
|
+ // 处理支付分扣费(如果订单使用了支付分)
|
|
|
+ processPayScorePayment(localOrder, orderMoney);
|
|
|
+
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理订单回调通知失败", e);
|
|
|
}
|
|
|
@@ -436,8 +451,8 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
saveOrderInfoToRedis(order, activityId);
|
|
|
}
|
|
|
|
|
|
- private void updateOrderFromCallback(Order order, String orderId, String activityId,
|
|
|
- Object orderMoney, String orderDetail,
|
|
|
+ private void updateOrderFromCallback(Order order, String orderId, String activityId,
|
|
|
+ Object orderMoney, String orderDetail,
|
|
|
String orderName, String orderGoodsStr) {
|
|
|
order.setOrderNo(orderId);
|
|
|
order.setActivityId(activityId);
|
|
|
@@ -457,14 +472,14 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
boolean updated = orderService.updateById(order);
|
|
|
if (updated) {
|
|
|
log.info("订单信息更新成功: {}", orderId);
|
|
|
-
|
|
|
+
|
|
|
saveOrderGoods(order.getId(), orderId, activityId, orderGoodsStr, order.getDeviceId(), order.getUserId());
|
|
|
} else {
|
|
|
log.error("订单信息更新失败: {}", orderId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void saveOrderGoods(Long orderId, String orderNo, String activityId,
|
|
|
+ private void saveOrderGoods(Long orderId, String orderNo, String activityId,
|
|
|
String orderGoodsStr, String deviceId, Long userId) {
|
|
|
if (orderGoodsStr == null || orderGoodsStr.isEmpty()) {
|
|
|
log.info("订单商品信息为空,跳过保存");
|
|
|
@@ -493,7 +508,7 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
goods.setProductName(goodsJson.getString("product_name"));
|
|
|
goods.setPic(goodsJson.getString("pic"));
|
|
|
goods.setProductNum(goodsJson.getInteger("product_num"));
|
|
|
-
|
|
|
+
|
|
|
if (goodsJson.get("money") != null) {
|
|
|
goods.setMoney(new BigDecimal(goodsJson.getString("money")));
|
|
|
}
|
|
|
@@ -626,8 +641,62 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
try {
|
|
|
return new BigDecimal(value.toString());
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.warn("无法转换为BigDecimal: {}", value);
|
|
|
+ log.warn("无法转换为 BigDecimal: {}", value);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理支付分扣费
|
|
|
+ * 如果订单使用了微信支付分,调用支付分完结接口进行扣费
|
|
|
+ *
|
|
|
+ * @param order 订单对象
|
|
|
+ * @param orderMoney 订单金额
|
|
|
+ */
|
|
|
+ private void processPayScorePayment(Order order, Object orderMoney) {
|
|
|
+ // 检查是否为支付分订单
|
|
|
+ if (order.getPayChannel() == null || !"wechat_payscore".equals(order.getPayChannel())) {
|
|
|
+ log.debug("订单未使用支付分,跳过扣费 - orderId: {}, payChannel: {}",
|
|
|
+ order.getId(), order.getPayChannel());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查支付分服务是否可用
|
|
|
+ if (payScoreService == null) {
|
|
|
+ log.warn("支付分服务未初始化,无法处理扣费 - orderId: {}", order.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否已创建支付分服务订单
|
|
|
+ if (order.getPayScoreOrderId() == null) {
|
|
|
+ log.warn("订单未创建支付分服务订单,无法扣费 - orderId: {}", order.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查订单状态,避免重复扣费
|
|
|
+ if ("DONE".equals(order.getPayScoreState()) || "REVOKED".equals(order.getPayScoreState())) {
|
|
|
+ log.info("订单已完结或已取消,跳过扣费 - orderId: {}, payScoreState: {}",
|
|
|
+ order.getId(), order.getPayScoreState());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ BigDecimal totalAmount = orderMoney != null ? new BigDecimal(orderMoney.toString()) : order.getTotalAmount();
|
|
|
+
|
|
|
+ log.info("开始处理支付分扣费 - orderId: {}, payScoreOrderId: {}, amount: {}元",
|
|
|
+ order.getId(), order.getPayScoreOrderId(), totalAmount);
|
|
|
+
|
|
|
+ PayScoreResult result = payScoreService.completePayScoreOrder(order.getId(), totalAmount, null);
|
|
|
+
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ log.info("支付分扣费成功 - orderId: {}, state: {}, outOrderNo: {}",
|
|
|
+ order.getId(), result.getState(), result.getOutOrderNo());
|
|
|
+ } else {
|
|
|
+ log.error("支付分扣费失败 - orderId: {}, errorCode: {}, errorMsg: {}",
|
|
|
+ order.getId(), result.getErrorCode(), result.getErrorMsg());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理支付分扣费异常 - orderId: {}", order.getId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|