feat(shop/store): 店铺管理增强 + 门店仓库加载
- shops: 支持修改 shop_name + 删除店铺查询改用 Op.notLike 前缀过滤 - store: loadStores 增加 Store 关联查 company_name 作为 label fallback - store: 新增 loadWarehouses(货主侧加载可用仓库) - index: 注册 loadWarehouses 权限
This commit is contained in:
parent
510b87632a
commit
888d026145
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user