diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 71a33da9..aa3a0cde 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -16,14 +16,27 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index 11c25fa4..97acf354 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -14,5 +14,28 @@
$ProjectFileDir$
+
+ mysql.8
+ true
+ true
+ $PROJECT_DIR$/YumiNail-Core/src/main/resources/application.yaml
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://localhost:3306/yumi_nail?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
+
+
+
+
+
+ $ProjectFileDir$
+
+
+ mysql.8
+ true
+ true
+ $PROJECT_DIR$/YumiNail-Calendar-Core/src/main/resources/application.yaml
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://localhost:3306/yumi_nail_calendar?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
+ $ProjectFileDir$
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 316eb68d..20483061 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -2,6 +2,8 @@
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 29cb5ef8..51e991c1 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -7,6 +7,8 @@
+
+
diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml
index f6badb19..6509128a 100644
--- a/.idea/sqldialects.xml
+++ b/.idea/sqldialects.xml
@@ -1,7 +1,9 @@
+
+
+
-
\ No newline at end of file
diff --git a/WeChatProgram/api/auth.js b/WeChatProgram/api/auth.js
index 6426784b..f304e537 100644
--- a/WeChatProgram/api/auth.js
+++ b/WeChatProgram/api/auth.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
@@ -78,5 +82,12 @@ module.exports = {
method: 'POST',
data
})
+ },
+
+ getCurrentAgreements() {
+ return request({
+ url: '/legal-agreement/current',
+ method: 'GET'
+ })
}
}
diff --git a/WeChatProgram/api/cart.js b/WeChatProgram/api/cart.js
index 4e781b55..cd6469a7 100644
--- a/WeChatProgram/api/cart.js
+++ b/WeChatProgram/api/cart.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/comment.js b/WeChatProgram/api/comment.js
index 8c7430c3..e5e25f8f 100644
--- a/WeChatProgram/api/comment.js
+++ b/WeChatProgram/api/comment.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/coupon.js b/WeChatProgram/api/coupon.js
index 74ae6a59..ff845f85 100644
--- a/WeChatProgram/api/coupon.js
+++ b/WeChatProgram/api/coupon.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/file.js b/WeChatProgram/api/file.js
index ce367e8b..72df1890 100644
--- a/WeChatProgram/api/file.js
+++ b/WeChatProgram/api/file.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/order.js b/WeChatProgram/api/order.js
index 8a915364..b90e01c6 100644
--- a/WeChatProgram/api/order.js
+++ b/WeChatProgram/api/order.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/product-like.js b/WeChatProgram/api/product-like.js
index c8ff0c9c..12094240 100644
--- a/WeChatProgram/api/product-like.js
+++ b/WeChatProgram/api/product-like.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/product.js b/WeChatProgram/api/product.js
index d80eb67a..3db0bc7a 100644
--- a/WeChatProgram/api/product.js
+++ b/WeChatProgram/api/product.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/shop.js b/WeChatProgram/api/shop.js
index 8ccdf068..7efbdf4a 100644
--- a/WeChatProgram/api/shop.js
+++ b/WeChatProgram/api/shop.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/tag.js b/WeChatProgram/api/tag.js
index f7927da0..451139f2 100644
--- a/WeChatProgram/api/tag.js
+++ b/WeChatProgram/api/tag.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/api/user.js b/WeChatProgram/api/user.js
index 72ad07cd..9b203ea9 100644
--- a/WeChatProgram/api/user.js
+++ b/WeChatProgram/api/user.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
const actionGuard = require('../utils/action-guard')
const { API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config')
@@ -39,6 +43,86 @@ module.exports = {
})
},
+ // 我的页常用数据:
+ // 资产、余额流水、消息、公告、VIP 充值档位和所属关系都从这里拿。
+ getMyAsset() {
+ return request({
+ url: '/user/asset/me'
+ })
+ },
+
+ getMyBalanceHistory() {
+ return request({
+ url: '/user/balance/history/me'
+ })
+ },
+
+ listMyMessages() {
+ return request({
+ url: '/system-message/my/list'
+ })
+ },
+
+ listMyPopupMessages() {
+ return request({
+ url: '/system-message/my/popup'
+ })
+ },
+
+ getMyUnreadMessageCount() {
+ return request({
+ url: '/system-message/my/unread-count'
+ })
+ },
+
+ markMessagePopupShown(id) {
+ return request({
+ url: `/system-message/my/${id}/popup-shown`,
+ method: 'PUT',
+ data: {}
+ })
+ },
+
+ markMessageRead(id) {
+ return request({
+ url: `/system-message/my/${id}/read`,
+ method: 'PUT',
+ data: {}
+ })
+ },
+
+ listMyAnnouncements() {
+ return request({
+ url: '/announcement/my/list'
+ })
+ },
+
+ // 这里只是“展示型充值档位”,不发起支付、不改余额。
+ listMyVipRechargePlans() {
+ return request({
+ url: '/vip-recharge-plan/my/list'
+ })
+ },
+
+ getShopManagerContact(shopId) {
+ return request({
+ url: `/contact-info/shop/${shopId}/manager`
+ })
+ },
+
+ getProductArtistContact(productId, artistId) {
+ return request({
+ url: `/contact-info/product/${productId}/artist/${artistId}`
+ })
+ },
+
+ getOrderArtistContact(orderId, artistId) {
+ return request({
+ url: `/contact-info/order/${orderId}/artist`,
+ data: artistId ? { artistId } : {}
+ })
+ },
+
updateUserInfo(data) {
return request({
url: '/user/update',
diff --git a/WeChatProgram/api/wishlist.js b/WeChatProgram/api/wishlist.js
index 0cbcab94..800f6bcb 100644
--- a/WeChatProgram/api/wishlist.js
+++ b/WeChatProgram/api/wishlist.js
@@ -1,3 +1,7 @@
+/**
+ * Mini program API wrapper for this module.
+ * Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
+ */
const request = require('../utils/request')
module.exports = {
diff --git a/WeChatProgram/app.json b/WeChatProgram/app.json
index 00c35001..83bd2349 100644
--- a/WeChatProgram/app.json
+++ b/WeChatProgram/app.json
@@ -11,6 +11,8 @@
"pages/orders/index",
"pages/wishlist/index",
"pages/coupons/index",
+ "pages/vip-center/index",
+ "pages/notifications/index",
"pages/settings/index"
],
"window": {
diff --git a/WeChatProgram/components/navigation-bar/navigation-bar.js b/WeChatProgram/components/navigation-bar/navigation-bar.js
index 579d25a0..f38f7589 100644
--- a/WeChatProgram/components/navigation-bar/navigation-bar.js
+++ b/WeChatProgram/components/navigation-bar/navigation-bar.js
@@ -52,7 +52,9 @@ Component({
show: {
type: Boolean,
value: true,
- observer: '_showChange',
+ observer(show) {
+ this._showChange(show)
+ },
},
delta: {
type: Number,
@@ -64,7 +66,9 @@ Component({
},
},
observers: {
- 'back, showBack, isTabPage': 'updateResolvedBack',
+ 'back, showBack, isTabPage': function () {
+ this.updateResolvedBack()
+ },
},
data: {
displayStyle: '',
diff --git a/WeChatProgram/components/product-card/product-card.wxml b/WeChatProgram/components/product-card/product-card.wxml
index 7013ef40..7609f721 100644
--- a/WeChatProgram/components/product-card/product-card.wxml
+++ b/WeChatProgram/components/product-card/product-card.wxml
@@ -6,6 +6,7 @@
{{item.displayTitle}}
+ {{item.shopNameText}}{{item.metaText}}{{item}}
diff --git a/WeChatProgram/components/product-card/product-card.wxss b/WeChatProgram/components/product-card/product-card.wxss
index 04208aa2..f3d2529c 100644
--- a/WeChatProgram/components/product-card/product-card.wxss
+++ b/WeChatProgram/components/product-card/product-card.wxss
@@ -215,3 +215,13 @@
font-weight: 700;
white-space: nowrap;
}
+
+.product-shop {
+ margin-top: 6rpx;
+ color: #8f6e7a;
+ font-size: 22rpx;
+ line-height: 1.45;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
diff --git a/WeChatProgram/pages/auth/index.js b/WeChatProgram/pages/auth/index.js
index 91f4e60d..372b22d0 100644
--- a/WeChatProgram/pages/auth/index.js
+++ b/WeChatProgram/pages/auth/index.js
@@ -16,6 +16,10 @@ const {
const phoneRegex = /^1[3-9]\d{9}$/
+/**
+ * auth page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 108
@@ -54,6 +58,10 @@ Page({
miniShopDisplayName: '',
miniShopNewUser: false,
miniShopSubmitting: false,
+ agreementAccepted: false,
+ agreements: [],
+ agreementModalVisible: false,
+ selectedAgreement: null,
form: {
account: '',
password: '',
@@ -71,6 +79,10 @@ Page({
}
}),
+ /**
+ * `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onLoad(options) {
this.ensureKeyboardSafe()
this.setData({
@@ -79,20 +91,33 @@ Page({
})
this.detectWechatMiniCapability()
this.loadShopOptions()
+ this.loadAgreements()
this.consumePendingWechatMiniLogin()
this.waitForPendingWechatMiniAutoLogin()
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.ensureKeyboardSafe()
this.consumePendingWechatMiniLogin()
},
+ /**
+ * `onHide` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
+ /**
+ * `onUnload` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
@@ -100,6 +125,10 @@ Page({
noop() {},
+ /**
+ * `ensureKeyboardSafe` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 108,
@@ -107,14 +136,26 @@ Page({
})
},
+ /**
+ * `handleKeyboardFocus` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleKeyboardFocus(event) {
handleKeyboardFocus(this, event)
},
+ /**
+ * `handleKeyboardBlur` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleKeyboardBlur() {
handleKeyboardBlur(this)
},
+ /**
+ * `detectWechatMiniCapability` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
detectWechatMiniCapability() {
let supported = false
let disabledReason = ''
@@ -122,6 +163,10 @@ Page({
try {
supported = wx.canIUse('button.open-type.getPhoneNumber')
const systemInfo = wx.getSystemInfoSync()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (systemInfo && systemInfo.platform === 'devtools') {
supported = false
disabledReason = '当前环境无法使用微信手机号登录,请使用账号密码或验证码登录'
@@ -130,6 +175,10 @@ Page({
supported = false
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!supported && !disabledReason) {
disabledReason = '当前环境无法使用微信手机号登录,请使用账号密码或验证码登录'
}
@@ -140,6 +189,10 @@ Page({
})
},
+ /**
+ * `waitForPendingWechatMiniAutoLogin` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
waitForPendingWechatMiniAutoLogin() {
const app = getApp()
if (
@@ -167,13 +220,25 @@ Page({
})
},
+ /**
+ * `consumePendingWechatMiniLogin` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
consumePendingWechatMiniLogin() {
const app = getApp()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!app || typeof app.consumePendingWechatMiniLogin !== 'function') {
return
}
const pending = app.consumePendingWechatMiniLogin()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (pending && pending.status === 'SELECT_SHOP') {
this.openMiniShopSelector(pending)
}
@@ -193,6 +258,87 @@ Page({
}
},
+ async loadAgreements() {
+ try {
+ const agreements = await authApi.getCurrentAgreements()
+ this.setData({
+ agreements: Array.isArray(agreements) ? agreements : []
+ })
+ } catch (error) {
+ wx.showToast({
+ title: '协议内容加载失败,请稍后重试',
+ icon: 'none'
+ })
+ }
+ },
+
+ buildAgreementPayload() {
+ const agreementVersions = {}
+ ;(this.data.agreements || []).forEach((item) => {
+ if (item && item.agreementType && item.version) {
+ agreementVersions[item.agreementType] = item.version
+ }
+ })
+ return {
+ agreementAccepted: !!this.data.agreementAccepted,
+ agreementVersions,
+ clientType: 'WECHAT_MINI'
+ }
+ },
+
+ ensureAgreementAccepted() {
+ if (!this.data.agreementAccepted) {
+ wx.showToast({
+ title: '请先阅读并同意用户协议和隐私政策',
+ icon: 'none'
+ })
+ return false
+ }
+
+ const versions = this.buildAgreementPayload().agreementVersions
+ if (!versions.USER_TERMS || !versions.PRIVACY_POLICY) {
+ wx.showToast({
+ title: '协议版本加载中,请稍后再试',
+ icon: 'none'
+ })
+ return false
+ }
+ return true
+ },
+
+ handleAgreementToggle() {
+ this.setData({
+ agreementAccepted: !this.data.agreementAccepted
+ })
+ },
+
+ openAgreement(event) {
+ const type = event.currentTarget.dataset.type
+ const selectedAgreement = (this.data.agreements || []).find((item) => item.agreementType === type)
+ if (!selectedAgreement) {
+ wx.showToast({
+ title: '协议内容暂不可用',
+ icon: 'none'
+ })
+ return
+ }
+ this.setData({
+ selectedAgreement,
+ agreementModalVisible: true
+ })
+ },
+
+ closeAgreementModal() {
+ this.setData({
+ agreementModalVisible: false,
+ selectedAgreement: null
+ })
+ },
+
+ /**
+ * `handleTabChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleTabChange(event) {
const tab = event.currentTarget.dataset.tab
resetKeyboardSafe(this)
@@ -210,6 +356,10 @@ Page({
})
},
+ /**
+ * `handleLoginTypeChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleLoginTypeChange(event) {
const type = event.currentTarget.dataset.type
resetKeyboardSafe(this)
@@ -227,6 +377,10 @@ Page({
})
},
+ /**
+ * `handleShowTraditionalLogin` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleShowTraditionalLogin() {
resetKeyboardSafe(this)
this.setData({
@@ -235,6 +389,10 @@ Page({
})
},
+ /**
+ * `handleToggleResetPanel` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleToggleResetPanel() {
resetKeyboardSafe(this)
this.setData({
@@ -242,6 +400,10 @@ Page({
})
},
+ /**
+ * `handleInputChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleInputChange(event) {
const field = event.currentTarget.dataset.field
const value = event.detail.value
@@ -249,7 +411,15 @@ Page({
[`form.${field}`]: value
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (field === 'account') {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.activeTab === 'login') {
patch.loginAccountStatusText = ''
patch.loginAccountStatusType = ''
@@ -267,7 +437,15 @@ Page({
}
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (field === 'phone') {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.activeTab === 'register') {
patch.registerPhoneStatusText = ''
patch.registerPhoneStatusType = ''
@@ -284,6 +462,10 @@ Page({
this.setData(patch)
},
+ /**
+ * `handleResetInputChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleResetInputChange(event) {
const field = event.currentTarget.dataset.field
this.setData({
@@ -291,6 +473,10 @@ Page({
})
},
+ /**
+ * `handleRegisterShopChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleRegisterShopChange(event) {
const index = Number(event.detail.value)
const shop = this.data.shops[index]
@@ -301,6 +487,10 @@ Page({
})
},
+ /**
+ * `handleLoginShopChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleLoginShopChange(event) {
const index = Number(event.detail.value)
const shop = this.data.loginShops[index]
@@ -311,6 +501,10 @@ Page({
})
},
+ /**
+ * `handleMiniShopChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleMiniShopChange(event) {
const index = Number(event.detail.value)
const shop = this.data.miniShops[index]
@@ -320,7 +514,15 @@ Page({
})
},
+ /**
+ * `handleCloseMiniShopSelector` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleCloseMiniShopSelector() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.miniShopSubmitting) {
return
}
@@ -329,7 +531,15 @@ Page({
})
},
+ /**
+ * `handleResumeMiniShopSelector` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleResumeMiniShopSelector() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.miniShopTicket || !this.data.miniShops.length) {
return
}
@@ -342,15 +552,27 @@ Page({
async handleAccountBlur() {
this.handleKeyboardBlur()
const account = this.data.form.account.trim()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!account) {
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.activeTab === 'register') {
await this.checkRegisterAccountAvailability()
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.loginType !== 'password') {
return
}
@@ -364,10 +586,18 @@ Page({
async handlePhoneBlur() {
this.handleKeyboardBlur()
const phone = this.data.form.phone.trim()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!phone) {
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.activeTab === 'register') {
if (phoneRegex.test(phone)) {
await this.checkRegisterPhoneAvailability()
@@ -382,6 +612,10 @@ Page({
await this.loadLoginShopsByPhone()
},
+ /**
+ * `applyLoginShopSelection` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
applyLoginShopSelection(selection) {
const shops = Array.isArray(selection && selection.shops) ? selection.shops : []
const allowLoginShopless = Boolean(selection && selection.allowShoplessLogin)
@@ -389,6 +623,10 @@ Page({
let loginShopDisplayName = ''
let shopId = ''
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!allowLoginShopless && shops.length === 1) {
loginShopIndex = 0
loginShopDisplayName = shops[0].shopName || ''
@@ -482,6 +720,10 @@ Page({
}
},
+ /**
+ * `startCountdown` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
startCountdown(fieldName) {
this.setData({
[fieldName]: 60
@@ -493,6 +735,10 @@ Page({
[fieldName]: nextValue
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (nextValue <= 0) {
clearInterval(timer)
}
@@ -500,6 +746,10 @@ Page({
},
async handleSendCode() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.countdown > 0) {
return
}
@@ -513,8 +763,16 @@ Page({
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.activeTab === 'register') {
const phoneAvailable = await this.checkRegisterPhoneAvailability()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!phoneAvailable) {
wx.showToast({
title: this.data.registerPhoneStatusText || '该手机号已被注册',
@@ -525,7 +783,10 @@ Page({
}
try {
- await runWithLoading(() => userApi.sendVerificationCode({ phone }))
+ await runWithLoading(() => userApi.sendVerificationCode({
+ phone,
+ sceneCode: this.data.activeTab === 'register' ? 'USER_REGISTER_SMS_CODE' : 'USER_LOGIN_SMS_CODE'
+ }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -540,6 +801,10 @@ Page({
},
async handleSendForgotCode() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.forgotCountdown > 0) {
return
}
@@ -554,7 +819,10 @@ Page({
}
try {
- await runWithLoading(() => authApi.sendVerificationCode({ phone }))
+ await runWithLoading(() => authApi.sendVerificationCode({
+ phone,
+ sceneCode: 'USER_RESET_PASSWORD_SMS_CODE'
+ }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -568,8 +836,16 @@ Page({
}
},
+ /**
+ * `validateLoginForm` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
validateLoginForm() {
const form = this.data.form
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.loginType === 'password') {
if (!form.account.trim() || !form.password) {
return '请输入账号和密码'
@@ -578,6 +854,10 @@ Page({
return '请输入正确的手机号和验证码'
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.allowLoginShopless && this.data.loginShops.length && !form.shopId) {
return '请选择登录门店'
}
@@ -599,12 +879,24 @@ Page({
if (!form.verificationCode.trim()) {
return '请输入验证码'
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!form.password || form.password.length < 6) {
return '密码至少 6 位'
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (form.password !== form.confirmPassword) {
return '两次输入的密码不一致'
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!form.shopId) {
return '请选择门店'
}
@@ -614,6 +906,10 @@ Page({
this.checkRegisterPhoneAvailability()
])
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!accountAvailable || !phoneAvailable) {
return '请先处理注册信息中的占用问题'
}
@@ -622,30 +918,45 @@ Page({
},
async handleSubmit() {
+ if (!this.ensureAgreementAccepted()) {
+ return
+ }
+
this.setData({
loading: true
})
try {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.activeTab === 'login') {
const loginError = this.validateLoginForm()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (loginError) {
throw new Error(loginError)
}
let payload
await runWithLoading(async () => {
+ const agreementPayload = this.buildAgreementPayload()
payload = this.data.loginType === 'phone'
? await authApi.phoneLogin({
phone: this.data.form.phone.trim(),
verificationCode: this.data.form.verificationCode.trim(),
- shopId: this.data.form.shopId || undefined
+ shopId: this.data.form.shopId || undefined,
+ ...agreementPayload
})
: await authApi.login({
account: this.data.form.account.trim(),
password: this.data.form.password,
rememberMe: true,
- shopId: this.data.form.shopId || undefined
+ shopId: this.data.form.shopId || undefined,
+ ...agreementPayload
})
})
@@ -654,6 +965,10 @@ Page({
}
const registerError = await this.validateRegisterForm()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (registerError) {
throw new Error(registerError)
}
@@ -664,7 +979,8 @@ Page({
nickname: this.data.form.nickname.trim(),
phone: this.data.form.phone.trim(),
verificationCode: this.data.form.verificationCode.trim(),
- shopId: this.data.form.shopId
+ shopId: this.data.form.shopId,
+ ...this.buildAgreementPayload()
}))
wx.showToast({
@@ -708,6 +1024,10 @@ Page({
})
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!form.newPassword || form.newPassword.length < 6) {
wx.showToast({
title: '新密码至少 6 位',
@@ -750,6 +1070,10 @@ Page({
}
},
+ /**
+ * `handleWechatMiniUnavailableTap` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleWechatMiniUnavailableTap() {
wx.showToast({
title: this.data.wechatMiniDisabledReason || '请使用账号密码或验证码登录',
@@ -758,12 +1082,24 @@ Page({
},
async handleWechatMiniPhoneLogin(event) {
+ if (!this.ensureAgreementAccepted()) {
+ return
+ }
+
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.wechatMiniSupported || this.data.wechatMiniLoading) {
this.handleWechatMiniUnavailableTap()
return
}
const detail = event.detail || {}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!detail.code) {
wx.showToast({
title: this.resolveWechatAuthorizeError(detail),
@@ -781,7 +1117,8 @@ Page({
const result = await runWithLoading(() => authApi.wechatMiniPhoneLogin({
wxCode,
phoneCode: detail.code,
- preferredShopId: authStore.getPreferredMiniLoginShopId() || undefined
+ preferredShopId: authStore.getPreferredMiniLoginShopId() || undefined,
+ ...this.buildAgreementPayload()
}))
await this.handleWechatMiniResult(result)
} catch (error) {
@@ -797,7 +1134,15 @@ Page({
},
async handleConfirmMiniShopLogin() {
+ if (!this.ensureAgreementAccepted()) {
+ return
+ }
+
const shop = this.data.miniShops[this.data.miniShopIndex]
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.miniShopTicket) {
wx.showToast({
title: '登录票据已失效,请重新发起微信登录',
@@ -805,6 +1150,10 @@ Page({
})
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!shop || !shop.id) {
wx.showToast({
title: '请选择门店',
@@ -820,8 +1169,13 @@ Page({
try {
const result = await runWithLoading(() => authApi.confirmWechatMiniLogin({
ticket: this.data.miniShopTicket,
- shopId: shop.id
+ shopId: shop.id,
+ ...this.buildAgreementPayload()
}))
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!result || result.status !== 'SUCCESS') {
throw new Error((result && result.message) || '确认登录失败')
}
@@ -839,6 +1193,10 @@ Page({
}
},
+ /**
+ * `resolveWechatAuthorizeError` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
resolveWechatAuthorizeError(detail) {
const errMsg = String((detail && detail.errMsg) || '')
if (errMsg.includes('user deny') || errMsg.includes('user cancel')) {
@@ -850,8 +1208,16 @@ Page({
return '未获取到微信手机号授权,请稍后重试。'
},
+ /**
+ * `requestWechatMiniCode` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
requestWechatMiniCode() {
const app = getApp()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (app && typeof app.requestWechatMiniCode === 'function') {
return app.requestWechatMiniCode()
}
@@ -859,6 +1225,10 @@ Page({
return new Promise((resolve, reject) => {
wx.login({
success: res => {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (res && res.code) {
resolve(res.code)
return
@@ -871,15 +1241,27 @@ Page({
},
async handleWechatMiniResult(result) {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!result) {
throw new Error('微信登录未返回结果')
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (result.status === 'SUCCESS') {
await this.finishLogin(result, result.newUser ? '注册并登录成功' : '登录成功')
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (result.status === 'SELECT_SHOP') {
this.openMiniShopSelector(result)
return
@@ -891,9 +1273,17 @@ Page({
})
},
+ /**
+ * `openMiniShopSelector` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
openMiniShopSelector(result) {
resetKeyboardSafe(this)
const shops = Array.isArray(result && result.shops) ? result.shops : []
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!shops.length) {
wx.showToast({
title: result && result.message ? result.message : '暂无可选门店,请稍后重试',
@@ -917,6 +1307,10 @@ Page({
})
},
+ /**
+ * `clearMiniShopSelector` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
clearMiniShopSelector() {
this.setData({
showMiniShopSelector: false,
@@ -951,10 +1345,22 @@ Page({
}
},
+ /**
+ * `buildAuthHelperText` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
buildAuthHelperText(activeTab, loginType) {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (activeTab === 'register') {
return '注册前请先选门店'
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (loginType === 'phone') {
return '未注册手机号会先选门店'
}
diff --git a/WeChatProgram/pages/auth/index.wxml b/WeChatProgram/pages/auth/index.wxml
index 499971f4..2033791b 100644
--- a/WeChatProgram/pages/auth/index.wxml
+++ b/WeChatProgram/pages/auth/index.wxml
@@ -37,6 +37,16 @@
{{wechatMiniSupported ? '单门店可直接登录' : wechatMiniDisabledReason}}
+
+
+ {{agreementAccepted ? '✓' : ''}}
+
+ 我已阅读并同意
+ 《用户协议》
+ 和
+ 《隐私政策》
+
+
@@ -216,7 +226,17 @@
忘记密码?
- {{activeTab === 'login' ? '立即登录' : '完成注册'}}
+
+ {{agreementAccepted ? '✓' : ''}}
+
+ 我已阅读并同意
+ 《用户协议》
+ 和
+ 《隐私政策》
+
+
+
+ {{activeTab === 'login' ? '立即登录' : '完成注册'}}
@@ -303,10 +323,31 @@
首次登录会自动注册并绑定手机号。
+
+ {{agreementAccepted ? '✓' : ''}}
+
+ 我已阅读并同意
+ 《用户协议》
+ 和
+ 《隐私政策》
+
+
+
稍后再选{{miniShopSubmitting ? '确认中...' : '确认登录'}}
+
+
+
+ {{selectedAgreement.title || '协议详情'}}
+ 版本:{{selectedAgreement.version || '-'}}
+
+ {{selectedAgreement.content || '暂无协议内容'}}
+
+ 我知道了
+
+
diff --git a/WeChatProgram/pages/auth/index.wxss b/WeChatProgram/pages/auth/index.wxss
index 4decb5e9..4e88ca6d 100644
--- a/WeChatProgram/pages/auth/index.wxss
+++ b/WeChatProgram/pages/auth/index.wxss
@@ -238,6 +238,110 @@
margin-top: 24rpx;
}
+.submit-btn.disabled {
+ opacity: 0.52;
+}
+
+.agreement-row {
+ display: flex;
+ align-items: flex-start;
+ gap: 14rpx;
+ margin-top: 22rpx;
+ color: #7a6871;
+ font-size: 23rpx;
+ line-height: 1.6;
+}
+
+.agreement-check {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 34rpx;
+ height: 34rpx;
+ margin-top: 2rpx;
+ border: 2rpx solid #d9b8c4;
+ border-radius: 10rpx;
+ color: #ffffff;
+ font-size: 22rpx;
+ font-weight: 800;
+ flex-shrink: 0;
+}
+
+.agreement-check.checked {
+ border-color: #c6597d;
+ background: #c6597d;
+}
+
+.agreement-copy {
+ flex: 1;
+ min-width: 0;
+}
+
+.agreement-link {
+ color: #c6597d;
+ font-weight: 700;
+}
+
+.mini-shop-agreement {
+ margin-top: 22rpx;
+}
+
+.wechat-agreement {
+ width: 100%;
+ margin-top: 18rpx;
+ text-align: left;
+}
+
+.agreement-mask {
+ position: fixed;
+ inset: 0;
+ z-index: 80;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 28rpx;
+ background: rgba(45, 36, 48, 0.42);
+}
+
+.agreement-modal {
+ width: 100%;
+ max-width: 690rpx;
+ max-height: 82vh;
+ padding: 30rpx 28rpx;
+ border-radius: 32rpx;
+ background: #ffffff;
+}
+
+.agreement-modal-title {
+ font-size: 32rpx;
+ line-height: 1.35;
+ font-weight: 800;
+ color: #2d2430;
+}
+
+.agreement-modal-meta {
+ margin-top: 10rpx;
+ font-size: 22rpx;
+ color: #9a8590;
+}
+
+.agreement-modal-body {
+ height: 640rpx;
+ max-height: 56vh;
+ margin-top: 22rpx;
+ padding: 20rpx;
+ border-radius: 22rpx;
+ background: #fff7f8;
+ color: #5a4a52;
+ font-size: 24rpx;
+ line-height: 1.85;
+ box-sizing: border-box;
+}
+
+.agreement-modal-close {
+ margin-top: 22rpx;
+}
+
.mini-shop-mask {
position: fixed;
inset: 0;
diff --git a/WeChatProgram/pages/cart/index.js b/WeChatProgram/pages/cart/index.js
index 30aaa61d..e26a22f8 100644
--- a/WeChatProgram/pages/cart/index.js
+++ b/WeChatProgram/pages/cart/index.js
@@ -27,6 +27,10 @@ function getCouponDisplay(coupon) {
}
function calculateCouponDiscount(coupon, amount) {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!coupon || amount <= 0) {
return 0
}
@@ -47,32 +51,56 @@ function buildCheckoutIssues(items) {
const issues = []
const selectedItems = items.filter(item => item.selected)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!selectedItems.length) {
issues.push('请先勾选要结算的作品')
return issues
}
const missingArtist = selectedItems.find(item => !item.artistId)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (missingArtist) {
issues.push(`请先为“${missingArtist.productTitle}”选择美甲师`)
}
const missingTime = selectedItems.find(item => !item.appointmentValue)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (missingTime) {
issues.push(`请先为“${missingTime.productTitle}”选择预约时间`)
}
const expiredTime = selectedItems.find(item => item.appointmentValue && isPastAppointment(item.appointmentValue))
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (expiredTime) {
issues.push(`“${expiredTime.productTitle}”的预约时间已过,请重新选择`)
}
const shopIds = Array.from(new Set(selectedItems.map(item => item.shopId).filter(Boolean)))
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (shopIds.length > 1) {
issues.push('跨门店作品请分开结算')
}
const artistIds = Array.from(new Set(selectedItems.map(item => item.artistId).filter(Boolean)))
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (artistIds.length > 1) {
issues.push('不同美甲师的项目请分开结算')
}
@@ -80,6 +108,10 @@ function buildCheckoutIssues(items) {
return issues
}
+/**
+ * cart page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: {
isLoggedIn: false,
@@ -98,6 +130,10 @@ Page({
submittingOrder: false
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.loadCartItems()
},
@@ -107,14 +143,26 @@ Page({
wx.stopPullDownRefresh()
},
+ /**
+ * `getSelectedItems` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
getSelectedItems() {
return this.data.cartItems.filter(item => item.selected)
},
+ /**
+ * `getSelectedCoupon` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
getSelectedCoupon() {
return this.data.availableCoupons.find(item => item.key === this.data.selectedCouponKey) || null
},
+ /**
+ * `refreshSummary` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
refreshSummary() {
const selectedItems = this.getSelectedItems()
const selectedCoupon = this.getSelectedCoupon()
@@ -143,6 +191,10 @@ Page({
loading: isLoggedIn
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!isLoggedIn) {
this.setData({
cartItems: [],
@@ -163,7 +215,10 @@ Page({
const availableArtists = Array.isArray(item.availableArtists) ? item.availableArtists.map(artist => ({
id: artist.id,
name: artist.name,
- avatar: artist.avatar
+ avatar: artist.avatar,
+ userType: artist.userType,
+ roleLabel: artist.roleLabel,
+ participateProduction: artist.participateProduction
})) : []
const artist = availableArtists.find(current => String(current.id) === String(item.artistId || ''))
@@ -204,6 +259,10 @@ Page({
async loadAvailableCoupons() {
const selectedItems = this.getSelectedItems()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!selectedItems.length) {
this.setData({
availableCoupons: [],
@@ -241,9 +300,17 @@ Page({
selectedCouponKey = NO_COUPON_KEY
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (selectedCouponKey === NO_COUPON_KEY) {
const bestCoupons = list
.sort((left, right) => calculateCouponDiscount(right, subtotalAmount) - calculateCouponDiscount(left, subtotalAmount))
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (bestCoupons.length) {
selectedCouponKey = bestCoupons[0].key
}
@@ -263,10 +330,18 @@ Page({
}
},
+ /**
+ * `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenAuth() {
navigation.openAuth('/pages/cart/index')
},
+ /**
+ * `handleBrowseProducts` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBrowseProducts() {
navigation.switchTab('/pages/products/index')
},
@@ -275,6 +350,10 @@ Page({
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!item) {
return
}
@@ -296,11 +375,19 @@ Page({
const delta = Number(event.currentTarget.dataset.delta)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!item) {
return
}
const nextQuantity = Number(item.quantity || 0) + delta
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (nextQuantity < 1 || nextQuantity > 99) {
return
}
@@ -337,6 +424,10 @@ Page({
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!item) {
return
}
@@ -349,6 +440,10 @@ Page({
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!confirmed) {
return
}
@@ -369,8 +464,16 @@ Page({
}
},
+ /**
+ * `handleOpenProduct` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenProduct(event) {
const productId = event.currentTarget.dataset.productId
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!productId) {
return
}
@@ -384,10 +487,18 @@ Page({
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!item) {
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!item.availableArtists.length) {
wx.showToast({
title: '当前作品暂时没有可预约美甲师',
@@ -398,29 +509,41 @@ Page({
const tapIndex = await new Promise(resolve => {
wx.showActionSheet({
- itemList: item.availableArtists.map(artist => artist.name),
+ itemList: item.availableArtists.map(artist => artist.roleLabel ? `${artist.name}(${artist.roleLabel})` : artist.name),
success: res => resolve(res.tapIndex),
fail: () => resolve(-1)
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (tapIndex < 0 || tapIndex >= item.availableArtists.length) {
return
}
const artist = item.availableArtists[tapIndex]
item.artistId = artist.id
- item.artistName = artist.name
+ item.artistName = artist.roleLabel ? `${artist.name}(${artist.roleLabel})` : artist.name
this.setData({
cartItems
})
this.refreshSummary()
},
+ /**
+ * `handleDateChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleDateChange(event) {
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!item) {
return
}
@@ -433,10 +556,18 @@ Page({
this.refreshSummary()
},
+ /**
+ * `handleTimeChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleTimeChange(event) {
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!item) {
return
}
@@ -449,6 +580,10 @@ Page({
this.refreshSummary()
},
+ /**
+ * `handleCouponChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleCouponChange(event) {
this.setData({
selectedCouponKey: event.detail.value
@@ -457,12 +592,20 @@ Page({
},
async handleCheckout() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.submittingOrder) {
return
}
const selectedItems = this.getSelectedItems()
const checkoutIssues = buildCheckoutIssues(this.data.cartItems)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (checkoutIssues.length) {
wx.showToast({
title: checkoutIssues[0],
diff --git a/WeChatProgram/pages/coupons/index.js b/WeChatProgram/pages/coupons/index.js
index 804f3e1d..78609d31 100644
--- a/WeChatProgram/pages/coupons/index.js
+++ b/WeChatProgram/pages/coupons/index.js
@@ -9,6 +9,10 @@ function getBenefitText(coupon) {
return `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
}
+/**
+ * coupons page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: {
loading: false,
@@ -24,6 +28,10 @@ Page({
]
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.loadCoupons()
},
@@ -35,6 +43,10 @@ Page({
loading: isLoggedIn
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!isLoggedIn) {
this.setData({
coupons: [],
@@ -74,11 +86,19 @@ Page({
}
},
+ /**
+ * `applyFilter` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
applyFilter(filterValue, sourceCoupons) {
const activeFilter = filterValue || 'all'
const coupons = Array.isArray(sourceCoupons) ? sourceCoupons : this.data.coupons
let filteredCoupons = coupons
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (activeFilter === 'available') {
filteredCoupons = coupons.filter(item => Number(item.status) === 1)
} else if (activeFilter === 'used') {
@@ -93,18 +113,34 @@ Page({
})
},
+ /**
+ * `handleFilterChange` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleFilterChange(event) {
const value = event.currentTarget.dataset.value
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!value || value === this.data.activeFilter) {
return
}
this.applyFilter(value)
},
+ /**
+ * `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenAuth() {
navigation.openAuth('/pages/coupons/index')
},
+ /**
+ * `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBack() {
navigation.goBack('/pages/profile/index')
}
diff --git a/WeChatProgram/pages/home/index.js b/WeChatProgram/pages/home/index.js
index 3cfa18c9..152f91ac 100644
--- a/WeChatProgram/pages/home/index.js
+++ b/WeChatProgram/pages/home/index.js
@@ -16,6 +16,10 @@ const productApi = require('../../api/product')
const shopApi = require('../../api/shop')
const userApi = require('../../api/user')
+/**
+ * home page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 96
@@ -32,31 +36,52 @@ Page({
bannerImages: [],
featuredItems: [],
popularItems: [],
+ announcements: [],
popularPage: 1,
pageSize: 6,
hasMore: false,
popularTotal: 0
}),
+ /**
+ * `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onLoad() {
this.homeRequestId = 0
this.ensureKeyboardSafe()
this.loadHomeData()
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.ensureKeyboardSafe()
this.syncUserState()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.initialized && this.data.isLoggedIn) {
this.loadUserProfile()
}
},
+ /**
+ * `onHide` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
+ /**
+ * `onUnload` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
@@ -68,13 +93,25 @@ Page({
wx.stopPullDownRefresh()
},
+ /**
+ * `onReachBottom` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onReachBottom() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.hasMore || this.data.loadingMore) {
return
}
this.loadPopularProducts(false)
},
+ /**
+ * `ensureKeyboardSafe` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 96,
@@ -82,6 +119,10 @@ Page({
})
},
+ /**
+ * `syncUserState` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
syncUserState() {
const app = getApp()
const userInfo = auth.getStoredUserInfo()
@@ -89,6 +130,10 @@ Page({
const navTitle = userInfo && String(userInfo.shopName || '').trim()
? String(userInfo.shopName).trim()
: '游客模式'
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (app) {
app.globalData.userInfo = userInfo
app.globalData.isLoggedIn = isLoggedIn
@@ -118,6 +163,24 @@ Page({
} catch (error) {}
},
+ async loadAnnouncements() {
+ if (!auth.isLoggedIn()) {
+ this.setData({ announcements: [] })
+ return
+ }
+ try {
+ const list = await userApi.listMyAnnouncements()
+ this.setData({
+ announcements: Array.isArray(list) ? list.map(item => ({
+ ...item,
+ displayText: `${item.publisherName || '平台'}:${item.content || ''}`
+ })) : []
+ })
+ } catch (error) {
+ this.setData({ announcements: [] })
+ }
+ },
+
async loadHomeData() {
const requestId = ++this.homeRequestId
this.setData({ loading: true })
@@ -126,11 +189,16 @@ Page({
try {
await Promise.all([
this.loadUserProfile(),
+ this.loadAnnouncements(),
this.loadBannerImages(requestId),
this.loadFeaturedProducts(requestId),
this.loadPopularProducts(true, requestId)
])
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (requestId === this.homeRequestId) {
this.setData({
initialized: true
@@ -142,6 +210,10 @@ Page({
icon: 'none'
})
} finally {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (requestId === this.homeRequestId) {
this.setData({ loading: false })
}
@@ -166,6 +238,10 @@ Page({
return resolved.filter(item => item.imageUrl)
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (requestId === this.homeRequestId) {
this.setData({
bannerImages: Array.isArray(banners) ? banners : []
@@ -183,6 +259,10 @@ Page({
return buildProductCards(result && result.list ? result.list : [])
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (requestId === this.homeRequestId) {
this.setData({
featuredItems: Array.isArray(items) ? items : []
@@ -203,6 +283,10 @@ Page({
tag: '热门'
})
const cards = await buildProductCards(result && result.list ? result.list : [])
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (currentRequestId !== this.homeRequestId) {
return
}
@@ -215,6 +299,10 @@ Page({
hasMore: mergedItems.length < total
})
} catch (error) {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (currentRequestId !== this.homeRequestId) {
return
}
@@ -223,6 +311,10 @@ Page({
icon: 'none'
})
} finally {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (currentRequestId === this.homeRequestId) {
this.setData({
loadingMore: false
@@ -231,20 +323,36 @@ Page({
}
},
+ /**
+ * `handleSearchInput` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSearchInput(event) {
this.setData({
searchKeyword: event.detail.value
})
},
+ /**
+ * `handleSearchFocus` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSearchFocus(event) {
handleKeyboardFocus(this, event)
},
+ /**
+ * `handleSearchBlur` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSearchBlur() {
handleKeyboardBlur(this)
},
+ /**
+ * `handleSearchConfirm` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSearchConfirm() {
resetKeyboardSafe(this)
navigation.openProducts({
@@ -252,8 +360,16 @@ Page({
})
},
+ /**
+ * `handleBannerTap` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBannerTap(event) {
const shopId = event.currentTarget.dataset.shopId
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!shopId) {
return
}
@@ -264,7 +380,15 @@ Page({
})
},
+ /**
+ * `handleProfileTap` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleProfileTap() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.isLoggedIn) {
navigation.switchTab('/pages/profile/index')
return
@@ -273,8 +397,16 @@ Page({
navigation.openAuth()
},
+ /**
+ * `handleProductSelect` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleProductSelect(event) {
const product = event.detail || {}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!product.id) {
return
}
@@ -284,12 +416,20 @@ Page({
})
},
+ /**
+ * `handleSeeAllFeatured` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSeeAllFeatured() {
navigation.openProducts({
tag: '精选'
})
},
+ /**
+ * `handleSeeAllPopular` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSeeAllPopular() {
navigation.openProducts({
tag: '热门'
diff --git a/WeChatProgram/pages/home/index.wxml b/WeChatProgram/pages/home/index.wxml
index 299a63a8..209bca94 100644
--- a/WeChatProgram/pages/home/index.wxml
+++ b/WeChatProgram/pages/home/index.wxml
@@ -32,6 +32,12 @@
搜索
+
+
+ {{item.displayText}}
+
+
+
门店橱窗
diff --git a/WeChatProgram/pages/home/index.wxss b/WeChatProgram/pages/home/index.wxss
index a3d37fd9..0f72d443 100644
--- a/WeChatProgram/pages/home/index.wxss
+++ b/WeChatProgram/pages/home/index.wxss
@@ -94,6 +94,26 @@
background: rgba(255, 255, 255, 0.9);
}
+.announcement-strip {
+ height: 58rpx;
+ margin-top: 18rpx;
+ border-radius: 16rpx;
+ background: #fff7ed;
+ border: 1rpx solid #fed7aa;
+ overflow: hidden;
+}
+
+.announcement-item {
+ height: 58rpx;
+ line-height: 58rpx;
+ padding: 0 22rpx;
+ font-size: 24rpx;
+ color: #7c2d12;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+}
+
.banner-badge {
display: inline-flex;
align-items: center;
diff --git a/WeChatProgram/pages/index/index.js b/WeChatProgram/pages/index/index.js
index b2f7b47e..aede9054 100644
--- a/WeChatProgram/pages/index/index.js
+++ b/WeChatProgram/pages/index/index.js
@@ -1,10 +1,18 @@
const auth = require('../../utils/auth')
+/**
+ * index page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: {
navTitle: '游客模式'
},
+ /**
+ * `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onLoad() {
this.syncNavTitle()
wx.switchTab({
@@ -12,10 +20,18 @@ Page({
})
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.syncNavTitle()
},
+ /**
+ * `syncNavTitle` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
syncNavTitle() {
const userInfo = auth.getStoredUserInfo()
const navTitle = userInfo && String(userInfo.shopName || '').trim()
diff --git a/WeChatProgram/pages/notifications/index.js b/WeChatProgram/pages/notifications/index.js
new file mode 100644
index 00000000..1e722332
--- /dev/null
+++ b/WeChatProgram/pages/notifications/index.js
@@ -0,0 +1,117 @@
+const userApi = require('../../api/user')
+const navigation = require('../../utils/navigation')
+
+/**
+ * notifications page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
+Page({
+ data: {
+ loading: false,
+ messages: [],
+ unreadCount: 0,
+ detailVisible: false,
+ currentMessage: null
+ },
+
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ onShow() {
+ this.loadMessages()
+ },
+
+ async loadMessages() {
+ if (!navigation.ensureLogin('查看消息通知')) {
+ return
+ }
+ this.setData({ loading: true })
+ try {
+ const messages = await userApi.listMyMessages()
+ const list = Array.isArray(messages) ? messages : []
+ this.setData({
+ messages: list,
+ unreadCount: list.filter(item => item.readStatus !== 1).length
+ })
+ } catch (error) {
+ wx.showToast({
+ title: error.message || '消息加载失败',
+ icon: 'none'
+ })
+ } finally {
+ this.setData({ loading: false })
+ }
+ },
+
+ async handleOpenMessage(event) {
+ const id = event.currentTarget.dataset.id
+ const item = this.data.messages.find(message => String(message.id) === String(id))
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ if (!item) {
+ return
+ }
+ this.setData({
+ currentMessage: item,
+ detailVisible: true
+ })
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ if (item.readStatus !== 1) {
+ try {
+ await userApi.markMessageRead(item.id)
+ await this.loadMessages()
+ } catch (error) {
+ wx.showToast({
+ title: error.message || '标记已读失败',
+ icon: 'none'
+ })
+ }
+ }
+ },
+
+ /**
+ * `handleCloseDetail` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ handleCloseDetail() {
+ this.setData({
+ detailVisible: false,
+ currentMessage: null
+ })
+ },
+
+ /**
+ * `handlePreviewImage` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ handlePreviewImage() {
+ const imageUrl = this.data.currentMessage && this.data.currentMessage.imageUrl
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ if (!imageUrl) {
+ return
+ }
+ wx.previewImage({
+ current: imageUrl,
+ urls: [imageUrl]
+ })
+ },
+
+ noop() {},
+
+ /**
+ * `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ handleBack() {
+ navigation.goBack('/pages/profile/index')
+ }
+})
diff --git a/WeChatProgram/pages/notifications/index.json b/WeChatProgram/pages/notifications/index.json
new file mode 100644
index 00000000..3e9557e9
--- /dev/null
+++ b/WeChatProgram/pages/notifications/index.json
@@ -0,0 +1,6 @@
+{
+ "navigationStyle": "custom",
+ "usingComponents": {
+ "navigation-bar": "/components/navigation-bar/navigation-bar"
+ }
+}
diff --git a/WeChatProgram/pages/notifications/index.wxml b/WeChatProgram/pages/notifications/index.wxml
new file mode 100644
index 00000000..d6cb98e8
--- /dev/null
+++ b/WeChatProgram/pages/notifications/index.wxml
@@ -0,0 +1,50 @@
+
+
+
+
+ 消息通知
+ {{unreadCount}} 条未读消息
+
+
+
+
+
+
+ {{item.title}}
+ {{item.publisherName || '系统消息'}} · {{item.publishTime || item.createTime}}
+ 含图片
+
+ >
+
+
+
+
+ 暂无消息
+
+
+
+
+
+
+ {{currentMessage.title}}
+ {{currentMessage.publisherName || '系统消息'}} · {{currentMessage.publishTime || currentMessage.createTime}}
+
+
+
+ {{currentMessage.content}}
+
+
+
+
diff --git a/WeChatProgram/pages/notifications/index.wxss b/WeChatProgram/pages/notifications/index.wxss
new file mode 100644
index 00000000..795b482e
--- /dev/null
+++ b/WeChatProgram/pages/notifications/index.wxss
@@ -0,0 +1,152 @@
+.notifications-page {
+ min-height: 100vh;
+ padding: 176rpx 28rpx 40rpx;
+ background: #fff7f8;
+ box-sizing: border-box;
+}
+
+.summary-card,
+.message-item,
+.empty-card {
+ border-radius: 18rpx;
+ background: #ffffff;
+ box-shadow: 0 16rpx 40rpx rgba(150, 82, 105, 0.08);
+}
+
+.summary-card {
+ padding: 34rpx;
+ margin-bottom: 22rpx;
+}
+
+.summary-title {
+ color: #2d2430;
+ font-size: 38rpx;
+ font-weight: 800;
+}
+
+.summary-desc {
+ margin-top: 8rpx;
+ color: #927f88;
+ font-size: 26rpx;
+}
+
+.message-list {
+ display: flex;
+ flex-direction: column;
+ gap: 18rpx;
+}
+
+.message-item {
+ display: flex;
+ align-items: center;
+ gap: 18rpx;
+ padding: 28rpx;
+}
+
+.message-dot {
+ width: 16rpx;
+ height: 16rpx;
+ border-radius: 50%;
+ background: #d7c9cf;
+}
+
+.message-item.unread .message-dot {
+ background: #ff5c8a;
+}
+
+.message-copy {
+ flex: 1;
+ min-width: 0;
+}
+
+.message-title {
+ color: #2d2430;
+ font-size: 30rpx;
+ font-weight: 700;
+}
+
+.message-meta {
+ margin-top: 8rpx;
+ color: #9b8d94;
+ font-size: 24rpx;
+}
+
+.message-badge {
+ display: inline-block;
+ margin-top: 10rpx;
+ padding: 4rpx 16rpx;
+ border-radius: 999rpx;
+ background: #fff0f4;
+ color: #d74270;
+ font-size: 22rpx;
+}
+
+.message-arrow {
+ color: #c3aab4;
+}
+
+.empty-card {
+ padding: 60rpx;
+ color: #9b8d94;
+ text-align: center;
+}
+
+.detail-mask {
+ position: fixed;
+ inset: 0;
+ z-index: 1000;
+ display: flex;
+ align-items: flex-end;
+ background: rgba(26, 18, 24, 0.45);
+}
+
+.detail-panel {
+ width: 100%;
+ max-height: 82vh;
+ padding: 34rpx 30rpx 46rpx;
+ border-radius: 28rpx 28rpx 0 0;
+ background: #fff;
+ box-sizing: border-box;
+ overflow-y: auto;
+}
+
+.detail-header {
+ display: flex;
+ gap: 20rpx;
+ align-items: flex-start;
+ justify-content: space-between;
+}
+
+.detail-title {
+ color: #2d2430;
+ font-size: 34rpx;
+ font-weight: 800;
+}
+
+.detail-meta {
+ margin-top: 8rpx;
+ color: #9b8d94;
+ font-size: 24rpx;
+}
+
+.detail-close {
+ margin: 0;
+ border-radius: 999rpx;
+}
+
+.detail-content {
+ margin-top: 28rpx;
+ color: #4b4048;
+ font-size: 28rpx;
+ line-height: 1.8;
+ white-space: pre-wrap;
+}
+
+.detail-image {
+ width: 100%;
+ min-height: 320rpx;
+ max-height: 760rpx;
+ margin-top: 24rpx;
+ border-radius: 18rpx;
+ background: #fff7f8;
+}
diff --git a/WeChatProgram/pages/orders/index.js b/WeChatProgram/pages/orders/index.js
index 344b0c14..3ae6ebb1 100644
--- a/WeChatProgram/pages/orders/index.js
+++ b/WeChatProgram/pages/orders/index.js
@@ -6,6 +6,10 @@ const { resolveLegacyImage } = require('../../utils/file')
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
+/**
+ * orders page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: {
loading: false,
@@ -13,6 +17,10 @@ Page({
orders: []
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.loadOrders()
},
@@ -24,6 +32,10 @@ Page({
loading: isLoggedIn
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!isLoggedIn) {
this.setData({
orders: [],
@@ -39,6 +51,7 @@ Page({
...order,
statusText: getOrderStatusText(order),
statusClass: getOrderStatusClass(order),
+ shopNameText: order.shopName ? `所属店铺:${order.shopName}` : '',
actualAmountText: `\u00a5${formatPrice(order.actualAmount)}`,
items: await Promise.all((order.items || []).map(async item => ({
...item,
@@ -66,16 +79,28 @@ Page({
}
},
+ /**
+ * `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenAuth() {
navigation.openAuth('/pages/orders/index')
},
+ /**
+ * `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBack() {
navigation.goBack('/pages/profile/index')
},
async handleCancelOrder(event) {
const orderId = event.currentTarget.dataset.orderId
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!orderId) {
return
}
@@ -90,6 +115,10 @@ Page({
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!confirmed) {
return
}
diff --git a/WeChatProgram/pages/orders/index.wxml b/WeChatProgram/pages/orders/index.wxml
index 8e8a3f40..c98ddb71 100644
--- a/WeChatProgram/pages/orders/index.wxml
+++ b/WeChatProgram/pages/orders/index.wxml
@@ -23,6 +23,7 @@
{{item.statusText}}
+ {{item.shopNameText}}
diff --git a/WeChatProgram/pages/orders/index.wxss b/WeChatProgram/pages/orders/index.wxss
index 4b9c630b..20e311a5 100644
--- a/WeChatProgram/pages/orders/index.wxss
+++ b/WeChatProgram/pages/orders/index.wxss
@@ -23,6 +23,13 @@
border-bottom: 2rpx solid #f3e7eb;
}
+.order-shop {
+ margin: 14rpx 0 0;
+ color: #8f6e7a;
+ font-size: 24rpx;
+ line-height: 1.5;
+}
+
.order-head-copy {
flex: 1;
min-width: 0;
diff --git a/WeChatProgram/pages/product-detail/index.js b/WeChatProgram/pages/product-detail/index.js
index 2aab32ec..11647bf9 100644
--- a/WeChatProgram/pages/product-detail/index.js
+++ b/WeChatProgram/pages/product-detail/index.js
@@ -13,11 +13,19 @@ const { formatPrice, getProductTitle, splitCsv } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
function parseTimeRange(businessHours) {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!businessHours) {
return null
}
const matched = String(businessHours).replace(/\s+/g, '').match(/(\d{1,2}:\d{2}).*?(\d{1,2}:\d{2})/)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!matched) {
return null
}
@@ -30,6 +38,10 @@ function parseTimeRange(businessHours) {
function estimateEarliestBookable(businessHours) {
const range = parseTimeRange(businessHours)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!range) {
return businessHours || '以门店安排为准'
}
@@ -43,10 +55,18 @@ function estimateEarliestBookable(businessHours) {
openTime.setHours(startParts[0], startParts[1], 0, 0)
closeTime.setHours(endParts[0], endParts[1], 0, 0)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (next <= openTime) {
return `今天 ${range.start}`
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (next >= closeTime) {
return `明天 ${range.start}`
}
@@ -58,6 +78,10 @@ function estimateEarliestBookable(businessHours) {
return `${month}-${date} ${hour}:${minute}`
}
+/**
+ * product-detail page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: {
loading: true,
@@ -75,6 +99,10 @@ Page({
earliestBookableText: '以门店安排为准'
},
+ /**
+ * `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onLoad(options) {
this.setData({
productId: options && options.id ? options.id : ''
@@ -90,6 +118,10 @@ Page({
async loadProductDetail() {
const productId = this.data.productId
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!productId) {
this.setData({
loading: false,
@@ -148,6 +180,10 @@ Page({
async loadInteractionStatus() {
const product = this.data.product
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!product || !product.id) {
return
}
@@ -166,6 +202,10 @@ Page({
async loadComments() {
const product = this.data.product
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!product || !product.id) {
this.setData({ comments: [] })
return
@@ -180,12 +220,24 @@ Page({
}
},
+ /**
+ * `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBack() {
navigation.goBack('/pages/products/index')
},
+ /**
+ * `handlePreviewImage` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handlePreviewImage(event) {
const current = event.currentTarget.dataset.url
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!current) {
return
}
@@ -196,8 +248,16 @@ Page({
})
},
+ /**
+ * `handleOpenShop` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenShop() {
const shopInfo = this.data.shopInfo
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!shopInfo || !shopInfo.id) {
return
}
@@ -217,6 +277,10 @@ Page({
try {
await actionGuard.run(this, `wishlist:toggle:${product.id}`, async () => {
const nextFavorite = !this.data.isFavorite
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.isFavorite) {
await runWithLoading(() => wishlistApi.removeFromWishlist(product.id))
product.collectCount = Math.max(0, Number(product.collectCount || 0) - 1)
@@ -257,6 +321,10 @@ Page({
try {
await actionGuard.run(this, `like:toggle:${product.id}`, async () => {
const nextLiked = !this.data.isLiked
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.isLiked) {
await runWithLoading(() => productLikeApi.unlikeProduct(product.id))
product.likeCount = Math.max(0, Number(product.likeCount || 0) - 1)
@@ -346,12 +414,20 @@ Page({
}
,
+ /**
+ * `handleCommentInput` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleCommentInput(event) {
this.setData({
commentText: event.detail.value
})
},
+ /**
+ * `handleReply` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleReply(event) {
const comment = event.currentTarget.dataset.comment
this.setData({
@@ -365,6 +441,10 @@ Page({
if (!product || !product.id || !navigation.ensureLogin('发表评论')) {
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!content) {
wx.showToast({ title: '请输入评论内容', icon: 'none' })
return
diff --git a/WeChatProgram/pages/products/index.js b/WeChatProgram/pages/products/index.js
index cadf1b1f..a56baf90 100644
--- a/WeChatProgram/pages/products/index.js
+++ b/WeChatProgram/pages/products/index.js
@@ -21,6 +21,10 @@ const ALL_CATEGORY = '\u5168\u90e8'
const FILTER_BUSY_MESSAGE = '\u7b5b\u9009\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
const CART_BUSY_MESSAGE = '\u8d2d\u7269\u8f66\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
+/**
+ * products page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 96
@@ -39,6 +43,10 @@ Page({
hasMore: false
}),
+ /**
+ * `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onLoad(options) {
this.filterRequestId = 0
this.ensureKeyboardSafe()
@@ -51,6 +59,10 @@ Page({
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
if (this.data.initialized && pendingFilter && (pendingFilter.keyword || pendingFilter.tag)) {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (app && app.globalData) {
app.globalData.pendingProductFilter = null
}
@@ -58,16 +70,28 @@ Page({
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.initialized) {
await this.syncProductCartState()
}
},
+ /**
+ * `onHide` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
+ /**
+ * `onUnload` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
@@ -78,13 +102,25 @@ Page({
wx.stopPullDownRefresh()
},
+ /**
+ * `onReachBottom` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onReachBottom() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.hasMore || this.data.loadingMore) {
return
}
this.loadProducts(false)
},
+ /**
+ * `ensureKeyboardSafe` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 96,
@@ -127,6 +163,10 @@ Page({
const app = getApp()
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
if (pendingFilter && (pendingFilter.keyword || pendingFilter.tag)) {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (app && app.globalData) {
app.globalData.pendingProductFilter = null
}
@@ -169,6 +209,10 @@ Page({
})
const cards = await buildProductCards(result && result.list ? result.list : [])
const displayCards = await this.attachCartState(cards)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (requestId !== this.filterRequestId) {
return
}
@@ -183,9 +227,17 @@ Page({
filterSummaryText: this.buildFilterSummary(keyword, tag, total)
})
} catch (error) {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (requestId !== this.filterRequestId) {
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (reset) {
this.setData({
products: [],
@@ -199,6 +251,10 @@ Page({
icon: 'none'
})
} finally {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (requestId === this.filterRequestId) {
this.setData({
loading: false,
@@ -208,11 +264,23 @@ Page({
}
},
+ /**
+ * `buildFilterSummary` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
buildFilterSummary(keyword, tag, total) {
const chips = []
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (tag) {
chips.push(tag)
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (keyword) {
chips.push(`\u641c\u7d22\uff1a${keyword}`)
}
@@ -220,6 +288,10 @@ Page({
return chips.join(' \u00b7 ')
},
+ /**
+ * `normalizeId` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
},
@@ -250,6 +322,10 @@ Page({
return this.markCardsInCart(cards, idSet)
},
+ /**
+ * `markCardsInCart` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
markCardsInCart(cards, idSet) {
const productIdSet = idSet || new Set()
return (Array.isArray(cards) ? cards : []).map(item => ({
@@ -265,8 +341,16 @@ Page({
})
},
+ /**
+ * `markProductInCart` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
markProductInCart(productId) {
const normalizedId = this.normalizeId(productId)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!normalizedId) {
return
}
@@ -286,16 +370,28 @@ Page({
})
},
+ /**
+ * `handleSearchInput` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSearchInput(event) {
this.setData({
searchKeyword: event.detail.value
})
},
+ /**
+ * `handleSearchFocus` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSearchFocus(event) {
handleKeyboardFocus(this, event)
},
+ /**
+ * `handleSearchBlur` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleSearchBlur() {
handleKeyboardBlur(this)
},
@@ -372,8 +468,16 @@ Page({
}
},
+ /**
+ * `handleProductSelect` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleProductSelect(event) {
const product = event.detail || {}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!product.id) {
return
}
@@ -386,6 +490,10 @@ Page({
async handleQuickAdd(event) {
const product = event.detail || {}
const productId = this.normalizeId(product.id)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!productId) {
return
}
diff --git a/WeChatProgram/pages/profile/index.js b/WeChatProgram/pages/profile/index.js
index c367b9a9..0abfdeeb 100644
--- a/WeChatProgram/pages/profile/index.js
+++ b/WeChatProgram/pages/profile/index.js
@@ -9,6 +9,10 @@ const navigation = require('../../utils/navigation')
const { DEFAULT_AVATAR } = require('../../utils/config')
const { runWithLoading } = require('../../utils/loading')
+/**
+ * profile page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: {
isLoggedIn: false,
@@ -18,9 +22,14 @@ Page({
orderCount: 0,
couponCount: 0,
wishlistCount: 0,
+ unreadMessageCount: 0,
defaultAvatar: DEFAULT_AVATAR
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.loadProfile()
},
@@ -34,6 +43,10 @@ Page({
loading: isLoggedIn
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!isLoggedIn) {
this.setData({
userInfo: null,
@@ -46,11 +59,12 @@ Page({
}
try {
- const [userInfo, orders, coupons, wishlist] = await Promise.all([
+ const [userInfo, orders, coupons, wishlist, unreadMessages] = await Promise.all([
userApi.getUserInfo(),
orderApi.getOrderList(),
couponApi.listUserCoupons(),
- wishlistApi.getWishlist()
+ wishlistApi.getWishlist(),
+ userApi.getMyUnreadMessageCount()
])
getApp().refreshUserInfo(userInfo)
@@ -58,8 +72,10 @@ Page({
userInfo,
orderCount: Array.isArray(orders) ? orders.length : 0,
couponCount: Array.isArray(coupons) ? coupons.length : 0,
- wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0
+ wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0,
+ unreadMessageCount: Number((unreadMessages && unreadMessages.unreadCount) || 0)
})
+ await this.checkPopupMessages()
} catch (error) {
wx.showToast({
title: error.message || '\u4e2a\u4eba\u4e2d\u5fc3\u52a0\u8f7d\u5931\u8d25',
@@ -72,11 +88,23 @@ Page({
}
},
+ /**
+ * `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenAuth() {
navigation.openAuth('/pages/profile/index')
},
+ /**
+ * `handleOpenSettings` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenSettings() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.isLoggedIn) {
this.handleOpenAuth()
return
@@ -84,6 +112,10 @@ Page({
navigation.navigate('/pages/settings/index')
},
+ /**
+ * `handleOpenOrders` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenOrders() {
if (!navigation.ensureLogin('\u67e5\u770b\u8ba2\u5355')) {
return
@@ -91,6 +123,10 @@ Page({
navigation.navigate('/pages/orders/index')
},
+ /**
+ * `handleOpenWishlist` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenWishlist() {
if (!navigation.ensureLogin('\u67e5\u770b\u6536\u85cf')) {
return
@@ -98,6 +134,10 @@ Page({
navigation.navigate('/pages/wishlist/index')
},
+ /**
+ * `handleOpenCoupons` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenCoupons() {
if (!navigation.ensureLogin('\u67e5\u770b\u4f18\u60e0\u5238')) {
return
@@ -105,6 +145,62 @@ Page({
navigation.navigate('/pages/coupons/index')
},
+ /**
+ * `handleOpenVipCenter` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ handleOpenVipCenter() {
+ if (!navigation.ensureLogin('查看 VIP 中心')) {
+ return
+ }
+ navigation.navigate('/pages/vip-center/index')
+ },
+
+ /**
+ * `handleOpenNotifications` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ handleOpenNotifications() {
+ if (!navigation.ensureLogin('查看消息通知')) {
+ return
+ }
+ navigation.navigate('/pages/notifications/index')
+ },
+
+ async checkPopupMessages() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ if (this._checkingPopupMessages) {
+ return
+ }
+ this._checkingPopupMessages = true
+ try {
+ const messages = await userApi.listMyPopupMessages()
+ /**
+ * `for` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ for (const item of messages || []) {
+ await new Promise(resolve => {
+ wx.showModal({
+ title: item.title || '消息通知',
+ content: item.content || '',
+ showCancel: false,
+ confirmText: '我知道了',
+ complete: resolve
+ })
+ })
+ await userApi.markMessagePopupShown(item.id)
+ }
+ } catch (error) {
+ console.error('加载待弹窗消息失败', error)
+ } finally {
+ this._checkingPopupMessages = false
+ }
+ },
+
async handleSwitchShop() {
if (!navigation.ensureLogin('\u5207\u6362\u95e8\u5e97')) {
return
@@ -114,6 +210,10 @@ Page({
const shopIds = userInfo && Array.isArray(userInfo.shopIds) ? userInfo.shopIds : []
const shopNames = userInfo && Array.isArray(userInfo.shopNames) ? userInfo.shopNames : []
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!shopIds.length) {
wx.showToast({
title: '\u5f53\u524d\u8d26\u53f7\u8fd8\u6ca1\u6709\u53ef\u7528\u95e8\u5e97',
@@ -122,6 +222,10 @@ Page({
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (shopIds.length === 1) {
navigation.navigate('/pages/shop-detail/index', {
id: shopIds[0],
@@ -140,6 +244,10 @@ Page({
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (selection < 0 || selection >= shopIds.length) {
return
}
@@ -168,6 +276,10 @@ Page({
},
async handleLogout() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.isLoggedIn) {
this.handleOpenAuth()
return
@@ -183,6 +295,10 @@ Page({
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!confirmed) {
return
}
@@ -209,10 +325,18 @@ Page({
async handleAvatarError() {
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!currentAvatar) {
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this._avatarReloadSource === currentAvatar) {
this.setData({
'userInfo.avatar': ''
@@ -225,6 +349,10 @@ Page({
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
this.setData({
'userInfo.avatar': ''
diff --git a/WeChatProgram/pages/profile/index.wxml b/WeChatProgram/pages/profile/index.wxml
index 9c7fd8ab..c702cad6 100644
--- a/WeChatProgram/pages/profile/index.wxml
+++ b/WeChatProgram/pages/profile/index.wxml
@@ -67,6 +67,15 @@
我的优惠券>
+
+ VIP 中心
+ >
+
+
+ 消息通知
+ {{unreadMessageCount}}
+ >
+ 设置中心>
diff --git a/WeChatProgram/pages/profile/index.wxss b/WeChatProgram/pages/profile/index.wxss
index 1489bc7f..2fa97750 100644
--- a/WeChatProgram/pages/profile/index.wxss
+++ b/WeChatProgram/pages/profile/index.wxss
@@ -161,6 +161,23 @@
color: #c3aab4;
}
+.menu-badge {
+ margin-left: auto;
+ min-width: 36rpx;
+ height: 36rpx;
+ padding: 0 10rpx;
+ border-radius: 18rpx;
+ background: #ff5c8a;
+ color: #ffffff;
+ font-size: 22rpx;
+ line-height: 36rpx;
+ text-align: center;
+}
+
+.menu-badge + .menu-arrow {
+ margin-left: 16rpx;
+}
+
.logout-item {
color: #d5536f;
font-weight: 700;
diff --git a/WeChatProgram/pages/settings/index.js b/WeChatProgram/pages/settings/index.js
index 4615e5f4..f0262081 100644
--- a/WeChatProgram/pages/settings/index.js
+++ b/WeChatProgram/pages/settings/index.js
@@ -18,6 +18,10 @@ const phoneRegex = /^1[3-9]\d{9}$/
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
const SETTINGS_DRAFT_KEY = 'user-settings'
+/**
+ * settings page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 108
@@ -53,15 +57,27 @@ Page({
}
}),
+ /**
+ * `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onLoad() {
this.ensureKeyboardSafe()
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.ensureKeyboardSafe()
this.loadSettings()
},
+ /**
+ * `onHide` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
@@ -69,6 +85,10 @@ Page({
clearDraftTimer(this)
},
+ /**
+ * `onUnload` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
@@ -76,6 +96,10 @@ Page({
clearDraftTimer(this)
},
+ /**
+ * `ensureKeyboardSafe` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 108,
@@ -83,21 +107,41 @@ Page({
})
},
+ /**
+ * `handleKeyboardFocus` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleKeyboardFocus(event) {
handleKeyboardFocus(this, event)
},
+ /**
+ * `handleKeyboardBlur` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleKeyboardBlur() {
handleKeyboardBlur(this)
},
+ /**
+ * `clearCountdown` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
clearCountdown() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.countdownTimer) {
clearInterval(this.countdownTimer)
this.countdownTimer = null
}
},
+ /**
+ * `resetSecurityForms` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
resetSecurityForms() {
this.setData({
bindPhoneForm: {
@@ -116,8 +160,16 @@ Page({
})
},
+ /**
+ * `restoreDraftValues` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
restoreDraftValues() {
const draft = getDraftValue(SETTINGS_DRAFT_KEY, null)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!draft || typeof draft !== 'object') {
return
}
@@ -131,6 +183,10 @@ Page({
})
},
+ /**
+ * `scheduleSettingsDraft` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
scheduleSettingsDraft() {
scheduleDraftSave(this, SETTINGS_DRAFT_KEY, () => ({
activeSecurityPanel: this.data.activeSecurityPanel,
@@ -147,6 +203,10 @@ Page({
}))
},
+ /**
+ * `startCountdown` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
startCountdown() {
this.clearCountdown()
this.setData({
@@ -155,6 +215,10 @@ Page({
this.countdownTimer = setInterval(() => {
const next = this.data.countdown - 1
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (next <= 0) {
this.clearCountdown()
this.setData({
@@ -177,6 +241,10 @@ Page({
loading: isLoggedIn
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!isLoggedIn) {
this.clearCountdown()
this.setData({
@@ -209,14 +277,26 @@ Page({
}
},
+ /**
+ * `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBack() {
navigation.goBack('/pages/profile/index')
},
+ /**
+ * `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenAuth() {
navigation.openAuth('/pages/settings/index')
},
+ /**
+ * `handleFormInput` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleFormInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
@@ -225,26 +305,46 @@ Page({
this.scheduleSettingsDraft()
},
+ /**
+ * `handleBindPhoneInput` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBindPhoneInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`bindPhoneForm.${field}`]: event.detail.value
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (field === 'phone') {
this.scheduleSettingsDraft()
}
},
+ /**
+ * `handleChangePhoneInput` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleChangePhoneInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`changePhoneForm.${field}`]: event.detail.value
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (field === 'newPhone') {
this.scheduleSettingsDraft()
}
},
+ /**
+ * `handlePasswordInput` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handlePasswordInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
@@ -252,6 +352,10 @@ Page({
})
},
+ /**
+ * `handleToggleSecurityPanel` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleToggleSecurityPanel(event) {
const panel = event.currentTarget.dataset.panel
const nextPanel = this.data.activeSecurityPanel === panel ? '' : panel
@@ -265,6 +369,10 @@ Page({
this.scheduleSettingsDraft()
},
+ /**
+ * `handleCloseSecurityPanel` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleCloseSecurityPanel() {
resetKeyboardSafe(this)
this.resetSecurityForms()
@@ -312,7 +420,15 @@ Page({
}
},
+ /**
+ * `handleChooseAvatar` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleChooseAvatar() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.uploadingAvatar) {
return
}
@@ -323,6 +439,10 @@ Page({
sourceType: ['album', 'camera'],
success: async res => {
const filePath = Array.isArray(res.tempFilePaths) ? res.tempFilePaths[0] : ''
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!filePath) {
return
}
@@ -353,6 +473,10 @@ Page({
},
async handleDeleteAvatar() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.userInfo || !this.data.userInfo.avatar) {
return
}
@@ -365,6 +489,10 @@ Page({
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!confirmed) {
return
}
@@ -395,6 +523,10 @@ Page({
const shopIds = userInfo && Array.isArray(userInfo.shopIds) ? userInfo.shopIds : []
const shopNames = userInfo && Array.isArray(userInfo.shopNames) ? userInfo.shopNames : []
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!shopIds.length) {
wx.showToast({
title: '当前账号还没有可用门店',
@@ -403,6 +535,10 @@ Page({
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (shopIds.length === 1) {
navigation.navigate('/pages/shop-detail/index', {
id: shopIds[0],
@@ -419,6 +555,10 @@ Page({
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (selection < 0 || selection >= shopIds.length) {
return
}
@@ -442,6 +582,10 @@ Page({
},
async handleSendBindPhoneCode() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.countdown > 0) {
return
}
@@ -456,7 +600,10 @@ Page({
}
try {
- await runWithLoading(() => userApi.sendVerificationCode({ phone }))
+ await runWithLoading(() => userApi.sendVerificationCode({
+ phone,
+ sceneCode: 'USER_BIND_PHONE_SMS_CODE'
+ }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -482,6 +629,10 @@ Page({
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
@@ -519,6 +670,10 @@ Page({
},
async handleSendChangePhoneCode() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.countdown > 0) {
return
}
@@ -533,7 +688,10 @@ Page({
}
try {
- await runWithLoading(() => userApi.sendVerificationCode({ phone: newPhone }))
+ await runWithLoading(() => userApi.sendVerificationCode({
+ phone: newPhone,
+ sceneCode: 'USER_CHANGE_PHONE_SMS_CODE'
+ }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -553,6 +711,10 @@ Page({
const newPhone = String(this.data.changePhoneForm.newPhone || '').trim()
const verificationCode = String(this.data.changePhoneForm.verificationCode || '').trim()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!oldPhone) {
wx.showToast({
title: '请先绑定手机号',
@@ -569,6 +731,10 @@ Page({
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
@@ -607,12 +773,20 @@ Page({
},
async handleSendPasswordCode() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.countdown > 0) {
return
}
const userInfo = this.data.userInfo || {}
const phone = String(userInfo.phone || '').trim()
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!phone) {
wx.showToast({
title: '请先绑定手机号',
@@ -622,7 +796,10 @@ Page({
}
try {
- await runWithLoading(() => authApi.sendVerificationCode({ phone }))
+ await runWithLoading(() => authApi.sendVerificationCode({
+ phone,
+ sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
+ }))
wx.showToast({
title: '验证码已发送',
icon: 'none'
@@ -642,6 +819,10 @@ Page({
const confirmPassword = String(this.data.passwordForm.confirmPassword || '')
const userInfo = this.data.userInfo || {}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!userInfo.phone) {
wx.showToast({
title: '请先绑定手机号',
@@ -650,6 +831,10 @@ Page({
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!verificationCode) {
wx.showToast({
title: '请输入验证码',
@@ -666,6 +851,10 @@ Page({
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (password !== confirmPassword) {
wx.showToast({
title: '两次输入的密码不一致',
@@ -704,6 +893,10 @@ Page({
},
async handleDeactivateAccount() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this.data.deactivating) {
return
}
@@ -717,6 +910,10 @@ Page({
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!confirmed) {
return
}
@@ -757,6 +954,10 @@ Page({
})
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!confirmed) {
return
}
@@ -778,10 +979,18 @@ Page({
async handleAvatarError() {
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!currentAvatar) {
return
}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (this._avatarReloadSource === currentAvatar) {
this.setData({
'userInfo.avatar': ''
@@ -794,6 +1003,10 @@ Page({
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
this.setData({
'userInfo.avatar': ''
diff --git a/WeChatProgram/pages/shop-detail/index.js b/WeChatProgram/pages/shop-detail/index.js
index 3fdb1398..0f9b572e 100644
--- a/WeChatProgram/pages/shop-detail/index.js
+++ b/WeChatProgram/pages/shop-detail/index.js
@@ -3,6 +3,10 @@ const navigation = require('../../utils/navigation')
const { resolveImageList } = require('../../utils/file')
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
+/**
+ * shop-detail page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: {
loading: true,
@@ -10,9 +14,14 @@ Page({
shopId: '',
returnTo: '/pages/home/index',
shopInfo: null,
+ distanceText: '',
shopImages: []
},
+ /**
+ * `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onLoad(options) {
this.setData({
shopId: options && options.id ? options.id : '',
@@ -27,6 +36,10 @@ Page({
},
async loadShopDetail() {
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!this.data.shopId) {
this.setData({
loading: false,
@@ -45,8 +58,10 @@ Page({
const shopImages = await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE)
this.setData({
shopInfo,
- shopImages
+ shopImages,
+ distanceText: ''
})
+ this.loadCurrentDistance()
} catch (error) {
this.setData({
loadError: error.message || '门店详情加载失败'
@@ -58,12 +73,24 @@ Page({
}
},
+ /**
+ * `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBack() {
navigation.goBack(this.data.returnTo || '/pages/home/index')
},
+ /**
+ * `handlePreviewImage` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handlePreviewImage(event) {
const url = event.currentTarget.dataset.url
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!url) {
return
}
@@ -74,8 +101,16 @@ Page({
})
},
+ /**
+ * `handleCopyName` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleCopyName() {
const shopInfo = this.data.shopInfo
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!shopInfo || !shopInfo.shopName) {
return
}
@@ -85,8 +120,16 @@ Page({
})
},
+ /**
+ * `handleCopyAddress` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleCopyAddress() {
const shopInfo = this.data.shopInfo
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!shopInfo || !shopInfo.address) {
return
}
@@ -94,5 +137,73 @@ Page({
wx.setClipboardData({
data: shopInfo.address
})
+ },
+
+ handleOpenLocation() {
+ const shopInfo = this.data.shopInfo
+ if (!shopInfo || !shopInfo.latitude || !shopInfo.longitude) {
+ wx.showToast({
+ title: '店铺暂未设置地图位置',
+ icon: 'none'
+ })
+ return
+ }
+
+ wx.openLocation({
+ latitude: Number(shopInfo.latitude),
+ longitude: Number(shopInfo.longitude),
+ name: shopInfo.shopName || '店铺位置',
+ address: shopInfo.address || '',
+ scale: 16
+ })
+ },
+
+ handleOpenAmapNavigation() {
+ const shopInfo = this.data.shopInfo
+ const amapUrl = shopInfo && shopInfo.navigationUrls && shopInfo.navigationUrls.AMAP
+ if (!amapUrl) {
+ wx.showToast({
+ title: '店铺暂未设置地图位置',
+ icon: 'none'
+ })
+ return
+ }
+ wx.setClipboardData({
+ data: amapUrl,
+ success: () => {
+ wx.showToast({
+ title: '高德导航链接已复制',
+ icon: 'none'
+ })
+ }
+ })
+ },
+
+ loadCurrentDistance() {
+ const shopInfo = this.data.shopInfo
+ if (!shopInfo || !shopInfo.latitude || !shopInfo.longitude || typeof wx.getLocation !== 'function') {
+ return
+ }
+ wx.getLocation({
+ type: 'gcj02',
+ success: (res) => {
+ this.setData({
+ distanceText: this.formatDistance(res.latitude, res.longitude, Number(shopInfo.latitude), Number(shopInfo.longitude))
+ })
+ }
+ })
+ },
+
+ formatDistance(currentLat, currentLng, shopLat, shopLng) {
+ if (![currentLat, currentLng, shopLat, shopLng].every(Number.isFinite)) {
+ return ''
+ }
+ const toRad = value => value * Math.PI / 180
+ const earthRadius = 6371000
+ const dLat = toRad(shopLat - currentLat)
+ const dLng = toRad(shopLng - currentLng)
+ const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(currentLat)) * Math.cos(toRad(shopLat)) * Math.sin(dLng / 2) ** 2
+ const meters = 2 * earthRadius * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
+ return meters >= 1000 ? `距你约 ${(meters / 1000).toFixed(1)} km` : `距你约 ${Math.round(meters)} m`
}
})
diff --git a/WeChatProgram/pages/shop-detail/index.wxml b/WeChatProgram/pages/shop-detail/index.wxml
index 9d49dd29..a4a5e1ee 100644
--- a/WeChatProgram/pages/shop-detail/index.wxml
+++ b/WeChatProgram/pages/shop-detail/index.wxml
@@ -19,6 +19,7 @@
门店详情{{shopInfo.shopName}}{{shopInfo.address || '门店地址待补充'}}
+ {{distanceText}}
@@ -47,6 +48,11 @@
复制门店名复制地址
+
+
+ 查看地图位置
+ 复制高德导航链接
+
diff --git a/WeChatProgram/pages/shop-detail/index.wxss b/WeChatProgram/pages/shop-detail/index.wxss
index 56baa0b3..257a55a0 100644
--- a/WeChatProgram/pages/shop-detail/index.wxss
+++ b/WeChatProgram/pages/shop-detail/index.wxss
@@ -46,6 +46,13 @@
line-height: 1.7;
}
+.shop-distance {
+ margin-top: 8rpx;
+ color: #8f6e7a;
+ font-size: 24rpx;
+ line-height: 1.5;
+}
+
.shop-summary {
margin-top: 24rpx;
}
@@ -77,6 +84,17 @@
margin-top: 26rpx;
}
+.map-row {
+ display: grid;
+ grid-template-columns: 1fr;
+ gap: 16rpx;
+ margin-top: 18rpx;
+}
+
+.map-btn {
+ width: 100%;
+}
+
.gallery-list {
display: flex;
flex-wrap: wrap;
diff --git a/WeChatProgram/pages/vip-center/index.js b/WeChatProgram/pages/vip-center/index.js
new file mode 100644
index 00000000..2e268344
--- /dev/null
+++ b/WeChatProgram/pages/vip-center/index.js
@@ -0,0 +1,114 @@
+const userApi = require('../../api/user')
+const navigation = require('../../utils/navigation')
+
+function money(value) {
+ return Number(value || 0).toFixed(2)
+}
+
+function formatTime(value) {
+ return value ? String(value).replace('T', ' ').slice(0, 16) : '--'
+}
+
+function sceneText(scene) {
+ const map = {
+ MANUAL_RECHARGE: '手工充值',
+ MANUAL_DEDUCT: '手工扣减',
+ ORDER_PAY: '订单消费',
+ ORDER_REFUND: '订单退款',
+ RECHARGE: '充值',
+ CONSUME: '消费'
+ }
+ return map[scene] || scene || '余额变动'
+}
+
+/**
+ * vip-center page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
+Page({
+ data: {
+ asset: {
+ vipLevel: '普通',
+ balanceText: '0.00',
+ totalRechargeText: '0.00',
+ lastRechargeText: '--',
+ vipStartText: '--',
+ manualOverride: false
+ },
+ history: [],
+ rechargePlans: [],
+ rechargePanelVisible: false
+ },
+
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ onShow() {
+ if (!navigation.ensureLogin('查看 VIP 中心')) {
+ return
+ }
+ this.loadData()
+ },
+
+ async loadData() {
+ try {
+ const [asset, history, plans] = await Promise.all([
+ userApi.getMyAsset(),
+ userApi.getMyBalanceHistory(),
+ userApi.listMyVipRechargePlans().catch(() => [])
+ ])
+ this.setData({
+ asset: {
+ ...asset,
+ balanceText: money(asset && asset.balance),
+ totalRechargeText: money(asset && asset.totalRechargeAmount),
+ lastRechargeText: formatTime(asset && asset.lastRechargeTime),
+ vipStartText: formatTime(asset && asset.vipStartTime)
+ },
+ history: (Array.isArray(history) ? history : []).map(item => {
+ const amountNumber = Number(item.amount || 0)
+ return {
+ ...item,
+ amountNumber,
+ amountText: `${amountNumber > 0 ? '+' : ''}¥${money(amountNumber)}`,
+ sceneText: sceneText(item.changeScene || item.type),
+ changeTimeText: formatTime(item.changeTime)
+ }
+ }),
+ rechargePlans: (Array.isArray(plans) ? plans : []).map(item => ({
+ ...item,
+ amountText: `充 ${money(item.rechargeAmount)} 送 ${money(item.giftAmount)}`
+ }))
+ })
+ } catch (error) {
+ wx.showToast({
+ title: error.message || 'VIP 信息加载失败',
+ icon: 'none'
+ })
+ }
+ },
+
+ /**
+ * `openRechargePanel` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ openRechargePanel() {
+ this.setData({ rechargePanelVisible: true })
+ },
+
+ /**
+ * `closeRechargePanel` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ closeRechargePanel() {
+ this.setData({ rechargePanelVisible: false })
+ },
+
+ /**
+ * `noop` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
+ noop() {
+ }
+})
diff --git a/WeChatProgram/pages/vip-center/index.json b/WeChatProgram/pages/vip-center/index.json
new file mode 100644
index 00000000..8632c9b0
--- /dev/null
+++ b/WeChatProgram/pages/vip-center/index.json
@@ -0,0 +1,5 @@
+{
+ "usingComponents": {
+ "navigation-bar": "/components/navigation-bar/navigation-bar"
+ }
+}
diff --git a/WeChatProgram/pages/vip-center/index.wxml b/WeChatProgram/pages/vip-center/index.wxml
new file mode 100644
index 00000000..1d8189d6
--- /dev/null
+++ b/WeChatProgram/pages/vip-center/index.wxml
@@ -0,0 +1,61 @@
+
+
+
+ 会员等级
+ {{asset.vipLevel || '普通'}}
+ {{asset.benefitInfo || '暂无额外权益说明'}}
+
+
+
+
+ 余额
+ ¥{{asset.balanceText}}
+
+
+ 累计充值
+ ¥{{asset.totalRechargeText}}
+
+
+
+ 去充值 / 查看充值说明
+
+
+ 会员信息
+ 最近充值{{asset.lastRechargeText}}
+ 生效时间{{asset.vipStartText}}
+ 等级来源{{asset.manualOverride ? '后台指定' : '自动计算'}}
+
+
+
+ 余额变动
+
+
+
+ {{item.sceneText}}
+ {{item.changeTimeText}}
+ {{item.remark}}
+
+ {{item.amountText}}
+
+
+ 暂无余额变动
+
+
+
+
+ 充值档位展示
+
+
+
+ {{item.title}}
+ {{item.vipLevel}}
+
+ {{item.amountText}}
+ {{item.description || '该档位仅展示,暂不发起支付。'}}
+
+
+ 暂无可展示充值档位
+ 关闭
+
+
+
diff --git a/WeChatProgram/pages/vip-center/index.wxss b/WeChatProgram/pages/vip-center/index.wxss
new file mode 100644
index 00000000..591d049b
--- /dev/null
+++ b/WeChatProgram/pages/vip-center/index.wxss
@@ -0,0 +1,162 @@
+.vip-page {
+ min-height: 100vh;
+ padding: 24rpx;
+ background: #f7f4f1;
+ box-sizing: border-box;
+}
+
+.vip-hero {
+ display: flex;
+ flex-direction: column;
+ gap: 10rpx;
+ padding: 36rpx;
+ border-radius: 16rpx;
+ color: #fff;
+ background: linear-gradient(135deg, #2b2522, #8a704e);
+}
+
+.vip-kicker, .vip-benefit {
+ color: rgba(255,255,255,.76);
+ font-size: 24rpx;
+}
+
+.vip-level {
+ font-size: 56rpx;
+ font-weight: 700;
+}
+
+.metric-grid {
+ display: grid;
+ grid-template-columns: 1fr 1fr;
+ gap: 16rpx;
+ margin-top: 20rpx;
+}
+
+.metric, .section {
+ padding: 28rpx;
+ border-radius: 16rpx;
+ background: #fff;
+}
+
+.metric {
+ display: flex;
+ flex-direction: column;
+ gap: 10rpx;
+ color: #7f7470;
+}
+
+.metric-value {
+ color: #2d2927;
+ font-size: 36rpx;
+ font-weight: 700;
+}
+
+.section {
+ margin-top: 20rpx;
+}
+
+.section-title {
+ margin-bottom: 20rpx;
+ color: #2d2927;
+ font-size: 32rpx;
+ font-weight: 700;
+}
+
+.info-row, .history-row {
+ display: flex;
+ justify-content: space-between;
+ gap: 20rpx;
+ padding: 18rpx 0;
+ border-bottom: 1rpx solid #f0ece8;
+}
+
+.info-row:last-child, .history-row:last-child {
+ border-bottom: 0;
+}
+
+.history-title, .history-time, .history-remark {
+ display: block;
+}
+
+.history-title {
+ color: #2d2927;
+ font-weight: 600;
+}
+
+.history-time, .history-remark, .empty {
+ margin-top: 6rpx;
+ color: #9a918d;
+ font-size: 24rpx;
+}
+
+.history-amount {
+ color: #2d2927;
+ font-weight: 700;
+ white-space: nowrap;
+}
+
+.history-amount.income {
+ color: #0f8f63;
+}
+
+.recharge-entry {
+ margin-top: 20rpx;
+ padding: 20rpx;
+ border-radius: 16rpx;
+ background: #fff7ed;
+ color: #9a5b2e;
+ font-weight: 700;
+ text-align: center;
+}
+
+.recharge-mask {
+ position: fixed;
+ inset: 0;
+ background: rgba(0, 0, 0, 0.4);
+ z-index: 30;
+ display: flex;
+ align-items: flex-end;
+}
+
+.recharge-panel {
+ width: 100%;
+ max-height: 75vh;
+ overflow: auto;
+ border-radius: 24rpx 24rpx 0 0;
+ background: #fff;
+ padding: 24rpx;
+}
+
+.recharge-plan {
+ padding: 18rpx 0;
+ border-bottom: 1rpx solid #f0ece8;
+}
+
+.plan-head {
+ display: flex;
+ justify-content: space-between;
+ gap: 18rpx;
+ color: #2d2927;
+ font-weight: 700;
+}
+
+.plan-amount {
+ display: block;
+ margin-top: 10rpx;
+ color: #9a5b2e;
+}
+
+.plan-desc {
+ display: block;
+ margin-top: 6rpx;
+ color: #9a918d;
+ font-size: 24rpx;
+}
+
+.recharge-close {
+ margin-top: 18rpx;
+ padding: 18rpx;
+ border-radius: 16rpx;
+ background: #f4f0eb;
+ text-align: center;
+}
diff --git a/WeChatProgram/pages/wishlist/index.js b/WeChatProgram/pages/wishlist/index.js
index 18b7a546..ab9a56ff 100644
--- a/WeChatProgram/pages/wishlist/index.js
+++ b/WeChatProgram/pages/wishlist/index.js
@@ -6,6 +6,10 @@ const navigation = require('../../utils/navigation')
const { buildProductCard } = require('../../utils/product')
const { runWithLoading } = require('../../utils/loading')
+/**
+ * wishlist page logic.
+ * Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
+ */
Page({
data: {
loading: false,
@@ -13,6 +17,10 @@ Page({
wishlist: []
},
+ /**
+ * `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
onShow() {
this.loadWishlist()
},
@@ -24,6 +32,10 @@ Page({
loading: isLoggedIn
})
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!isLoggedIn) {
this.cartProductIdSet = new Set()
this.setData({
@@ -63,6 +75,10 @@ Page({
}
},
+ /**
+ * `normalizeId` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
},
@@ -83,6 +99,10 @@ Page({
}
},
+ /**
+ * `markCardInCart` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
markCardInCart(card, idSet) {
return {
...card,
@@ -90,8 +110,16 @@ Page({
}
},
+ /**
+ * `markWishlistProductInCart` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
markWishlistProductInCart(productId) {
const normalizedId = this.normalizeId(productId)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!normalizedId) {
return
}
@@ -114,12 +142,24 @@ Page({
})
},
+ /**
+ * `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleOpenAuth() {
navigation.openAuth('/pages/wishlist/index')
},
+ /**
+ * `handleProductSelect` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleProductSelect(event) {
const product = event.detail || {}
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!product.id) {
return
}
@@ -132,6 +172,10 @@ Page({
async handleQuickAdd(event) {
const product = event.detail || {}
const productId = this.normalizeId(product.id)
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!productId) {
return
}
@@ -174,6 +218,10 @@ Page({
async handleRemove(event) {
const productId = event.currentTarget.dataset.productId
+ /**
+ * `if` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
if (!productId) {
return
}
@@ -198,6 +246,10 @@ Page({
}
},
+ /**
+ * `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
+ * Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
+ */
handleBack() {
navigation.goBack('/pages/profile/index')
}
diff --git a/WeChatProgram/utils/product.js b/WeChatProgram/utils/product.js
index 6a76ff20..124b9554 100644
--- a/WeChatProgram/utils/product.js
+++ b/WeChatProgram/utils/product.js
@@ -19,7 +19,8 @@ async function buildProductCard(product) {
...product,
displayTitle: getProductTitle(product),
priceText: `¥${formatPrice(product && product.price)}`,
- metaText: (product && (product.approximateDuration || product.shopName)) || '支持预约',
+ metaText: (product && product.approximateDuration) || '支持预约',
+ shopNameText: product && product.shopName ? `所属店铺:${product.shopName}` : '',
coverUrl: images[0],
imageUrls: images,
tagsPreview: getProductTags(product),
diff --git a/WeChatProgram/utils/request.js b/WeChatProgram/utils/request.js
index 6fc9b4ce..6d40b177 100644
--- a/WeChatProgram/utils/request.js
+++ b/WeChatProgram/utils/request.js
@@ -36,6 +36,7 @@ function isWhitelistedPath(url) {
'/user/phone-login',
'/user/wechat-mini/',
'/user/reset-password-by-phone',
+ '/legal-agreement/current',
'/product/get/',
'/product/list/',
'/comment/list/product/',
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/AuthInterceptor.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/AuthInterceptor.java
index 2c238ed6..9f481a83 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/AuthInterceptor.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/AuthInterceptor.java
@@ -91,11 +91,22 @@ public class AuthInterceptor implements HandlerInterceptor {
if (!canAccessShop) {
String message = currentShopId == null || currentShopId <= 0
? "当前登录未选择可用店铺,请重新登录"
- : "当前登录店铺已停用或账号已失去该店铺访问权限";
+ : (userShopBindingSupport.isShopEnabledIgnoringAuthorization(currentShopId)
+ && userShopBindingSupport.isShopAuthorizationExpired(currentShopId)
+ ? "店铺已被冻结"
+ : "当前登录店铺已停用或账号已失去该店铺访问权限");
writeJsonResponse(response, HttpServletResponse.SC_UNAUTHORIZED, message);
return false;
}
+ if (adminPath
+ && !Integer.valueOf(4).equals(currentUser.getType())
+ && userShopBindingSupport.isShopAuthorizationExpired(currentShopId)
+ && !isExpiredAdminAllowedPath(path)) {
+ writeJsonResponse(response, HttpServletResponse.SC_FORBIDDEN, "授权已到期,请联系管理员");
+ return false;
+ }
+
if (requiresSignature(request)) {
try {
requestSignatureService.validateRequest(request, token, userId);
@@ -142,6 +153,14 @@ public class AuthInterceptor implements HandlerInterceptor {
return path.startsWith("/admin/") || path.startsWith("/order/admin/");
}
+ private boolean isExpiredAdminAllowedPath(String path) {
+ return path.startsWith("/admin/auth/")
+ || path.equals("/admin/user/info")
+ || path.equals("/permission/list/user/current")
+ || path.equals("/api/permission/list/user/current")
+ || path.startsWith("/admin/shops/");
+ }
+
private void writeJsonResponse(HttpServletResponse response, int status, String message) throws Exception {
response.setStatus(status);
response.setContentType("application/json;charset=UTF-8");
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/LoginLockProperties.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/LoginLockProperties.java
new file mode 100644
index 00000000..ff5ba5a0
--- /dev/null
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/LoginLockProperties.java
@@ -0,0 +1,17 @@
+package com.xiaowang.yuminailcore.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "yuminail.security.login-lock")
+public class LoginLockProperties {
+
+ private int maxFailures = 5;
+
+ private long windowSeconds = 600;
+
+ private long lockSeconds = 900;
+}
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/RateLimitProperties.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/RateLimitProperties.java
index 1954bb98..c85d146a 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/RateLimitProperties.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/RateLimitProperties.java
@@ -14,10 +14,16 @@ public class RateLimitProperties {
private LimitRule login = new LimitRule(10, 60);
+ private LimitRule register = new LimitRule(5, 300);
+
private LimitRule sendCode = new LimitRule(5, 60);
private LimitRule resetPassword = new LimitRule(5, 600);
+ private LimitRule wechatMiniLogin = new LimitRule(10, 60);
+
+ private LimitRule agreementRead = new LimitRule(60, 60);
+
private LimitRule authenticatedWrite = new LimitRule(80, 60);
private LimitRule orderCreate = new LimitRule(10, 60);
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/SecurityHeadersFilter.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/SecurityHeadersFilter.java
new file mode 100644
index 00000000..80dac6f5
--- /dev/null
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/SecurityHeadersFilter.java
@@ -0,0 +1,26 @@
+package com.xiaowang.yuminailcore.config;
+
+import org.springframework.stereotype.Component;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Component
+public class SecurityHeadersFilter implements Filter {
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+ if (response instanceof HttpServletResponse httpResponse) {
+ httpResponse.setHeader("X-Content-Type-Options", "nosniff");
+ httpResponse.setHeader("X-Frame-Options", "DENY");
+ httpResponse.setHeader("Referrer-Policy", "strict-origin-when-cross-origin");
+ httpResponse.setHeader("Content-Security-Policy", "default-src 'self'; img-src 'self' data: blob: http: https:; style-src 'self' 'unsafe-inline'; script-src 'self'; connect-src 'self' http: https:");
+ }
+ chain.doFilter(request, response);
+ }
+}
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/UploadSecurityProperties.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/UploadSecurityProperties.java
new file mode 100644
index 00000000..670a5ee7
--- /dev/null
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/UploadSecurityProperties.java
@@ -0,0 +1,23 @@
+package com.xiaowang.yuminailcore.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "yuminail.security.upload")
+public class UploadSecurityProperties {
+
+ private long maxSize = 10 * 1024 * 1024;
+
+ private List allowedMimeTypes = new ArrayList<>(List.of(
+ "image/jpeg",
+ "image/png",
+ "image/webp",
+ "image/gif"
+ ));
+}
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/WebMvcConfig.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/WebMvcConfig.java
index 85b8cbbc..3d851d7f 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/WebMvcConfig.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/WebMvcConfig.java
@@ -30,6 +30,10 @@ public class WebMvcConfig implements WebMvcConfigurer {
"/user/phone-login",
"/user/wechat-mini/**",
"/user/reset-password-by-phone",
+ "/legal-agreement/current",
+ "/legal-agreement/current/**",
+ "/api/legal-agreement/current",
+ "/api/legal-agreement/current/**",
"/product/get/**",
"/product/list/**",
"/comment/list/product/**",
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminAuthController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminAuthController.java
index 3352914c..78bd8840 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminAuthController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminAuthController.java
@@ -6,6 +6,7 @@ import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
import com.xiaowang.yuminailcore.dto.RefreshTokenRequestDTO;
import com.xiaowang.yuminailcore.dto.SwitchShopRequestDTO;
import com.xiaowang.yuminailcore.service.UserService;
+import com.xiaowang.yuminailcore.service.SecurityAuditLogService;
import com.xiaowang.yuminailcore.support.security.RequestThrottleService;
import com.xiaowang.yuminailcore.support.security.OperationGuardStrategy;
import com.xiaowang.yuminailcore.utils.AccountValidationUtils;
@@ -20,26 +21,64 @@ import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("/admin/auth")
@RequiredArgsConstructor
+/**
+ * AdminAuthController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class AdminAuthController {
-
+ /**
+ * Variable `userService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final UserService userService;
+ /**
+ * Variable `requestThrottleService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final RequestThrottleService requestThrottleService;
+ private final SecurityAuditLogService securityAuditLogService;
@PostMapping("/login")
@OperationGuard(action = "admin-login", ttlSeconds = 8, message = "登录处理中,请勿重复提交")
+ /**
+ * Run the login flow.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param loginRequestDTO parameter `loginRequestDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result login(HttpServletRequest request, @Valid @RequestBody LoginRequestDTO loginRequestDTO) {
requestThrottleService.checkLogin(request, loginRequestDTO.getAccount());
- LoginResponseVO loginResponseVO = userService.adminLogin(loginRequestDTO);
- return Result.success(loginResponseVO);
+ try {
+ LoginResponseVO loginResponseVO = userService.adminLogin(loginRequestDTO);
+ requestThrottleService.clearLoginFailure(request, loginRequestDTO.getAccount());
+ securityAuditLogService.record(loginResponseVO.getUserInfo().getId(), loginRequestDTO.getAccount(), "ADMIN_LOGIN", "SUCCESS", null, request);
+ return Result.success(loginResponseVO);
+ } catch (RuntimeException exception) {
+ requestThrottleService.recordLoginFailure(request, loginRequestDTO.getAccount());
+ securityAuditLogService.record(null, loginRequestDTO.getAccount(), "ADMIN_LOGIN", "FAIL", exception.getMessage(), request);
+ throw exception;
+ }
}
@GetMapping("/login-shops/{account}")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param account parameter `account` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result getLoginShops(@PathVariable String account) {
return Result.success(userService.getAdminLoginShopSelection(AccountValidationUtils.requireValidAccount(account)));
}
@PostMapping("/switch-shop")
@OperationGuard(action = "admin-switch-shop", ttlSeconds = 10, message = "门店切换中,请勿重复操作")
+ /**
+ * Run business method `switchShop`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param switchShopRequestDTO parameter `switchShopRequestDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result switchShop(HttpServletRequest request, @RequestBody SwitchShopRequestDTO switchShopRequestDTO) {
Long userId = (Long) request.getAttribute("userId");
return Result.success(userService.switchAdminShop(userId, switchShopRequestDTO.getShopId(), (String) request.getAttribute("sessionId")));
@@ -47,16 +86,33 @@ public class AdminAuthController {
@PostMapping("/logout")
@OperationGuard(action = "admin-logout", strategy = OperationGuardStrategy.NOOP_IF_DUPLICATE, ttlSeconds = 5)
+ /**
+ * Run business method `logout`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result logout(HttpServletRequest request) {
return Result.success(userService.logout((String) request.getAttribute("sessionId")));
}
@PostMapping("/refresh")
+ /**
+ * Run business method `refreshToken`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param refreshTokenRequestDTO parameter `refreshTokenRequestDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result refreshToken(@RequestBody RefreshTokenRequestDTO refreshTokenRequestDTO) {
LoginResponseVO loginResponseVO = userService.refreshToken(refreshTokenRequestDTO.getRefreshToken());
if (loginResponseVO.getUserInfo() == null
|| loginResponseVO.getUserInfo().getType() == null
|| loginResponseVO.getUserInfo().getType() < 2) {
+ /**
+ * Run business method `RuntimeException`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return throw new result consumed by the caller or returned to the frontend
+ */
throw new RuntimeException("您没有后台管理权限");
}
return Result.success(loginResponseVO);
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCommentController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCommentController.java
index de372499..21f1db1f 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCommentController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCommentController.java
@@ -20,9 +20,18 @@ import java.util.List;
@RestController
@RequestMapping("/admin/comment")
@RequiredArgsConstructor
+/**
+ * AdminCommentController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class AdminCommentController {
-
+ /**
+ * Variable `commentService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final CommentService commentService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
@GetMapping("/list")
@@ -41,6 +50,13 @@ public class AdminCommentController {
@DeleteMapping("/delete/{id}")
@RequirePermission("comment:delete")
+ /**
+ * Delete, revoke, or logically remove a record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result deleteComment(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
Long managedShopId = adminScopeHelper.resolveShopScope(currentUser, null);
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCouponController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCouponController.java
index f68ed184..6901e521 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCouponController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCouponController.java
@@ -25,9 +25,17 @@ import java.util.stream.Collectors;
@RequestMapping("/admin/coupon")
@RequiredArgsConstructor
public class AdminCouponController {
-
+ /**
+ * Variable `couponService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final CouponService couponService;
+ /**
+ * Variable `userService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final UserService userService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
/**
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminLegalAgreementController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminLegalAgreementController.java
new file mode 100644
index 00000000..e0e3b4a1
--- /dev/null
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminLegalAgreementController.java
@@ -0,0 +1,73 @@
+package com.xiaowang.yuminailcore.controller;
+
+import com.xiaowang.yuminailcore.annotation.OperationGuard;
+import com.xiaowang.yuminailcore.annotation.RequirePermission;
+import com.xiaowang.yuminailcore.common.Result;
+import com.xiaowang.yuminailcore.dto.LegalAgreementDTO;
+import com.xiaowang.yuminailcore.entity.UserDO;
+import com.xiaowang.yuminailcore.service.LegalAgreementService;
+import com.xiaowang.yuminailcore.service.SecurityAuditLogService;
+import com.xiaowang.yuminailcore.support.AdminScopeHelper;
+import com.xiaowang.yuminailcore.vo.LegalAgreementVO;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
+import java.util.List;
+
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/admin/legal-agreement")
+public class AdminLegalAgreementController {
+
+ private final LegalAgreementService legalAgreementService;
+ private final AdminScopeHelper adminScopeHelper;
+ private final SecurityAuditLogService securityAuditLogService;
+
+ @GetMapping("/list")
+ @RequirePermission("legal_agreement:manage")
+ public Result> list(HttpServletRequest request) {
+ return Result.success(legalAgreementService.listAdminAgreements(adminScopeHelper.getCurrentUser(request)));
+ }
+
+ @PostMapping("/create")
+ @RequirePermission("legal_agreement:manage")
+ @OperationGuard(action = "admin-legal-agreement-create", ttlSeconds = 8, message = "协议保存处理中,请勿重复提交")
+ public Result create(HttpServletRequest request, @Valid @RequestBody LegalAgreementDTO dto) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ Long id = legalAgreementService.createAgreement(currentUser, dto);
+ securityAuditLogService.record(currentUser.getId(), currentUser.getAccount(), "LEGAL_AGREEMENT_CREATE", "SUCCESS", dto.getAgreementType(), request);
+ return Result.success(id);
+ }
+
+ @PutMapping("/{id}")
+ @RequirePermission("legal_agreement:manage")
+ @OperationGuard(action = "admin-legal-agreement-update", ttlSeconds = 8, message = "协议保存处理中,请勿重复提交")
+ public Result update(HttpServletRequest request, @PathVariable Long id, @Valid @RequestBody LegalAgreementDTO dto) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ Boolean result = legalAgreementService.updateAgreement(currentUser, id, dto);
+ securityAuditLogService.record(currentUser.getId(), currentUser.getAccount(), "LEGAL_AGREEMENT_UPDATE", "SUCCESS", String.valueOf(id), request);
+ return Result.success(result);
+ }
+
+ @PutMapping("/{id}/publish")
+ @RequirePermission("legal_agreement:manage")
+ @OperationGuard(action = "admin-legal-agreement-publish", ttlSeconds = 8, message = "协议发布处理中,请勿重复提交")
+ public Result publish(HttpServletRequest request, @PathVariable Long id) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ Boolean result = legalAgreementService.publishAgreement(currentUser, id);
+ securityAuditLogService.record(currentUser.getId(), currentUser.getAccount(), "LEGAL_AGREEMENT_PUBLISH", "SUCCESS", String.valueOf(id), request);
+ return Result.success(result);
+ }
+
+ @PutMapping("/{id}/disable")
+ @RequirePermission("legal_agreement:manage")
+ @OperationGuard(action = "admin-legal-agreement-disable", ttlSeconds = 8, message = "协议停用处理中,请勿重复提交")
+ public Result disable(HttpServletRequest request, @PathVariable Long id) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ Boolean result = legalAgreementService.disableAgreement(currentUser, id);
+ securityAuditLogService.record(currentUser.getId(), currentUser.getAccount(), "LEGAL_AGREEMENT_DISABLE", "SUCCESS", String.valueOf(id), request);
+ return Result.success(result);
+ }
+}
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminNailArtistController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminNailArtistController.java
index 3de2852d..8f32e65e 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminNailArtistController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminNailArtistController.java
@@ -21,17 +21,32 @@ import java.util.List;
@RestController
@RequestMapping("/admin/nail-artist")
@RequiredArgsConstructor
+/**
+ * AdminNailArtistController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class AdminNailArtistController {
private static final String USER_NOT_FOUND_MESSAGE = "用户信息不存在";
private static final String VIEW_SCOPE_MESSAGE = "当前登录店铺无权查看该美甲师,请切换到所属店铺后重试";
private static final String EDIT_SCOPE_MESSAGE = "当前登录店铺无权编辑该美甲师,请切换到所属店铺后重试";
-
+ /**
+ * Variable `nailArtistInfoService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final NailArtistInfoService nailArtistInfoService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
@RequirePermission("nail_artist:view")
@GetMapping("/list")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> getAllNailArtists(HttpServletRequest request) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
if (currentUser == null) {
@@ -52,6 +67,13 @@ public class AdminNailArtistController {
@RequirePermission("nail_artist:view")
@GetMapping("/get/{userId}")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param userId parameter `userId` supplied by the caller
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result getNailArtistInfo(@PathVariable Long userId, HttpServletRequest request) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
if (currentUser == null) {
@@ -77,6 +99,13 @@ public class AdminNailArtistController {
@RequirePermission("nail_artist:edit")
@PostMapping("/save")
@OperationGuard(action = "admin-nail-artist-save", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Save submitted data.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param nailArtistInfoDTO parameter `nailArtistInfoDTO` supplied by the caller
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result saveNailArtistInfo(@RequestBody NailArtistInfoDTO nailArtistInfoDTO, HttpServletRequest request) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
if (currentUser == null) {
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminOrderController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminOrderController.java
index 511fd207..752dbc06 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminOrderController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminOrderController.java
@@ -21,8 +21,13 @@ import java.util.List;
@RequestMapping("/admin/order")
@RequiredArgsConstructor
public class AdminOrderController {
-
+ /**
+ * Variable `orderService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final OrderService orderService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
/**
@@ -87,6 +92,11 @@ public class AdminOrderController {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
if (Integer.valueOf(3).equals(currentUser.getType())) {
if (!Integer.valueOf(2).equals(status)) {
+ /**
+ * Run business method `RuntimeException`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return throw new result consumed by the caller or returned to the frontend
+ */
throw new RuntimeException("美甲师只能完成属于自己的订单");
}
orderService.completeArtistOrder(id, currentUser.getId());
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminPermissionController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminPermissionController.java
index 981b049c..14363999 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminPermissionController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminPermissionController.java
@@ -19,15 +19,34 @@ import java.util.List;
@RestController
@RequestMapping("/admin/permission")
@RequiredArgsConstructor
+/**
+ * AdminPermissionController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class AdminPermissionController {
-
+ /**
+ * Variable `permissionService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final PermissionService permissionService;
+ /**
+ * Variable `userService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final UserService userService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
@PostMapping("/create")
@RequirePermission("permission:create")
@OperationGuard(action = "admin-permission-create", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Create a new record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param permissionDTO parameter `permissionDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result createPermission(HttpServletRequest request, @RequestBody PermissionDTO permissionDTO) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
@@ -38,6 +57,14 @@ public class AdminPermissionController {
@PutMapping("/update/{id}")
@RequirePermission("permission:edit")
@OperationGuard(action = "admin-permission-update", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param permissionDTO parameter `permissionDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result updatePermission(HttpServletRequest request, @PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
@@ -48,6 +75,13 @@ public class AdminPermissionController {
@DeleteMapping("/delete/{id}")
@RequirePermission("permission:delete")
@OperationGuard(action = "admin-permission-delete", ttlSeconds = 10, message = "操作处理中,请勿重复提交")
+ /**
+ * Delete, revoke, or logically remove a record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result deletePermission(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
@@ -57,6 +91,12 @@ public class AdminPermissionController {
@GetMapping("/get/{id}")
@RequirePermission("permission:view")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result getPermissionById(@PathVariable Long id) {
PermissionVO permissionVO = permissionService.getPermissionById(id);
return Result.success(permissionVO);
@@ -64,6 +104,11 @@ public class AdminPermissionController {
@GetMapping("/list/all")
@RequirePermission("permission:view")
+ /**
+ * List records for the current query or current user scope.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> listAllPermissions() {
List permissionVOs = permissionService.listAllPermissions();
return Result.success(permissionVOs);
@@ -71,6 +116,12 @@ public class AdminPermissionController {
@GetMapping("/list/group/{permissionGroup}")
@RequirePermission("permission:view")
+ /**
+ * List records for the current query or current user scope.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param permissionGroup parameter `permissionGroup` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> listPermissionsByGroup(@PathVariable String permissionGroup) {
List permissionVOs = permissionService.listPermissionsByGroup(permissionGroup);
return Result.success(permissionVOs);
@@ -78,11 +129,23 @@ public class AdminPermissionController {
@GetMapping("/user/{userId}")
@RequirePermission("permission:view")
+ /**
+ * List records for the current query or current user scope.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param userId parameter `userId` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> listUserPermissions(HttpServletRequest request, @PathVariable Long userId) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
UserDO targetUser = userService.getById(userId);
if (targetUser == null) {
+ /**
+ * Run business method `RuntimeException`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return throw new result consumed by the caller or returned to the frontend
+ */
throw new RuntimeException("目标用户不存在");
}
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userId, "无权查看其他店铺用户权限");
@@ -93,6 +156,13 @@ public class AdminPermissionController {
@GetMapping("/assignable/{userId}")
@RequirePermission("permission:assign")
+ /**
+ * List records for the current query or current user scope.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param userId parameter `userId` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> listAssignablePermissionIds(HttpServletRequest request, @PathVariable Long userId) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
@@ -103,6 +173,12 @@ public class AdminPermissionController {
}
@GetMapping("/user/current")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> getCurrentUserPermissions(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
userService.syncManagedPermissions(userId);
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminProductController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminProductController.java
index 4e809fd9..e5ce2985 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminProductController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminProductController.java
@@ -18,9 +18,18 @@ import java.util.List;
@RestController
@RequestMapping("/admin/product")
@RequiredArgsConstructor
+/**
+ * AdminProductController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class AdminProductController {
-
+ /**
+ * Variable `productService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final ProductService productService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
@GetMapping("/list")
@@ -41,6 +50,13 @@ public class AdminProductController {
@PostMapping("/create")
@RequirePermission("product:create")
@OperationGuard(action = "admin-product-create", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Create a new record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param productDTO parameter `productDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result createProduct(HttpServletRequest request, @RequestBody ProductDTO productDTO) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
productDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, productDTO.getShopId()));
@@ -51,6 +67,14 @@ public class AdminProductController {
@PutMapping("/update/{id}")
@RequirePermission("product:edit")
@OperationGuard(action = "admin-product-update", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param productDTO parameter `productDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result updateProduct(HttpServletRequest request, @PathVariable Long id, @RequestBody ProductDTO productDTO) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
ProductVO productVO = productService.getProductById(id);
@@ -67,6 +91,13 @@ public class AdminProductController {
@DeleteMapping("/delete/{id}")
@RequirePermission("product:delete")
@OperationGuard(action = "admin-product-delete", ttlSeconds = 10, message = "操作处理中,请勿重复提交")
+ /**
+ * Delete, revoke, or logically remove a record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result deleteProduct(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
ProductVO productVO = productService.getProductById(id);
@@ -80,6 +111,12 @@ public class AdminProductController {
@GetMapping("/list/all")
@RequirePermission("product:view")
+ /**
+ * List records for the current query or current user scope.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> listAllProducts(HttpServletRequest request) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminShopController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminShopController.java
index 0fbca040..7bd4f283 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminShopController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminShopController.java
@@ -19,9 +19,18 @@ import java.util.List;
@RestController
@RequestMapping("/admin/shops")
@RequiredArgsConstructor
+/**
+ * AdminShopController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class AdminShopController {
-
+ /**
+ * Variable `shopService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final ShopService shopService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
@GetMapping("/list")
@@ -42,6 +51,13 @@ public class AdminShopController {
@PostMapping("/create")
@RequirePermission("shop:create")
@OperationGuard(action = "admin-shop-create", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Create a new record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param shopDTO parameter `shopDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result createShop(HttpServletRequest request, @RequestBody ShopDTO shopDTO) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以创建店铺");
@@ -52,6 +68,14 @@ public class AdminShopController {
@PutMapping("/update/{id}")
@RequirePermission("shop:edit")
@OperationGuard(action = "admin-shop-update", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param shopDTO parameter `shopDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result updateShop(HttpServletRequest request, @PathVariable Long id, @RequestBody ShopDTO shopDTO) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
ShopVO shopVO = shopService.getShopById(id);
@@ -59,6 +83,9 @@ public class AdminShopController {
return Result.success(false);
}
adminScopeHelper.ensureShopAccessible(currentUser, shopVO.getId(), "无权编辑其他店铺信息");
+ if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
+ shopDTO.setAuthorizationExpireTime(shopVO.getAuthorizationExpireTime());
+ }
boolean success = shopService.updateShop(id, shopDTO);
return Result.success(success);
}
@@ -66,6 +93,13 @@ public class AdminShopController {
@DeleteMapping("/delete/{id}")
@RequirePermission("shop:delete")
@OperationGuard(action = "admin-shop-delete", ttlSeconds = 10, message = "操作处理中,请勿重复提交")
+ /**
+ * Delete, revoke, or logically remove a record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result deleteShop(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以删除店铺");
@@ -76,6 +110,14 @@ public class AdminShopController {
@PutMapping("/status/{id}")
@RequirePermission("shop:edit")
@OperationGuard(action = "admin-shop-status", ttlSeconds = 10, message = "操作处理中,请勿重复提交")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param statusRequest parameter `statusRequest` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result updateShopStatus(HttpServletRequest request, @PathVariable Long id, @RequestBody StatusRequest statusRequest) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以启停店铺");
@@ -85,6 +127,12 @@ public class AdminShopController {
@GetMapping("/list/all")
@RequirePermission("shop:view")
+ /**
+ * List records for the current query or current user scope.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> listAllShops(HttpServletRequest request) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
List shops;
@@ -99,6 +147,13 @@ public class AdminShopController {
@GetMapping("/{id}")
@RequirePermission("shop:view")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result getShop(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.ensureShopAccessible(currentUser, id, "无权查看其他店铺信息");
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminShopRoleController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminShopRoleController.java
new file mode 100644
index 00000000..089adb97
--- /dev/null
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminShopRoleController.java
@@ -0,0 +1,182 @@
+package com.xiaowang.yuminailcore.controller;
+
+import com.xiaowang.yuminailcore.annotation.RequirePermission;
+import com.xiaowang.yuminailcore.common.Result;
+import com.xiaowang.yuminailcore.dto.InviteCodeDTO;
+import com.xiaowang.yuminailcore.dto.ShopRoleDTO;
+import com.xiaowang.yuminailcore.entity.UserDO;
+import com.xiaowang.yuminailcore.service.PermissionService;
+import com.xiaowang.yuminailcore.service.ShopRoleService;
+import com.xiaowang.yuminailcore.support.AdminScopeHelper;
+import com.xiaowang.yuminailcore.vo.InviteCodeVO;
+import com.xiaowang.yuminailcore.vo.PermissionVO;
+import com.xiaowang.yuminailcore.vo.ShopRoleVO;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
+import java.util.List;
+
+@RestController
+@RequestMapping("/admin/shop-role")
+@RequiredArgsConstructor
+/**
+ * AdminShopRoleController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
+public class AdminShopRoleController {
+ /**
+ * Variable `shopRoleService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
+ private final ShopRoleService shopRoleService;
+ /**
+ * Variable `permissionService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
+ private final PermissionService permissionService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
+ private final AdminScopeHelper adminScopeHelper;
+
+ @GetMapping("/list")
+ @RequirePermission("role:view")
+ // 店铺角色是“只在本店生效”的角色,不是全局后台角色;
+ // 所以这里要先按当前登录人的店铺范围裁剪,再返回列表。
+ public Result> list(HttpServletRequest request, @RequestParam(required = false) Long shopId) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.listRoles(currentUser, shopId));
+ }
+
+ @PostMapping("/create")
+ @RequirePermission("role:create")
+ /**
+ * Create a new record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param dto parameter `dto` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result create(HttpServletRequest request, @Valid @RequestBody ShopRoleDTO dto) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.createRole(currentUser, dto));
+ }
+
+ @PutMapping("/{id}")
+ @RequirePermission("role:edit")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param dto parameter `dto` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result update(HttpServletRequest request, @PathVariable Long id, @RequestBody ShopRoleDTO dto) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.updateRole(currentUser, id, dto));
+ }
+
+ @DeleteMapping("/{id}")
+ @RequirePermission("role:delete")
+ /**
+ * Delete, revoke, or logically remove a record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result delete(HttpServletRequest request, @PathVariable Long id) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.deleteRole(currentUser, id));
+ }
+
+ @PostMapping("/{id}/permissions")
+ @RequirePermission("role:edit")
+ /**
+ * Run business method `assignPermissions`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param permissionIds parameter `permissionIds` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result assignPermissions(HttpServletRequest request, @PathVariable Long id, @RequestBody List permissionIds) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.assignPermissions(currentUser, id, permissionIds));
+ }
+
+ @PostMapping("/{id}/users")
+ @RequirePermission("role:edit")
+ /**
+ * Run business method `assignUsers`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param userIds parameter `userIds` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result assignUsers(HttpServletRequest request, @PathVariable Long id, @RequestBody List userIds) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.assignUsers(currentUser, id, userIds));
+ }
+
+ @GetMapping("/permission-options")
+ @RequirePermission("role:view")
+ /**
+ * Run business method `permissionOptions`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
+ public Result> permissionOptions() {
+ return Result.success(permissionService.listAllPermissions());
+ }
+
+ @GetMapping("/invite-code/list")
+ @RequirePermission("user:relation:view")
+ public Result> listInviteCodes(HttpServletRequest request, @RequestParam(required = false) Long shopId) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.listInviteCodes(currentUser, shopId));
+ }
+
+ @PostMapping("/invite-code/create")
+ @RequirePermission("user:relation:edit")
+ /**
+ * Create a new record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param dto parameter `dto` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result createInviteCode(HttpServletRequest request, @Valid @RequestBody InviteCodeDTO dto) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.createInviteCode(currentUser, dto));
+ }
+
+ @PutMapping("/invite-code/{id}/status")
+ @RequirePermission("user:relation:edit")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param status parameter `status` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result updateInviteCodeStatus(HttpServletRequest request, @PathVariable Long id, @RequestParam Integer status) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.updateInviteCodeStatus(currentUser, id, status));
+ }
+
+ @GetMapping("/invite-code/resolve")
+ // 注册页输入邀请码时调用这个接口,用来提前展示“会归属到谁、哪个店”。
+ /**
+ * Run business method `resolve`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param code parameter `code` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result resolve(@RequestParam String code) {
+ return Result.success(shopRoleService.resolveInviteCode(code));
+ }
+}
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminTagController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminTagController.java
index 5dfa4835..ddbf789e 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminTagController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminTagController.java
@@ -21,8 +21,13 @@ import java.util.List;
@RequestMapping("/admin/tag")
@RequiredArgsConstructor
public class AdminTagController {
-
+ /**
+ * Variable `tagService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final TagService tagService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
/**
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminUserController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminUserController.java
index 9f1d720b..c0db8643 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminUserController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminUserController.java
@@ -6,13 +6,18 @@ import com.xiaowang.yuminailcore.common.Result;
import com.xiaowang.yuminailcore.dto.AdminUserBalanceChangeDTO;
import com.xiaowang.yuminailcore.dto.AdminUserVipOverrideDTO;
import com.xiaowang.yuminailcore.dto.UserDTO;
+import com.xiaowang.yuminailcore.dto.UserRelationUpdateDTO;
import com.xiaowang.yuminailcore.entity.UserDO;
import com.xiaowang.yuminailcore.service.UserAssetService;
import com.xiaowang.yuminailcore.service.UserService;
+import com.xiaowang.yuminailcore.service.ShopRoleService;
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
+import com.xiaowang.yuminailcore.support.BookableArtistSupport;
import com.xiaowang.yuminailcore.vo.BalanceChangeDetailVO;
import com.xiaowang.yuminailcore.vo.PageResultVO;
+import com.xiaowang.yuminailcore.vo.UserStatisticsVO;
import com.xiaowang.yuminailcore.vo.UserAssetVO;
+import com.xiaowang.yuminailcore.vo.UserRelationVO;
import com.xiaowang.yuminailcore.vo.UserVO;
import lombok.Data;
import lombok.RequiredArgsConstructor;
@@ -26,11 +31,31 @@ import java.util.stream.Collectors;
@RestController
@RequestMapping("/admin/user")
@RequiredArgsConstructor
+/**
+ * AdminUserController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class AdminUserController {
-
+ /**
+ * Variable `userService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final UserService userService;
+ /**
+ * Variable `userAssetService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final UserAssetService userAssetService;
+ /**
+ * Variable `shopRoleService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
+ private final ShopRoleService shopRoleService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
+ /**
+ * Variable `bookableArtistSupport`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
+ private final BookableArtistSupport bookableArtistSupport;
@GetMapping("/list")
@RequirePermission("user:view")
@@ -40,17 +65,87 @@ public class AdminUserController {
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) Long shopId,
- @RequestParam(required = false) Integer type
+ @RequestParam(required = false) Integer type,
+ @RequestParam(required = false) Long roleId,
+ @RequestParam(required = false) Long parentUserId,
+ @RequestParam(required = false) String sourceType,
+ @RequestParam(required = false) Integer status,
+ @RequestParam(required = false) String vipLevel,
+ @RequestParam(required = false) String createdFrom,
+ @RequestParam(required = false) String createdTo,
+ @RequestParam(required = false) Boolean hasPhone,
+ @RequestParam(required = false) Boolean hasOrder
) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
- PageResultVO result = userService.pageUsers(page, size, keyword, shopId, type);
+ PageResultVO result = userService.pageUsers(page, size, keyword, shopId, type, roleId, parentUserId, sourceType, status, vipLevel, createdFrom, createdTo, hasPhone, hasOrder);
return Result.success(result);
}
+ @GetMapping("/statistics")
+ @RequirePermission("user:view")
+ public Result statisticsUsers(HttpServletRequest request,
+ @RequestParam(required = false) String keyword,
+ @RequestParam(required = false) Long shopId,
+ @RequestParam(required = false) Integer type,
+ @RequestParam(required = false) Long roleId,
+ @RequestParam(required = false) Long parentUserId,
+ @RequestParam(required = false) String sourceType,
+ @RequestParam(required = false) Integer status,
+ @RequestParam(required = false) String vipLevel,
+ @RequestParam(required = false) String createdFrom,
+ @RequestParam(required = false) String createdTo,
+ @RequestParam(required = false) Boolean hasPhone,
+ @RequestParam(required = false) Boolean hasOrder) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
+ return Result.success(userService.statisticsUsers(keyword, shopId, type, roleId, parentUserId, sourceType, status, vipLevel, createdFrom, createdTo, hasPhone, hasOrder));
+ }
+
+ @GetMapping("/relation/me")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result getMyRelation(HttpServletRequest request) {
+ Long userId = (Long) request.getAttribute("userId");
+ return Result.success(userService.getCurrentUserRelation(userId));
+ }
+
+ @GetMapping("/relation/options")
+ @RequirePermission("user:relation:view")
+ public Result> relationOptions(HttpServletRequest request, @RequestParam(required = false) Long shopId) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.listRelationOptions(currentUser, shopId));
+ }
+
+ @PutMapping("/{id}/relation")
+ @RequirePermission("user:relation:edit")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param dto parameter `dto` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result updateRelation(HttpServletRequest request, @PathVariable Long id, @RequestBody UserRelationUpdateDTO dto) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(shopRoleService.updateUserRelation(currentUser, id, dto));
+ }
+
@PostMapping("/create")
@RequirePermission("user:create")
@OperationGuard(action = "admin-user-create", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Create a new record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param userDTO parameter `userDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result createUser(HttpServletRequest request, @Valid @RequestBody UserDTO userDTO) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
@@ -66,6 +161,14 @@ public class AdminUserController {
@PutMapping("/update/{id}")
@RequirePermission("user:edit")
@OperationGuard(action = "admin-user-update", ttlSeconds = 10, message = "保存处理中,请勿重复提交")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param userDTO parameter `userDTO` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result updateUser(HttpServletRequest request, @PathVariable Long id, @Valid @RequestBody UserDTO userDTO) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
UserVO targetUser = userService.getUserById(id);
@@ -87,6 +190,14 @@ public class AdminUserController {
@PutMapping("/status/{id}")
@RequirePermission("user:disable")
@OperationGuard(action = "admin-user-status", ttlSeconds = 10, message = "操作处理中,请勿重复提交")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param httpRequest parameter `httpRequest` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result updateUserStatus(HttpServletRequest httpRequest, @PathVariable Long id, @RequestBody StatusRequest request) {
UserDO currentUser = adminScopeHelper.getCurrentUser(httpRequest);
adminScopeHelper.requirePlatformAdmin(currentUser, "仅系统管理员可以停用用户");
@@ -96,6 +207,11 @@ public class AdminUserController {
}
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, id, "无权变更其他店铺用户状态");
if (Integer.valueOf(4).equals(targetUser.getType())) {
+ /**
+ * Run business method `RuntimeException`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return throw new result consumed by the caller or returned to the frontend
+ */
throw new RuntimeException("管理员账号不允许停用");
}
boolean success = userService.updateUserStatus(id, request.getStatus());
@@ -105,6 +221,13 @@ public class AdminUserController {
@PostMapping("/reset-password/{userId}")
@RequirePermission("user:reset_password")
@OperationGuard(action = "admin-user-reset-password", ttlSeconds = 10, message = "操作处理中,请勿重复提交")
+ /**
+ * Run business method `resetPassword`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param userId parameter `userId` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result resetPassword(HttpServletRequest request, @PathVariable Long userId) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
UserVO targetUser = userService.getUserById(userId);
@@ -120,6 +243,13 @@ public class AdminUserController {
@DeleteMapping("/delete/{id}")
@RequirePermission("user:delete")
@OperationGuard(action = "admin-user-delete", ttlSeconds = 10, message = "操作处理中,请勿重复提交")
+ /**
+ * Delete, revoke, or logically remove a record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result deleteUser(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requirePlatformAdmin(currentUser, "仅系统管理员可以删除用户");
@@ -128,6 +258,11 @@ public class AdminUserController {
return Result.success(false);
}
if (Integer.valueOf(4).equals(targetUser.getType())) {
+ /**
+ * Run business method `RuntimeException`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return throw new result consumed by the caller or returned to the frontend
+ */
throw new RuntimeException("管理员账号不允许删除");
}
boolean success = userService.deleteUser(id);
@@ -137,6 +272,13 @@ public class AdminUserController {
@PutMapping("/unbind/{id}")
@RequirePermission("user:unbind")
@OperationGuard(action = "admin-user-unbind", ttlSeconds = 10, message = "操作处理中,请勿重复提交")
+ /**
+ * Run business method `unbindUser`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result unbindUser(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
UserVO targetUser = userService.getUserById(id);
@@ -146,6 +288,11 @@ public class AdminUserController {
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, id, "无权解绑其他店铺用户");
adminScopeHelper.ensureAssignableUserType(currentUser, targetUser.getType());
if (Integer.valueOf(4).equals(targetUser.getType())) {
+ /**
+ * Run business method `RuntimeException`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return throw new result consumed by the caller or returned to the frontend
+ */
throw new RuntimeException("管理员账号不允许解绑");
}
boolean success = userService.unbindUserInShopWithOperator(id, currentUser.getShopId(), currentUser.getType());
@@ -154,6 +301,13 @@ public class AdminUserController {
@GetMapping("/{id}/asset")
@RequirePermission("user:balance:view")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result getUserAsset(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
UserVO targetUser = requireAccessibleUser(currentUser, id, "无权查看其他店铺用户资产");
@@ -163,6 +317,13 @@ public class AdminUserController {
@GetMapping("/{id}/balance/history")
@RequirePermission("user:balance:view")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> getUserBalanceHistory(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
UserVO targetUser = requireAccessibleUser(currentUser, id, "无权查看其他店铺用户余额流水");
@@ -201,6 +362,13 @@ public class AdminUserController {
@PostMapping("/{id}/vip/recalculate")
@RequirePermission("user:vip:manage")
@OperationGuard(action = "admin-user-vip-recalculate", ttlSeconds = 15, message = "操作处理中,请勿重复提交")
+ /**
+ * Run business method `recalculateUserVip`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result recalculateUserVip(HttpServletRequest request, @PathVariable Long id) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
UserVO targetUser = requireAccessibleUser(currentUser, id, "无权重算其他店铺用户 VIP");
@@ -209,6 +377,12 @@ public class AdminUserController {
}
@GetMapping("/info")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result getUserInfo(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
UserVO userVO = userService.getUserById(userId);
@@ -239,8 +413,12 @@ public class AdminUserController {
public Result> listArtists(HttpServletRequest request, @RequestParam(required = false) Long shopId) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
+ final Long resolvedScopeShopId = shopId;
+ List artists = userService.listAllUsers().stream()
+ .filter(user -> Integer.valueOf(2).equals(user.getType()) || Integer.valueOf(3).equals(user.getType()))
+ .filter(user -> bookableArtistSupport.isValidBookableArtist(resolvedScopeShopId, user.getId()))
+ .collect(Collectors.toList());
// 用户类型 3 表示美甲师
- List artists = userService.listUsersByType(3);
// 如果指定了店铺ID,则过滤该店铺的美甲师
if (shopId != null) {
final Long resolvedShopId = shopId;
@@ -251,9 +429,22 @@ public class AdminUserController {
return Result.success(artists);
}
+ /**
+ * Run business method `requireAccessibleUser`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param currentUser parameter `currentUser` supplied by the caller
+ * @param userId parameter `userId` supplied by the caller
+ * @param message parameter `message` supplied by the caller
+ * @return private UserVO result consumed by the caller or returned to the frontend
+ */
private UserVO requireAccessibleUser(UserDO currentUser, Long userId, String message) {
UserVO targetUser = userService.getUserById(userId);
if (targetUser == null) {
+ /**
+ * Run business method `RuntimeException`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return throw new result consumed by the caller or returned to the frontend
+ */
throw new RuntimeException("目标用户不存在");
}
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userId, message);
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AnnouncementController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AnnouncementController.java
new file mode 100644
index 00000000..d64a73a7
--- /dev/null
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AnnouncementController.java
@@ -0,0 +1,119 @@
+package com.xiaowang.yuminailcore.controller;
+
+import com.xiaowang.yuminailcore.annotation.OperationGuard;
+import com.xiaowang.yuminailcore.annotation.RequirePermission;
+import com.xiaowang.yuminailcore.common.Result;
+import com.xiaowang.yuminailcore.dto.AnnouncementCreateDTO;
+import com.xiaowang.yuminailcore.entity.UserDO;
+import com.xiaowang.yuminailcore.service.AnnouncementService;
+import com.xiaowang.yuminailcore.support.AdminScopeHelper;
+import com.xiaowang.yuminailcore.vo.AnnouncementVO;
+import com.xiaowang.yuminailcore.vo.MessageTargetOptionsVO;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
+import java.util.List;
+
+@RestController
+@RequiredArgsConstructor
+@RequestMapping({"/announcement", "/api/announcement"})
+/**
+ * AnnouncementController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
+public class AnnouncementController {
+ /**
+ * Variable `announcementService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
+ private final AnnouncementService announcementService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
+ private final AdminScopeHelper adminScopeHelper;
+
+ @PostMapping("/admin/create")
+ @RequirePermission("announcement:create")
+ @OperationGuard(action = "announcement-create", ttlSeconds = 8, message = "公告发布处理中,请勿重复提交")
+ // 后台发布公告时,targetType 决定“全平台 / 指定店铺 / 指定用户”的范围。
+ // 前端只需要按 target-options 返回值组装表单即可。
+ /**
+ * Run business method `publish`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param dto parameter `dto` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result publish(HttpServletRequest request, @Valid @RequestBody AnnouncementCreateDTO dto) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(announcementService.publishAnnouncement(currentUser, dto));
+ }
+
+ @GetMapping("/admin/list")
+ @RequirePermission("announcement:view")
+ /**
+ * List records for the current query or current user scope.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
+ public Result> listAdmin(HttpServletRequest request) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(announcementService.listAdminAnnouncements(currentUser));
+ }
+
+ @GetMapping("/admin/{id}")
+ @RequirePermission("announcement:view")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result getAdmin(HttpServletRequest request, @PathVariable Long id) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(announcementService.getAdminAnnouncement(currentUser, id));
+ }
+
+ @PutMapping("/admin/{id}/revoke")
+ @RequirePermission("announcement:delete")
+ @OperationGuard(action = "announcement-revoke", ttlSeconds = 8, message = "公告撤回处理中,请勿重复操作")
+ /**
+ * Run business method `revoke`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param id parameter `id` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result revoke(HttpServletRequest request, @PathVariable Long id) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(announcementService.revokeAnnouncement(currentUser, id));
+ }
+
+ @GetMapping("/admin/target-options")
+ @RequirePermission("announcement:create")
+ /**
+ * Run business method `targetOptions`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result targetOptions(HttpServletRequest request) {
+ UserDO currentUser = adminScopeHelper.getCurrentUser(request);
+ return Result.success(announcementService.listTargetOptions(currentUser));
+ }
+
+ @GetMapping("/my/list")
+ /**
+ * List records for the current query or current user scope.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
+ public Result> listMy(HttpServletRequest request) {
+ Long userId = (Long) request.getAttribute("userId");
+ return Result.success(announcementService.listMyAnnouncements(userId));
+ }
+}
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/BalanceChangeDetailController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/BalanceChangeDetailController.java
index d16135a0..4755a668 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/BalanceChangeDetailController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/BalanceChangeDetailController.java
@@ -20,7 +20,9 @@ import java.util.List;
@RequestMapping({"/balance-change-detail", "/api/balance-change-detail"})
@RequiredArgsConstructor
public class BalanceChangeDetailController {
-
+ /**
+ * Variable `balanceChangeDetailService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final BalanceChangeDetailService balanceChangeDetailService;
/**
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/BalanceController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/BalanceController.java
index 900ff893..89f2b1b1 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/BalanceController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/BalanceController.java
@@ -20,7 +20,9 @@ import java.util.List;
@RequestMapping({"/balance", "/api/balance"})
@RequiredArgsConstructor
public class BalanceController {
-
+ /**
+ * Variable `balanceService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final BalanceService balanceService;
/**
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CartController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CartController.java
index f2ffdc25..67e7049e 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CartController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CartController.java
@@ -14,6 +14,10 @@ import java.util.List;
@RestController
@RequestMapping("/cart")
+/**
+ * CartController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class CartController {
@Resource
@@ -21,6 +25,13 @@ public class CartController {
@PostMapping("/add")
@OperationGuard(action = "cart-add", ttlSeconds = 10, message = "购物车处理中,请勿重复操作")
+ /**
+ * Add a new record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param cartDTO parameter `cartDTO` supplied by the caller
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result addToCart(@RequestBody CartDTO cartDTO, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
cartService.addToCart(userId, cartDTO);
@@ -29,6 +40,13 @@ public class CartController {
@DeleteMapping("/remove/{productId}")
@OperationGuard(action = "cart-remove", strategy = OperationGuardStrategy.NOOP_IF_DUPLICATE, ttlSeconds = 10)
+ /**
+ * Remove a record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param productId parameter `productId` supplied by the caller
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result removeFromCart(@PathVariable Long productId, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
cartService.removeFromCart(userId, productId);
@@ -37,6 +55,13 @@ public class CartController {
@PostMapping("/batch-remove")
@OperationGuard(action = "cart-batch-remove", strategy = OperationGuardStrategy.NOOP_IF_DUPLICATE, ttlSeconds = 10)
+ /**
+ * Run business method `batchRemoveFromCart`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param cartItemIds parameter `cartItemIds` supplied by the caller
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result batchRemoveFromCart(@RequestBody List cartItemIds, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
cartService.batchRemoveFromCart(userId, cartItemIds);
@@ -45,6 +70,13 @@ public class CartController {
@PutMapping("/update")
@OperationGuard(action = "cart-update", ttlSeconds = 10, message = "购物车处理中,请勿重复操作")
+ /**
+ * Update an existing record.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param cartDTO parameter `cartDTO` supplied by the caller
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result updateCartQuantity(@RequestBody CartDTO cartDTO, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
cartService.updateCartQuantity(userId, cartDTO);
@@ -52,6 +84,12 @@ public class CartController {
}
@GetMapping("/list")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result> result consumed by the caller or returned to the frontend
+ */
public Result> getCartList(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
List cartList = cartService.getCartList(userId);
@@ -60,6 +98,12 @@ public class CartController {
@DeleteMapping("/clear")
@OperationGuard(action = "cart-clear", strategy = OperationGuardStrategy.NOOP_IF_DUPLICATE, ttlSeconds = 10)
+ /**
+ * Run business method `clearCart`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result clearCart(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
cartService.clearCart(userId);
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CommentController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CommentController.java
index 78a82839..59e46782 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CommentController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CommentController.java
@@ -21,7 +21,9 @@ import java.util.List;
@RequestMapping({"/comment", "/api/comment"})
@RequiredArgsConstructor
public class CommentController {
-
+ /**
+ * Variable `commentService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final CommentService commentService;
/**
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/ContactInfoController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/ContactInfoController.java
new file mode 100644
index 00000000..f03c9503
--- /dev/null
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/ContactInfoController.java
@@ -0,0 +1,66 @@
+package com.xiaowang.yuminailcore.controller;
+
+import com.xiaowang.yuminailcore.common.Result;
+import com.xiaowang.yuminailcore.service.ContactInfoService;
+import com.xiaowang.yuminailcore.vo.ContactInfoVO;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+@RestController
+@RequiredArgsConstructor
+@RequestMapping({"/contact-info", "/api/contact-info"})
+/**
+ * ContactInfoController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
+public class ContactInfoController {
+ /**
+ * Variable `contactInfoService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
+ private final ContactInfoService contactInfoService;
+
+ @GetMapping("/shop/{shopId}/manager")
+ /**
+ * Run business method `shopManager`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param shopId parameter `shopId` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result shopManager(HttpServletRequest request, @PathVariable Long shopId) {
+ Long userId = (Long) request.getAttribute("userId");
+ return Result.success(contactInfoService.getShopManagerContact(userId, shopId));
+ }
+
+ @GetMapping("/product/{productId}/artist/{artistId}")
+ /**
+ * Run business method `productArtist`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @param productId parameter `productId` supplied by the caller
+ * @param artistId parameter `artistId` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result productArtist(HttpServletRequest request, @PathVariable Long productId, @PathVariable Long artistId) {
+ Long userId = (Long) request.getAttribute("userId");
+ return Result.success(contactInfoService.getProductArtistContact(userId, productId, artistId));
+ }
+
+ @GetMapping("/order/{orderId}/artist")
+ public Result orderArtist(HttpServletRequest request, @PathVariable Long orderId, @RequestParam(required = false) Long artistId) {
+ Long userId = (Long) request.getAttribute("userId");
+ return Result.success(contactInfoService.getOrderArtistContact(userId, orderId, artistId));
+ }
+
+ @GetMapping("/platform")
+ /**
+ * Run business method `platform`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return Result result consumed by the caller or returned to the frontend
+ */
+ public Result platform() {
+ return Result.success(contactInfoService.getPlatformContact());
+ }
+}
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CouponController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CouponController.java
index e7b61b60..8a22ea71 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CouponController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/CouponController.java
@@ -24,9 +24,17 @@ import java.util.List;
@RequestMapping("/coupon")
@RequiredArgsConstructor
public class CouponController {
-
+ /**
+ * Variable `couponService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final CouponService couponService;
+ /**
+ * Variable `userService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final UserService userService;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
/**
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/DashboardController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/DashboardController.java
index 21df8f19..7a4701b2 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/DashboardController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/DashboardController.java
@@ -38,21 +38,60 @@ import java.util.stream.Collectors;
@RestController
@RequestMapping("/admin/dashboard")
@RequiredArgsConstructor
+/**
+ * DashboardController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
+ * Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
+ */
public class DashboardController {
-
+ /**
+ * Variable `userMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final UserMapper userMapper;
+ /**
+ * Variable `productMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final ProductMapper productMapper;
+ /**
+ * Variable `shopMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final ShopMapper shopMapper;
+ /**
+ * Variable `commentMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final CommentMapper commentMapper;
+ /**
+ * Variable `orderMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final OrderMapper orderMapper;
+ /**
+ * Variable `orderItemMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final OrderItemMapper orderItemMapper;
+ /**
+ * Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AdminScopeHelper adminScopeHelper;
+ /**
+ * Variable `userShopBindingSupport`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final UserShopBindingSupport userShopBindingSupport;
+ /**
+ * Variable `multiLevelCacheService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final MultiLevelCacheService multiLevelCacheService;
+ /**
+ * Variable `appCacheProperties`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final AppCacheProperties appCacheProperties;
@GetMapping("/stats")
@RequirePermission("dashboard:view")
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param request parameter `request` supplied by the caller
+ * @return Result result consumed by the caller or returned to the frontend
+ */
public Result getDashboardStats(HttpServletRequest request) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
Long shopIdScope = resolveShopScope(currentUser);
@@ -69,6 +108,13 @@ public class DashboardController {
return Result.success(stats);
}
+ /**
+ * Run business method `buildDashboardStats`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param currentUser parameter `currentUser` supplied by the caller
+ * @param shopIdScope parameter `shopIdScope` supplied by the caller
+ * @return private DashboardStatsVO result consumed by the caller or returned to the frontend
+ */
private DashboardStatsVO buildDashboardStats(UserDO currentUser, Long shopIdScope) {
DashboardStatsVO stats = new DashboardStatsVO();
@@ -110,6 +156,12 @@ public class DashboardController {
return stats;
}
+ /**
+ * Run business method `resolveShopScope`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param currentUser parameter `currentUser` supplied by the caller
+ * @return private Long result consumed by the caller or returned to the frontend
+ */
private Long resolveShopScope(UserDO currentUser) {
if (currentUser == null || currentUser.getType() == 4) {
return null;
@@ -117,6 +169,12 @@ public class DashboardController {
return currentUser.getShopId();
}
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param shopId parameter `shopId` supplied by the caller
+ * @return private Long result consumed by the caller or returned to the frontend
+ */
private Long getTodayOrders(Long shopId) {
// 获取今天的开始时间
LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
@@ -133,6 +191,12 @@ public class DashboardController {
}
}
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param shopId parameter `shopId` supplied by the caller
+ * @return private List result consumed by the caller or returned to the frontend
+ */
private List getHotProducts(Long shopId) {
// 通过订单商品表统计每个商品的订单数量,按订单数量排序
// 使用SQL查询获取商品及其订单数量
@@ -180,6 +244,12 @@ public class DashboardController {
return hotProducts;
}
+ /**
+ * Load data by the supplied parameter.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @param shopId parameter `shopId` supplied by the caller
+ * @return private List result consumed by the caller or returned to the frontend
+ */
private List getRecentActivities(Long shopId) {
List activities = new ArrayList<>();
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/EffectDiagramController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/EffectDiagramController.java
index 3779b2fe..9a366373 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/EffectDiagramController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/EffectDiagramController.java
@@ -20,7 +20,9 @@ import java.util.List;
@RequestMapping({"/effect-diagram", "/api/effect-diagram"})
@RequiredArgsConstructor
public class EffectDiagramController {
-
+ /**
+ * Variable `effectDiagramService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final EffectDiagramService effectDiagramService;
/**
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/FrontendFileController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/FrontendFileController.java
index c02fc27b..154f0a09 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/FrontendFileController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/FrontendFileController.java
@@ -19,9 +19,17 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/file")
@RequiredArgsConstructor
public class FrontendFileController {
-
+ /**
+ * Variable `objectStorageFileService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final ObjectStorageFileService objectStorageFileService;
+ /**
+ * Variable `minioService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final MinioService minioService;
+ /**
+ * Variable `objectStorageUrlSupport`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final ObjectStorageUrlSupport objectStorageUrlSupport;
/**
diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/HealthController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/HealthController.java
index 911fc0b3..ecf16e50 100644
--- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/HealthController.java
+++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/HealthController.java
@@ -27,10 +27,21 @@ import java.util.Map;
@RequestMapping("/health")
@RequiredArgsConstructor
public class HealthController {
-
+ /**
+ * Variable `dataSource`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final DataSource dataSource;
+ /**
+ * Variable `stringRedisTemplate`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final StringRedisTemplate stringRedisTemplate;
+ /**
+ * Variable `discoveryClient`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final DiscoveryClient discoveryClient;
+ /**
+ * Variable `environment`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
+ */
private final Environment environment;
/**
@@ -42,6 +53,11 @@ public class HealthController {
}
@GetMapping("/diagnostics")
+ /**
+ * Run business method `diagnostics`.
+ * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
+ * @return Result