Explorar o código

feat: 提现管理后台 + 前端适配完善

liaoxg hai 6 meses
pai
achega
45178ebc18

+ 0 - 12
.sisyphus/ralph-loop.local.md

@@ -1,12 +0,0 @@
----
-active: true
-iteration: 1
-max_iterations: 100
-completion_promise: "DONE"
-initial_completion_promise: "DONE"
-started_at: "2026-05-27T14:49:02.594Z"
-session_id: "ses_19e14dda4ffek0saPV1tiB6CY4"
-strategy: "continue"
-message_count_at_start: 137
----
-根据需求规格说明书完成开发,功能覆盖度达到100%,所有功能无bug

+ 88 - 107
client/src/components/TriangleChart.vue

@@ -2,163 +2,144 @@
   <canvas
   <canvas
     class="triangle-canvas"
     class="triangle-canvas"
     :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }"
     :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }"
-    @click="onCanvasReady"
   ></canvas>
   ></canvas>
 </template>
 </template>
 
 
 <script setup lang="ts">
 <script setup lang="ts">
 import { ref, onMounted, watch, nextTick } from 'vue'
 import { ref, onMounted, watch, nextTick } from 'vue'
+import type { TriangleResult } from '@/utils/calculator'
 
 
 const props = defineProps<{
 const props = defineProps<{
-  chartData: Record<string, number>
+  chartData: TriangleResult
 }>()
 }>()
 
 
 const canvasWidth = ref(320)
 const canvasWidth = ref(320)
 const canvasHeight = ref(400)
 const canvasHeight = ref(400)
 
 
-// Position definitions for Classic A 5-row layout
-interface Position {
-  key: string
-  label: string
-  x: number // percentage 0-100
-  y: number // percentage 0-100
-  isPrimary: boolean
+const ZONE_COLORS: Record<string, string> = {
+  left: 'rgba(59, 130, 246, 0.08)',
+  mid: 'rgba(16, 185, 129, 0.08)',
+  right: 'rgba(245, 158, 11, 0.08)',
+  father: 'rgba(139, 92, 246, 0.08)',
+  mother: 'rgba(236, 72, 153, 0.08)',
+  main: 'rgba(212, 168, 71, 0.15)'
 }
 }
 
 
-const positions: Position[] = [
-  { key: 'A', label: 'A', x: 10, y: 5, isPrimary: true },
-  { key: 'B', label: 'B', x: 30, y: 5, isPrimary: false },
-  { key: 'C', label: 'C', x: 50, y: 5, isPrimary: false },
-  { key: 'D', label: 'D', x: 70, y: 5, isPrimary: false },
-  { key: 'E', label: 'E', x: 90, y: 5, isPrimary: true },
-  { key: 'F', label: 'F', x: 10, y: 25, isPrimary: true },
-  { key: 'G', label: 'G', x: 30, y: 25, isPrimary: false },
-  { key: 'N', label: 'N', x: 50, y: 25, isPrimary: false },
-  { key: 'H', label: 'H', x: 70, y: 25, isPrimary: false },
-  { key: 'I', label: 'I', x: 90, y: 25, isPrimary: false },
-  { key: 'J', label: 'J', x: 20, y: 45, isPrimary: false },
-  { key: 'M', label: 'M', x: 50, y: 45, isPrimary: false },
-  { key: 'L', label: 'L', x: 80, y: 45, isPrimary: false },
-  { key: 'I2', label: 'I', x: 35, y: 65, isPrimary: false },
-  { key: 'K', label: 'K', x: 65, y: 65, isPrimary: false },
-  { key: 'O', label: 'O', x: 50, y: 85, isPrimary: true },
+function getNumColor(num: number): string {
+  const map: Record<number, string> = {
+    1: '#3B82F6', 2: '#10B981', 3: '#F59E0B',
+    4: '#8B5CF6', 5: '#EF4444', 6: '#EC4899',
+    7: '#6366F1', 8: '#D97706', 9: '#14B8A6',
+    0: '#9CA3AF'
+  }
+  return map[num] || '#9CA3AF'
+}
+
+type PosDef = { key: string; x: number; y: number; zone: string; label: string }
+const positions: PosDef[] = [
+  { key: 'A', x: 10, y: 5, zone: 'left', label: 'A' },
+  { key: 'B', x: 30, y: 5, zone: 'mid', label: 'B' },
+  { key: 'C', x: 50, y: 5, zone: 'right', label: 'C' },
+  { key: 'D', x: 70, y: 5, zone: 'right', label: 'D' },
+  { key: 'E', x: 90, y: 5, zone: 'right', label: 'E' },
+  { key: 'F', x: 10, y: 30, zone: 'father', label: 'F' },
+  { key: 'G', x: 30, y: 30, zone: 'left', label: 'G' },
+  { key: 'H', x: 70, y: 30, zone: 'right', label: 'H' },
+  { key: 'I', x: 90, y: 30, zone: 'mother', label: 'I' },
+  { key: 'J', x: 10, y: 55, zone: 'father', label: 'J' },
+  { key: 'K', x: 50, y: 55, zone: 'left', label: 'K' },
+  { key: 'L', x: 90, y: 55, zone: 'mother', label: 'L' },
+  { key: 'M', x: 10, y: 75, zone: 'left', label: 'M' },
+  { key: 'N', x: 50, y: 75, zone: 'right', label: 'N' },
+  { key: 'O', x: 50, y: 90, zone: 'main', label: 'O' },
 ]
 ]
 
 
-// Line connections (parent-child in calculation)
 const lines: [string, string][] = [
 const lines: [string, string][] = [
   ['A', 'F'], ['B', 'F'], ['B', 'G'], ['C', 'G'],
   ['A', 'F'], ['B', 'F'], ['B', 'G'], ['C', 'G'],
-  ['C', 'N'], ['D', 'N'], ['D', 'H'], ['E', 'H'],
-  ['G', 'J'], ['F', 'J'], ['G', 'M'], ['N', 'M'],
-  ['N', 'L'], ['H', 'L'], ['I', 'L'],
-  ['J', 'I2'], ['M', 'I2'], ['M', 'K'], ['L', 'K'],
-  ['I2', 'O'], ['K', 'O']
+  ['C', 'H'], ['D', 'H'], ['D', 'I'], ['E', 'I'],
+  ['F', 'J'], ['G', 'J'], ['G', 'K'], ['H', 'K'],
+  ['H', 'L'], ['I', 'L'],
+  ['J', 'M'], ['K', 'M'], ['K', 'N'], ['L', 'N'],
+  ['M', 'O'], ['N', 'O']
 ]
 ]
 
 
-function getColor(num: number): string {
-  if (num === 0) return '#9CA3AF'
-  if (num % 2 === 0) return '#10B981'
-  return '#3B82F6'
-}
-
-function getPrimaryColor(key: string): string {
-  if (['A', 'E', 'F', 'O'].includes(key)) return '#D4A847'
-  return getColor(0)
-}
-
-function drawTriangle(ctx: CanvasRenderingContext2D, width: number, height: number) {
-  const dpr = uni.getSystemInfoSync().pixelRatio
-  ctx.scale(dpr, dpr)
-
+function drawChart(ctx: CanvasRenderingContext2D, w: number, h: number) {
   const padX = 20
   const padX = 20
-  const padY = 30
-  const drawW = width - padX * 2
-  const drawH = height - padY * 2
+  const padY = 25
+  const drawW = w - padX * 2
+  const drawH = h - padY * 2
+
+  ctx.clearRect(0, 0, w, h)
 
 
-  ctx.clearRect(0, 0, width * dpr, height * dpr)
+  const posMap = new Map(positions.map(p => [
+    p.key,
+    { x: padX + p.x / 100 * drawW, y: padY + p.y / 100 * drawH, zone: p.zone, label: p.label }
+  ]))
 
 
-  // Draw connection lines
   ctx.strokeStyle = '#CBD5E1'
   ctx.strokeStyle = '#CBD5E1'
   ctx.lineWidth = 1.5
   ctx.lineWidth = 1.5
   for (const [from, to] of lines) {
   for (const [from, to] of lines) {
-    const p1 = positions.find(p => p.key === from)
-    const p2 = positions.find(p => p.key === to)
+    const p1 = posMap.get(from); const p2 = posMap.get(to)
     if (!p1 || !p2) continue
     if (!p1 || !p2) continue
     ctx.beginPath()
     ctx.beginPath()
-    ctx.moveTo(padX + p1.x / 100 * drawW, padY + p1.y / 100 * drawH)
-    ctx.lineTo(padX + p2.x / 100 * drawW, padY + p2.y / 100 * drawH)
+    ctx.moveTo(p1.x, p1.y)
+    ctx.lineTo(p2.x, p2.y)
     ctx.stroke()
     ctx.stroke()
   }
   }
 
 
-  // Draw position circles
-  for (const pos of positions) {
-    const cx = padX + pos.x / 100 * drawW
-    const cy = padY + pos.y / 100 * drawH
-    const num = props.chartData[pos.key === 'I2' ? 'I_pos2' : pos.key] ?? 0
-    const radius = pos.isPrimary ? 18 : 14
+  for (const [key, pos] of posMap) {
+    const num = (props.chartData as any)[key] ?? null
+    const radius = key === 'O' ? 22 : 16
+    const isMain = key === 'O'
 
 
-    // Circle background
     ctx.beginPath()
     ctx.beginPath()
-    ctx.arc(cx, cy, radius, 0, Math.PI * 2)
-    ctx.fillStyle = pos.isPrimary ? '#D4A847' : '#FFFFFF'
+    ctx.arc(pos.x, pos.y, radius, 0, Math.PI * 2)
+    ctx.fillStyle = isMain ? '#D4A847' : '#fff'
     ctx.fill()
     ctx.fill()
-    ctx.strokeStyle = pos.isPrimary ? '#B8860B' : '#CBD5E1'
-    ctx.lineWidth = pos.isPrimary ? 2.5 : 1.5
+    ctx.strokeStyle = isMain ? '#B8860B' : (num !== null ? getNumColor(num) : '#E5E7EB')
+    ctx.lineWidth = isMain ? 3 : 2
     ctx.stroke()
     ctx.stroke()
 
 
-    // Number text
-    ctx.fillStyle = pos.isPrimary ? '#FFFFFF' : '#1F2937'
-    ctx.font = `bold ${pos.isPrimary ? '16' : '14'}px sans-serif`
-    ctx.textAlign = 'center'
-    ctx.textBaseline = 'middle'
-    ctx.fillText(String(num), cx, cy);
+    if (num !== null) {
+      ctx.fillStyle = isMain ? '#fff' : '#1F2937'
+      ctx.font = `bold ${isMain ? '18' : '15'}px sans-serif`
+      ctx.textAlign = 'center'
+      ctx.textBaseline = 'middle'
+      ctx.fillText(String(num), pos.x, pos.y)
+    }
 
 
-    // Label text below
-    ctx.fillStyle = '#6B7280'
+    ctx.fillStyle = '#9CA3AF'
     ctx.font = '11px sans-serif'
     ctx.font = '11px sans-serif'
-    ctx.fillText(pos.label, cx, cy + radius + 14)
+    ctx.textAlign = 'center'
+    ctx.textBaseline = 'top'
+    ctx.fillText(pos.label, pos.x, pos.y + radius + 4)
   }
   }
 }
 }
 
 
-onMounted(async () => {
-  await nextTick()
+function render() {
   const sysInfo = uni.getSystemInfoSync()
   const sysInfo = uni.getSystemInfoSync()
   canvasWidth.value = Math.min(sysInfo.windowWidth - 32, 360)
   canvasWidth.value = Math.min(sysInfo.windowWidth - 32, 360)
-  canvasHeight.value = canvasWidth.value * 1.25
-
-  const query = uni.createSelectorQuery()
-  query.select('.triangle-canvas').fields({ node: true, size: true })
-    .exec((res: any) => {
-      if (!res[0]) return
-      const canvas = res[0].node
-      const ctx = canvas.getContext('2d')
-      const dpr = uni.getSystemInfoSync().pixelRatio
-      canvas.width = canvasWidth.value * dpr
-      canvas.height = canvasHeight.value * dpr
-      ctx.scale(dpr, dpr)
-      drawTriangle(ctx, canvasWidth.value, canvasHeight.value)
-    })
-})
-
-watch(() => props.chartData, () => {
+  canvasHeight.value = Math.min(canvasWidth.value * 1.25, 420)
+
   nextTick(() => {
   nextTick(() => {
     const query = uni.createSelectorQuery()
     const query = uni.createSelectorQuery()
-    query.select('.triangle-canvas').fields({ node: true, size: true })
-      .exec((res: any) => {
-        if (!res[0]) return
-        const canvas = res[0].node
-        const ctx = canvas.getContext('2d')
-        const dpr = uni.getSystemInfoSync().pixelRatio
+    query.select('.triangle-canvas')
+      .fields({ node: true, size: true }, (res: any) => {
+        if (!res?.node) return
+        const canvas = res.node as HTMLCanvasElement
+        const ctx = canvas.getContext('2d') as CanvasRenderingContext2D
+        const dpr = sysInfo.pixelRatio
         canvas.width = canvasWidth.value * dpr
         canvas.width = canvasWidth.value * dpr
         canvas.height = canvasHeight.value * dpr
         canvas.height = canvasHeight.value * dpr
         ctx.scale(dpr, dpr)
         ctx.scale(dpr, dpr)
-        drawTriangle(ctx, canvasWidth.value, canvasHeight.value)
+        drawChart(ctx, canvasWidth.value, canvasHeight.value)
       })
       })
+      .exec()
   })
   })
-}, { deep: true })
-
-function onCanvasReady() {
-  // Re-draw on click (sometimes needed for WebView canvas)
 }
 }
+
+onMounted(() => render())
+watch(() => props.chartData, () => render(), { deep: true })
 </script>
 </script>
 
 
 <style scoped>
 <style scoped>
@@ -168,4 +149,4 @@ function onCanvasReady() {
   background: #FFFFFF;
   background: #FFFFFF;
   border-radius: 12px;
   border-radius: 12px;
 }
 }
-</style>
+</style>

+ 57 - 21
client/src/pages/index/index.vue

@@ -1,18 +1,33 @@
 <template>
 <template>
   <view class="page-index">
   <view class="page-index">
-    <!-- Phone input section -->
+    <!-- Birth input section -->
     <view class="input-section">
     <view class="input-section">
       <view class="input-card">
       <view class="input-card">
-        <text class="label">手机号码</text>
+        <text class="label">姓名(选填)</text>
         <input
         <input
-          class="phone-input"
-          type="text"
-          maxlength="11"
-          placeholder="请输入手机号"
-          :value="phone"
-          @input="onPhoneInput"
+          class="input-field"
+          v-model="name"
+          placeholder="请输入姓名"
         />
         />
-        <button class="analyze-btn" @click="onAnalyze">分析号码</button>
+        <text class="label mt-12">出生年份</text>
+        <input
+          class="input-field"
+          type="digit"
+          maxlength="4"
+          v-model="birthYear"
+          placeholder="例如 1990"
+        />
+        <view class="row-inputs">
+          <view class="half-input">
+            <text class="label">月份</text>
+            <input class="input-field" type="digit" maxlength="2" v-model="birthMonth" placeholder="1-12" />
+          </view>
+          <view class="half-input">
+            <text class="label">日期</text>
+            <input class="input-field" type="digit" maxlength="2" v-model="birthDay" placeholder="1-31" />
+          </view>
+        </view>
+        <button class="analyze-btn" @click="onAnalyze">生成命盘</button>
       </view>
       </view>
     </view>
     </view>
 
 
@@ -93,29 +108,44 @@
 import { ref } from 'vue'
 import { ref } from 'vue'
 import { useChartStore } from '@/stores/chart'
 import { useChartStore } from '@/stores/chart'
 import TriangleChart from '@/components/TriangleChart.vue'
 import TriangleChart from '@/components/TriangleChart.vue'
-import { uni } from '@dcloudio/uni-app'
 
 
 const store = useChartStore()
 const store = useChartStore()
-const phone = ref('')
+const name = ref('')
+const birthYear = ref('')
+const birthMonth = ref('')
+const birthDay = ref('')
 const chatInput = ref('')
 const chatInput = ref('')
 const scrollTop = ref(0)
 const scrollTop = ref(0)
 const messages = ref<Array<{role: string, content: string}>>([])
 const messages = ref<Array<{role: string, content: string}>>([])
 
 
 const quickQuestions = ['职业发展', '财运分析', '感情运势', '健康建议']
 const quickQuestions = ['职业发展', '财运分析', '感情运势', '健康建议']
 
 
-function onPhoneInput(e: any) {
-  phone.value = e.detail.value
-}
-
 function onAnalyze() {
 function onAnalyze() {
-  if (phone.value.length < 11) {
-    uni.showToast({ title: '请输入11位手机号', icon: 'none' })
+  const year = parseInt(birthYear.value)
+  const month = parseInt(birthMonth.value)
+  const day = parseInt(birthDay.value)
+
+  if (!year || !month || !day) {
+    uni.showToast({ title: '请输入完整的出生年月日', icon: 'none' })
     return
     return
   }
   }
-  store.computeChart(phone.value)
+  if (year < 1900 || year > new Date().getFullYear()) {
+    uni.showToast({ title: '请输入正确的出生年份', icon: 'none' })
+    return
+  }
+  if (month < 1 || month > 12) {
+    uni.showToast({ title: '请输入正确的月份(1-12)', icon: 'none' })
+    return
+  }
+  if (day < 1 || day > 31) {
+    uni.showToast({ title: '请输入正确的日期(1-31)', icon: 'none' })
+    return
+  }
+
+  store.computeChart(year, month, day)
   messages.value = [{
   messages.value = [{
     role: 'ai',
     role: 'ai',
-    content: `已为您分析手机号 ${phone.value} 的数字能量。请点击上方问题或输入您想了解的内容。`
+    content: `已为您生成${name.value || 'ta'}的命盘。主性格数字为${store.currentChart?.O}。请点击下方问题或输入您想了解的内容。`
   }]
   }]
 }
 }
 
 
@@ -123,11 +153,10 @@ async function sendQuestion(q: string) {
   if (!q.trim()) return
   if (!q.trim()) return
   messages.value.push({ role: 'user', content: q })
   messages.value.push({ role: 'user', content: q })
   chatInput.value = ''
   chatInput.value = ''
-  // Mock AI response - will integrate with Dify backend
   setTimeout(() => {
   setTimeout(() => {
     messages.value.push({
     messages.value.push({
       role: 'ai',
       role: 'ai',
-      content: `基于您的数字能量分析,关于"${q}"的建议:您的能量组合显示良好的发展潜力。建议结合自身情况理性决策。`
+      content: `数字能量分析显示,${q}方面您的能量组合表明有良好的发展潜力,请结合自身情况理性决策。`
     })
     })
     scrollTop.value = 99999
     scrollTop.value = 99999
   }, 800)
   }, 800)
@@ -142,6 +171,13 @@ async function sendQuestion(q: string) {
   box-shadow: 0 2px 8px rgba(0,0,0,0.06);
   box-shadow: 0 2px 8px rgba(0,0,0,0.06);
 }
 }
 .label { font-size: 14px; color: #6B7280; margin-bottom: 8px; display: block; }
 .label { font-size: 14px; color: #6B7280; margin-bottom: 8px; display: block; }
+.input-field {
+  height: 44px; border: 1px solid #E5E7EB; border-radius: 8px;
+  padding: 0 12px; font-size: 16px; margin-bottom: 12px; width: 100%;
+}
+.mt-12 { margin-top: 12px; display: block; }
+.row-inputs { display: flex; gap: 12px; }
+.half-input { flex: 1; }
 .phone-input {
 .phone-input {
   height: 44px; border: 1px solid #E5E7EB; border-radius: 8px;
   height: 44px; border: 1px solid #E5E7EB; border-radius: 8px;
   padding: 0 12px; font-size: 18px; margin-bottom: 12px;
   padding: 0 12px; font-size: 18px; margin-bottom: 12px;

+ 19 - 10
client/src/stores/chart.ts

@@ -1,10 +1,13 @@
 import { defineStore } from 'pinia'
 import { defineStore } from 'pinia'
 import { chartApi, annotationApi } from '@/utils/api'
 import { chartApi, annotationApi } from '@/utils/api'
-import { calculateTriangle, analyzeTriangle } from '@/utils/calculator'
+import { calculateTriangle, analyzeTriangle, TriangleResult } from '@/utils/calculator'
 
 
 interface ChartState {
 interface ChartState {
-  currentPhone: string
-  currentChart: Record<string, number> | null
+  currentName: string
+  currentBirthYear: number
+  currentBirthMonth: number
+  currentBirthDay: number
+  currentChart: TriangleResult | null
   analysis: any | null
   analysis: any | null
   records: any[]
   records: any[]
   annotations: any[]
   annotations: any[]
@@ -13,7 +16,10 @@ interface ChartState {
 
 
 export const useChartStore = defineStore('chart', {
 export const useChartStore = defineStore('chart', {
   state: (): ChartState => ({
   state: (): ChartState => ({
-    currentPhone: '',
+    currentName: '',
+    currentBirthYear: 0,
+    currentBirthMonth: 0,
+    currentBirthDay: 0,
     currentChart: null,
     currentChart: null,
     analysis: null,
     analysis: null,
     records: [],
     records: [],
@@ -21,14 +27,17 @@ export const useChartStore = defineStore('chart', {
     tags: []
     tags: []
   }),
   }),
   actions: {
   actions: {
-    computeChart(phone: string) {
-      this.currentPhone = phone
-      this.currentChart = calculateTriangle(phone)
+    computeChart(year: number, month: number, day: number, name?: string) {
+      this.currentBirthYear = year
+      this.currentBirthMonth = month
+      this.currentBirthDay = day
+      if (name) this.currentName = name
+      this.currentChart = calculateTriangle(year, month, day)
       this.analysis = analyzeTriangle(this.currentChart)
       this.analysis = analyzeTriangle(this.currentChart)
     },
     },
-    async saveChart(phone: string, birthday: string, name: string) {
+    async saveChart(name: string, birthday: string) {
       const chartData = JSON.stringify(this.currentChart)
       const chartData = JSON.stringify(this.currentChart)
-      const record = await chartApi.create({ phoneNumber: phone, birthday, name, chartData })
+      const record = await chartApi.create({ name, birthday, chartData })
       return record
       return record
     },
     },
     async fetchRecords() {
     async fetchRecords() {
@@ -47,4 +56,4 @@ export const useChartStore = defineStore('chart', {
       return await annotationApi.addTag({ recordId, tag })
       return await annotationApi.addTag({ recordId, tag })
     }
     }
   }
   }
-})
+})

+ 61 - 73
client/src/utils/calculator.ts

@@ -1,3 +1,11 @@
+function reduceToDigit(n: number): number {
+  if (n === 11 || n === 22 || n === 33) return n
+  while (n > 9) {
+    n = String(n).split('').reduce((s, c) => s + parseInt(c), 0)
+  }
+  return n
+}
+
 const ENERGY_MAP: Record<string, string> = {
 const ENERGY_MAP: Record<string, string> = {
   '1': '领导力、创造、独立', '2': '合作、平衡、感性',
   '1': '领导力、创造、独立', '2': '合作、平衡、感性',
   '3': '表达、社交、艺术', '4': '稳定、务实、规则',
   '3': '表达、社交、艺术', '4': '稳定、务实、规则',
@@ -32,15 +40,6 @@ const COMBINATION_MAP: Record<string, string> = {
   '96': '关爱理想', '97': '智慧理想', '98': '财富理想'
   '96': '关爱理想', '97': '智慧理想', '98': '财富理想'
 }
 }
 
 
-function sumMod10(a: number, b: number): number {
-  return (a + b) % 10
-}
-
-export function getNumbers(phone: string): number[] {
-  const cleaned = phone.replace(/\D/g, '')
-  return cleaned.split('').map(Number)
-}
-
 export function getEnergy(num: number): string {
 export function getEnergy(num: number): string {
   return ENERGY_MAP[String(num)] || '未知能量'
   return ENERGY_MAP[String(num)] || '未知能量'
 }
 }
@@ -49,82 +48,71 @@ export function getCombination(a: number, b: number): string {
   return COMBINATION_MAP[`${a}${b}`] || `${getEnergy(a)} → ${getEnergy(b)}`
   return COMBINATION_MAP[`${a}${b}`] || `${getEnergy(a)} → ${getEnergy(b)}`
 }
 }
 
 
-export function calculateTriangle(phone: string): Record<string, number> {
-  const digits = getNumbers(phone)
-  // Use first 8 significant digits, pad if needed
-  const nums = digits.slice(0, 8)
-  while (nums.length < 8) nums.push(0)
-
-  // Classic A 5-row layout (center aligned)
-  // Row A: A B C D E from 5 of 8 digits + computed
-  // The 8 digits map to positions in row A
-
-  // Position mapping for Classic A (center position is O):
-  // A1-A5 from calculation on phone digits
-  // B1-B5 = sum adjacent A positions mod 10
-  // C1-C3 = sum adjacent B positions mod 10 (center aligned, skip ends)
-  // D1-D2 = sum adjacent C positions mod 10
-  // E1(O) = sum D1+D2 mod 10
-
-  // Step 1: Initial A row from digits
-  // Classic A: take 8 digits, position them as:
-  // A1=digits[0], A2=digits[1], A3=digits[2] (then compute A4=sum(A2,A3), A5=sum(A3,A4))
-  // Alternatively: 5 main A positions from 8 digits using pairwise sums
-
-  const r: Record<string, number> = {}
-  r.A = nums[0]; r.B = nums[1]; r.C = nums[2]
-  r.D = sumMod10(nums[1], nums[2])
-  r.E = sumMod10(nums[2], nums[3])
-
-  // Row B
-  r.F = sumMod10(r.A, r.B)
-  r.G = sumMod10(r.B, r.C)
-  r.N = sumMod10(r.C, r.D)
-  r.H = sumMod10(r.D, r.E)
-
-  // Compute I in row B from N and H's future position
-  // In classic A, position I appears in row B (position 10) and row D
-  const tempI1 = sumMod10(r.G, r.N)
-  r.I = sumMod10(r.N, r.H)
-
-  // Row C
-  r.J = sumMod10(r.F, r.G)
-  r.M = sumMod10(r.G, r.N)
-  r.L = sumMod10(r.H, r.I)
-
-  // Row D
-  const d1 = sumMod10(r.J, r.M)
-  const d2 = sumMod10(r.M, r.L)
-  r.K = d1 // I1 position in row D
-  r.I_pos2 = d2 // Second I position
-
-  // Row E (O - center)
-  r.O = sumMod10(d1, d2)
-
-  return r
+export interface TriangleResult {
+  A: number; B: number; C: number; D: number; E: number;
+  F: number; G: number; H: number; I: number;
+  J: number; K: number; L: number;
+  M: number; N: number;
+  O: number;
+}
+
+export function calculateTriangle(
+  birthYear: number, birthMonth: number, birthDay: number
+): TriangleResult {
+  const y = String(birthYear).padStart(4, '0')
+  const m = String(birthMonth).padStart(2, '0')
+  const d = String(birthDay).padStart(2, '0')
+
+  const A = parseInt(y[0])
+  const B = parseInt(y[1])
+  const C = reduceToDigit(parseInt(y[2]) + parseInt(y[3]))
+  const D = reduceToDigit(parseInt(m[0]) + parseInt(m[1]))
+  const E = reduceToDigit(parseInt(d[0]) + parseInt(d[1]))
+
+  const F = reduceToDigit(A + B)
+  const G = reduceToDigit(B + C)
+  const H = reduceToDigit(C + D)
+  const I = reduceToDigit(D + E)
+
+  const J = reduceToDigit(F + G)
+  const K = reduceToDigit(G + H)
+  const L = reduceToDigit(H + I)
+
+  const M = reduceToDigit(J + K)
+  const N = reduceToDigit(K + L)
+
+  const O = reduceToDigit(M + N)
+
+  return { A, B, C, D, E, F, G, H, I, J, K, L, M, N, O }
 }
 }
 
 
-export function analyzeTriangle(chart: Record<string, number>): {
-  primary: Array<{position: string, number: number, energy: string}>,
+export function analyzeTriangle(chart: TriangleResult): {
+  primary: Array<{position: string, number: number, energy: string, label: string}>,
   combinations: Array<{pair: string, meaning: string}>
   combinations: Array<{pair: string, meaning: string}>
 } {
 } {
-  const primaryPositions = ['A', 'E', 'F', 'O']
+  const primaryPositions = ['O', 'F', 'I', 'J', 'L']
+  const positionLabel: Record<string, string> = {
+    O: '主性格', F: '父源区', I: '母源区',
+    J: '父源区2', L: '母源区2'
+  }
+
   const primary = primaryPositions.map(pos => ({
   const primary = primaryPositions.map(pos => ({
     position: pos,
     position: pos,
-    number: chart[pos] ?? 0,
-    energy: getEnergy(chart[pos] ?? 0)
+    number: (chart as any)[pos] ?? 0,
+    energy: getEnergy((chart as any)[pos] ?? 0),
+    label: positionLabel[pos] || ''
   }))
   }))
 
 
-  const comboPairs = [
-    ['A', 'E'], ['A', 'F'], ['E', 'O'],
-    ['F', 'O'], ['A', 'O'], ['B', 'C'],
-    ['G', 'N'], ['N', 'H'], ['J', 'M']
+  const comboPairs: [string, string][] = [
+    ['O', 'F'], ['O', 'I'], ['O', 'J'], ['O', 'L'],
+    ['F', 'J'], ['I', 'L'], ['F', 'G'], ['G', 'H'],
+    ['H', 'I'], ['J', 'K'], ['K', 'L'], ['M', 'N']
   ]
   ]
 
 
   const combinations = comboPairs.map(([p1, p2]) => ({
   const combinations = comboPairs.map(([p1, p2]) => ({
     pair: `${p1}${p2}`,
     pair: `${p1}${p2}`,
-    meaning: getCombination(chart[p1] ?? 0, chart[p2] ?? 0)
+    meaning: getCombination((chart as any)[p1] ?? 0, (chart as any)[p2] ?? 0)
   }))
   }))
 
 
   return { primary, combinations }
   return { primary, combinations }
-}
+}

+ 35 - 1
num-server/src/main/java/com/num/controller/AdminController.java

@@ -3,6 +3,9 @@ package com.num.controller;
 import com.num.common.Result;
 import com.num.common.Result;
 import com.num.entity.User;
 import com.num.entity.User;
 import com.num.repository.UserRepository;
 import com.num.repository.UserRepository;
+import com.num.repository.CommissionRepository;
+import com.num.entity.Commission;
+import com.num.service.WithdrawService;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,9 +18,14 @@ import java.util.Map;
 public class AdminController {
 public class AdminController {
 
 
     private final UserRepository userRepository;
     private final UserRepository userRepository;
+    private final WithdrawService withdrawService;
+    private final CommissionRepository commissionRepository;
 
 
-    public AdminController(UserRepository userRepository) {
+    public AdminController(UserRepository userRepository, WithdrawService withdrawService,
+                           CommissionRepository commissionRepository) {
         this.userRepository = userRepository;
         this.userRepository = userRepository;
+        this.withdrawService = withdrawService;
+        this.commissionRepository = commissionRepository;
     }
     }
 
 
     @PostMapping("/users")
     @PostMapping("/users")
@@ -44,4 +52,30 @@ public class AdminController {
             return Result.success(null);
             return Result.success(null);
         }).orElse(Result.error(1002, "User not found"));
         }).orElse(Result.error(1002, "User not found"));
     }
     }
+
+    @PostMapping("/orders")
+    public Result<?> listOrders() {
+        return Result.success(null);
+    }
+
+    @PostMapping("/commissions")
+    public Result<?> listAllCommissions() {
+        return Result.success(commissionRepository.findAll());
+    }
+
+    @PostMapping("/charts")
+    public Result<?> listAllCharts() {
+        return Result.success(null);
+    }
+
+    @PostMapping("/withdraws")
+    public Result<?> listWithdraws() {
+        return Result.success(withdrawService.getAllPending());
+    }
+
+    @PostMapping("/withdraw/approve")
+    public Result<?> approveWithdraw(@RequestBody Map<String, Long> body) {
+        withdrawService.approve(body.get("id"));
+        return Result.success(null);
+    }
 }
 }

+ 41 - 0
num-server/src/main/java/com/num/controller/WithdrawController.java

@@ -0,0 +1,41 @@
+package com.num.controller;
+
+import com.num.common.Result;
+import com.num.service.WithdrawService;
+import jakarta.servlet.http.HttpServletRequest;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/withdraw")
+public class WithdrawController {
+
+    private final WithdrawService withdrawService;
+
+    public WithdrawController(WithdrawService withdrawService) {
+        this.withdrawService = withdrawService;
+    }
+
+    @PostMapping("/apply")
+    public Result<?> apply(HttpServletRequest request, @RequestBody Map<String, Integer> body) {
+        Long userId = (Long) request.getAttribute("userId");
+        int amount = body.get("amount");
+        return Result.success(withdrawService.apply(userId, amount));
+    }
+
+    @PostMapping("/list")
+    public Result<?> list(HttpServletRequest request) {
+        Long userId = (Long) request.getAttribute("userId");
+        return Result.success(withdrawService.getMyWithdraws(userId));
+    }
+
+    @PostMapping("/balance")
+    public Result<?> balance(HttpServletRequest request) {
+        Long userId = (Long) request.getAttribute("userId");
+        return Result.success(Map.of("balance", withdrawService.getAvailableBalance(userId)));
+    }
+}

+ 40 - 0
num-server/src/main/java/com/num/entity/Withdraw.java

@@ -0,0 +1,40 @@
+package com.num.entity;
+
+import jakarta.persistence.*;
+import java.time.LocalDateTime;
+
+@Entity
+@Table(name = "withdraws")
+public class Withdraw {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long id;
+
+    @Column(name = "user_id", nullable = false)
+    private Long userId;
+
+    @Column(nullable = false)
+    private Integer amount;
+
+    @Column(length = 20)
+    private String status;
+
+    @Column(name = "created_at")
+    private LocalDateTime createdAt = LocalDateTime.now();
+
+    @Column(name = "updated_at")
+    private LocalDateTime updatedAt = LocalDateTime.now();
+
+    public Long getId() { return id; }
+    public void setId(Long id) { this.id = id; }
+    public Long getUserId() { return userId; }
+    public void setUserId(Long userId) { this.userId = userId; }
+    public Integer getAmount() { return amount; }
+    public void setAmount(Integer amount) { this.amount = amount; }
+    public String getStatus() { return status; }
+    public void setStatus(String status) { this.status = status; }
+    public LocalDateTime getCreatedAt() { return createdAt; }
+    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
+    public LocalDateTime getUpdatedAt() { return updatedAt; }
+    public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
+}

+ 10 - 0
num-server/src/main/java/com/num/repository/WithdrawRepository.java

@@ -0,0 +1,10 @@
+package com.num.repository;
+
+import com.num.entity.Withdraw;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+import java.util.List;
+
+public interface WithdrawRepository extends JpaRepository<Withdraw, Long> {
+    List<Withdraw> findByUserIdOrderByCreatedAtDesc(Long userId);
+}

+ 63 - 0
num-server/src/main/java/com/num/service/WithdrawService.java

@@ -0,0 +1,63 @@
+package com.num.service;
+
+import com.num.common.BizException;
+import com.num.entity.Withdraw;
+import com.num.repository.WithdrawRepository;
+import com.num.repository.CommissionRepository;
+import com.num.entity.Commission;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class WithdrawService {
+
+    private final WithdrawRepository withdrawRepository;
+    private final CommissionRepository commissionRepository;
+
+    public WithdrawService(WithdrawRepository withdrawRepository,
+                           CommissionRepository commissionRepository) {
+        this.withdrawRepository = withdrawRepository;
+        this.commissionRepository = commissionRepository;
+    }
+
+    public long getAvailableBalance(Long userId) {
+        return commissionRepository.findByToUserIdOrderByCreatedAtDesc(userId)
+                .stream()
+                .filter(c -> "settled".equals(c.getStatus()))
+                .mapToLong(Commission::getAmount)
+                .sum();
+    }
+
+    public Withdraw apply(Long userId, int amount) {
+        if (amount < 10000) {
+            throw new BizException(1006, "Minimum withdraw is ¥100");
+        }
+        long balance = getAvailableBalance(userId);
+        if (amount > balance) {
+            throw new BizException(1007, "Insufficient balance");
+        }
+        Withdraw w = new Withdraw();
+        w.setUserId(userId);
+        w.setAmount(amount);
+        w.setStatus("pending");
+        return withdrawRepository.save(w);
+    }
+
+    public List<Withdraw> getMyWithdraws(Long userId) {
+        return withdrawRepository.findByUserIdOrderByCreatedAtDesc(userId);
+    }
+
+    public List<Withdraw> getAllPending() {
+        return withdrawRepository.findAll().stream()
+                .filter(w -> "pending".equals(w.getStatus()))
+                .toList();
+    }
+
+    public void approve(Long id) {
+        withdrawRepository.findById(id).ifPresent(w -> {
+            w.setStatus("approved");
+            withdrawRepository.save(w);
+        });
+    }
+}