|
@@ -1,15 +1,23 @@
|
|
package com.yonge.cooleshow.teacher.controller;
|
|
package com.yonge.cooleshow.teacher.controller;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.microsvc.toolkit.common.response.template.R;
|
|
|
|
+import com.microsvc.toolkit.config.jwt.utils.JwtUserInfo;
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
|
|
import com.yonge.cooleshow.biz.dal.dto.search.OrderSearch;
|
|
import com.yonge.cooleshow.biz.dal.dto.search.OrderSearch;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.TenantStaff;
|
|
import com.yonge.cooleshow.biz.dal.entity.UserOrder;
|
|
import com.yonge.cooleshow.biz.dal.entity.UserOrder;
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.service.TenantStaffService;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.service.UserPaymentCoreService;
|
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.UserPaymentOrderWrapper;
|
|
import com.yonge.cooleshow.common.enums.CacheNameEnum;
|
|
import com.yonge.cooleshow.common.enums.CacheNameEnum;
|
|
import com.yonge.cooleshow.biz.dal.service.UserOrderService;
|
|
import com.yonge.cooleshow.biz.dal.service.UserOrderService;
|
|
|
|
+import com.yonge.cooleshow.teacher.vo.UserPaymentOrderVo;
|
|
import com.yonge.toolset.payment.util.DistributedLock;
|
|
import com.yonge.toolset.payment.util.DistributedLock;
|
|
import com.yonge.toolset.mybatis.support.PageUtil;
|
|
import com.yonge.toolset.mybatis.support.PageUtil;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
@@ -31,6 +39,7 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
|
|
@@ -41,6 +50,7 @@ import java.time.LocalDateTime;
|
|
import java.time.LocalTime;
|
|
import java.time.LocalTime;
|
|
import java.time.temporal.TemporalAdjusters;
|
|
import java.time.temporal.TemporalAdjusters;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -59,6 +69,12 @@ public class UserOrderController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private RedissonClient redissonClient;
|
|
private RedissonClient redissonClient;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private TenantStaffService tenantStaffService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserPaymentCoreService userPaymentCoreService;
|
|
|
|
+
|
|
@ApiOperation(value = "下单接口")
|
|
@ApiOperation(value = "下单接口")
|
|
@PostMapping("/executeOrder")
|
|
@PostMapping("/executeOrder")
|
|
public HttpResponseResult<UserOrder> executeOrder(@Valid @RequestBody OrderReq orderReq) {
|
|
public HttpResponseResult<UserOrder> executeOrder(@Valid @RequestBody OrderReq orderReq) {
|
|
@@ -213,4 +229,98 @@ public class UserOrderController extends BaseController {
|
|
UserOrderVo detail = userOrderService.detailApp(param);
|
|
UserOrderVo detail = userOrderService.detailApp(param);
|
|
return succeed(detail);
|
|
return succeed(detail);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "用户下单", notes = "用户下单")
|
|
|
|
+ @PostMapping("/executeOrder/v2")
|
|
|
|
+ public R<UserPaymentOrderWrapper.PaymentConfig> executeOrderV2(@Validated @RequestBody UserPaymentOrderVo.OrderReq orderReq) {
|
|
|
|
+
|
|
|
|
+ // 设置下单用户信息
|
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
|
+ if (Objects.isNull(sysUser)) {
|
|
|
|
+ throw com.microsvc.toolkit.common.webportal.exception.BizException.from("用户信息不存在");
|
|
|
|
+ }
|
|
|
|
+ orderReq.setUserId(sysUser.getId());
|
|
|
|
+ orderReq.setPaymentClient(ClientEnum.TEACHER.name());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 用户下单请求
|
|
|
|
+ UserPaymentOrderWrapper.UserPaymentOrder order = JSON.parseObject(orderReq.jsonString(), UserPaymentOrderWrapper.UserPaymentOrder.class);
|
|
|
|
+
|
|
|
|
+ TenantStaff tenantStaff = tenantStaffService.getByUserId(sysUser.getId());
|
|
|
|
+ if (Objects.isNull(tenantStaff)) {
|
|
|
|
+ throw com.microsvc.toolkit.common.webportal.exception.BizException.from("用户信息不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ order.setTenantId(tenantStaff.getTenantId());
|
|
|
|
+ // 新增数据
|
|
|
|
+ UserPaymentOrderWrapper.PaymentConfig paymentConfig = userPaymentCoreService.executeOrderCreate(order);
|
|
|
|
+ if (Objects.isNull(paymentConfig)) {
|
|
|
|
+ throw com.microsvc.toolkit.common.webportal.exception.BizException.from("下单失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return R.from(paymentConfig);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "用户付款", notes = "用户付款")
|
|
|
|
+ @PostMapping("/orderPay/v2")
|
|
|
|
+ public R<UserPaymentOrderWrapper.PaymentReq> executePaymentV2(@Validated @RequestBody UserPaymentOrderVo.PaymentReqConfig config) {
|
|
|
|
+ // 设置下单用户信息
|
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
|
+ if (Objects.isNull(sysUser)) {
|
|
|
|
+ throw com.microsvc.toolkit.common.webportal.exception.BizException.from("用户信息不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 用户下单请求
|
|
|
|
+ UserPaymentOrderWrapper.PaymentOrderReqConfig reqConfig = UserPaymentOrderWrapper.PaymentOrderReqConfig.from(config.jsonString());
|
|
|
|
+
|
|
|
|
+ // 创建用户支付数据
|
|
|
|
+ UserPaymentOrderWrapper.PaymentReq paymentConfig = userPaymentCoreService.executePayment(JwtUserInfo.builder()
|
|
|
|
+ .userId(sysUser.getId().toString()).clientType(ClientEnum.TEACHER.getCode()).build(), reqConfig);
|
|
|
|
+ if (Objects.isNull(paymentConfig)) {
|
|
|
|
+ throw com.microsvc.toolkit.common.webportal.exception.BizException.from("付款失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return R.from(paymentConfig);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "取消订单")
|
|
|
|
+ @PostMapping("/orderCancel/v2")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "orderNo", value = "订单号", paramType = "query", dataType = "String", required = true),
|
|
|
|
+ @ApiImplicitParam(name = "reason", value = "取消说明", paramType = "query", dataType = "String")
|
|
|
|
+ })
|
|
|
|
+ public HttpResponseResult<Boolean> orderCancelV2(@ApiIgnore @RequestBody OrderPayReq payReq) {
|
|
|
|
+ SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
|
+ if (user == null || null == user.getId()) {
|
|
|
|
+ return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isEmpty(payReq.getOrderNo())) {
|
|
|
|
+ return failed("订单号不能为空");
|
|
|
|
+ }
|
|
|
|
+ payReq.setUserId(user.getId());
|
|
|
|
+
|
|
|
|
+ // 用户取消支付
|
|
|
|
+ userPaymentCoreService.cancelPayment(JwtUserInfo.builder().userId(user.getId().toString()).clientType(ClientEnum.TEACHER.getCode()).build(), payReq.getOrderNo());
|
|
|
|
+
|
|
|
|
+ return HttpResponseResult.status(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "检测订单应该使用哪种支付方式")
|
|
|
|
+ @PostMapping("/orderPayType")
|
|
|
|
+ public HttpResponseResult<UserPaymentOrderWrapper.OrderPayTypeResp> orderPayType(@ApiIgnore @RequestBody UserPaymentOrderWrapper.OrderPayTypeReq payTypeReq) {
|
|
|
|
+ SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
|
+ if (user == null || null == user.getId()) {
|
|
|
|
+ return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ payTypeReq.setBuyId(user.getId());
|
|
|
|
+ payTypeReq.setClientType(ClientEnum.TEACHER);
|
|
|
|
+
|
|
|
|
+ return HttpResponseResult.succeed(userPaymentCoreService.orderPayType(payTypeReq));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|