|
|
@@ -20,9 +20,11 @@ import com.haha.common.vo.OrderStatisticsVO;
|
|
|
import com.haha.common.vo.OrderVO;
|
|
|
import com.haha.entity.Device;
|
|
|
import com.haha.entity.Order;
|
|
|
+import com.haha.entity.OrderGoods;
|
|
|
import com.haha.entity.Shop;
|
|
|
import com.haha.entity.User;
|
|
|
import com.haha.mapper.DeviceMapper;
|
|
|
+import com.haha.mapper.OrderGoodsMapper;
|
|
|
import com.haha.mapper.OrderMapper;
|
|
|
import com.haha.mapper.ShopMapper;
|
|
|
import com.haha.mapper.UserMapper;
|
|
|
@@ -32,6 +34,7 @@ import com.haha.service.OrderService;
|
|
|
import com.haha.service.InviteActivityService;
|
|
|
import com.haha.service.payment.PaymentService;
|
|
|
import com.haha.service.payment.RefundResult;
|
|
|
+import com.haha.service.payment.payscore.PayScoreCreateRequest;
|
|
|
import com.haha.service.payment.payscore.PayScoreResult;
|
|
|
import com.haha.service.payment.payscore.PayScoreService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -81,6 +84,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
@Lazy
|
|
|
private InviteActivityService inviteActivityService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private OrderGoodsMapper orderGoodsMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<Order> getPage(int page, int pageSize, String orderNo, String deviceId,
|
|
|
String payStatus, Integer status, String startDate, String endDate,
|
|
|
@@ -583,6 +590,40 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return order;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 构建后付费项目列表(post_payments)
|
|
|
+ * 从 order_goods 表查询已保存的商品,按微信支付分智慧零售规范构建
|
|
|
+ * name="商品信息", description=商品名, amount=单价(元), count=数量
|
|
|
+ */
|
|
|
+ private List<PayScoreCreateRequest.PostPayment> buildPostPayments(Long orderId) {
|
|
|
+ List<PayScoreCreateRequest.PostPayment> payments = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ List<OrderGoods> goodsList = orderGoodsMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<OrderGoods>()
|
|
|
+ .eq(OrderGoods::getOrderId, orderId));
|
|
|
+
|
|
|
+ if (goodsList == null || goodsList.isEmpty()) {
|
|
|
+ log.warn("未找到订单商品信息,无法构建post_payments - orderId: {}", orderId);
|
|
|
+ return payments;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (OrderGoods goods : goodsList) {
|
|
|
+ PayScoreCreateRequest.PostPayment payment = new PayScoreCreateRequest.PostPayment();
|
|
|
+ payment.setName("商品信息");
|
|
|
+ payment.setAmount(goods.getPrice() != null ? goods.getPrice()
|
|
|
+ : (goods.getMoney() != null ? goods.getMoney() : BigDecimal.ZERO));
|
|
|
+ payment.setDescription(goods.getProductName() != null ? goods.getProductName() : "未知商品");
|
|
|
+ payment.setCount(goods.getProductNum() != null ? goods.getProductNum() : 1);
|
|
|
+ payments.add(payment);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("构建post_payments成功 - orderId: {}, 商品数量: {}", orderId, payments.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("构建post_payments失败 - orderId: {}", orderId, e);
|
|
|
+ }
|
|
|
+ return payments;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 使用支付分完结订单(扣费)
|
|
|
*
|
|
|
@@ -626,7 +667,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- PayScoreResult result = payScoreService.completePayScoreOrder(orderId, totalAmount, null);
|
|
|
+ List<PayScoreCreateRequest.PostPayment> payments = buildPostPayments(orderId);
|
|
|
+ PayScoreResult result = payScoreService.completePayScoreOrder(orderId, totalAmount, payments);
|
|
|
|
|
|
if (result.isSuccess()) {
|
|
|
log.info("[支付分集成] 支付分完结成功 - orderId: {}, state: {}", orderId, result.getState());
|