|
|
@@ -33,10 +33,7 @@ import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.security.Authority;
|
|
|
import com.izouma.nineth.service.sms.SmsService;
|
|
|
-import com.izouma.nineth.utils.AESEncryptUtil;
|
|
|
-import com.izouma.nineth.utils.JpaUtils;
|
|
|
-import com.izouma.nineth.utils.SecurityUtils;
|
|
|
-import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
+import com.izouma.nineth.utils.*;
|
|
|
import com.izouma.nineth.utils.excel.ExcelUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -44,6 +41,8 @@ import org.apache.commons.codec.EncoderException;
|
|
|
import org.apache.commons.codec.net.URLCodec;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
+import org.apache.commons.lang3.RandomUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.rocketmq.client.producer.SendResult;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
@@ -61,6 +60,7 @@ import org.springframework.ui.Model;
|
|
|
import java.io.File;
|
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.Duration;
|
|
|
import java.time.LocalDate;
|
|
|
@@ -299,8 +299,8 @@ public class OrderService {
|
|
|
.contactName(Optional.ofNullable(userAddress).map(UserAddress::getName).orElse(null))
|
|
|
.contactPhone(Optional.ofNullable(userAddress).map(UserAddress::getPhone).orElse(null))
|
|
|
.address(Optional.ofNullable(userAddress).map(u ->
|
|
|
- u.getProvinceName() + " " + u.getCityName() + " " + u.getDistrictName() + " " + u
|
|
|
- .getAddress())
|
|
|
+ u.getProvinceName() + " " + u.getCityName() + " " + u.getDistrictName() + " " + u
|
|
|
+ .getAddress())
|
|
|
.orElse(null))
|
|
|
.status(OrderStatus.NOT_PAID)
|
|
|
.assetId(collection.getAssetId())
|
|
|
@@ -980,4 +980,65 @@ public class OrderService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public List<Order> addOrder(Long collectionId, List<Long> userIds, LocalDateTime time, boolean notify) {
|
|
|
+ Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("藏品不存在"));
|
|
|
+ User minter = userRepo.findById(collection.getMinterId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ int i = 0;
|
|
|
+ List<Order> list = new ArrayList<>();
|
|
|
+ for (Long userId : userIds) {
|
|
|
+ time = time.plusSeconds(i++);
|
|
|
+ BigDecimal gasFee = new BigDecimal("1");
|
|
|
+ Order order = Order.builder()
|
|
|
+ .id(snowflakeIdWorker.nextId())
|
|
|
+ .userId(userId)
|
|
|
+ .collectionId(collectionId)
|
|
|
+ .name(collection.getName())
|
|
|
+ .pic(collection.getPic())
|
|
|
+ .detail(collection.getDetail())
|
|
|
+ .properties(collection.getProperties())
|
|
|
+ .category(collection.getCategory())
|
|
|
+ .canResale(collection.isCanResale())
|
|
|
+ .royalties(collection.getRoyalties())
|
|
|
+ .serviceCharge(collection.getServiceCharge())
|
|
|
+ .type(collection.getType())
|
|
|
+ .source(collection.getSource())
|
|
|
+ .minterId(collection.getMinterId())
|
|
|
+ .minter(minter.getNickname())
|
|
|
+ .minterAvatar(minter.getAvatar())
|
|
|
+ .qty(1)
|
|
|
+ .price(collection.getPrice())
|
|
|
+ .gasPrice(gasFee)
|
|
|
+ .totalPrice(collection.getPrice().multiply(BigDecimal.valueOf(1)).add(gasFee))
|
|
|
+ .status(notify ? OrderStatus.NOT_PAID : OrderStatus.FINISH)
|
|
|
+ .assetId(collection.getAssetId())
|
|
|
+ .countId(collection.getCountId())
|
|
|
+ .build();
|
|
|
+ orderRepo.saveAndFlush(order);
|
|
|
+
|
|
|
+ String txHash = RandomStringUtils.randomAlphanumeric(64).toLowerCase(Locale.ROOT);
|
|
|
+ String transactionId = DateTimeUtils.format(LocalDateTime.now(), "yyyyMMdd") +
|
|
|
+ RandomStringUtils.randomNumeric(24);
|
|
|
+ BigInteger gas = new BigInteger("157377");
|
|
|
+
|
|
|
+ if (notify) {
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
+ new OrderNotifyEvent(order.getId(), PayMethod.ALIPAY, order.getTransactionId()
|
|
|
+ , System.currentTimeMillis()));
|
|
|
+ } else {
|
|
|
+ order.setCreatedAt(ObjectUtils.clone(time));
|
|
|
+ order.setPayTime(time.plusSeconds(RandomUtils.nextInt(5, 50)));
|
|
|
+ order.setTransactionId(transactionId);
|
|
|
+ order.setTxHash(txHash);
|
|
|
+ order.setGasUsed(gas);
|
|
|
+ order.setPayMethod(PayMethod.ALIPAY);
|
|
|
+ order.setStatus(OrderStatus.FINISH);
|
|
|
+ order.setModifiedAt(order.getPayTime());
|
|
|
+ order.setModifiedBy("system");
|
|
|
+ order.setCreatedBy("system");
|
|
|
+ orderRepo.save(order);
|
|
|
+ }
|
|
|
+ list.add(order);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|