licailing 3 년 전
부모
커밋
df1e30e125

+ 2 - 1
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -31,7 +31,8 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
             "c.properties = ?9, c.model3d = ?10, c.max_count = ?11, c.count_id = ?12, c.scan_code = ?13, " +
             "c.no_sold_out = ?14, c.assignment = ?15, c.coupon_payment = ?16, c.share_bg = ?17," +
             "c.register_bg = ?18, c.vip_quota = ?19, c.time_delay = ?20, c.sale_time = ?21, c.hold_days = ?22, " +
-            "c.open_quota = ?23, c.showroom_bg = ?24, c.max_collection = ?25 where c.id = ?1", nativeQuery = true)
+            "c.open_quota = ?23, c.showroom_bg = ?24, c.max_collection = ?25, c.total_quota = ?26, c.invite_code = ?27" +
+            " where c.id = ?1", nativeQuery = true)
     @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
     void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
                 boolean schedule, int sort, String detail, String privileges,

+ 110 - 0
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -858,4 +858,114 @@ public class OrderService {
     public void releaseOrderLock(Long orderId) {
         redisTemplate.delete(RedisKeys.ORDER_LOCK + orderId);
     }
+
+    public Order create1(Long userId, Long collectionId, Long userCouponId, Long invitor, Long id) {
+        long t = System.currentTimeMillis();
+        int qty = 1;
+        int stock = Optional.ofNullable(collectionService.decreaseStock(collectionId, qty))
+                .map(Math::toIntExact)
+                .orElseThrow(new BusinessException("很遗憾,藏品已售罄", ErrorCode.SOLD_OUT));
+
+
+        // 创建订单出错后需要回滚库存,所以需要try-catch
+        try {
+            if (stock < 0) {
+                throw new BusinessException("很遗憾,藏品已售罄", ErrorCode.SOLD_OUT);
+            }
+            Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("藏品不存在"));
+            if (collection.getAssetId() != null && collection.getAssetId().equals(778359L)) {
+                throw new BusinessException("很遗憾,藏品已售罄", ErrorCode.SOLD_OUT);
+            }
+            if (collection.getAssetId() != null) {
+                Asset asset = assetRepo.findById(collection.getAssetId()).orElseThrow(new BusinessException("藏品不存在"));
+                if (asset.getStatus() != AssetStatus.NORMAL) {
+                    throw new BusinessException("藏品已下架");
+                }
+            }
+            User minter = userRepo.findById(collection.getMinterId()).orElseThrow(new BusinessException("铸造者不存在"));
+
+            if (collection.isScheduleSale()) {
+                if (collection.getStartTime().isAfter(LocalDateTime.now())) {
+                    throw new BusinessException("当前还未开售");
+                }
+            }
+            if (!collection.isOnShelf()) {
+                if (!collection.isScanCode()) {
+                    throw new BusinessException("藏品已下架");
+                }
+            }
+
+            if (!collection.isSalable()) {
+                throw new BusinessException("该藏品当前不可购买");
+            }
+
+            if (collection.getMaxCount() > 0) {
+                int count;
+                if (StringUtils.isNotBlank(collection.getCountId())) {
+                    count = orderRepo.countByUserIdAndCountIdAndStatusIn(userId, collection.getCountId(), Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
+                } else {
+                    count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userId, collectionId, Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
+                }
+                if (count >= collection.getMaxCount()) {
+                    throw new BusinessException("限购" + collection.getMaxCount() + "件");
+                }
+            }
+
+            if (StringUtils.isNotBlank(collection.getName())) {
+                User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
+                if (!user.getInviteCode().equals(collection.getName())) {
+                    throw new BusinessException("非活动用户");
+                }
+            }
+
+            Order order = Order.builder()
+                    .id(Optional.ofNullable(id).orElse(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(qty)
+                    .price(collection.getPrice())
+                    .gasPrice(BigDecimal.ZERO)
+                    .totalPrice(BigDecimal.ZERO)
+                    .status(OrderStatus.NOT_PAID)
+                    .assetId(collection.getAssetId())
+                    .couponId(userCouponId)
+                    .invitor(invitor)
+                    .countId(collection.getCountId())
+                    .vip(false)
+                    .vipPoint(0)
+                    .build();
+
+            if (collection.getSource() == CollectionSource.TRANSFER) {
+                Asset asset = assetRepo.findById(collection.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
+                asset.setStatus(AssetStatus.TRADING);
+                assetRepo.save(asset);
+                collectionRepo.setOnShelf(collectionId, false);
+            }
+            order = orderRepo.save(order);
+            if (order.getTotalPrice().equals(BigDecimal.ZERO)) {
+                notifyOrder(order.getId(), PayMethod.WEIXIN, null);
+            }
+
+
+            rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), collectionId, 10000);
+            log.info("订单创建完成, id={}, {}ms", order.getId(), System.currentTimeMillis() - t);
+            return order;
+        } catch (Exception e) {
+            collectionService.increaseStock(collectionId, qty);
+            throw e;
+        }
+    }
 }

+ 24 - 2
src/main/vue/src/views/BlindBoxEdit.vue

@@ -212,10 +212,10 @@
                         </el-radio-group>
                     </el-form-item>
                     <div class="inline-wrapper">
-                        <el-form-item label="品牌活动兑换" prop="">
+                        <el-form-item label="品牌活动兑换">
                             <el-radio-group v-model="inviteCode">
                                 <el-radio :label="true">品牌活动</el-radio>
-                                <el-radio :label="false">非品牌活动</el-radio>
+                                <el-radio :label="false">正常藏品</el-radio>
                             </el-radio-group>
                         </el-form-item>
                         <el-form-item prop="inviteCode" label="邀请码" v-if="inviteCode">
@@ -362,6 +362,10 @@ export default {
                             if (res.totalQuota !== res.vipQuota) {
                                 this.editQuota = false;
                             }
+                            console.log(res.inviteCode);
+                            if (res.inviteCode !== '' && res.inviteCode !== undefined) {
+                                this.inviteCode = true;
+                            }
                             resolve();
                         })
                         .catch(e => {
@@ -633,6 +637,21 @@ export default {
                         },
                         trigger: 'blur'
                     }
+                ],
+                inviteCode: [
+                    {
+                        validator: (rule, value, callback) => {
+                            if (this.inviteCode) {
+                                if (value === '' || value === undefined) {
+                                    callback(new Error('请输入邀请码'));
+                                    return;
+                                }
+                            }
+
+                            callback();
+                        },
+                        trigger: 'blur'
+                    }
                 ]
             },
             typeOptions: [
@@ -680,6 +699,9 @@ export default {
             if (this.editQuota && this.formData.totalQuota) {
                 this.formData.vipQuota = this.formData.totalQuota;
             }
+            if (!this.inviteCode) {
+                this.formData.inviteCode = null;
+            }
             if (this.formData.id) {
                 this.saving = true;
                 this.$http