'use strict'; const DELETED_SHOP_NAME_PREFIX = 'DELETED_SHOP_'; /** * 判断店铺名是否为软删除墓碑名。 * * @param {*} shopName 店铺名称 * @return {boolean} 是否为已软删除店铺 */ function isDeletedShopName(shopName) { return String(shopName || '').trim().startsWith(DELETED_SHOP_NAME_PREFIX); } /** * 判断店铺记录是否为软删除状态。 * * @param {Object} shop 店铺记录或模型实例 * @return {boolean} 是否已软删除 */ function isSoftDeletedShop(shop) { if (!shop || typeof shop !== 'object') { return false; } const plainShop = typeof shop.get === 'function' ? shop.get({ plain: true }) : shop; return isDeletedShopName(plainShop && plainShop.shop_name); } /** * 构建排除软删除店铺的 Sequelize where 条件。 * * @param {import('egg').Application} app Egg 应用实例 * @param {string} [fieldName='shop_name'] 店铺名字段名 * @return {Object} Sequelize where 条件 */ function buildNotDeletedShopWhere(app, fieldName = 'shop_name') { return { [fieldName]: { [app.Sequelize.Op.notLike]: `${DELETED_SHOP_NAME_PREFIX}%`, }, }; } module.exports = { DELETED_SHOP_NAME_PREFIX, isDeletedShopName, isSoftDeletedShop, buildNotDeletedShopWhere, };