xin
2025-09-27 b500e0ad05da794f2b3764b81fb1181e1debf597
oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java
@@ -6,6 +6,7 @@
import com.oying.modules.hwc.service.SwiftPassService;
import com.oying.modules.pc.product.domain.Product;
import com.oying.modules.pc.product.domain.enums.ProductStatusEnum;
import com.oying.modules.pc.product.service.ProductInventoryService;
import com.oying.modules.pc.product.service.ProductService;
import com.oying.modules.pc.store.domain.Store;
import com.oying.modules.pc.store.domain.enums.StoreStatusEnum;
@@ -19,6 +20,7 @@
import com.oying.modules.sh.domain.vo.OrderResponse;
import com.oying.modules.sh.domain.vo.ProductInfo;
import com.oying.modules.sh.service.*;
import com.oying.service.PayConfigService;
import com.oying.utils.*;
import com.oying.utils.enums.*;
import lombok.RequiredArgsConstructor;
@@ -26,6 +28,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oying.modules.sh.domain.dto.OrderQueryCriteria;
import com.oying.modules.sh.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -54,9 +57,14 @@
    private final RedisUtils redisUtils;
    private final StoreService storeService;
    private final OrderOperationLogService operationLogService;
    private final ProductInventoryService productInventoryService;
    private final PayConfigService payConfigService;
    @Value("${oying.enabled}")
    private Boolean oyingEnabled;
    private static final String DESCRIBE = "哦应:";
    private static final String ORDER_KEY = "oying:order";
    private static final String ORDER_STORE_KEY = "oying:order:store";
    private static final String ORDER_CODE = "ORDER";
    @Override
    public PageResult<Order> queryAll(OrderQueryCriteria criteria, Page<Object> page) {
@@ -74,9 +82,11 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public synchronized Order submitOrder(SubmitOrder submit, HttpServletRequest request) {
        submit.setPayType(payConfigService.findInfo(oyingEnabled));
        switch (submit.getPayType()) {
            case HWC:
            case HWC2:
            case HWC3:
                break;
            default:
                throw new BadRequestException("支付类型暂未开放");
@@ -95,12 +105,11 @@
        }
        // 订单号
        String orderNum = redisUtils.generateSn(ORDER_KEY, GenerateEnum.ORDER.getKey());
        // 总金额
        BigDecimal amount = BigDecimal.ZERO;
        // 商品快照
        List<OrderProductSnapshot> snapshots = new ArrayList<>();
        for (ProductInfo productInfo : info.getProducts()) {
            Product product = productInfo.getProduct();
            productInventoryService.decreaseStock(product.getProductId(), productInfo.getCount());
            OrderProductSnapshot snapshot = new OrderProductSnapshot();
            snapshot.setOrderNum(orderNum);
            snapshot.setStoreId(submit.getStoreId());
@@ -115,7 +124,6 @@
            snapshot.setOriginalPrice(product.getPrice());
            snapshot.setPaidPrice(product.getPrice());
            BigDecimal decimal = BigDecimalUtils.multiply(product.getPrice(), productInfo.getCount());
            amount = BigDecimalUtils.add(amount, decimal);
            snapshot.setActuallyPayPrice(decimal);
            snapshot.setPayState(PayStateEnum.NOTPAY.getKey());
            snapshots.add(snapshot);
@@ -138,6 +146,7 @@
        order.setOrderTime(submit.getDateTime());
        order.setSendPrice(store.getDeliveryFee());
        order.setSendType(SendTypeEnum.LY.getKey());
        order.setPackagingPrice(info.getPackagingPrice());
        order.setUserId(SecurityUtils.getCurrentUserId());
        order.setUsername(SecurityUtils.getCurrentUsername());
        order.setStoreId(submit.getStoreId());
@@ -147,14 +156,14 @@
        order.setStoreLongitude(BigDecimal.valueOf(store.getLongitude()));
        order.setStoreLatitude(BigDecimal.valueOf(store.getLatitude()));
        order.setOrderDescribe(DESCRIBE + submit.getStoreId());
        order.setOriginalPrice(amount);
        order.setPaidPrice(amount);
        order.setActuallyPayPrice(amount);
        order.setOriginalPrice(info.getAmount());
        order.setPaidPrice(BigDecimalUtils.subtract(info.getAmount(), info.getPromotionAmount()));
        order.setActuallyPayPrice(info.getPayAmount());
        order.setOpenid(openid);
        order.setPayType(submit.getPayType().getKey());
        order.setExpireTime(expire);
        order.setOpenid(openid);
        Long total = BigDecimalUtils.yuanToCents(amount);
        Long total = BigDecimalUtils.yuanToCents(info.getAmount());
        if (total > 0) {
            HwcResponse response = swiftPassService.pay(StringUtils.getIp(request), total.toString(), expire,
                    DESCRIBE + submit.getStoreId(), openid, orderNum, submit.getPayType());
@@ -247,11 +256,15 @@
        OrderInfo info = new OrderInfo();
        info.setStore(store);
        info.setProducts(products);
        info.setAmount(amount);
        info.setPayAmount(amount);
        info.setPromotionAmount(BigDecimal.ZERO);
        info.setDeliveryPrice(store.getDeliveryFee());
        info.setPackagingPrice(BigDecimalUtils.multiply(store.getPackagingFee(), count));
        BigDecimal packagingPrice = BigDecimalUtils.multiply(store.getPackagingFee(), count);
        info.setPackagingPrice(packagingPrice);
        amount = BigDecimalUtils.add(amount, packagingPrice);
        amount = BigDecimalUtils.add(amount, store.getDeliveryFee());
        info.setAmount(amount);
        info.setPayAmount(amount);
        info.setUserAddresses(userAddressService.queryUserAddress(store.getLongitude(), store.getLatitude()));
        return info;
    }
@@ -267,7 +280,7 @@
    public OrderResponse getByOrderNum(String orderNum) {
        return new OrderResponse(orderMapper.getByOrderNum(orderNum),
                addressSnapshotService.queryByOrderNum(orderNum),
                operationLogService.getByOrderNum(orderNum, null));
                operationLogService.getByOrderNum(orderNum, ORDER_CODE));
    }
    @Override
@@ -306,6 +319,7 @@
        switch (anEnum) {
            case HWC:
            case HWC2:
            case HWC3:
                JSONObject object = swiftPassService.query(orderNum, anEnum);
                if (!object.getString("trade_state").equals(PayStateEnum.NOTPAY.getKey())) {
                    throw new BadRequestException(PayStateEnum.getValue(order.getPayState()));