From 865c5d54ca63ed7a5bda4a92d27ea0b7c6e61b04 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 17 十二月 2025 18:02:56 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/jiashida
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPhysicalGoodsOrderServiceImpl.java | 77 ++++++++++++++++++++++++++++++++++++--
1 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPhysicalGoodsOrderServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPhysicalGoodsOrderServiceImpl.java
index d38ea76..0d55c84 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPhysicalGoodsOrderServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPhysicalGoodsOrderServiceImpl.java
@@ -1,13 +1,28 @@
package com.ruoyi.system.service.impl;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.system.model.TPhysicalGoodsOrder;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.system.config.ICBCConfig;
+import com.ruoyi.system.dto.PhysicalGoodsPlaceOrderDTO;
+import com.ruoyi.system.mapper.TPhysicalGoodsMapper;
import com.ruoyi.system.mapper.TPhysicalGoodsOrderMapper;
+import com.ruoyi.system.model.TPhysicalGoods;
+import com.ruoyi.system.model.TPhysicalGoodsOrder;
import com.ruoyi.system.query.BigGiftPackageQuery;
import com.ruoyi.system.service.TPhysicalGoodsOrderService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.system.utils.ICBCPayUtil;
+import com.ruoyi.system.utils.OrderCodeGenerator;
+import com.ruoyi.system.vo.PlaceOrderVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
@@ -19,17 +34,71 @@
* @author xiaochen
* @since 2025-12-08
*/
+@Slf4j
@Service
public class TPhysicalGoodsOrderServiceImpl extends ServiceImpl<TPhysicalGoodsOrderMapper, TPhysicalGoodsOrder> implements TPhysicalGoodsOrderService {
+
+ @Resource
+ private TPhysicalGoodsMapper physicalGoodsMapper;
+
+ @Resource
+ private ICBCPayUtil icbcPayUtil;
+
+ @Autowired
+ private ICBCConfig icbcConfig;
@Override
public Page<TPhysicalGoodsOrder> pageList(BigGiftPackageQuery query) {
Page<TPhysicalGoodsOrder> page = new Page<>(query.getPageNum(), query.getPageSize());
- return this.baseMapper.pageList(page,query);
+ return this.baseMapper.pageList(page, query);
}
@Override
public List<TPhysicalGoodsOrder> export(BigGiftPackageQuery query) {
- return this.baseMapper.export(query);
+ return this.baseMapper.export(query);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public PlaceOrderVO placeOrder(PhysicalGoodsPlaceOrderDTO dto, Integer appUserId, String openid) {
+ // 1. 校验商品是否存在
+ TPhysicalGoods physicalGoods = physicalGoodsMapper.selectById(dto.getPhysicalGoodsId());
+ if (physicalGoods == null) {
+ throw new ServiceException("商品不存在");
+ }
+
+ // 2. 创建订单
+ TPhysicalGoodsOrder order = new TPhysicalGoodsOrder();
+ String orderCode = OrderCodeGenerator.generatePhysicalGoodsOrderCode();
+ order.setCode(orderCode);
+ order.setAppUserId(appUserId);
+ order.setCreateTime(LocalDateTime.now());
+ order.setPhysicalGoodsId(dto.getPhysicalGoodsId());
+ order.setPhysicalGoods(JSON.toJSONString(physicalGoods));
+ order.setOrderPrice(physicalGoods.getTotalPrice());
+ order.setPaymentPrice(physicalGoods.getTotalPrice());
+ // 支付方式:1=微信
+ order.setPaymentMethod(1);
+ // 订单状态:1=待付款
+ order.setStatus(1);
+ order.setDelFlag(0);
+
+ this.save(order);
+
+ // 3. 更新商品销量
+ Integer currentSales = physicalGoods.getSales() == null ? 0 : physicalGoods.getSales();
+ physicalGoods.setSales(currentSales + 1);
+ physicalGoodsMapper.updateById(physicalGoods);
+
+ // 4. 调用工行支付
+ log.info("实物商品下单,订单号:{},支付金额:{},用户ID:{}", orderCode, physicalGoods.getTotalPrice(), appUserId);
+ JSONObject paymentParams = icbcPayUtil.wechatPay(orderCode, physicalGoods.getTotalPrice(), physicalGoods.getName(), openid,icbcConfig.getNotifyUrl()+"/physical/pay-notify");
+
+ // 5. 构建返回结果
+ PlaceOrderVO vo = new PlaceOrderVO();
+ vo.setOrderIds(Collections.singletonList(order.getId()));
+ vo.setOrderCodes(Collections.singletonList(orderCode));
+ vo.setPaymentParams(paymentParams);
+ return vo;
}
}
--
Gitblit v1.7.1