'use strict'; const MainService = require('../main'); /** * 店铺-快递绑定策略 methods 出口。 * * 支持以下 method 调用(通过 /system?method=storeExpressBindingPolicy.xxx): * - storeExpressBindingPolicy.list 分页查询策略列表 * - storeExpressBindingPolicy.add 新增策略 * - storeExpressBindingPolicy.edit 编辑策略 * - storeExpressBindingPolicy.del 软删除策略 */ class StoreExpressBindingPolicyMethodService extends MainService { /** * 初始化鉴权配置。 * @param {Egg.Context} ctx 上下文对象 */ constructor(ctx) { super(ctx); const _noNeedLogin = ''; const _noNeedRight = ''; const _noNeedLog = '*'; const _noNeedAuth = ''; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } /** * 统一调用业务服务。 * @param {string} methodName 业务方法名 * @param {Object} data 请求参数 * @param {string} fallbackMessage 默认错误文案 * @return {Promise} methods 标准返回 */ async callSystem(methodName, data, fallbackMessage) { const { service } = this; try { const result = await service.systems.storeExpressBindingPolicy[methodName](data); return this.success('ok', { data: result, code: 200 }); } catch (error) { return this.fail(error.message || fallbackMessage, { code: Number(error.code) || 500, }); } } /** * storeExpressBindingPolicy.list:分页查询策略列表。 * @param {Object} [data={}] 请求参数 * @return {Promise} 查询结果 */ async list(data = {}) { const payload = { ...(data && typeof data === 'object' ? data : {}), }; this.prepareWhereContext(payload, { specialFieldMap: this.service.systems.storeExpressBindingPolicy.getListWhereSpecialFieldMap(), }); return await this.callSystem('list', payload, '查询策略列表失败'); } /** * storeExpressBindingPolicy.add:新增策略。 * @param {Object} [data={}] 请求参数 * @return {Promise} 新增结果 */ async add(data = {}) { const { custom_name: customName, customName: customNameCamel, express_code: expressCode, expressCode: expressCodeCamel, priority, is_enabled: isEnabled, isEnabled: isEnabledCamel, regions, shop_name: shopName, store_ids: storeIds, exclude_regions: excludeRegions, min_weight_g: minWeightG, max_weight_g: maxWeightG, weight_type: weightType, prohibited_type_id: prohibitedTypeId, prohibitedTypeId: prohibitedTypeIdCamel, remark, creator_id: creatorId, creatorId: creatorIdCamel, } = data || {}; return await this.callSystem('add', { custom_name: customName !== undefined ? customName : customNameCamel, express_code: expressCode !== undefined ? expressCode : expressCodeCamel, priority, is_enabled: isEnabled !== undefined ? isEnabled : isEnabledCamel, regions, shop_name: shopName, store_ids: storeIds, exclude_regions: excludeRegions, min_weight_g: minWeightG, max_weight_g: maxWeightG, weight_type: weightType, prohibited_type_id: prohibitedTypeId !== undefined ? prohibitedTypeId : prohibitedTypeIdCamel, remark, creator_id: creatorId !== undefined ? creatorId : creatorIdCamel, }, '新增策略失败'); } /** * storeExpressBindingPolicy.edit:编辑策略。 * @param {Object} [data={}] 请求参数 * @return {Promise} 编辑结果 */ async edit(data = {}) { const { id, policy_id: policyId, policyId: policyIdCamel, custom_name: customName, customName: customNameCamel, express_code: expressCode, expressCode: expressCodeCamel, priority, is_enabled: isEnabled, isEnabled: isEnabledCamel, regions, shop_name: shopName, store_ids: storeIds, exclude_regions: excludeRegions, min_weight_g: minWeightG, max_weight_g: maxWeightG, weight_type: weightType, prohibited_type_id: prohibitedTypeId, prohibitedTypeId: prohibitedTypeIdCamel, remark, creator_id: creatorId, creatorId: creatorIdCamel, } = data || {}; const payload = { id: id !== undefined ? id : (policyId !== undefined ? policyId : policyIdCamel), }; if (customName !== undefined || customNameCamel !== undefined) { payload.custom_name = customName !== undefined ? customName : customNameCamel; } if (expressCode !== undefined || expressCodeCamel !== undefined) { payload.express_code = expressCode !== undefined ? expressCode : expressCodeCamel; } if (priority !== undefined) { payload.priority = priority; } if (isEnabled !== undefined || isEnabledCamel !== undefined) { payload.is_enabled = isEnabled !== undefined ? isEnabled : isEnabledCamel; } if (regions !== undefined) { payload.regions = regions; } if (shopName !== undefined) { payload.shop_name = shopName; } if (storeIds !== undefined) { payload.store_ids = storeIds; } if (excludeRegions !== undefined) { payload.exclude_regions = excludeRegions; } if (minWeightG !== undefined) { payload.min_weight_g = minWeightG; } if (maxWeightG !== undefined) { payload.max_weight_g = maxWeightG; } if (weightType !== undefined) { payload.weight_type = weightType; } if (prohibitedTypeId !== undefined || prohibitedTypeIdCamel !== undefined) { payload.prohibited_type_id = prohibitedTypeId !== undefined ? prohibitedTypeId : prohibitedTypeIdCamel; } if (remark !== undefined) { payload.remark = remark; } if (creatorId !== undefined || creatorIdCamel !== undefined) { payload.creator_id = creatorId !== undefined ? creatorId : creatorIdCamel; } return await this.callSystem('edit', payload, '编辑策略失败'); } /** * storeExpressBindingPolicy.del:软删除策略。 * @param {Object} [data={}] 请求参数 * @return {Promise} 删除结果 */ async del(data = {}) { const { id, policy_id: policyId, policyId: policyIdCamel, } = data || {}; return await this.callSystem('del', { id: id !== undefined ? id : (policyId !== undefined ? policyId : policyIdCamel), }, '删除策略失败'); } } module.exports = StoreExpressBindingPolicyMethodService;