|
@@ -1,5 +1,6 @@
|
|
|
package com.kxs.product.biz.service.impl;
|
|
package com.kxs.product.biz.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
import com.alipay.api.AlipayApiException;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
@@ -12,11 +13,14 @@ import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
import com.kxs.common.core.util.R;
|
|
import com.kxs.common.core.util.R;
|
|
|
import com.kxs.common.pay.enums.PayConstants;
|
|
import com.kxs.common.pay.enums.PayConstants;
|
|
|
import com.kxs.common.pay.enums.PayPlatformEnum;
|
|
import com.kxs.common.pay.enums.PayPlatformEnum;
|
|
|
|
|
+import com.kxs.common.pay.enums.PayStatusCommEnum;
|
|
|
import com.kxs.common.pay.factory.PaymentFactory;
|
|
import com.kxs.common.pay.factory.PaymentFactory;
|
|
|
import com.kxs.common.pay.model.PayRequest;
|
|
import com.kxs.common.pay.model.PayRequest;
|
|
|
import com.kxs.common.pay.model.PayResponse;
|
|
import com.kxs.common.pay.model.PayResponse;
|
|
|
|
|
+import com.kxs.common.pay.model.YuePayMessage;
|
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
|
import com.kxs.product.api.dto.kxsapp.shop.GoodsSubmitDTO;
|
|
import com.kxs.product.api.dto.kxsapp.shop.GoodsSubmitDTO;
|
|
|
|
|
+import com.kxs.product.api.dto.kxsapp.shop.PayOrderDTO;
|
|
|
import com.kxs.product.api.model.KxsShopGoods;
|
|
import com.kxs.product.api.model.KxsShopGoods;
|
|
|
import com.kxs.product.api.model.KxsShopOrder;
|
|
import com.kxs.product.api.model.KxsShopOrder;
|
|
|
import com.kxs.product.api.model.KxsShopOrderInfo;
|
|
import com.kxs.product.api.model.KxsShopOrderInfo;
|
|
@@ -28,6 +32,7 @@ import com.kxs.product.biz.mapper.KxsShopOrderInfoMapper;
|
|
|
import com.kxs.product.biz.mapper.KxsShopOrderMapper;
|
|
import com.kxs.product.biz.mapper.KxsShopOrderMapper;
|
|
|
import com.kxs.product.biz.service.KxsShopOrderService;
|
|
import com.kxs.product.biz.service.KxsShopOrderService;
|
|
|
import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
|
|
+import com.lly835.bestpay.enums.OrderStatusEnum;
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -35,7 +40,9 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -119,7 +126,7 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@GlobalTransactional(rollbackFor = Exception.class)
|
|
@GlobalTransactional(rollbackFor = Exception.class)
|
|
|
- public R payOrder(KxsShopOrder param) {
|
|
|
|
|
|
|
+ public R payOrder(PayOrderDTO param) {
|
|
|
|
|
|
|
|
if(param.getId() == null){
|
|
if(param.getId() == null){
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
@@ -131,45 +138,57 @@ public class KxsShopOrderServiceImpl extends ServiceImpl<KxsShopOrderMapper, Kxs
|
|
|
if(order == null){
|
|
if(order == null){
|
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
return R.failed(ProductErrorTypeEnum.ORDER_EMPTY.getDescription());
|
|
|
}
|
|
}
|
|
|
|
|
+ if(!Objects.equals(order.getStatus(), KxsShopEnum.ORDER_NO_PAY.getType())){
|
|
|
|
|
+ return R.failed(ProductErrorTypeEnum.ORDER_STATUS_ERROR.getDescription());
|
|
|
|
|
+ }
|
|
|
List<KxsShopOrderInfo> kxsShopOrderInfos = orderInfoMapper.selectList(Wrappers.<KxsShopOrderInfo>lambdaQuery().eq(KxsShopOrderInfo::getOrderId, order.getId()));
|
|
List<KxsShopOrderInfo> kxsShopOrderInfos = orderInfoMapper.selectList(Wrappers.<KxsShopOrderInfo>lambdaQuery().eq(KxsShopOrderInfo::getOrderId, order.getId()));
|
|
|
String subject = kxsShopOrderInfos.stream().map(KxsShopOrderInfo::getGoodsName).collect(Collectors.joining(","));
|
|
String subject = kxsShopOrderInfos.stream().map(KxsShopOrderInfo::getGoodsName).collect(Collectors.joining(","));
|
|
|
|
|
|
|
|
- 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());
|
|
|
|
|
|
|
+ //支付宝支付
|
|
|
|
|
+ if(param.getPayType().equals(KxsShopEnum.ALI_PAY.getType())){
|
|
|
|
|
+ return this.aliPay(order, subject);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
//余额支付
|
|
//余额支付
|
|
|
if(param.getPayType().equals(KxsShopEnum.YUE_PAY.getType())){
|
|
if(param.getPayType().equals(KxsShopEnum.YUE_PAY.getType())){
|
|
|
|
|
+ Optional.ofNullable(param.getPayPwd()).orElseThrow(() -> new GlobalCustomerException("请输入支付密码"));
|
|
|
|
|
+ //校验支付密码
|
|
|
|
|
+ R<Boolean> booleanR = remoteKxsUserService.checkPayPwd(param.getPayPwd());
|
|
|
|
|
+ if(booleanR.getStatus() != 1 || !booleanR.getData()){
|
|
|
|
|
+ return R.failed("支付密码错误");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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());
|
|
|
|
|
+
|
|
|
PayRequest payReq = new PayRequest();
|
|
PayRequest payReq = new PayRequest();
|
|
|
payReq.setPayTypeEnum(PayPlatformEnum.ALIPAY);
|
|
payReq.setPayTypeEnum(PayPlatformEnum.ALIPAY);
|
|
|
payReq.setOutTradeNo(order.getOrderSn());
|
|
payReq.setOutTradeNo(order.getOrderSn());
|
|
|
payReq.setSubject(subject);
|
|
payReq.setSubject(subject);
|
|
|
- payReq.setTotalAmount(param.getPayPrice().doubleValue());
|
|
|
|
|
|
|
+ payReq.setTotalAmount(order.getPayPrice().doubleValue());
|
|
|
try {
|
|
try {
|
|
|
PayResponse payResponse = paymentFactory.getPayService(PayPlatformEnum.YUEPAY.getType()).appPay(payReq);
|
|
PayResponse payResponse = paymentFactory.getPayService(PayPlatformEnum.YUEPAY.getType()).appPay(payReq);
|
|
|
- if (PayConstants.YUE_PAY_SUCCESS.equals(payResponse.getResult())) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ YuePayMessage payMessage = BeanUtil.toBean(payResponse, YuePayMessage.class);
|
|
|
|
|
+ if (payMessage != null) {
|
|
|
//支付成功
|
|
//支付成功
|
|
|
lambdaUpdateWrapper.set(KxsShopOrder::getStatus, KxsShopEnum.ORDER_NO_SEND.getType());
|
|
lambdaUpdateWrapper.set(KxsShopOrder::getStatus, KxsShopEnum.ORDER_NO_SEND.getType());
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ lambdaUpdateWrapper.set(KxsShopOrder::getPayTime, LocalDateTime.now());
|
|
|
}else{
|
|
}else{
|
|
|
return R.failed(payResponse.getResult());
|
|
return R.failed(payResponse.getResult());
|
|
|
}
|
|
}
|
|
|
} catch (AlipayApiException e) {
|
|
} catch (AlipayApiException e) {
|
|
|
throw new GlobalCustomerException("余额支付异常");
|
|
throw new GlobalCustomerException("余额支付异常");
|
|
|
}
|
|
}
|
|
|
|
|
+ //修改订单信息
|
|
|
|
|
+ this.update(lambdaUpdateWrapper);
|
|
|
|
|
+ //TODO 余额走支付接下来的逻辑
|
|
|
}
|
|
}
|
|
|
- //修改订单信息
|
|
|
|
|
- this.update(lambdaUpdateWrapper);
|
|
|
|
|
|
|
|
|
|
- //支付宝支付
|
|
|
|
|
- if(param.getPayType().equals(KxsShopEnum.ALI_PAY.getType())){
|
|
|
|
|
- return this.aliPay(order, subject);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- return R.failed("未知的支付方式!");
|
|
|
|
|
|
|
+ return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|