feat(assoc): v4.0.1 合伙人关联码、分佣账单与 H5 用户管理

订单佣金只认关联用户;合伙人备注写入独立表;H5 增加用户管理与首页统计。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-30 14:35:39 +08:00
parent 3b669f7e38
commit 9c8d5f2cad
125 changed files with 6355 additions and 1436 deletions
+68
View File
@@ -0,0 +1,68 @@
export const BENEFIT_SLOGAN = '购杜康好酒,赠用餐权益';
export const BENEFIT_INTRO =
'购杜康好酒,赠用餐权益,到签约饭店核销。权益随酒赠送,仅限签约饭店到店用餐,不可兑现、不可转卖。';
export const BENEFIT_INTRO_EMPHASIS = '不可兑现、不可转卖。';
export const BENEFIT_GIFT_TAG = '买酒即赠用餐权益';
export const BENEFIT_TAG = '好客权益';
export const BENEFIT_RULES_PATH = '/pages/benefit-rules/index';
export const BENEFIT_RULES_TITLE = '好客权益使用说明';
export const BENEFIT_RULES_SUMMARY =
'购杜康好酒,赠用餐权益,到签约饭店核销。权益随酒赠送,仅限杜康好客平台签约饭店到店用餐,不可兑现、不可转卖。';
export const BENEFIT_RULES_SECTIONS = [
{
heading: '一、权益从哪来',
paragraphs: [
'好客权益是购买杜康好酒时随酒赠送的用餐权益,用于在签约饭店到店用餐,不是储值卡、预付卡,也不是现金账户。',
],
},
{
heading: '二、如何获得',
paragraphs: [
'在小程序内购买杜康好酒并支付成功后,系统按商品说明发放对应用餐权益。未支付或已取消的订单不产生权益。不支持单独购买或充值权益。',
],
},
{
heading: '三、如何使用',
paragraphs: [
'1. 在「门店」中选择签约饭店,到店用餐时出示核销码或提供手机号,由门店完成核销。',
'2. 核销码有效期为 3 分钟,过期请重新生成。',
'3. 权益可按实际消费分次核销,累计核销金额不可超过已获得的权益总额。',
],
},
{
heading: '四、使用范围',
paragraphs: [
'仅限杜康好客平台签约饭店到店用餐使用。香烟、酒水一律不可核销。其他菜品是否可核销以门店当场说明为准。',
],
emphasize: '香烟、酒水一律不可核销。',
},
{
heading: '五、使用限制',
paragraphs: ['不可兑现、不可转卖、不可提现、不可充值,不可当现金使用。'],
emphasizeAll: true,
},
{
heading: '六、退货与权益收回',
paragraphs: [
'酒水退货退款时,未使用的权益将收回;已核销部分不退回。酒款按原支付路径退回。仅换货不退款的,一般保留原权益。',
],
},
{
heading: '七、有效期',
paragraphs: ['好客权益暂无使用期限,持续有效,直至收回或全部核销完毕。'],
},
{
heading: '八、联系客服',
paragraphs: ['如有疑问,可通过小程序「联系客服」咨询,或拨打客服电话。'],
},
] as const;
export const BENEFIT_RULES_FOOTER = '请理性饮酒。未满十八周岁不得饮酒。过量饮酒有害健康。';
+1 -1
View File
@@ -2,7 +2,7 @@ import Taro from '@tarojs/taro';
import { fetchClientConfig } from './pay-wechat';
/** 与 package.json version 同步,供服务端 minClientVersion 比对 */
export const APP_VERSION = '3.5.10';
export const APP_VERSION = '3.5.16';
export const APP_VERSION_LABEL = `v${APP_VERSION}`;
@@ -0,0 +1,316 @@
/** Canvas 金龙:盘成一圈,仿照立体金龙的鳞片、须、角、爪与光晕 */
export type DragonCanvasNode = {
width: number;
height: number;
getContext: (type: '2d') => CanvasRenderingContext2D;
requestAnimationFrame?: (cb: (time: number) => void) => number;
cancelAnimationFrame?: (id: number) => void;
};
type SpinePt = {
x: number;
y: number;
ang: number;
nx: number;
ny: number;
w: number;
};
const GOLD_HI = '#fff6c8';
const GOLD = '#ffbf00';
const GOLD_MID = '#e8a800';
const GOLD_DEEP = '#b87500';
function lerp(a: number, b: number, t: number) {
return a + (b - a) * t;
}
function fillOval(
ctx: CanvasRenderingContext2D,
x: number,
y: number,
rw: number,
rh: number,
rot: number,
) {
ctx.save();
ctx.translate(x, y);
ctx.rotate(rot);
ctx.scale(Math.max(0.01, rw), Math.max(0.01, rh));
ctx.beginPath();
ctx.arc(0, 0, 1, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
function easeInCubic(t: number) {
return t * t * t;
}
function buildSpine(cx: number, cy: number, r: number, phase: number, segs: number): SpinePt[] {
const pts: SpinePt[] = [];
const turns = 0.94;
for (let i = 0; i < segs; i++) {
const u = i / (segs - 1);
const ang = -Math.PI / 2 + u * Math.PI * 2 * turns;
const wobble = Math.sin(u * 14 + phase) * r * 0.042 + Math.sin(u * 5.5 - phase * 0.7) * r * 0.02;
const rr = r + wobble;
const nx = Math.cos(ang);
const ny = Math.sin(ang);
pts.push({
x: cx + nx * rr,
y: cy + ny * rr,
ang,
nx,
ny,
w: lerp(20, 6.5, u ** 0.62),
});
}
return pts;
}
function strokeRibbon(
ctx: CanvasRenderingContext2D,
pts: SpinePt[],
widthScale: number,
color: string,
alpha: number,
) {
if (pts.length < 2) return;
ctx.save();
ctx.globalAlpha = alpha;
ctx.strokeStyle = color;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.beginPath();
ctx.moveTo(pts[0].x, pts[0].y);
for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y);
ctx.lineWidth = pts[Math.floor(pts.length * 0.15)].w * widthScale;
ctx.stroke();
ctx.restore();
}
function drawScales(ctx: CanvasRenderingContext2D, pts: SpinePt[]) {
for (let i = 2; i < pts.length - 1; i += 1) {
const p = pts[i];
const u = i / (pts.length - 1);
const ox = p.x + p.nx * p.w * 0.18;
const oy = p.y + p.ny * p.w * 0.18;
ctx.save();
ctx.translate(ox, oy);
ctx.rotate(p.ang + Math.PI / 2);
ctx.fillStyle = i % 2 === 0 ? GOLD_HI : GOLD;
ctx.globalAlpha = 0.55 + (1 - u) * 0.25;
fillOval(ctx, 0, 0, p.w * 0.55, p.w * 0.38, 0);
ctx.restore();
}
}
function drawSpines(ctx: CanvasRenderingContext2D, pts: SpinePt[]) {
ctx.fillStyle = GOLD_HI;
for (let i = 3; i < pts.length - 6; i += 3) {
const p = pts[i];
const len = p.w * 1.35;
ctx.save();
ctx.globalAlpha = 0.85;
ctx.beginPath();
ctx.moveTo(p.x + p.nx * p.w * 0.2, p.y + p.ny * p.w * 0.2);
ctx.lineTo(
p.x + p.nx * (p.w + len),
p.y + p.ny * (p.w + len),
);
const tx = -p.ny;
const ty = p.nx;
ctx.lineTo(p.x + tx * 2.2, p.y + ty * 2.2);
ctx.closePath();
ctx.fill();
ctx.restore();
}
}
function drawClaw(ctx: CanvasRenderingContext2D, p: SpinePt, side: number) {
const tx = -p.ny * side;
const ty = p.nx * side;
const baseX = p.x + tx * p.w * 0.7;
const baseY = p.y + ty * p.w * 0.7;
ctx.save();
ctx.translate(baseX, baseY);
ctx.rotate(Math.atan2(ty, tx));
ctx.fillStyle = GOLD;
ctx.strokeStyle = GOLD_DEEP;
ctx.lineWidth = 0.8;
for (let k = -1; k <= 1; k++) {
ctx.beginPath();
ctx.moveTo(0, k * 4);
ctx.quadraticCurveTo(10, k * 6 - 2, 18, k * 5);
ctx.quadraticCurveTo(10, k * 4, 0, k * 3);
ctx.closePath();
ctx.fill();
ctx.stroke();
}
ctx.restore();
}
function drawHead(ctx: CanvasRenderingContext2D, p: SpinePt, phase: number) {
ctx.save();
ctx.translate(p.x + p.nx * 10, p.y + p.ny * 10);
ctx.rotate(Math.atan2(p.ny, p.nx) + Math.PI / 2);
const mane = 6;
for (let i = 0; i < mane; i++) {
const a = -0.9 + (i / (mane - 1)) * 1.8;
ctx.beginPath();
ctx.strokeStyle = i % 2 ? GOLD_HI : GOLD;
ctx.globalAlpha = 0.7;
ctx.lineWidth = 2.2;
ctx.moveTo(Math.sin(a) * 6, -4);
ctx.quadraticCurveTo(Math.sin(a) * 16, -18 - Math.sin(phase + i) * 3, Math.sin(a) * 8, -28);
ctx.stroke();
}
ctx.globalAlpha = 1;
ctx.beginPath();
ctx.moveTo(-7, -18);
ctx.quadraticCurveTo(-16, -32, -5, -38);
ctx.quadraticCurveTo(-2, -26, -3, -16);
ctx.fillStyle = GOLD_MID;
ctx.fill();
ctx.beginPath();
ctx.moveTo(7, -18);
ctx.quadraticCurveTo(16, -32, 5, -38);
ctx.quadraticCurveTo(2, -26, 3, -16);
ctx.fill();
const g = ctx.createRadialGradient(-4, -4, 2, 0, 4, 20);
g.addColorStop(0, GOLD_HI);
g.addColorStop(0.45, GOLD);
g.addColorStop(1, GOLD_DEEP);
ctx.fillStyle = g;
fillOval(ctx, 0, 2, 16, 18, 0);
ctx.fillStyle = GOLD_MID;
fillOval(ctx, 0, 10, 9, 8, 0);
for (const sx of [-6.5, 6.5]) {
ctx.fillStyle = '#3a1a00';
fillOval(ctx, sx, -2, 3.2, 3.6, 0);
ctx.fillStyle = '#ffe566';
fillOval(ctx, sx, -2.4, 1.5, 1.7, 0);
ctx.fillStyle = '#fff';
fillOval(ctx, sx - 0.5, -3, 0.6, 0.6, 0);
}
ctx.strokeStyle = GOLD_HI;
ctx.lineWidth = 1.15;
ctx.globalAlpha = 0.9;
for (const side of [-1, 1]) {
ctx.beginPath();
ctx.moveTo(side * 12, 6);
ctx.quadraticCurveTo(side * 36, 10 + Math.sin(phase) * 2, side * 42, 22);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(side * 10, 9);
ctx.quadraticCurveTo(side * 28, 18, side * 34, 28);
ctx.stroke();
}
ctx.globalAlpha = 1;
ctx.restore();
}
function drawSparks(
ctx: CanvasRenderingContext2D,
cx: number,
cy: number,
r: number,
phase: number,
) {
for (let i = 0; i < 28; i++) {
const a = (i / 28) * Math.PI * 2 + phase * 0.35;
const rr = r * (0.72 + ((i * 17) % 10) / 40);
const x = cx + Math.cos(a) * rr + Math.sin(phase * 1.4 + i) * 4;
const y = cy + Math.sin(a) * rr + Math.cos(phase * 1.1 + i) * 3;
const s = 1.1 + (i % 5) * 0.35;
ctx.beginPath();
ctx.globalAlpha = 0.25 + (Math.sin(phase * 2 + i) + 1) * 0.25;
ctx.fillStyle = i % 3 === 0 ? GOLD_HI : GOLD;
ctx.arc(x, y, s, 0, Math.PI * 2);
ctx.fill();
}
ctx.globalAlpha = 1;
}
export function drawJiuzuDragonFrame(
ctx: CanvasRenderingContext2D,
width: number,
height: number,
elapsedMs: number,
) {
const cx = width / 2;
const cy = height * 0.42;
const radius = Math.min(width, height) * 0.3;
const fadeIn = Math.min(1, elapsedMs / 380);
const spinT = Math.min(1, Math.max(0, (elapsedMs - 120) / 2050));
const flyT = Math.min(1, Math.max(0, (elapsedMs - 2200) / 1200));
const spin = spinT * Math.PI * 2;
const fly = easeInCubic(flyT);
const phase = elapsedMs / 220;
ctx.clearRect(0, 0, width, height);
ctx.save();
ctx.globalAlpha = fadeIn * (1 - fly);
ctx.translate(cx, cy + fly * -height * 0.42);
ctx.scale(1 + fly * 0.55, 1 + fly * 0.55);
ctx.rotate(spin);
ctx.translate(-cx, -cy);
const pts = buildSpine(cx, cy, radius, phase, 56);
strokeRibbon(ctx, pts, 2.4, 'rgba(255, 191, 0, 0.18)', 1);
strokeRibbon(ctx, pts, 1.55, 'rgba(255, 214, 80, 0.4)', 1);
ctx.save();
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.beginPath();
ctx.moveTo(pts[0].x, pts[0].y);
for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y);
const bodyGrad = ctx.createLinearGradient(cx - radius, cy, cx + radius, cy);
bodyGrad.addColorStop(0, GOLD_DEEP);
bodyGrad.addColorStop(0.5, GOLD);
bodyGrad.addColorStop(1, GOLD_HI);
ctx.strokeStyle = bodyGrad;
ctx.lineWidth = pts[0].w * 1.15;
ctx.shadowColor = 'rgba(255, 191, 0, 0.7)';
ctx.shadowBlur = 16;
ctx.stroke();
ctx.shadowBlur = 0;
ctx.restore();
drawScales(ctx, pts);
drawSpines(ctx, pts);
drawClaw(ctx, pts[Math.floor(pts.length * 0.32)], 1);
drawClaw(ctx, pts[Math.floor(pts.length * 0.68)], -1);
drawHead(ctx, pts[0], phase);
drawSparks(ctx, cx, cy, radius, phase);
ctx.restore();
}
export function scheduleDragonFrame(
canvas: DragonCanvasNode,
cb: (time: number) => void,
): number {
if (typeof canvas.requestAnimationFrame === 'function') {
return canvas.requestAnimationFrame(cb);
}
return requestAnimationFrame(cb);
}
export function cancelDragonFrame(canvas: DragonCanvasNode, id: number) {
if (typeof canvas.cancelAnimationFrame === 'function') {
canvas.cancelAnimationFrame(id);
return;
}
cancelAnimationFrame(id);
}
+22
View File
@@ -0,0 +1,22 @@
import Taro from '@tarojs/taro';
import { JIUZU_SPLASH_GIF_URL, JIUZU_SPLASH_MARK_URL } from '@dukang/shared-types';
/** 冷启动会话内是否已播过「酒祖杜康」开场(进程级,切 Tab 不重播) */
let played = false;
export function hasJiuzuSplashPlayed() {
return played;
}
export function markJiuzuSplashPlayed() {
played = true;
}
/** 冷启动预拉 OSS 开场图(仅 weappH5 的 getImageInfo 会走 CORS */
export function prefetchJiuzuSplashAssets() {
if (played) return;
if (process.env.TARO_ENV !== 'weapp') return;
void Taro.getImageInfo({ src: JIUZU_SPLASH_GIF_URL }).catch(() => {});
void Taro.getImageInfo({ src: JIUZU_SPLASH_MARK_URL }).catch(() => {});
}
+74 -1
View File
@@ -1,7 +1,8 @@
import Taro from '@tarojs/taro';
import { request } from './api';
import { request, isLoggedIn, toast } from './api';
const PROMO_ID_KEY = 'dukang_promo_id';
const ASSOC_SCENE_KEY = 'dukang_partner_assoc_scene';
/** 同一次进入只 touch 一次扫码计数,避免首页反复 onShow 刷量 */
let lastScanTouchKey = '';
@@ -28,10 +29,54 @@ type EnterOptionsLike = {
path?: string;
};
function normalizeAssocScene(raw: unknown): string | null {
if (raw == null || raw === '') return null;
const s = safeDecode(String(raw)).trim();
return /^pa_\d+$/.test(s) ? s : null;
}
function extractAssocSceneFromEnterOptions(opts?: EnterOptionsLike | null): string | null {
if (!opts) return null;
const q = opts.query ?? {};
return (
normalizeAssocScene(q.scene) ||
normalizeAssocScene(opts.scene) ||
normalizeAssocScene(q.partnerId) ||
null
);
}
export function getStoredAssocScene(): string | null {
try {
return normalizeAssocScene(Taro.getStorageSync(ASSOC_SCENE_KEY));
} catch {
return null;
}
}
export function setStoredAssocScene(scene: string) {
const id = normalizeAssocScene(scene);
if (!id) return;
try {
Taro.setStorageSync(ASSOC_SCENE_KEY, id);
} catch {
/* ignore */
}
}
export function clearStoredAssocScene() {
try {
Taro.removeStorageSync(ASSOC_SCENE_KEY);
} catch {
/* ignore */
}
}
/** 从启动/进入参数解析推广活动 ID(优先 query.scene,与 getwxacodeunlimit 一致) */
export function extractPromoIdFromEnterOptions(opts?: EnterOptionsLike | null): string | null {
if (!opts) return null;
const q = opts.query ?? {};
if (extractAssocSceneFromEnterOptions(opts)) return null;
return (
normalizePromoId(q.scene) ||
normalizePromoId(q.promoId) ||
@@ -92,8 +137,35 @@ function readEnterOptions(): EnterOptionsLike | null {
* 主页面进入时:取出 scene(活动 ID)本地缓存,并回传 /promo/touch 累加扫码次数。
* 同一进入会话只计一次扫码。
*/
async function bindStoredAssocIfLoggedIn(): Promise<void> {
const scene = getStoredAssocScene();
if (!scene || !isLoggedIn()) return;
try {
const result = await request<{ alreadyBound?: boolean; bound?: boolean }>('/user/partner-assoc/bind', {
method: 'POST',
data: { scene },
});
clearStoredAssocScene();
if (result.alreadyBound) toast('已关联');
else if (result.bound) toast('关联成功', 'success');
} catch (e) {
const msg = e instanceof Error ? e.message : '';
if (msg.includes('已关联')) {
clearStoredAssocScene();
toast('已关联');
}
}
}
export async function capturePromoSceneAndTouchScan(): Promise<void> {
const opts = readEnterOptions();
const assocScene = extractAssocSceneFromEnterOptions(opts);
if (assocScene) {
setStoredAssocScene(assocScene);
await bindStoredAssocIfLoggedIn();
return;
}
const fromEnter = extractPromoIdFromEnterOptions(opts);
if (fromEnter) {
setStoredPromoId(fromEnter);
@@ -109,6 +181,7 @@ export async function capturePromoSceneAndTouchScan(): Promise<void> {
/** 登录成功后:用已缓存的活动 ID 做归因(不重复加扫码次数) */
export async function touchStoredPromoAfterLogin(): Promise<void> {
await bindStoredAssocIfLoggedIn();
const promoId = getStoredPromoId();
if (!promoId) return;
await touchPromo({ promoId, countScan: false });
+53
View File
@@ -0,0 +1,53 @@
export type StoreCategoryLike = {
id?: string;
name?: string;
parentId?: string | null;
parent?: { name?: string } | null;
};
export type StoreCategoryTreeNode = {
id: string;
name: string;
children?: { id: string; name: string }[];
};
export function storeStarCount(rating?: number | string | null): number {
const n = Number(rating);
if (!Number.isFinite(n) || n <= 0) return 5;
return Math.min(5, Math.max(1, Math.round(n)));
}
export function storeCategoryTags(
store: {
tags?: unknown;
categoryId?: string | null;
category?: StoreCategoryLike | null;
},
tree: StoreCategoryTreeNode[] = [],
): string[] {
const fromJson = Array.isArray(store.tags)
? store.tags.map((t) => String(t).trim()).filter(Boolean)
: [];
if (fromJson.length) return fromJson;
const names: string[] = [];
const childName = String(store.category?.name || '').trim();
const parentName = String(store.category?.parent?.name || '').trim();
if (parentName) names.push(parentName);
if (childName && childName !== parentName) names.push(childName);
const storeCatId = String(store.categoryId || store.category?.id || '');
const storeParentId = String(store.category?.parentId || '');
for (const root of tree) {
if (root.id === storeParentId || root.id === storeCatId) {
if (root.name && !names.includes(root.name)) names.unshift(root.name);
}
for (const child of root.children ?? []) {
if (child.id === storeCatId) {
if (root.name && !names.includes(root.name)) names.unshift(root.name);
if (child.name && !names.includes(child.name)) names.push(child.name);
}
}
}
return names;
}
+7 -2
View File
@@ -19,6 +19,8 @@ export type StoresSessionCategory = {
childName: string;
};
export type StoreSortKey = 'nearby' | 'rating' | 'redeem';
export type StoresListCache = {
cityKey: string;
cityCode: string;
@@ -30,6 +32,7 @@ export type StoresListCache = {
keyword: string;
keywordInput: string;
category: StoresSessionCategory;
sort?: StoreSortKey;
};
type StoresSession = {
@@ -37,7 +40,7 @@ type StoresSession = {
cache: StoresListCache | null;
};
const STORAGE_KEY = 'dukang_stores_session_v1';
const STORAGE_KEY = 'dukang_stores_session_v2';
let memory: StoresSession | null = null;
@@ -94,7 +97,7 @@ export function setStoresListCache(cache: StoresListCache | null): void {
export function patchStoresFilterCache(
patch: Partial<
Pick<StoresListCache, 'filterRegion' | 'keyword' | 'keywordInput' | 'category'>
Pick<StoresListCache, 'filterRegion' | 'keyword' | 'keywordInput' | 'category' | 'sort'>
>,
): void {
const cur = readSession();
@@ -105,6 +108,7 @@ export function patchStoresFilterCache(
cache: {
cityKey: '',
cityCode: '',
authKey: '',
listRegion: patch.filterRegion ?? { province: '', city: '', district: '' },
items: [],
filterRegion: patch.filterRegion ?? { province: '', city: '', district: '' },
@@ -116,6 +120,7 @@ export function patchStoresFilterCache(
childId: '',
childName: '',
},
sort: patch.sort ?? 'nearby',
},
});
return;
@@ -0,0 +1,59 @@
import Taro from '@tarojs/taro';
import { STORE_RATING_MAX_IMAGES } from '@dukang/shared-types';
export async function chooseAndUploadRatingImages(already: number): Promise<string[]> {
const remain = STORE_RATING_MAX_IMAGES - already;
if (remain <= 0) {
throw new Error(`最多上传${STORE_RATING_MAX_IMAGES}张图片`);
}
const picked = await Taro.chooseImage({
count: remain,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
});
const paths = picked.tempFilePaths || [];
if (!paths.length) return [];
const urls: string[] = [];
for (const path of paths) {
urls.push(await uploadRatingImage(path));
}
return urls;
}
export async function uploadRatingImage(tempFilePath: string): Promise<string> {
const { API_BASE, CLIENT_APP, getToken } = await import('./api');
const { compressWeappImageIfNeeded } = await import('./compress-image');
const token = getToken();
if (!token) throw new Error('请先登录');
const filePath = await compressWeappImageIfNeeded(tempFilePath);
const res = await Taro.uploadFile({
url: `${API_BASE}/common/resources/upload`,
filePath,
name: 'file',
formData: {
bizType: 'STORE_RATING',
mediaType: 'IMAGE',
},
header: {
Authorization: `Bearer ${token}`,
'X-Client-App': CLIENT_APP,
},
});
let body: { code?: number; message?: string; data?: { url?: string } } = {};
try {
body = JSON.parse(String(res.data || '{}')) as typeof body;
} catch {
throw new Error('图片上传响应异常');
}
if (res.statusCode === 401 || body.code === 401) {
throw new Error(body.message || '登录已过期,请重新登录');
}
if (res.statusCode >= 400 || body.code !== 0 || !body.data?.url) {
throw new Error(body.message || '图片上传失败');
}
return body.data.url;
}