package com.ruoyi.web.controller.api;
|
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.system.dto.BigGiftPlaceOrderDTO;
|
import com.ruoyi.system.dto.FinalPaymentDTO;
|
import com.ruoyi.system.dto.PhysicalGoodsPlaceOrderDTO;
|
import com.ruoyi.system.model.TAppUser;
|
import com.ruoyi.system.service.TAppUserService;
|
import com.ruoyi.system.service.TBigGiftPackageOrderService;
|
import com.ruoyi.system.service.TPhysicalGoodsOrderService;
|
import com.ruoyi.system.vo.PlaceOrderVO;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.validation.Valid;
|
|
/**
|
* 下单接口
|
*
|
* @author mitao
|
* @since 2025-12-16
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/order")
|
@Api(tags = "下单模块")
|
@Validated
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
public class OrderController {
|
|
private final TokenService tokenService;
|
private final TAppUserService appUserService;
|
private final TBigGiftPackageOrderService bigGiftPackageOrderService;
|
private final TPhysicalGoodsOrderService physicalGoodsOrderService;
|
|
/**
|
* 大礼包商品下单
|
*
|
* @param dto 下单请求参数
|
* @return 下单结果(包含订单信息和支付参数)
|
*/
|
@ApiOperation(value = "大礼包商品下单", response = PlaceOrderVO.class)
|
@PostMapping("/big-gift/place")
|
public R<PlaceOrderVO> placeBigGiftOrder(@Valid @RequestBody BigGiftPlaceOrderDTO dto) {
|
// 获取当前登录用户
|
Integer userId = tokenService.getLoginUserApplet().getUserId();
|
TAppUser appUser = appUserService.getById(userId);
|
if (appUser == null) {
|
return R.fail("用户不存在");
|
}
|
if (appUser.getOpenid() == null || appUser.getOpenid().isEmpty()) {
|
return R.fail("用户未绑定微信");
|
}
|
|
PlaceOrderVO result = bigGiftPackageOrderService.placeOrder(dto, userId, appUser.getOpenid());
|
return R.ok(result);
|
}
|
|
/**
|
* 实物商品下单
|
*
|
* @param dto 下单请求参数
|
* @return 下单结果(包含订单信息和支付参数)
|
*/
|
@ApiOperation(value = "实物商品下单", response = PlaceOrderVO.class)
|
@PostMapping("/physical/place")
|
public R<PlaceOrderVO> placePhysicalGoodsOrder(@Valid @RequestBody PhysicalGoodsPlaceOrderDTO dto) {
|
// 获取当前登录用户
|
Integer userId = tokenService.getLoginUserApplet().getUserId();
|
TAppUser appUser = appUserService.getById(userId);
|
if (appUser == null) {
|
return R.fail("用户不存在");
|
}
|
if (appUser.getOpenid() == null || appUser.getOpenid().isEmpty()) {
|
return R.fail("用户未绑定微信");
|
}
|
|
PlaceOrderVO result = physicalGoodsOrderService.placeOrder(dto, userId, appUser.getOpenid());
|
return R.ok(result);
|
}
|
|
/**
|
* 大礼包尾款支付
|
*
|
* @param dto 尾款支付请求参数
|
* @return 支付结果(包含订单信息和支付参数)
|
*/
|
@ApiOperation(value = "大礼包尾款支付", response = PlaceOrderVO.class)
|
@PostMapping("/big-gift/pay-final")
|
public R<PlaceOrderVO> payFinalPayment(@Valid @RequestBody FinalPaymentDTO dto) {
|
// 获取当前登录用户
|
Integer userId = tokenService.getLoginUserApplet().getUserId();
|
TAppUser appUser = appUserService.getById(userId);
|
if (appUser == null) {
|
return R.fail("用户不存在");
|
}
|
if (appUser.getOpenid() == null || appUser.getOpenid().isEmpty()) {
|
return R.fail("用户未绑定微信");
|
}
|
|
PlaceOrderVO result = bigGiftPackageOrderService.payFinalPayment(dto.getOrderId(), userId, appUser.getOpenid());
|
return R.ok(result);
|
}
|
}
|