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) {
|
constructor(ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
const _noNeedLogin = 'getI18nMessage,putI18nCollect,test,getCainiaoStfTemplates,polyapiAuthorizeUrl';
|
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 _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);
|
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||||
}
|
}
|
||||||
async fastWhereTree(data) {
|
async fastWhereTree(data) {
|
||||||
@ -1069,6 +1069,11 @@ class indexService extends MainService {
|
|||||||
const result = await service.systems.store.loadStores();
|
const result = await service.systems.store.loadStores();
|
||||||
return this.success('ok', { stores: result, code: 200 });
|
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) {
|
async getCOSUploadConfig(datas) {
|
||||||
const { service } = this;
|
const { service } = this;
|
||||||
const { data } = datas;
|
const { data } = datas;
|
||||||
|
|||||||
@ -108,6 +108,8 @@ class ShopsMethodService extends MainService {
|
|||||||
id,
|
id,
|
||||||
shop_id: shopId,
|
shop_id: shopId,
|
||||||
shopId: shopIdCamel,
|
shopId: shopIdCamel,
|
||||||
|
shop_name: shopName,
|
||||||
|
shopName: shopNameCamel,
|
||||||
custom_name: customName,
|
custom_name: customName,
|
||||||
customName: customNameCamel,
|
customName: customNameCamel,
|
||||||
platform_code: platformCode,
|
platform_code: platformCode,
|
||||||
@ -118,6 +120,10 @@ class ShopsMethodService extends MainService {
|
|||||||
id: id !== undefined ? id : (shopId !== undefined ? shopId : shopIdCamel),
|
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) {
|
if (customName !== undefined || customNameCamel !== undefined) {
|
||||||
payload.custom_name = customName !== undefined ? customName : customNameCamel;
|
payload.custom_name = customName !== undefined ? customName : customNameCamel;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -373,8 +373,10 @@ class ShopsService extends Service {
|
|||||||
const where = {
|
const where = {
|
||||||
warehouse_id: warehouseId,
|
warehouse_id: warehouseId,
|
||||||
platform_code: platformCode,
|
platform_code: platformCode,
|
||||||
shop_name: shopName,
|
shop_name: {
|
||||||
...buildNotDeletedShopWhere(app),
|
[Op.eq]: shopName,
|
||||||
|
[Op.notLike]: `${DELETED_SHOP_NAME_PREFIX}%`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (excludeId !== null) {
|
if (excludeId !== null) {
|
||||||
@ -537,9 +539,11 @@ class ShopsService extends Service {
|
|||||||
|| Object.prototype.hasOwnProperty.call(data, 'platformCode');
|
|| Object.prototype.hasOwnProperty.call(data, 'platformCode');
|
||||||
const hasCustomName = Object.prototype.hasOwnProperty.call(data, 'custom_name')
|
const hasCustomName = Object.prototype.hasOwnProperty.call(data, 'custom_name')
|
||||||
|| Object.prototype.hasOwnProperty.call(data, 'customName');
|
|| Object.prototype.hasOwnProperty.call(data, 'customName');
|
||||||
|
const hasShopName = Object.prototype.hasOwnProperty.call(data, 'shop_name')
|
||||||
|
|| Object.prototype.hasOwnProperty.call(data, 'shopName');
|
||||||
|
|
||||||
if (!hasPlatformCode && !hasCustomName) {
|
if (!hasPlatformCode && !hasCustomName && !hasShopName) {
|
||||||
throw this.createError('仅允许修改 platform_code 或 custom_name', 400);
|
throw this.createError('仅允许修改 platform_code、custom_name 或 shop_name', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPlatformCode) {
|
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 nextPlatformCode = updates.platform_code || shop.platform_code;
|
||||||
const nextShopName = shop.shop_name;
|
const nextShopName = updates.shop_name || shop.shop_name;
|
||||||
|
|
||||||
await this.ensureShopNameUnique({
|
await this.ensureShopNameUnique({
|
||||||
warehouseId: this.getCurrentWarehouseId(),
|
warehouseId: this.getCurrentWarehouseId(),
|
||||||
@ -697,16 +709,22 @@ class ShopsService extends Service {
|
|||||||
attributes: [ 'get_auth_platform_name' ],
|
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, {
|
const respone = await ctx.curl(authUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
data: {
|
data: requestData,
|
||||||
RedirectCodeUrl: callbackUrl,
|
|
||||||
command: 'saveShop',
|
|
||||||
platName: printPlatform ? printPlatform.get_auth_platform_name : platformCode,
|
|
||||||
shopName: shopPlain.shop_name,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (respone.data && respone.data.code === 0) {
|
if (respone.data && respone.data.code === 0) {
|
||||||
const sessionKey = respone.data.data || null;
|
const sessionKey = respone.data.data || null;
|
||||||
|
|||||||
@ -948,24 +948,62 @@ class StoreService extends Service {
|
|||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const stores = await ctx.model.StoreWarehouse.findAll({
|
const rows = await ctx.model.StoreWarehouse.findAll({
|
||||||
where: {
|
where: {
|
||||||
warehouse_use_status: 1,
|
warehouse_use_status: 1,
|
||||||
warehouse_id: ctx.user.store_id,
|
warehouse_id: ctx.user.store_id,
|
||||||
},
|
},
|
||||||
attributes: [
|
attributes: [ 'store_id', 'store_remask' ],
|
||||||
[ 'store_id', 'value' ], // store_id 字段别名为 value
|
include: [
|
||||||
[ 'store_remask', 'label' ], // store_remask 字段别名为 label
|
{
|
||||||
|
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) {
|
} catch (error) {
|
||||||
ctx.logger.error('[Service.loadStores] 查询失败:', error);
|
ctx.logger.error('[Service.loadStores] 查询失败:', error);
|
||||||
throw 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;
|
module.exports = StoreService;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user