CashierDeskController.java 2.42 KB
package com.diligrp.cashier.boss.controller;

import com.diligrp.cashier.boss.domain.CashierOrderDTO;
import com.diligrp.cashier.boss.domain.CashierPaymentUrl;
import com.diligrp.cashier.boss.service.ICashierDeskService;
import com.diligrp.cashier.boss.service.IMerchantService;
import com.diligrp.cashier.boss.util.CashierOrderConverter;
import com.diligrp.cashier.pipeline.domain.OnlinePaymentStatus;
import com.diligrp.cashier.shared.domain.Message;
import com.diligrp.cashier.shared.util.AssertUtils;
import com.diligrp.cashier.trade.domain.CashierOrder;
import com.diligrp.cashier.trade.domain.CashierPayment;
import com.diligrp.cashier.trade.domain.Merchant;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/payment/cashier")
public class CashierDeskController {

    @Resource
    private IMerchantService merchantService;

    @Resource
    private ICashierDeskService cashierDeskService;

    @RequestMapping("/submitOrder")
    public Message<?> submitOrder(@RequestBody CashierOrderDTO request) {
        // 基本参数校验
        AssertUtils.notNull(request.getMchId(), "mchId missed");
        AssertUtils.notEmpty(request.getUserId(), "userId missed");
        AssertUtils.notNull(request.getCashierType(), "cashierType missed");
        AssertUtils.notEmpty(request.getGoods(), "goods missed");
        AssertUtils.notNull(request.getAmount(), "amount missed");
        AssertUtils.isTrue(request.getAmount() > 0, "Invalid amount");
        AssertUtils.notEmpty(request.getOutTradeNo(), "outTradeNo missed");

        CashierOrder cashierOrder = CashierOrderConverter.INSTANCE.convert(request);
        Merchant merchant = merchantService.loadCashierMerchant(request.getMchId());
        CashierPaymentUrl paymentUrl = cashierDeskService.doSubmit(merchant, cashierOrder);
        return Message.success(paymentUrl);
    }

    @RequestMapping("/orderPayment")
    public Message<?> orderPayment(@RequestBody CashierPayment request) {
        // 基本参数校验
        AssertUtils.notEmpty(request.getTradeId(), "paymentId missed");
        AssertUtils.notNull(request.getPipelineId(), "pipelineId missed");

        OnlinePaymentStatus paymentStatus = cashierDeskService.doPayment(request);
        return Message.success(paymentStatus);
    }
}