'use strict'; const _ = require('lodash'); const idToData = async (ctx, id) => { const res = await ctx.service.util.httpUtil.cget(`/mechanism/${id}`, 'hnhmain'); return res; }; module.exports = options => { return async function medium(ctx, next) { await next(); const request = ctx.request; const { method } = request; if (method === 'GET') { // 处理get的时coupons_id换成对应的数据 let { data } = ctx.body; data = JSON.parse(JSON.stringify(data)); if (_.isArray(data)) { // 数组,多个,循环查 for (const i of data) { const { medium_id } = i; const res = await idToData(ctx, medium_id); if (res)i.medium = res; } } else if (_.isObject(data)) { // 一个,找完就完事 const { medium_id } = data; const res = await idToData(ctx, medium_id); if (res) data.medium = res; } ctx.body.data = data; } }; };