|
|
@@ -2,6 +2,7 @@ package com.kxs.product.biz.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
@@ -9,24 +10,25 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.kxs.common.core.constant.CommonConstants;
|
|
|
import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
import com.kxs.common.core.util.R;
|
|
|
+import com.kxs.common.pay.enums.PayConstants;
|
|
|
import com.kxs.common.pay.enums.PayPlatformEnum;
|
|
|
import com.kxs.common.pay.factory.PaymentFactory;
|
|
|
import com.kxs.common.pay.model.PayRequest;
|
|
|
import com.kxs.common.pay.model.PayResponse;
|
|
|
-import com.kxs.common.pay.service.PayService;
|
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
|
+import com.kxs.product.api.dto.kxsapp.shop.GoodsSubmitDTO;
|
|
|
import com.kxs.product.api.model.KxsShopGoods;
|
|
|
+import com.kxs.product.api.model.KxsShopOrder;
|
|
|
import com.kxs.product.api.model.KxsShopOrderInfo;
|
|
|
-import com.kxs.product.api.dto.kxsapp.shop.GoodsSubmitDTO;
|
|
|
import com.kxs.product.api.vo.kxsapp.shop.*;
|
|
|
import com.kxs.product.biz.constant.enums.KxsShopEnum;
|
|
|
import com.kxs.product.biz.constant.enums.ProductErrorTypeEnum;
|
|
|
import com.kxs.product.biz.mapper.KxsShopGoodsMapper;
|
|
|
import com.kxs.product.biz.mapper.KxsShopOrderInfoMapper;
|
|
|
import com.kxs.product.biz.mapper.KxsShopOrderMapper;
|
|
|
-import com.kxs.product.api.model.KxsShopOrder;
|
|
|
import com.kxs.product.biz.service.KxsShopOrderService;
|
|
|
import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
+import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
@@ -116,7 +118,7 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class)
|
|
|
public R payOrder(KxsShopOrder param) {
|
|
|
|
|
|
if(param.getId() == null){
|
|
|
@@ -130,28 +132,48 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
|
}
|
|
|
List<KxsShopOrderInfo> kxsShopOrderInfos = orderInfoMapper.selectList(Wrappers.<KxsShopOrderInfo>lambdaQuery().eq(KxsShopOrderInfo::getOrderId, order.getId()));
|
|
|
+ String subject = kxsShopOrderInfos.stream().map(KxsShopOrderInfo::getGoodsName).collect(Collectors.joining(","));
|
|
|
|
|
|
- //修改订单内容
|
|
|
- this.update(Wrappers.<KxsShopOrder>lambdaUpdate().eq(KxsShopOrder::getId, param.getId())
|
|
|
- .set(KxsShopOrder::getPayType, param.getPayType())
|
|
|
+ LambdaUpdateWrapper<KxsShopOrder> lambdaUpdateWrapper = Wrappers.<KxsShopOrder>lambdaUpdate().eq(KxsShopOrder::getId, param.getId());
|
|
|
+ lambdaUpdateWrapper.set(KxsShopOrder::getPayType, param.getPayType())
|
|
|
.set(KxsShopOrder::getGetMode, param.getGetMode())
|
|
|
- .set(KxsShopOrder::getRemark, param.getRemark()));
|
|
|
+ .set(KxsShopOrder::getRemark, param.getRemark());
|
|
|
|
|
|
//余额支付
|
|
|
if(param.getPayType().equals(KxsShopEnum.YUE_PAY.getType())){
|
|
|
- return this.yuePay(order);
|
|
|
+ PayRequest payReq = new PayRequest();
|
|
|
+ payReq.setPayTypeEnum(PayPlatformEnum.ALIPAY);
|
|
|
+ payReq.setOutTradeNo(order.getOrderSn());
|
|
|
+ payReq.setSubject(subject);
|
|
|
+ payReq.setTotalAmount(param.getPayPrice().doubleValue());
|
|
|
+ try {
|
|
|
+ PayResponse payResponse = paymentFactory.getPayService(PayPlatformEnum.YUEPAY.getType()).appPay(payReq);
|
|
|
+ if (PayConstants.YUE_PAY_SUCCESS.equals(payResponse.getResult())) {
|
|
|
+ //支付成功
|
|
|
+ lambdaUpdateWrapper.set(KxsShopOrder::getStatus, KxsShopEnum.ORDER_NO_SEND.getType());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }else{
|
|
|
+ return R.failed(payResponse.getResult());
|
|
|
+ }
|
|
|
+ } catch (AlipayApiException e) {
|
|
|
+ throw new GlobalCustomerException("余额支付异常");
|
|
|
+ }
|
|
|
}
|
|
|
+ //修改订单信息
|
|
|
+ this.update(lambdaUpdateWrapper);
|
|
|
|
|
|
//支付宝支付
|
|
|
if(param.getPayType().equals(KxsShopEnum.ALI_PAY.getType())){
|
|
|
- String subject = kxsShopOrderInfos.stream().map(KxsShopOrderInfo::getGoodsName).collect(Collectors.joining(","));
|
|
|
return this.aliPay(order, subject);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
return R.failed("未知的支付方式!");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public R cancelOrder(KxsShopOrder param) {
|
|
|
|
|
|
@@ -223,15 +245,6 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 余额支付
|
|
|
- *
|
|
|
- * @param param 参数
|
|
|
- * @return {@link R}
|
|
|
- */
|
|
|
- private R yuePay(KxsShopOrder param){
|
|
|
- return R.ok();
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 支付宝支付
|