Browse Source

fix: 配额跨日不重置bug + chart页按钮清理(查看AI解读/学业方向/分享命盘/申请方案)

配额修复:
- UserService: 新增 getAndResetDailyQuota() 公开方法,在跨日时重置并持久化
- ProfileController: /quota 端点改用新方法,前端始终获取当日真实数据

Chart页清理:
- 移除 查看AI解读 按钮,改为 onMounted 自动加载(fetchInterpret)
- 移除 学业方向分析 按钮/面板/骨架屏/升级卡/关联JS和CSS
- 移除 分享命盘 按钮/onShareTap/performShare/ChartShareCanvas组件
- 移除 申请人工深度方案 按钮/goPlanApply函数/相关CSS
- 清理所有死代码引用和导入
liaoxg 3 months ago
parent
commit
8bf190b1ba

+ 5 - 454
client/pages/chart/index.vue

@@ -29,14 +29,7 @@
       <text class="menu-btn" @click="showMenu">···</text>
     </view>
 
-    <!-- US-3.1: AI Interpretation section -->
-    <view class="interpret-bar">
-      <button class="interpret-btn" :disabled="interpreting" @click="fetchInterpret">
-        {{ interpreting ? '解读生成中...' : '🔮 查看AI解读' }}
-      </button>
-    </view>
-
-    <!-- US-3.1: Interpretation panel -->
+    <!-- US-3.1: AI Interpretation panel -->
     <view v-if="interpretData" id="interpret-section" class="interpret-panel">
       <view
         v-for="(section, key) in interpretData"
@@ -72,74 +65,7 @@
       </view>
     </view>
 
-     <!-- US-9.1: Academic orientation button -->
-     <view class="academic-bar">
-       <button class="academic-btn" :disabled="academicLoading" @click="fetchAcademicOrientation">
-         {{ academicLoading ? '分析生成中...' : '🎓 学业方向分析' }}
-       </button>
-       <text v-if="!userStore.isVipActive && maxAcademic > 0" class="academic-quota">
-         今日 {{ usedAcademic }}/{{ maxAcademic }} 次
-       </text>
-     </view>
-
-     <!-- US-2.1: Share bar -->
-     <view class="share-bar">
-       <button class="share-btn" :disabled="shareGenerating" @click="onShareTap">
-         {{ shareGenerating ? '生成中...' : '📸 分享命盘' }}
-       </button>
-       <text v-if="!userStore.isVipActive" class="share-quota">
-         今日剩余 {{ shareRemaining }} 次
-       </text>
-     </view>
-
-     <!-- US-9.1: Academic orientation panel -->
-    <view v-if="academicData" id="academic-section" class="academic-panel">
-      <view class="academic-section-title">🎯 学业方向深度分析</view>
-      <view
-        v-for="(section, key) in academicData"
-        :key="key"
-        class="academic-card"
-        :class="{ expanded: academicExpanded[key], talent: key==='talentTendency', direction: key==='suitableDirection', learning: key==='learningStyle', parenting: key==='parentingAdvice', periods: key==='keyPeriods' }"
-        @click="toggleAcademicSection(key)"
-      >
-        <view class="academic-card-header">
-          <text class="academic-card-title">{{ section.title }}</text>
-          <text class="academic-toggle">{{ academicExpanded[key] ? '▾' : '▸' }}</text>
-        </view>
-        <view v-show="academicExpanded[key]" class="academic-card-body">
-          <text class="academic-content">{{ section.content }}</text>
-          <view v-if="section.matchPercentages" class="match-bars">
-            <view v-for="(pct, dir) in section.matchPercentages" :key="dir" class="match-row">
-              <text class="match-label">{{ dir }}</text>
-              <view class="match-track">
-                <view class="match-fill" :style="{ width: pct + '%' }" :class="'pct-' + pct"></view>
-              </view>
-              <text class="match-value">{{ pct }}%</text>
-            </view>
-          </view>
-        </view>
-      </view>
-      <view class="academic-disclaimer">
-        <text class="disclaimer-text">💡 以上分析由AI生成,如需人工深度方案,可申请能量师出方案</text>
-      </view>
-    </view>
-
-    <!-- US-9.1: Loading skeleton -->
-    <view v-if="academicLoading" class="academic-skeleton">
-      <view v-for="n in 3" :key="n" class="skeleton-card">
-        <view class="skeleton-header"></view>
-        <view v-if="n === 1" class="skeleton-body">
-          <view class="skeleton-line"></view><view class="skeleton-line short"></view><view class="skeleton-line"></view>
-        </view>
-      </view>
-    </view>
 
-    <!-- US-9.1: Academic quota exceeded upgrade card -->
-    <view v-if="quotaAcademicExceeded && !academicData && !academicLoading" class="academic-upgrade-card">
-      <text class="academic-upgrade-title">🎓 学业方向分析</text>
-      <text class="academic-upgrade-desc">今日学业分析次数已用完,开通会员享无限次</text>
-      <button class="academic-upgrade-btn" @click="goSubscribeC">开通会员 ¥131/年</button>
-    </view>
 
     <!-- AI Chat -->
     <view class="chat-section">
@@ -301,23 +227,9 @@
         </view>
       </view>
 
-      <!-- EPIC 9: Apply for practitioner plan -->
-     <view class="plan-apply-bar">
-       <button class="plan-apply-btn" @click="goPlanApply">
-         💼 申请人工深度方案
-       </button>
-     </view>
    </view>
 
-   <!-- Share canvas (hidden off-screen) -->
-   <ChartShareCanvas
-     ref="shareCanvas"
-     :chart="store.currentChart || {}"
-     :name="store.currentName"
-     :birthday="store.currentBirthYear && store.currentBirthMonth && store.currentBirthDay ?
-       `${store.currentBirthYear}-${String(store.currentBirthMonth).padStart(2,'0')}-${String(store.currentBirthDay).padStart(2,'0')}` : ''"
-     @ready="onCanvasReady"
-   />
+
  </template>
 
 <script>
@@ -355,7 +267,6 @@ import { ref, computed, onMounted, onUnmounted } from 'vue'
 import { useChartStore } from '@/stores/chart'
 import { useUserStore } from '@/stores/user'
 import TriangleChart from '@/components/TriangleChart.vue'
-import ChartShareCanvas from '@/components/ChartShareCanvas.vue'
 import { chartApi, chatApi, consultationApi, profileApi, annotationApi, exportApi, interventionApi, planApi, proposalApi, deliveryApi, payApi } from '@/utils/api'
 
 const store = useChartStore()
@@ -366,9 +277,6 @@ const messages = ref([])
 const loading = ref(false)
 const usedChats = ref(0)
 const maxChats = ref(0)
-const usedAcademic = ref(0)
-const maxAcademic = ref(0)
-
 // US-9.3: Intervention state
 const hasActiveIntervention = ref(false)
 const activeInterventionId = ref(null)
@@ -386,10 +294,6 @@ const rejecting = ref(false)
 const planOrder = ref(null)
 const deliveryData = ref([])
 
-// Share canvas ref
-const shareCanvas = ref(null)
-const shareGenerating = ref(false)
-
 // Annotation / Tag state (US-7.1 / US-7.2)
 const annotations = ref([])
 const allTags = ref([])
@@ -399,12 +303,6 @@ const interpretData = ref(null)
 const interpreting = ref(false)
 const interpretExpanded = ref({})
 
-// US-9.1: Academic orientation state
-const academicData = ref(null)
-const academicLoading = ref(false)
-const academicExpanded = ref({})
-// US-2.1: Share state (shareGenerating declared above with shareCanvas)
-
 const quotaExceeded = computed(() => {
   if (userStore.isVipActive) return false
   return maxChats.value > 0 && usedChats.value >= maxChats.value
@@ -417,11 +315,6 @@ const shareRemaining = computed(() => {
   return limit > 0 ? Math.max(0, limit - count) : 0
 })
 
-const quotaAcademicExceeded = computed(() => {
-  if (userStore.isVipActive) return false
-  return maxAcademic.value > 0 && usedAcademic.value >= maxAcademic.value
-})
-
 // US-9.4: Computed proposal message from logs
 const proposalMessage = computed(() => {
   const proposalLog = logs.value.find(l => l.action === 'proposal')
@@ -451,8 +344,6 @@ onMounted(async () => {
   if (store.currentChart) {
       maxChats.value = userStore.maxChats || 3
       usedChats.value = userStore.usedChats || 0
-      usedAcademic.value = userStore.usedAcademic || 0
-      maxAcademic.value = userStore.maxAcademic || 1
 
     // Load annotations and tags for this record (US-7.1/7.2)
     if (store.currentRecordId) {
@@ -462,6 +353,9 @@ onMounted(async () => {
     // US-9.4: Load plan request for this chart
     loadPlanRequest()
 
+    // US-3.1: Auto-load AI interpretation (no longer behind a button)
+    fetchInterpret()
+
     // Use consultationMessages from store (set during startConsultation) if available
     if (store.consultationMessages && store.consultationMessages.length > 0) {
       messages.value = store.consultationMessages.map(m => ({
@@ -594,50 +488,6 @@ function toggleInterpretSection(key) {
   interpretExpanded.value[key] = !interpretExpanded.value[key]
 }
 
-// US-9.1: Fetch academic orientation
-async function fetchAcademicOrientation() {
-  if (!store.currentRecordId) {
-    uni.showToast({ title: '暂无命盘数据', icon: 'none' })
-    return
-  }
-  if (academicData.value) {
-    scrollToAcademic()
-    return
-  }
-  if (quotaAcademicExceeded.value) {
-    uni.showToast({ title: '今日学业分析次数已用完', icon: 'none' })
-    return
-  }
-  academicLoading.value = true
-  try {
-    const data = await chartApi.academicOrientation(store.currentRecordId)
-    academicData.value = data
-    academicExpanded.value = { talentTendency: true }
-    usedAcademic.value++
-    userStore.usedAcademic = usedAcademic.value
-    uni.showToast({ title: '分析已生成', icon: 'success' })
-    scrollToAcademic()
-  } catch (e) {
-    if (e.code === 1008) {
-      usedAcademic.value = maxAcademic.value
-      userStore.usedAcademic = maxAcademic.value
-    }
-    uni.showToast({ title: e.message || '分析生成失败', icon: 'none' })
-  } finally {
-    academicLoading.value = false
-  }
-}
-
-function scrollToAcademic() {
-  uni.createSelectorQuery().select('#academic-section').boundingClientRect(res => {
-    if (res) uni.pageScrollTo({ scrollTop: res.top - 20, duration: 300 })
-  }).exec()
-}
-
-function toggleAcademicSection(key) {
-  academicExpanded.value[key] = !academicExpanded.value[key]
-}
-
 async function sendQuestion(q) {
   if (!q.trim() || loading.value) return
   if (quotaExceeded.value) {
@@ -776,87 +626,6 @@ function goPoster() {
   uni.navigateTo({ url: '/pages/subscribe/index' })
 }
 
-// EPIC 9: Navigate to plan apply page
-function goPlanApply() {
-  if (!userStore.isLoggedIn) {
-    uni.navigateTo({ url: '/pages/login/index' })
-    return
-  }
-  if (!store.currentRecordId) {
-    uni.showToast({ title: '暂无命盘数据', icon: 'none' })
-    return
-  }
-  uni.navigateTo({ url: `/pages/plan/apply?chartRecordId=${store.currentRecordId}` })
-}
-
-// US-2.1: Share chart image
-async function onShareTap() {
-  if (shareGenerating.value) return
-
-  // Check quota for non-VIP
-  if (!userStore.isVipActive && shareRemaining.value <= 0) {
-    uni.showToast({ title: '今日分享次数已用完', icon: 'none' })
-    return
-  }
-
-  // Show action sheet
-  uni.showActionSheet({
-    itemList: ['保存到相册', '分享给微信好友', '分享到朋友圈'],
-    success: async (res) => {
-      await performShare(res.tapIndex)
-    },
-    fail: (err) => {
-      if (err.errMsg && err.errMsg.includes('cancel')) return
-      uni.showToast({ title: '操作取消', icon: 'none' })
-    }
-  })
-}
-
-async function performShare(actionIndex) {
-  shareGenerating.value = true
-  try {
-    // Consume quota if not VIP
-    if (!userStore.isVipActive) {
-      try {
-        await profileApi.trackShare()
-        // Optimistically update local store
-        userStore.shareCount++
-      } catch (e) {
-        uni.showToast({ title: '分享次数不足', icon: 'none' })
-        shareGenerating.value = false
-        return
-      }
-    }
-
-    // Generate image via canvas
-    if (!shareCanvas.value) throw new Error('Canvas未就绪')
-    const filePath = await shareCanvas.value.generate()
-
-    if (actionIndex === 0) {
-      // Save to album
-      await uni.saveImageToPhotosAlbum({ filePath })
-      uni.showToast({ title: '已保存到相册', icon: 'success' })
-    } else {
-      // Share via WeChat
-      const scene = actionIndex === 1 ? 'WXSceneSession' : 'WXSceneTimeline'
-      const title = store.currentChart?.O
-        ? `我的命盘主性格数字是${store.currentChart.O},快来测测你的!`
-        : '数字能量命盘分析'
-      await uni.share({
-        provider: 'weixin',
-        scene,
-        type: 'image',
-        imageUrl: filePath,
-        title
-      })
-    }
-  } catch (e) {
-    uni.showToast({ title: e.message || '分享失败', icon: 'none' })
-  } finally {
-    shareGenerating.value = false
-  }
-}
-
 // US-2.2: Export PDF (paid users only)
 async function exportPdf() {
   if (!store.currentRecordId) {
@@ -1090,27 +859,6 @@ async function submitCounter() {
   background: rgba(255, 255, 255, 0.08);
 }
 
-/* US-3.1: Interpret button bar */
-.interpret-bar {
-  flex-shrink: 0;
-  margin: 0 14px 10px;
-}
-.interpret-btn {
-  width: 100%;
-  height: 44px;
-  background: linear-gradient(135deg, #7c3aed, #6366f1);
-  color: #fff;
-  border: none;
-  border-radius: 12px;
-  line-height: 44px;
-  font-size: 15px;
-  font-weight: 600;
-  letter-spacing: 1px;
-}
-.interpret-btn[disabled] {
-  opacity: 0.5;
-}
-
 /* Interpretation panel */
 .interpret-panel {
   flex-shrink: 0;
@@ -1209,181 +957,6 @@ async function submitCounter() {
   width: 70%;
 }
 
-/* US-9.1: Academic bar */
-.academic-bar {
-  flex-shrink: 0;
-  margin: 0 14px 10px;
-  display: flex;
-  gap: 8px;
-  align-items: center;
-}
-.academic-btn {
-  flex: 1;
-  height: 44px;
-  background: linear-gradient(135deg, #0891b2, #06b6d4);
-  color: #fff;
-  border: none;
-  border-radius: 12px;
-  line-height: 44px;
-  font-size: 15px;
-  font-weight: 600;
-  letter-spacing: 1px;
-}
-.academic-btn[disabled] { opacity: 0.5; }
-.academic-quota {
-  font-size: 11px;
-  color: #22d3ee;
-  background: rgba(34, 211, 238, 0.1);
-  padding: 3px 10px;
-  border-radius: 10px;
-  border: 1px solid rgba(34, 211, 238, 0.15);
-  white-space: nowrap;
-}
-
-/* US-9.1: Academic panel */
-.academic-panel {
-  flex-shrink: 0;
-  margin: 0 14px 16px;
-}
-.academic-section-title {
-  font-size: 16px;
-  font-weight: 700;
-  color: #22d3ee;
-  margin-bottom: 12px;
-  padding-left: 2px;
-}
-.academic-card {
-  border-radius: 12px;
-  margin-bottom: 10px;
-  overflow: hidden;
-  transition: border-color 0.2s;
-}
-.academic-card.talent { background: rgba(8, 145, 178, 0.06); border: 1px solid rgba(8, 145, 178, 0.12); }
-.academic-card.talent.expanded { border-color: rgba(8, 145, 178, 0.25); background: rgba(8, 145, 178, 0.08); }
-.academic-card.direction { background: rgba(251, 191, 36, 0.06); border: 1px solid rgba(251, 191, 36, 0.12); }
-.academic-card.direction.expanded { border-color: rgba(251, 191, 36, 0.25); background: rgba(251, 191, 36, 0.08); }
-.academic-card.learning { background: rgba(52, 211, 153, 0.06); border: 1px solid rgba(52, 211, 153, 0.12); }
-.academic-card.learning.expanded { border-color: rgba(52, 211, 153, 0.25); background: rgba(52, 211, 153, 0.08); }
-.academic-card.parenting { background: rgba(244, 114, 182, 0.06); border: 1px solid rgba(244, 114, 182, 0.12); }
-.academic-card.parenting.expanded { border-color: rgba(244, 114, 182, 0.25); background: rgba(244, 114, 182, 0.08); }
-.academic-card.periods { background: rgba(167, 139, 250, 0.06); border: 1px solid rgba(167, 139, 250, 0.12); }
-.academic-card.periods.expanded { border-color: rgba(167, 139, 250, 0.25); background: rgba(167, 139, 250, 0.08); }
-
-.academic-card-header {
-  display: flex;
-  align-items: center;
-  padding: 12px 14px;
-  gap: 10px;
-}
-.academic-card-title {
-  flex: 1;
-  font-size: 14px;
-  font-weight: 600;
-  color: rgba(255,255,255,0.85);
-}
-.academic-toggle {
-  font-size: 12px;
-  color: rgba(255,255,255,0.35);
-}
-.academic-card-body {
-  padding: 0 14px 14px;
-}
-.academic-content {
-  display: block;
-  font-size: 13px;
-  line-height: 1.7;
-  color: rgba(255,255,255,0.65);
-  white-space: pre-wrap;
-}
-
-/* Match percentage bars */
-.match-bars {
-  margin-top: 10px;
-}
-.match-row {
-  display: flex;
-  align-items: center;
-  gap: 8px;
-  margin-bottom: 8px;
-}
-.match-label {
-  width: 32px;
-  font-size: 12px;
-  color: rgba(255,255,255,0.55);
-  text-align: right;
-}
-.match-track {
-  flex: 1;
-  height: 8px;
-  background: rgba(255,255,255,0.06);
-  border-radius: 4px;
-  overflow: hidden;
-}
-.match-fill {
-  height: 100%;
-  border-radius: 4px;
-  transition: width 0.4s ease;
-}
-.match-fill.pct-80, .match-fill.pct-85, .match-fill.pct-90, .match-fill.pct-95 { background: linear-gradient(90deg, #22d3ee, #06b6d4); }
-.match-fill.pct-60, .match-fill.pct-65, .match-fill.pct-70, .match-fill.pct-75 { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
-.match-fill.pct-40, .match-fill.pct-45, .match-fill.pct-50, .match-fill.pct-55 { background: linear-gradient(90deg, #f87171, #ef4444); }
-.match-value {
-  width: 36px;
-  font-size: 12px;
-  font-weight: 600;
-  color: rgba(255,255,255,0.6);
-  text-align: right;
-}
-
-/* Academic disclaimer */
-.academic-disclaimer {
-  text-align: center;
-  padding: 6px 0 2px;
-}
-.academic-disclaimer .disclaimer-text {
-  font-size: 11px;
-  color: rgba(255,255,255,0.2);
-}
-
-/* Academic loading skeleton */
-.academic-skeleton {
-  flex-shrink: 0;
-  margin: 0 14px 16px;
-}
-
-/* Academic quota exceeded upgrade card */
-.academic-upgrade-card {
-  flex-shrink: 0;
-  margin: 0 14px 16px;
-  background: linear-gradient(135deg, rgba(8, 145, 178, 0.08), rgba(6, 182, 212, 0.05));
-  border: 1px solid rgba(8, 145, 178, 0.15);
-  border-radius: 12px;
-  padding: 20px;
-  text-align: center;
-}
-.academic-upgrade-title {
-  display: block;
-  font-size: 15px;
-  font-weight: 600;
-  color: #22d3ee;
-  margin-bottom: 6px;
-}
-.academic-upgrade-desc {
-  display: block;
-  font-size: 12px;
-  color: rgba(255,255,255,0.45);
-  margin-bottom: 14px;
-}
-.academic-upgrade-btn {
-  background: linear-gradient(135deg, #0891b2, #06b6d4);
-  color: #fff;
-  border: none;
-  border-radius: 10px;
-  padding: 12px 40px;
-  font-size: 15px;
-  font-weight: 600;
-}
-
 .chat-section {
   flex: 1;
   display: flex;
@@ -1833,28 +1406,6 @@ async function submitCounter() {
   font-weight: 600;
 }
 
-/* EPIC 9: Plan apply button bar */
-.plan-apply-bar {
-  flex-shrink: 0;
-  margin: 10px 14px calc(env(safe-area-inset-bottom) + 16px);
-}
-.plan-apply-btn {
-  width: 100%;
-  height: 48px;
-  background: linear-gradient(135deg, #a78bfa, #7c3aed);
-  color: #fff;
-  border: none;
-  border-radius: 14px;
-  line-height: 48px;
-  font-size: 16px;
-  font-weight: 700;
-  letter-spacing: 1px;
-  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.25);
-}
-.plan-apply-btn:active {
-  opacity: 0.85;
-}
-
 /* US-9.5: Pending payment card */
 .pending-payment-card {
   background: linear-gradient(135deg, rgba(167, 139, 250, 0.08), rgba(124, 58, 237, 0.05));

+ 2 - 1
num-server/src/main/java/com/etotem/num/controller/ProfileController.java

@@ -113,7 +113,8 @@ public class ProfileController {
     @PostMapping("/quota")
     public Result<Map<String, Object>> quota(HttpServletRequest request) {
         Long userId = (Long) request.getAttribute("userId");
-        User user = userService.getById(userId);
+        // Reset daily counters if a new day has arrived, so frontend sees fresh data
+        User user = userService.getAndResetDailyQuota(userId);
         boolean isVip = userService.isVip(userId);
         Map<String, Object> result = new HashMap<>();
         result.put("isVip", isVip);

+ 11 - 0
num-server/src/main/java/com/etotem/num/service/UserService.java

@@ -181,6 +181,17 @@ public class UserService {
         }
     }
 
+    /**
+     * Load user and reset daily quota counters if a new day has arrived, then persist.
+     * Used by the /quota endpoint so the frontend always sees fresh daily counts.
+     */
+    public User getAndResetDailyQuota(Long userId) {
+        User user = getById(userId);
+        resetDailyIfNeeded(user);
+        userRepository.save(user);
+        return user;
+    }
+
     // US-6.1 §2: 6位大写字母+数字, 去掉易混淆 O/0/I/1
     private static final String RC_CHARS = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
     private static final int RC_LENGTH = 6;