|
|
@@ -22,6 +22,7 @@ import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.MarketSettlement;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
+import com.izouma.nineth.dto.PayQuery;
|
|
|
import com.izouma.nineth.dto.UserBankCard;
|
|
|
import com.izouma.nineth.enums.*;
|
|
|
import com.izouma.nineth.event.CreateAssetEvent;
|
|
|
@@ -45,6 +46,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.rocketmq.client.producer.SendResult;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
@@ -71,38 +73,81 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
-@AllArgsConstructor
|
|
|
@Slf4j
|
|
|
public class OrderService {
|
|
|
|
|
|
- private OrderRepo orderRepo;
|
|
|
- private CollectionRepo collectionRepo;
|
|
|
- private UserAddressRepo userAddressRepo;
|
|
|
- private UserRepo userRepo;
|
|
|
- private Environment env;
|
|
|
- private AlipayClient alipayClient;
|
|
|
- private AlipayProperties alipayProperties;
|
|
|
- private WxPayService wxPayService;
|
|
|
- private WxPayProperties wxPayProperties;
|
|
|
- private AssetService assetService;
|
|
|
- private SysConfigService sysConfigService;
|
|
|
- private AssetRepo assetRepo;
|
|
|
- private UserCouponRepo userCouponRepo;
|
|
|
- private CollectionService collectionService;
|
|
|
- private CommissionRecordRepo commissionRecordRepo;
|
|
|
- private AdapayProperties adapayProperties;
|
|
|
- private GeneralProperties generalProperties;
|
|
|
- private RocketMQTemplate rocketMQTemplate;
|
|
|
+ private OrderRepo orderRepo;
|
|
|
+ private CollectionRepo collectionRepo;
|
|
|
+ private UserAddressRepo userAddressRepo;
|
|
|
+ private UserRepo userRepo;
|
|
|
+ private Environment env;
|
|
|
+ private AlipayClient alipayClient;
|
|
|
+ private AlipayProperties alipayProperties;
|
|
|
+ private WxPayService wxPayService;
|
|
|
+ private WxPayProperties wxPayProperties;
|
|
|
+ private AssetService assetService;
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
+ private AssetRepo assetRepo;
|
|
|
+ private UserCouponRepo userCouponRepo;
|
|
|
+ private CollectionService collectionService;
|
|
|
+ private CommissionRecordRepo commissionRecordRepo;
|
|
|
+ private AdapayProperties adapayProperties;
|
|
|
+ private GeneralProperties generalProperties;
|
|
|
+ private RocketMQTemplate rocketMQTemplate;
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
- private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
- private SmsService smsService;
|
|
|
- private ErrorOrderRepo errorOrderRepo;
|
|
|
- private ShowCollectionRepo showCollectionRepo;
|
|
|
- private ShowroomService showroomService;
|
|
|
- private CollectionPrivilegeRepo collectionPrivilegeRepo;
|
|
|
- private UserBankCardRepo userBankCardRepo;
|
|
|
- private CacheService cacheService;
|
|
|
- private UserPropertyRepo userPropertyRepo;
|
|
|
+ private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
+ private SmsService smsService;
|
|
|
+ private ErrorOrderRepo errorOrderRepo;
|
|
|
+ private ShowCollectionRepo showCollectionRepo;
|
|
|
+ private ShowroomService showroomService;
|
|
|
+ private CollectionPrivilegeRepo collectionPrivilegeRepo;
|
|
|
+ private UserBankCardRepo userBankCardRepo;
|
|
|
+ private CacheService cacheService;
|
|
|
+ private UserPropertyRepo userPropertyRepo;
|
|
|
+ private OrderPayService orderPayService;
|
|
|
+
|
|
|
+ public OrderService(OrderRepo orderRepo, CollectionRepo collectionRepo, UserAddressRepo userAddressRepo,
|
|
|
+ UserRepo userRepo, Environment env, AlipayClient alipayClient,
|
|
|
+ AlipayProperties alipayProperties, WxPayService wxPayService, WxPayProperties wxPayProperties,
|
|
|
+ AssetService assetService, SysConfigService sysConfigService, AssetRepo assetRepo,
|
|
|
+ UserCouponRepo userCouponRepo, CollectionService collectionService,
|
|
|
+ CommissionRecordRepo commissionRecordRepo, AdapayProperties adapayProperties,
|
|
|
+ GeneralProperties generalProperties, RocketMQTemplate rocketMQTemplate,
|
|
|
+ RedisTemplate<String, Object> redisTemplate, SnowflakeIdWorker snowflakeIdWorker,
|
|
|
+ SmsService smsService, ErrorOrderRepo errorOrderRepo, ShowCollectionRepo showCollectionRepo,
|
|
|
+ ShowroomService showroomService, CollectionPrivilegeRepo collectionPrivilegeRepo,
|
|
|
+ UserBankCardRepo userBankCardRepo, CacheService cacheService, UserPropertyRepo userPropertyRepo,
|
|
|
+ @Lazy OrderPayService orderPayService) {
|
|
|
+ this.orderRepo = orderRepo;
|
|
|
+ this.collectionRepo = collectionRepo;
|
|
|
+ this.userAddressRepo = userAddressRepo;
|
|
|
+ this.userRepo = userRepo;
|
|
|
+ this.env = env;
|
|
|
+ this.alipayClient = alipayClient;
|
|
|
+ this.alipayProperties = alipayProperties;
|
|
|
+ this.wxPayService = wxPayService;
|
|
|
+ this.wxPayProperties = wxPayProperties;
|
|
|
+ this.assetService = assetService;
|
|
|
+ this.sysConfigService = sysConfigService;
|
|
|
+ this.assetRepo = assetRepo;
|
|
|
+ this.userCouponRepo = userCouponRepo;
|
|
|
+ this.collectionService = collectionService;
|
|
|
+ this.commissionRecordRepo = commissionRecordRepo;
|
|
|
+ this.adapayProperties = adapayProperties;
|
|
|
+ this.generalProperties = generalProperties;
|
|
|
+ this.rocketMQTemplate = rocketMQTemplate;
|
|
|
+ this.redisTemplate = redisTemplate;
|
|
|
+ this.snowflakeIdWorker = snowflakeIdWorker;
|
|
|
+ this.smsService = smsService;
|
|
|
+ this.errorOrderRepo = errorOrderRepo;
|
|
|
+ this.showCollectionRepo = showCollectionRepo;
|
|
|
+ this.showroomService = showroomService;
|
|
|
+ this.collectionPrivilegeRepo = collectionPrivilegeRepo;
|
|
|
+ this.userBankCardRepo = userBankCardRepo;
|
|
|
+ this.cacheService = cacheService;
|
|
|
+ this.userPropertyRepo = userPropertyRepo;
|
|
|
+ this.orderPayService = orderPayService;
|
|
|
+ }
|
|
|
|
|
|
public Page<Order> all(PageQuery pageQuery) {
|
|
|
return orderRepo.findAll(JpaUtils.toSpecification(pageQuery, Order.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -757,6 +802,20 @@ public class OrderService {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
+ PayQuery payQuery;
|
|
|
+ try {
|
|
|
+ payQuery = orderPayService.query(order.getId().toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ payQuery = new PayQuery();
|
|
|
+ payQuery.setExist(false);
|
|
|
+ }
|
|
|
+ if (payQuery.isExist()) {
|
|
|
+ if (PayStatus.SUCCESS == payQuery.getStatus() || PayStatus.PENDING == payQuery.getStatus()) {
|
|
|
+ log.info("订单 {} 已经支付无法取消, transactionId={}, channel={}", order.getId(), payQuery.getTransactionId(), payQuery.getChannel());
|
|
|
+ throw new BusinessException("已支付订单无法取消");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
throw new BusinessException("已支付订单无法取消");
|
|
|
}
|