+
门店名称
{storeName}
{String(s.address || s.district || '')}
-
- {pill.label}
- {audit && {audit.label}}
-
+
+ {storeStatusLabel(currentStatus)}
+
-
-
-
+
+
+ {currentStatus === 'PAUSED' && (
+
+ )}
+
edit
diff --git a/apps/h5-partner/src/styles.css b/apps/h5-partner/src/styles.css
index 95de32b..aadbbc5 100644
--- a/apps/h5-partner/src/styles.css
+++ b/apps/h5-partner/src/styles.css
@@ -926,6 +926,230 @@ html, body, #root {
font-size: 10px;
}
+.partner-upload-dashed--compact {
+ padding: 12px;
+ font-size: 10px;
+ aspect-ratio: 1;
+}
+
+.partner-oss-upload-input {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ opacity: 0;
+ overflow: hidden;
+ clip: rect(0, 0, 0, 0);
+}
+
+.partner-upload-preview {
+ position: relative;
+ display: block;
+ width: 100%;
+ border: none;
+ padding: 0;
+ background: transparent;
+ border-radius: 12px;
+ overflow: hidden;
+ cursor: pointer;
+}
+
+.partner-upload-preview--wide {
+ aspect-ratio: 16 / 9;
+}
+
+.partner-upload-preview img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ display: block;
+}
+
+.partner-upload-preview-mask {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 4px;
+ background: rgba(0, 0, 0, 0.35);
+ color: #fff;
+ opacity: 0;
+ transition: opacity 0.2s ease;
+}
+
+.partner-upload-preview:hover .partner-upload-preview-mask,
+.partner-upload-preview:focus-within .partner-upload-preview-mask {
+ opacity: 1;
+}
+
+.partner-upload-file {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ width: 100%;
+ min-height: 96px;
+ padding: 16px;
+ border-radius: 12px;
+ background-color: var(--color-surface-container-low);
+ border: 1px solid rgba(166, 29, 36, 0.2);
+ cursor: pointer;
+ text-align: left;
+}
+
+.partner-region-trigger {
+ width: 100%;
+ justify-content: flex-start;
+ text-align: left;
+}
+
+.partner-region-chevron {
+ margin-left: auto;
+}
+
+.partner-region-overlay {
+ position: fixed;
+ inset: 0;
+ z-index: 10000;
+ background: rgba(0, 0, 0, 0.45);
+ display: flex;
+ align-items: flex-end;
+ justify-content: center;
+ padding-bottom: env(safe-area-inset-bottom, 0px);
+}
+
+.partner-region-sheet {
+ width: 100%;
+ max-width: 480px;
+ max-height: min(78vh, 640px);
+ background: var(--color-surface);
+ border-radius: 16px 16px 0 0;
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+}
+
+.partner-region-sheet-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 12px 16px;
+ border-bottom: 1px solid var(--color-outline-variant);
+ flex-shrink: 0;
+}
+
+.partner-region-sheet-btn {
+ border: none;
+ background: transparent;
+ color: var(--color-on-surface-variant);
+ font-size: 14px;
+ padding: 8px;
+ min-width: 48px;
+}
+
+.partner-region-sheet-btn--primary {
+ color: var(--color-primary);
+ font-weight: 600;
+}
+
+.partner-region-sheet-btn--primary:disabled {
+ opacity: 0.4;
+}
+
+.partner-region-steps {
+ display: flex;
+ gap: 8px;
+ padding: 12px 16px 0;
+ overflow-x: auto;
+ -webkit-overflow-scrolling: touch;
+ flex-shrink: 0;
+}
+
+.partner-region-step {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ border: 1px solid var(--color-outline-variant);
+ border-radius: 999px;
+ padding: 6px 12px;
+ background: var(--color-surface-container-low);
+ color: var(--color-on-surface-variant);
+ font-size: 12px;
+ white-space: nowrap;
+}
+
+.partner-region-step--active {
+ border-color: var(--color-primary);
+ color: var(--color-primary);
+ background: rgba(166, 29, 36, 0.08);
+}
+
+.partner-region-step--done {
+ color: var(--color-on-surface);
+}
+
+.partner-region-step-index {
+ width: 18px;
+ height: 18px;
+ border-radius: 50%;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ background: var(--color-surface-container-highest);
+ font-size: 11px;
+ font-weight: 700;
+}
+
+.partner-region-step--active .partner-region-step-index {
+ background: var(--color-primary);
+ color: #fff;
+}
+
+.partner-region-breadcrumb {
+ padding: 8px 16px 0;
+ flex-shrink: 0;
+}
+
+.partner-region-list {
+ flex: 1;
+ min-height: 0;
+ overflow-y: auto;
+ -webkit-overflow-scrolling: touch;
+ overscroll-behavior: contain;
+ touch-action: pan-y;
+ padding: 8px 0 calc(12px + env(safe-area-inset-bottom, 0px));
+}
+
+.partner-region-columns {
+ display: none;
+}
+
+.partner-region-column {
+ overflow-y: auto;
+ border-right: 1px solid var(--color-outline-variant);
+}
+
+.partner-region-column:last-child {
+ border-right: none;
+}
+
+.partner-region-item {
+ display: block;
+ width: 100%;
+ border: none;
+ background: transparent;
+ text-align: left;
+ padding: 14px 16px;
+ font-size: 15px;
+ color: var(--color-on-surface);
+}
+
+.partner-region-item--active {
+ color: var(--color-primary);
+ background: rgba(166, 29, 36, 0.08);
+ font-weight: 600;
+}
+
.partner-sticky-footer {
position: fixed;
bottom: 0;
@@ -1053,7 +1277,39 @@ html, body, #root {
display: flex;
justify-content: space-between;
align-items: flex-start;
- margin-bottom: 16px;
+ gap: 12px;
+}
+
+.partner-store-card-hit {
+ display: block;
+ width: 100%;
+ color: inherit;
+ text-decoration: none;
+}
+
+.partner-audit-result {
+ margin: 48px var(--space-page) 0;
+ padding: 32px 24px;
+ text-align: center;
+ background: var(--color-card);
+ border-radius: var(--radius-md);
+ box-shadow: var(--shadow-card);
+}
+
+.partner-audit-result-icon {
+ width: 72px;
+ height: 72px;
+ margin: 0 auto 16px;
+ border-radius: 50%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: rgba(42, 110, 187, 0.12);
+ color: var(--color-status-blue);
+}
+
+.partner-audit-result-icon .material-symbols-outlined {
+ font-size: 36px;
}
.partner-status-pill {
@@ -1074,6 +1330,11 @@ html, body, #root {
color: var(--color-secondary);
}
+.partner-status-pill--auditing {
+ background: rgba(42, 110, 187, 0.12);
+ color: var(--color-status-blue);
+}
+
.partner-status-pill--closed {
background: var(--color-surface-container);
color: var(--color-subtle-gray);
@@ -1217,7 +1478,7 @@ html, body, #root {
padding: 12px 24px;
border-radius: 8px;
font-size: 14px;
- z-index: 200;
+ z-index: 10001;
}
/* ── Orders ── */
diff --git a/packages/weixin-sdk/src/chooseImage.ts b/packages/weixin-sdk/src/chooseImage.ts
new file mode 100644
index 0000000..e467939
--- /dev/null
+++ b/packages/weixin-sdk/src/chooseImage.ts
@@ -0,0 +1,83 @@
+import { getRuntimePlatform } from './env';
+import { ensureJssdkReady } from './jssdk';
+import type { WeixinSdkConfig } from './types';
+
+export type ChooseWechatImageOptions = {
+ count?: number;
+ sourceType?: Array<'album' | 'camera'>;
+};
+
+function base64ToFile(base64: string, fileName: string): File {
+ const normalized = base64.startsWith('data:')
+ ? base64
+ : `data:image/jpeg;base64,${base64.replace(/\s/g, '')}`;
+ const [header, body] = normalized.split(',');
+ const mime = header.match(/:(.*?);/)?.[1] ?? 'image/jpeg';
+ const binary = atob(body);
+ const bytes = new Uint8Array(binary.length);
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
+ return new File([bytes], fileName, { type: mime });
+}
+
+function localIdToFile(localId: string): Promise
{
+ return new Promise((resolve, reject) => {
+ if (!window.wx?.getLocalImgData) {
+ reject(new Error('微信 getLocalImgData 不可用'));
+ return;
+ }
+ window.wx.getLocalImgData({
+ localId,
+ success: (res) => {
+ try {
+ resolve(base64ToFile(res.localData, `wx-${Date.now()}.jpg`));
+ } catch (e) {
+ reject(e instanceof Error ? e : new Error('图片解析失败'));
+ }
+ },
+ fail: (err) => reject(new Error(err.errMsg || '读取图片失败')),
+ });
+ });
+}
+
+/** 微信内选图(相册/拍照),返回 File 列表;非微信环境返回 null */
+export async function chooseWechatImages(
+ config: WeixinSdkConfig,
+ options: ChooseWechatImageOptions = {},
+): Promise {
+ const platform = getRuntimePlatform();
+ if (platform === 'browser') return null;
+
+ const count = options.count ?? 1;
+ const sourceType = options.sourceType ?? ['album', 'camera'];
+
+ if (platform === 'wechat-h5') {
+ await ensureJssdkReady({
+ apiBase: config.apiBase ?? '/api/v1',
+ clientApp: config.clientApp,
+ getAccessToken: config.getAccessToken,
+ });
+ if (!window.wx?.chooseImage) return null;
+
+ const localIds = await new Promise((resolve, reject) => {
+ window.wx!.chooseImage!({
+ count,
+ sizeType: ['compressed'],
+ sourceType,
+ success: (res) => resolve(res.localIds ?? []),
+ fail: (err) => reject(new Error(err.errMsg || '无法打开相册')),
+ });
+ });
+
+ const files: File[] = [];
+ for (const localId of localIds) {
+ files.push(await localIdToFile(localId));
+ }
+ return files;
+ }
+
+ return null;
+}
+
+export function canUseWechatChooseImage(): boolean {
+ return getRuntimePlatform() !== 'browser';
+}
diff --git a/packages/weixin-sdk/src/index.ts b/packages/weixin-sdk/src/index.ts
index c7c0b5b..574f4c6 100644
--- a/packages/weixin-sdk/src/index.ts
+++ b/packages/weixin-sdk/src/index.ts
@@ -7,6 +7,8 @@ export {
} from './location';
export { scanQrCode } from './scan';
export { invokeWechatPay } from './pay';
+export { chooseWechatImages, canUseWechatChooseImage } from './chooseImage';
+export type { ChooseWechatImageOptions } from './chooseImage';
export {
getWechatOAuthUrl,
startWechatOAuthLogin,
@@ -25,6 +27,7 @@ import { initWechatJssdk } from './jssdk';
import { getWechatLocation } from './location';
import { scanQrCode } from './scan';
import { invokeWechatPay } from './pay';
+import { chooseWechatImages } from './chooseImage';
import {
wechatLogin,
handleWechatOAuthCallback,
@@ -43,6 +46,8 @@ export function createWeixinSdk(config: WeixinSdkConfig) {
getPhoneNumber: () => getWechatPhoneNumber(config),
getLocation: () => getWechatLocation(config),
scanQrCode: () => scanQrCode(config),
+ chooseImages: (options?: Parameters[1]) =>
+ chooseWechatImages(config, options),
pay: (prepay: Parameters[0]) =>
invokeWechatPay(prepay, { apiBase: config.apiBase, clientApp: config.clientApp }),
};
diff --git a/packages/weixin-sdk/src/types.ts b/packages/weixin-sdk/src/types.ts
index 2041494..00450d0 100644
--- a/packages/weixin-sdk/src/types.ts
+++ b/packages/weixin-sdk/src/types.ts
@@ -34,6 +34,18 @@ export type WxApi = {
fail?: (res: { errMsg: string }) => void;
cancel?: () => void;
}) => void;
+ chooseImage: (options: {
+ count?: number;
+ sizeType?: Array<'original' | 'compressed'>;
+ sourceType?: Array<'album' | 'camera'>;
+ success?: (res: { localIds: string[] }) => void;
+ fail?: (res: { errMsg: string }) => void;
+ }) => void;
+ getLocalImgData: (options: {
+ localId: string;
+ success?: (res: { localData: string }) => void;
+ fail?: (res: { errMsg: string }) => void;
+ }) => void;
};
export type MiniProgramWx = {
@@ -80,6 +92,8 @@ export const DEFAULT_JS_API_LIST = [
'getLocation',
'scanQRCode',
'chooseWXPay',
+ 'chooseImage',
+ 'getLocalImgData',
'updateAppMessageShareData',
'updateTimelineShareData',
] as const;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ac4c679..ac2c434 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -59,6 +59,12 @@ importers:
'@dukang/shared-ui':
specifier: workspace:*
version: link:../../packages/shared-ui
+ '@dukang/weixin-sdk':
+ specifier: workspace:*
+ version: link:../../packages/weixin-sdk
+ element-china-area-data:
+ specifier: ^6.1.0
+ version: 6.1.0
react:
specifier: ^18.3.1
version: 18.3.1
diff --git a/server/dukang-api/src/integrations/oss/oss.aliyun.provider.ts b/server/dukang-api/src/integrations/oss/oss.aliyun.provider.ts
index 29f43e0..7f31f26 100644
--- a/server/dukang-api/src/integrations/oss/oss.aliyun.provider.ts
+++ b/server/dukang-api/src/integrations/oss/oss.aliyun.provider.ts
@@ -6,7 +6,7 @@ import type {
OssUploadTokenInput,
OssUploadTokenResult,
} from './oss.interface';
-import { buildOssObjectKey } from './oss.key.util';
+import { buildOssObjectKey, resolveOssUploadDir } from './oss.key.util';
import { createAliyunOssClient, resolveOssUploadHost } from './oss.aliyun.client';
const DEFAULT_EXPIRE_SECONDS = 15 * 60;
@@ -64,13 +64,14 @@ export class OssAliyunProvider implements IOssProvider {
const ossKey = buildOssObjectKey(this.uploadPrefix, dto.bizType, dto.fileName);
const expireAt = new Date(Date.now() + this.expireSeconds * 1000);
const host = resolveOssUploadHost(this.bucket, this.region);
+ const keyPrefix = resolveOssUploadDir(this.uploadPrefix, dto.bizType);
const policy = {
expiration: expireAt.toISOString(),
conditions: [
['content-length-range', 0, this.maxUploadBytes],
['eq', '$bucket', this.bucket],
- ['starts-with', '$key', `${this.uploadPrefix}/${dto.bizType.toLowerCase()}/`],
+ ['starts-with', '$key', keyPrefix],
],
};
diff --git a/server/dukang-api/src/integrations/oss/oss.key.util.ts b/server/dukang-api/src/integrations/oss/oss.key.util.ts
index c098278..ca234b4 100644
--- a/server/dukang-api/src/integrations/oss/oss.key.util.ts
+++ b/server/dukang-api/src/integrations/oss/oss.key.util.ts
@@ -1,7 +1,20 @@
import { randomUUID } from 'crypto';
+/** 门店资源上传目录(OSS object key 前缀) */
+const STORE_UPLOAD_DIRS: Record = {
+ STORE_TITLE: 'store/title',
+ STORE_ENV: 'store/env',
+ STORE_CONTRACT: 'store/contract',
+};
+
+export function resolveOssUploadDir(uploadPrefix: string, bizType: string): string {
+ const storeDir = STORE_UPLOAD_DIRS[bizType];
+ if (storeDir) return `${storeDir}/`;
+ return `${uploadPrefix.replace(/\/$/, '')}/${bizType.toLowerCase()}/`;
+}
+
export function buildOssObjectKey(uploadPrefix: string, bizType: string, fileName: string): string {
const ext = fileName.includes('.') ? fileName.split('.').pop() : 'bin';
- const dir = `${uploadPrefix.replace(/\/$/, '')}/${bizType.toLowerCase()}/`;
+ const dir = resolveOssUploadDir(uploadPrefix, bizType);
return `${dir}${Date.now()}-${randomUUID().slice(0, 8)}.${ext}`;
}
diff --git a/server/dukang-api/src/integrations/wechat/wechat.api.provider.ts b/server/dukang-api/src/integrations/wechat/wechat.api.provider.ts
index a7619ba..168615d 100644
--- a/server/dukang-api/src/integrations/wechat/wechat.api.provider.ts
+++ b/server/dukang-api/src/integrations/wechat/wechat.api.provider.ts
@@ -119,7 +119,7 @@ export class WechatApiProvider implements IWechatProvider {
timestamp,
nonceStr,
signature,
- jsApiList: ['getLocation', 'scanQRCode', 'chooseWXPay'],
+ jsApiList: ['getLocation', 'scanQRCode', 'chooseWXPay', 'chooseImage', 'getLocalImgData'],
};
}
diff --git a/server/dukang-api/src/modules/store/store.controller.ts b/server/dukang-api/src/modules/store/store.controller.ts
index cdaee0d..d0d092b 100644
--- a/server/dukang-api/src/modules/store/store.controller.ts
+++ b/server/dukang-api/src/modules/store/store.controller.ts
@@ -29,10 +29,38 @@ export class PartnerStoreController {
return this.storeService.partnerListStores(user.actorId);
}
+ @Get('cities')
+ cities(@CurrentUser() user: AuthUser) {
+ return this.storeService.partnerListCities(user.actorId);
+ }
+
+ @Get(':id')
+ detail(@CurrentUser() user: AuthUser, @Param('id') id: string) {
+ return this.storeService.partnerGetStore(user.actorId, BigInt(id));
+ }
+
@Post()
create(@CurrentUser() user: AuthUser, @Body() body: Record) {
return this.storeService.createStore(user.actorId, body);
}
+
+ @Put(':id/status')
+ updateStatus(
+ @CurrentUser() user: AuthUser,
+ @Param('id') id: string,
+ @Body() body: { status: 'OPEN' | 'PAUSED' | 'CLOSED' },
+ ) {
+ return this.storeService.partnerUpdateStoreStatus(user.actorId, BigInt(id), body.status);
+ }
+
+ @Put(':id/basic')
+ updateBasic(
+ @CurrentUser() user: AuthUser,
+ @Param('id') id: string,
+ @Body() body: Record,
+ ) {
+ return this.storeService.partnerUpdateStoreBasic(user.actorId, BigInt(id), body);
+ }
}
@Controller('partner/dashboard')
diff --git a/server/dukang-api/src/modules/store/store.service.ts b/server/dukang-api/src/modules/store/store.service.ts
index 9811930..6b3c517 100644
--- a/server/dukang-api/src/modules/store/store.service.ts
+++ b/server/dukang-api/src/modules/store/store.service.ts
@@ -51,10 +51,44 @@ export class StoreService {
return serializeBigInt(stores.map(mapStoreCompat));
}
+ async partnerGetStore(partnerAccountId: bigint, storeId: bigint) {
+ const account = await this.getPartnerAccount(partnerAccountId);
+ const store = await this.prisma.store.findFirst({
+ where: { id: storeId, partnerId: account.partnerId },
+ include: { category: true, coverResource: true },
+ });
+ if (!store) throw new NotFoundException('门店不存在');
+
+ const media = await this.prisma.commonResource.findMany({
+ where: {
+ ownerType: 'STORE',
+ ownerId: storeId,
+ status: 'ACTIVE',
+ bizType: { in: ['ENV', 'CONTRACT'] },
+ },
+ orderBy: { sortOrder: 'asc' },
+ });
+ return serializeBigInt(mapStoreCompat({ ...store, media }));
+ }
+
+ async partnerListCities(partnerAccountId: bigint) {
+ const account = await this.getPartnerAccount(partnerAccountId);
+ const cities = await this.prisma.commonCity.findMany({
+ where: { partnerId: account.partnerId },
+ select: { id: true, name: true, code: true, province: true, partnerId: true },
+ orderBy: { createdAt: 'desc' },
+ });
+ return serializeBigInt(cities);
+ }
+
async createStore(partnerAccountId: bigint, body: Record) {
const account = await this.getPartnerAccount(partnerAccountId);
- const city = await this.prisma.commonCity.findFirst({ where: { partnerId: account.partnerId } });
- if (!city) throw new BadRequestException('合伙人未绑定开城');
+ const city = await this.resolvePartnerCity(account.partnerId, body.cityId);
+ const coverUrl = body.coverUrl ? String(body.coverUrl).trim() : '';
+ const envPhotoUrls = Array.isArray(body.envPhotoUrls)
+ ? body.envPhotoUrls.map((u) => String(u).trim()).filter(Boolean)
+ : [];
+ const contractUrl = body.contractUrl ? String(body.contractUrl).trim() : '';
const store = await this.prisma.store.create({
data: {
@@ -63,12 +97,11 @@ export class StoreService {
categoryId: body.categoryId ? BigInt(String(body.categoryId)) : null,
name: String(body.name),
phone: String(body.phone),
- province: String(body.province ?? '河南省'),
- cityName: String(body.city ?? '郑州市'),
+ province: String(body.province ?? city.province ?? '河南省'),
+ cityName: String(body.city ?? city.name ?? '郑州市'),
district: String(body.district ?? ''),
address: String(body.address),
intro: body.intro ? String(body.intro) : null,
- coverResourceId: body.coverResourceId ? BigInt(String(body.coverResourceId)) : null,
bankAccountName: body.bankAccountName ? String(body.bankAccountName) : null,
bankAccountNo: body.bankAccountNo ? String(body.bankAccountNo) : null,
bankBranch: body.bankBranch ? String(body.bankBranch) : null,
@@ -78,6 +111,52 @@ export class StoreService {
},
});
+ const ossBucket = process.env.OSS_BUCKET ?? 'legacy';
+
+ if (coverUrl) {
+ const cover = await this.prisma.commonResource.create({
+ data: {
+ ownerType: 'STORE',
+ ownerId: store.id,
+ bizType: 'COVER',
+ mediaType: 'IMAGE',
+ ossBucket,
+ ossKey: coverUrl,
+ url: coverUrl,
+ },
+ });
+ await this.prisma.store.update({ where: { id: store.id }, data: { coverResourceId: cover.id } });
+ }
+
+ for (let i = 0; i < envPhotoUrls.length; i++) {
+ await this.prisma.commonResource.create({
+ data: {
+ ownerType: 'STORE',
+ ownerId: store.id,
+ bizType: 'ENV',
+ mediaType: 'IMAGE',
+ ossBucket,
+ ossKey: envPhotoUrls[i],
+ url: envPhotoUrls[i],
+ sortOrder: i,
+ },
+ });
+ }
+
+ if (contractUrl) {
+ await this.prisma.commonResource.create({
+ data: {
+ ownerType: 'STORE',
+ ownerId: store.id,
+ bizType: 'CONTRACT',
+ mediaType: 'FILE',
+ ossBucket,
+ ossKey: contractUrl,
+ url: contractUrl,
+ },
+ });
+ }
+
const audit = await this.prisma.commonEvent.create({
data: {
eventType: 'STORE_AUDIT',
@@ -95,7 +174,10 @@ export class StoreService {
await this.prisma.storeAccount.create({
data: {
storeId: store.id,
- phone: String(body.accountPhone ?? body.phone),
+ phone: await this.resolveStoreAccountPhone(
+ String(body.accountPhone ?? body.phone),
+ store.id,
+ ),
name: String(body.accountName ?? body.name),
},
});
@@ -103,6 +185,71 @@ export class StoreService {
return serializeBigInt({ store, audit });
}
+ async partnerUpdateStoreStatus(
+ partnerAccountId: bigint,
+ storeId: bigint,
+ status: 'OPEN' | 'PAUSED' | 'CLOSED',
+ ) {
+ const account = await this.getPartnerAccount(partnerAccountId);
+ const store = await this.prisma.store.findFirst({
+ where: { id: storeId, partnerId: account.partnerId },
+ });
+ if (!store) throw new NotFoundException('门店不存在');
+ if (store.status === 'CLOSED') {
+ throw new BadRequestException('门店已关闭,不可变更状态');
+ }
+ if (!['OPEN', 'PAUSED', 'CLOSED'].includes(status)) {
+ throw new BadRequestException('无效的门店状态');
+ }
+
+ const updated = await this.prisma.store.update({
+ where: { id: storeId },
+ data: { status },
+ include: { coverResource: true },
+ });
+ return serializeBigInt(mapStoreCompat(updated));
+ }
+
+ async partnerUpdateStoreBasic(
+ partnerAccountId: bigint,
+ storeId: bigint,
+ body: Record,
+ ) {
+ const account = await this.getPartnerAccount(partnerAccountId);
+ const store = await this.prisma.store.findFirst({
+ where: { id: storeId, partnerId: account.partnerId },
+ });
+ if (!store) throw new NotFoundException('门店不存在');
+ if (store.status === 'CLOSED') {
+ throw new BadRequestException('门店已关闭,不可编辑');
+ }
+
+ const name = body.name !== undefined ? String(body.name).trim() : undefined;
+ const phone = body.phone !== undefined ? String(body.phone).trim() : undefined;
+ const address = body.address !== undefined ? String(body.address).trim() : undefined;
+ const introRaw = body.intro !== undefined ? String(body.intro).trim() : undefined;
+
+ if (name !== undefined && !name) throw new BadRequestException('请填写门店名称');
+ if (phone !== undefined && !/^1\d{10}$/.test(phone)) {
+ throw new BadRequestException('联系电话须为11位手机号');
+ }
+ if (address !== undefined && !address) throw new BadRequestException('请填写详细地址');
+ if (introRaw && (introRaw.length < 10 || introRaw.length > 500)) {
+ throw new BadRequestException('门店简介须为 10~500 字');
+ }
+
+ await this.prisma.store.update({
+ where: { id: storeId },
+ data: {
+ ...(name !== undefined ? { name } : {}),
+ ...(phone !== undefined ? { phone } : {}),
+ ...(address !== undefined ? { address } : {}),
+ ...(introRaw !== undefined ? { intro: introRaw || null } : {}),
+ },
+ });
+ return this.partnerGetStore(partnerAccountId, storeId);
+ }
+
async getShopStore(storeAccountId: bigint) {
const account = await this.prisma.storeAccount.findUniqueOrThrow({
where: { id: storeAccountId },
@@ -150,4 +297,26 @@ export class StoreService {
include: { partner: true },
});
}
+
+ private async resolvePartnerCity(partnerId: bigint, cityId: unknown) {
+ if (cityId) {
+ const city = await this.prisma.commonCity.findFirst({
+ where: { id: BigInt(String(cityId)), partnerId },
+ });
+ if (!city) throw new BadRequestException('所选地区未匹配到开城城市');
+ return city;
+ }
+ const city = await this.prisma.commonCity.findFirst({ where: { partnerId } });
+ if (!city) throw new BadRequestException('合伙人未绑定开城');
+ return city;
+ }
+
+ private async resolveStoreAccountPhone(phone: string, storeId: bigint): Promise {
+ const normalized = phone.trim();
+ const existing = await this.prisma.storeAccount.findUnique({ where: { phone: normalized } });
+ if (!existing) return normalized;
+ const suffix = String(storeId).slice(-4);
+ const candidate = `${normalized.slice(0, 15)}${suffix}`.slice(0, 20);
+ return candidate;
+ }
}