From 6b56672a7e02a0bf340021f00a4898bee9b13834 Mon Sep 17 00:00:00 2001
From: “mitao” <“2763622819@qq.com”>
Date: 星期二, 03 二月 2026 14:00:53 +0800
Subject: [PATCH] feat(applet):下单经销商支付参数根据用户预绑定推荐人获取
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBigGiftPackageOrderServiceImpl.java | 108 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 90 insertions(+), 18 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBigGiftPackageOrderServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBigGiftPackageOrderServiceImpl.java
index 9242efa..5f5e46b 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBigGiftPackageOrderServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBigGiftPackageOrderServiceImpl.java
@@ -9,6 +9,7 @@
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.config.ICBCConfig;
import com.ruoyi.system.dto.BigGiftPlaceOrderDTO;
+import com.ruoyi.system.enums.BigGiftPackageOrderStatusEnum;
import com.ruoyi.system.mapper.TBigGiftPackageMapper;
import com.ruoyi.system.mapper.TCommissionTransactionFlowMapper;
import com.ruoyi.system.mapper.TBigGiftPackageOrderMapper;
@@ -22,6 +23,7 @@
import com.ruoyi.system.query.GoldChangeRecordQuery;
import com.ruoyi.system.query.ProfitPageListQuery;
import com.ruoyi.system.query.UserProfitPageListQuery;
+import com.ruoyi.system.service.TAppUserService;
import com.ruoyi.system.service.TBigGiftPackageOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.service.TCommissionTransactionFlowService;
@@ -41,6 +43,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -70,6 +73,9 @@
@Autowired
private ICBCConfig icbcConfig;
+ @Autowired
+ private TAppUserService appUserService;
+
@Override
public List<TBigGiftPackageOrder> pageList(Page<TBigGiftPackageOrder> tBigGiftPackageOrderPage, BigGiftPackageOrderQuery query) {
String sTime = null;
@@ -90,12 +96,11 @@
tBigGiftPackageOrder.setCompanyName(tCompany1.getName());
}
});
- List<Integer> goodsIds = tBigGiftPackageOrders.stream().map(TBigGiftPackageOrder::getBigGiftPackageId).collect(Collectors.toList());
- List<TBigGiftPackage> bigGiftPackages = bigGiftPackageMapper.selectBatchIds(goodsIds);
tBigGiftPackageOrders.forEach(tBigGiftPackageOrder -> {
- TBigGiftPackage bigGiftPackage = bigGiftPackages.stream().filter(tBigGiftPackage -> tBigGiftPackage.getId().equals(tBigGiftPackageOrder.getBigGiftPackageId())).findFirst().orElse(null);
- if(bigGiftPackage!=null){
- tBigGiftPackageOrder.setBigGiftPackageName(bigGiftPackage.getName());
+ String bigGiftPackage1 = tBigGiftPackageOrder.getBigGiftPackage();
+ if(bigGiftPackage1!=null){
+ JSONObject jsonObject = JSON.parseObject(bigGiftPackage1);
+ tBigGiftPackageOrder.setBigGiftPackageName(jsonObject.getString("name"));
}
});
@@ -136,6 +141,9 @@
@Override
public List<ProfitPageListVo> profitPageList(Page<ProfitPageListVo> page, ProfitPageListQuery query) {
+ if (Objects.isNull(query.getCompanyId())) {
+ throw new ServiceException("公司ID不能为空");
+ }
String sTime = null;
String eTime = null;
if(query.getCreateTime()!=null && !query.getCreateTime().isEmpty()){
@@ -235,14 +243,14 @@
List<UserProfitPageListVo> profitPageListVos = this.baseMapper.profitUserPageList(page,query, sTime, eTime);
- if(!profitPageListVos.isEmpty()){
- List<Integer> orderIds = profitPageListVos.stream().map(UserProfitPageListVo::getId).collect(Collectors.toList());
- List<TCommissionTransactionFlow> tCommissionTransactionFlows = commissionTransactionFlowMapper.selectList(new LambdaQueryWrapper<TCommissionTransactionFlow>().in(TCommissionTransactionFlow::getOrderId, orderIds));
- for (UserProfitPageListVo profitPageListVo : profitPageListVos) {
- List<TCommissionTransactionFlow> flows = tCommissionTransactionFlows.stream().filter(e -> e.getOrderId().equals(profitPageListVo.getId()) && e.getAppUserId().equals(query.getUserId())).collect(Collectors.toList());
- profitPageListVo.setSelfProfit(flows.stream().map(TCommissionTransactionFlow::getCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add));
- }
- }
+// if(!profitPageListVos.isEmpty()){
+// List<Integer> orderIds = profitPageListVos.stream().map(UserProfitPageListVo::getId).collect(Collectors.toList());
+// List<TCommissionTransactionFlow> tCommissionTransactionFlows = commissionTransactionFlowMapper.selectList(new LambdaQueryWrapper<TCommissionTransactionFlow>().in(TCommissionTransactionFlow::getOrderId, orderIds));
+// for (UserProfitPageListVo profitPageListVo : profitPageListVos) {
+// List<TCommissionTransactionFlow> flows = tCommissionTransactionFlows.stream().filter(e -> e.getOrderId().equals(profitPageListVo.getId()) && e.getAppUserId().equals(query.getUserId())).collect(Collectors.toList());
+// profitPageListVo.setSelfProfit(flows.stream().map(TCommissionTransactionFlow::getCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add));
+// }
+// }
return profitPageListVos;
}
@@ -341,11 +349,13 @@
List<String> orderCodes = new ArrayList<>();
String goodsJson = JSON.toJSONString(bigGiftPackage);
LocalDateTime now = LocalDateTime.now();
-
+ //查询用户所属公司,获取经销商商户号
+ TCompany company = appUserService.getUserCompany(appUserId);
for (int i = 0; i < dto.getQuantity(); i++) {
TBigGiftPackageOrder order = new TBigGiftPackageOrder();
String orderCode = OrderCodeGenerator.generateBigGiftOrderCode();
order.setCode(orderCode);
+ order.setCompanyId(company.getId());
order.setPayOrderCode(payOrderCode);
order.setAppUserId(appUserId);
order.setCreateTime(now);
@@ -356,8 +366,9 @@
order.setFinalPayment(bigGiftPackage.getTotalPrice().subtract(bigGiftPackage.getDeposit()));
order.setPaymentType(dto.getPaymentType());
order.setEffectDayFlag(dto.getEffectDayFlag());
+ order.setPaymentPrice(dto.getPaymentType().equals(1) ? bigGiftPackage.getDeposit() : bigGiftPackage.getTotalPrice());
// 订单状态:1=待付款
- order.setStatus(1);
+ order.setStatus(BigGiftPackageOrderStatusEnum.PENDING_PAYMENT.getCode());
order.setDelFlag(0);
orderList.add(order);
@@ -372,10 +383,11 @@
.map(TBigGiftPackageOrder::getId)
.collect(Collectors.toList());
+
// 8. 调用工行支付
log.info("大礼包下单,支付订单号:{},业务订单号:{},支付金额:{},用户ID:{}", payOrderCode, orderCodes, paymentAmount, appUserId);
JSONObject paymentParams = icbcPayUtil.wechatPay(payOrderCode, paymentAmount, bigGiftPackage.getName(), openid,
- icbcConfig.getNotifyUrl() + "/big-gift/pay-notify");
+ icbcConfig.getNotifyUrl() + "/big-gift/pay-notify", company.getMerchantNumber(), company.getMerchantOpenid());
// 9. 构建返回结果
PlaceOrderVO vo = new PlaceOrderVO();
@@ -417,11 +429,14 @@
// 6. 生成尾款支付订单号
String finalPayOrderCode = OrderCodeGenerator.generateBigGiftFinalPayOrderCode();
-
+ order.setFinalPaymentSerialNumber(finalPayOrderCode);
+ this.updateById(order);
+ //查询用户所属公司,获取经销商商户号
+ TCompany company = appUserService.getUserCompany(appUserId);
// 7. 调用工行支付
log.info("大礼包尾款支付,订单ID:{},支付订单号:{},尾款金额:{},用户ID:{}", orderId, finalPayOrderCode, finalPayment, appUserId);
JSONObject paymentParams = icbcPayUtil.wechatPay(finalPayOrderCode, finalPayment, "大礼包尾款", openid,
- icbcConfig.getNotifyUrl() + "/big-gift/final-pay-notify");
+ icbcConfig.getNotifyUrl() + "/big-gift/final-pay-notify", company.getMerchantNumber(), company.getMerchantOpenid());
// 8. 构建返回结果
PlaceOrderVO vo = new PlaceOrderVO();
@@ -430,4 +445,61 @@
vo.setPaymentParams(paymentParams);
return vo;
}
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public PlaceOrderVO payNow(Integer orderId, Integer appUserId, String openid) {
+ // 1. 查询订单
+ TBigGiftPackageOrder order = this.getById(orderId);
+ if (order == null) {
+ throw new ServiceException("订单不存在");
+ }
+
+ // 2. 校验订单归属
+ if (!order.getAppUserId().equals(appUserId)) {
+ throw new ServiceException("无权操作此订单");
+ }
+
+ // 3. 校验订单状态(必须是待付款状态)
+ if (!BigGiftPackageOrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
+ throw new ServiceException("订单状态不正确,无法支付");
+ }
+
+ // 4. 获取商品信息
+ TBigGiftPackage bigGiftPackage = bigGiftPackageMapper.selectById(order.getBigGiftPackageId());
+ String goodsName = bigGiftPackage != null ? bigGiftPackage.getName() : "大礼包商品";
+
+ // 5. 计算支付金额
+ BigDecimal paymentAmount;
+ if (order.getPaymentType() == 1) {
+ // 订金+尾款模式,支付订金
+ paymentAmount = order.getDeposit();
+ } else {
+ // 全款模式
+ paymentAmount = order.getOrderPrice();
+ }
+
+ // 6. 生成新的支付订单号
+ String newPayOrderCode = OrderCodeGenerator.generateBigGiftPayOrderCode();
+
+ // 7. 更新当前订单的 payOrderCode
+ order.setPayOrderCode(newPayOrderCode);
+
+ this.updateById(order);
+
+ //查询用户所属公司,获取经销商商户号
+ TCompany company = appUserService.getUserCompany(appUserId);
+
+ // 8. 调用工行支付
+ log.info("大礼包立即支付,订单ID:{},新支付订单号:{},支付金额:{},用户ID:{}", orderId, newPayOrderCode, paymentAmount, appUserId);
+ JSONObject paymentParams = icbcPayUtil.wechatPay(newPayOrderCode, paymentAmount, goodsName, openid,
+ icbcConfig.getNotifyUrl() + "/big-gift/pay-notify", company.getMerchantNumber(), company.getMerchantOpenid());
+
+ // 9. 构建返回结果
+ PlaceOrderVO vo = new PlaceOrderVO();
+ vo.setOrderIds(Collections.singletonList(orderId));
+ vo.setOrderCodes(Collections.singletonList(order.getCode()));
+ vo.setPaymentParams(paymentParams);
+ return vo;
+ }
}
--
Gitblit v1.7.1