From 888d0261455f723bca077c7d8e8b9b75306a953a Mon Sep 17 00:00:00 2001 From: liufumingren Date: Mon, 27 Jul 2026 03:48:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(shop/store):=20=E5=BA=97=E9=93=BA=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=A2=9E=E5=BC=BA=20+=20=E9=97=A8=E5=BA=97=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - shops: 支持修改 shop_name + 删除店铺查询改用 Op.notLike 前缀过滤 - store: loadStores 增加 Store 关联查 company_name 作为 label fallback - store: 新增 loadWarehouses(货主侧加载可用仓库) - index: 注册 loadWarehouses 权限 --- app/service/systemMethods/index.js | 9 ++++-- app/service/systemMethods/shops.js | 6 ++++ app/service/systems/shops.js | 40 +++++++++++++++++------- app/service/systems/store.js | 50 ++++++++++++++++++++++++++---- 4 files changed, 86 insertions(+), 19 deletions(-) diff --git a/app/service/systemMethods/index.js b/app/service/systemMethods/index.js index 2db538f..a8fae05 100644 --- a/app/service/systemMethods/index.js +++ b/app/service/systemMethods/index.js @@ -1053,9 +1053,9 @@ class indexService extends MainService { constructor(ctx) { super(ctx); const _noNeedLogin = 'getI18nMessage,putI18nCollect,test,getCainiaoStfTemplates,polyapiAuthorizeUrl'; - const _noNeedRight = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,getImages,getCOSUploadConfig,uploadSuccessNotify,getMessageDetail,searchSpace,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder'; + const _noNeedRight = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,getImages,getCOSUploadConfig,uploadSuccessNotify,getMessageDetail,searchSpace,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder'; const _noNeedLog = '*'; - const _noNeedAuth = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,getImages,getMessageDetail,searchSpace,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,test,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder'; + const _noNeedAuth = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,getImages,getMessageDetail,searchSpace,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,test,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } async fastWhereTree(data) { @@ -1069,6 +1069,11 @@ class indexService extends MainService { const result = await service.systems.store.loadStores(); return this.success('ok', { stores: result, code: 200 }); } + async loadWarehouses() { + const { service } = this; + const result = await service.systems.store.loadWarehouses(); + return this.success('ok', { warehouses: result, code: 200 }); + } async getCOSUploadConfig(datas) { const { service } = this; const { data } = datas; diff --git a/app/service/systemMethods/shops.js b/app/service/systemMethods/shops.js index f7dc841..8c1034d 100644 --- a/app/service/systemMethods/shops.js +++ b/app/service/systemMethods/shops.js @@ -108,6 +108,8 @@ class ShopsMethodService extends MainService { id, shop_id: shopId, shopId: shopIdCamel, + shop_name: shopName, + shopName: shopNameCamel, custom_name: customName, customName: customNameCamel, platform_code: platformCode, @@ -118,6 +120,10 @@ class ShopsMethodService extends MainService { id: id !== undefined ? id : (shopId !== undefined ? shopId : shopIdCamel), }; + if (shopName !== undefined || shopNameCamel !== undefined) { + payload.shop_name = shopName !== undefined ? shopName : shopNameCamel; + } + if (customName !== undefined || customNameCamel !== undefined) { payload.custom_name = customName !== undefined ? customName : customNameCamel; } diff --git a/app/service/systems/shops.js b/app/service/systems/shops.js index 110cdd8..521e633 100644 --- a/app/service/systems/shops.js +++ b/app/service/systems/shops.js @@ -373,8 +373,10 @@ class ShopsService extends Service { const where = { warehouse_id: warehouseId, platform_code: platformCode, - shop_name: shopName, - ...buildNotDeletedShopWhere(app), + shop_name: { + [Op.eq]: shopName, + [Op.notLike]: `${DELETED_SHOP_NAME_PREFIX}%`, + }, }; if (excludeId !== null) { @@ -537,9 +539,11 @@ class ShopsService extends Service { || Object.prototype.hasOwnProperty.call(data, 'platformCode'); const hasCustomName = Object.prototype.hasOwnProperty.call(data, 'custom_name') || Object.prototype.hasOwnProperty.call(data, 'customName'); + const hasShopName = Object.prototype.hasOwnProperty.call(data, 'shop_name') + || Object.prototype.hasOwnProperty.call(data, 'shopName'); - if (!hasPlatformCode && !hasCustomName) { - throw this.createError('仅允许修改 platform_code 或 custom_name', 400); + if (!hasPlatformCode && !hasCustomName && !hasShopName) { + throw this.createError('仅允许修改 platform_code、custom_name 或 shop_name', 400); } if (hasPlatformCode) { @@ -556,8 +560,16 @@ class ShopsService extends Service { ); } + if (hasShopName) { + updates.shop_name = this.normalizeText( + data.shop_name !== undefined ? data.shop_name : data.shopName, + 'shop_name', + { required: true, maxLength: 100 } + ); + } + const nextPlatformCode = updates.platform_code || shop.platform_code; - const nextShopName = shop.shop_name; + const nextShopName = updates.shop_name || shop.shop_name; await this.ensureShopNameUnique({ warehouseId: this.getCurrentWarehouseId(), @@ -697,16 +709,22 @@ class ShopsService extends Service { attributes: [ 'get_auth_platform_name' ], }); + const platName = printPlatform ? printPlatform.get_auth_platform_name : platformCode; + const requestData = { + RedirectCodeUrl: callbackUrl, + command: 'saveShop', + platName, + shopName: shopPlain.shop_name, + }; + if (platName === '电商京东') { + requestData.VenderID = shopPlain.id; + } + const respone = await ctx.curl(authUrl, { method: 'POST', dataType: 'json', timeout: 5000, - data: { - RedirectCodeUrl: callbackUrl, - command: 'saveShop', - platName: printPlatform ? printPlatform.get_auth_platform_name : platformCode, - shopName: shopPlain.shop_name, - }, + data: requestData, }); if (respone.data && respone.data.code === 0) { const sessionKey = respone.data.data || null; diff --git a/app/service/systems/store.js b/app/service/systems/store.js index 50ddba7..5358472 100644 --- a/app/service/systems/store.js +++ b/app/service/systems/store.js @@ -948,24 +948,62 @@ class StoreService extends Service { const { ctx } = this; try { - const stores = await ctx.model.StoreWarehouse.findAll({ + const rows = await ctx.model.StoreWarehouse.findAll({ where: { warehouse_use_status: 1, warehouse_id: ctx.user.store_id, }, - attributes: [ - [ 'store_id', 'value' ], // store_id 字段别名为 value - [ 'store_remask', 'label' ], // store_remask 字段别名为 label + attributes: [ 'store_id', 'store_remask' ], + include: [ + { + model: ctx.model.Store, + as: 'store', + attributes: [ 'company_name' ], + required: false, + }, ], - raw: true, // 可选:返回纯JSON数据 + raw: true, }); - return stores; + return rows.map(row => ({ + value: row.store_id, + label: row.store_remask || (row['store.company_name'] || ''), + })); } catch (error) { ctx.logger.error('[Service.loadStores] 查询失败:', error); throw error; } } + async loadWarehouses() { + const { ctx } = this; + + try { + const rows = await ctx.model.StoreWarehouse.findAll({ + where: { + store_use_status: 1, + store_id: ctx.user.store_id, + }, + attributes: [ 'warehouse_id', 'warehouse_remask' ], + include: [ + { + model: ctx.model.Store, + as: 'warehouse', + attributes: [ 'company_name' ], + required: false, + }, + ], + raw: true, + }); + + return rows.map(row => ({ + value: row.warehouse_id, + label: row.warehouse_remask || (row['warehouse.company_name'] || ''), + })); + } catch (error) { + ctx.logger.error('[Service.loadWarehouses] 查询失败:', error); + throw error; + } + } } module.exports = StoreService;