|
@@ -0,0 +1,167 @@
|
|
|
+package com.zanxiang.sdk.service.Impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zanxiang.common.enums.OrderStateEnum;
|
|
|
+import com.zanxiang.common.utils.StringUtils;
|
|
|
+import com.zanxiang.common.utils.bean.BeanUtils;
|
|
|
+import com.zanxiang.sdk.domain.bo.PlatformOrderBO;
|
|
|
+import com.zanxiang.sdk.domain.dto.PlatformOrderDTO;
|
|
|
+import com.zanxiang.sdk.domain.entity.Order;
|
|
|
+import com.zanxiang.sdk.mapper.OrderMapper;
|
|
|
+import com.zanxiang.sdk.service.PlatformOrderService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.junit.jupiter.api.extension.ParameterResolutionException;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PlatformOrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements PlatformOrderService {
|
|
|
+ protected final Logger logger = LoggerFactory.getLogger(PlatformOrderServiceImpl.class);
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public String create(PlatformOrderBO platformOrderBO) {
|
|
|
+ try {
|
|
|
+ logger.info("生成订单请求参数 platformOrderBO:{}", platformOrderBO);
|
|
|
+ this.checkParam(platformOrderBO, "create");
|
|
|
+ Order data = BeanUtils.copy(platformOrderBO, Order.class);
|
|
|
+ if (save(data)) {
|
|
|
+ return data.getId();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("生成订单失败 platformOrderBO:{}, error:{}", platformOrderBO, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public Boolean pay(PlatformOrderBO platformOrderBO) {
|
|
|
+ logger.info("订单支付请求参数 platformOrderBO:{}", platformOrderBO);
|
|
|
+ try {
|
|
|
+ this.checkParam(platformOrderBO, "pay");
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getId, platformOrderBO.getId()));
|
|
|
+ if (!order.getStatus().equals(OrderStateEnum.NO_PAY.getCode())) {
|
|
|
+ throw new ParameterResolutionException("订单状态非待支付");
|
|
|
+ }
|
|
|
+ order.setRealAmount(platformOrderBO.getRealAmount());
|
|
|
+ order.setMerchantOrderNo(platformOrderBO.getMerchantOrderNo());
|
|
|
+ order.setStatus(OrderStateEnum.SUCCESS.getCode());
|
|
|
+ order.setGamePaywayId(platformOrderBO.getGamePaywayId());
|
|
|
+ order.setPayTime(LocalDateTime.now());
|
|
|
+ order.setMemNote(StringUtils.isEmpty(platformOrderBO.getMemNote()) ? null : platformOrderBO.getMemNote());
|
|
|
+ logger.info("订单支付提交数据 data:{}", order);
|
|
|
+ LambdaUpdateWrapper<Order> wrapper = Wrappers.lambdaUpdate(Order.class)
|
|
|
+ .eq(Order::getId, platformOrderBO.getId())
|
|
|
+ .eq(Order::getUserId, platformOrderBO.getUserId())
|
|
|
+ .setEntity(order);
|
|
|
+ return super.update(wrapper);
|
|
|
+ } catch (ParameterResolutionException e) {
|
|
|
+ logger.error("订单支付失败 platformOrderBO:{}, error:{}", platformOrderBO, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public Boolean cancel(PlatformOrderBO platformOrderBO) {
|
|
|
+ logger.info("订单支付取消请求参数 platformOrderBO:{}", platformOrderBO);
|
|
|
+ try {
|
|
|
+ this.checkParam(platformOrderBO, "cancel");
|
|
|
+ Order order = new Order();
|
|
|
+ order.setId(platformOrderBO.getId());
|
|
|
+ order.setStatus(OrderStateEnum.CANCEL.getCode());
|
|
|
+ order.setAdminNote(StringUtils.isEmpty(platformOrderBO.getAdminNote()) ? null : platformOrderBO.getAdminNote());
|
|
|
+ order.setRemark(StringUtils.isEmpty(platformOrderBO.getRemark()) ? null : platformOrderBO.getRemark());
|
|
|
+ logger.info("订单取消提交数据 data:{}", order);
|
|
|
+ LambdaUpdateWrapper<Order> wrapper = Wrappers.lambdaUpdate(Order.class)
|
|
|
+ .eq(Order::getId, platformOrderBO.getId())
|
|
|
+ .setEntity(order);
|
|
|
+ return super.update(wrapper);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("订单取消失败 platformOrderBO:{}, error:{}", platformOrderBO, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PlatformOrderDTO info(Long id) {
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getId, id));
|
|
|
+ return BeanUtils.copy(order, PlatformOrderDTO.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查订单创建参数
|
|
|
+ *
|
|
|
+ * @param platformOrderBO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Boolean checkParam(PlatformOrderBO platformOrderBO, String active) {
|
|
|
+ switch (active) {
|
|
|
+ case "create":
|
|
|
+ if (platformOrderBO.getCpId() == null) {
|
|
|
+ throw new NullPointerException("CpId");
|
|
|
+ }
|
|
|
+ if (platformOrderBO.getUserId() == null) {
|
|
|
+ throw new NullPointerException("UserId");
|
|
|
+ }
|
|
|
+ if (platformOrderBO.getMgUserId() == null) {
|
|
|
+ throw new NullPointerException("MgUserId");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(platformOrderBO.getProductId())) {
|
|
|
+ throw new NullPointerException("ProductId");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(platformOrderBO.getProductName())) {
|
|
|
+ throw new NullPointerException("ProductName");
|
|
|
+ }
|
|
|
+ if (platformOrderBO.getProductCnt() == null) {
|
|
|
+ throw new NullPointerException("ProductCnt");
|
|
|
+ }
|
|
|
+ if (platformOrderBO.getAmount() == null) {
|
|
|
+ throw new NullPointerException("Amount");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "pay":
|
|
|
+ if (platformOrderBO.getId() == null) {
|
|
|
+ throw new NullPointerException("id");
|
|
|
+ }
|
|
|
+ if (platformOrderBO.getStatus() == 0) {
|
|
|
+ throw new NullPointerException("Status");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(platformOrderBO.getGamePaywayId())) {
|
|
|
+ throw new NullPointerException("GamePaywayId");
|
|
|
+ }
|
|
|
+ if (platformOrderBO.getRealAmount() == null) {
|
|
|
+ throw new NullPointerException("RealAmount");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(platformOrderBO.getMerchantOrderNo())) {
|
|
|
+ throw new NullPointerException("MerchantOrderNo");
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "cancel":
|
|
|
+ if (platformOrderBO.getId() == null) {
|
|
|
+ throw new NullPointerException("id");
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|