'use strict'; const _ = require('lodash'); const Controller = require('egg').Controller; class HomeController extends Controller { async index() { const { ctx } = this; ctx.body = 'hi, egg'; } async utilMethod() { const res = await this.ctx.model.RoadShow.find(); for (const i of res) { const { picture, filepath } = i; if (_.isArray(picture) && picture.length > 0) { const arr = []; for (let i = 0; i < picture.length; i++) { if (_.isString(picture[i])) arr.push({ name: `img${i + 1}`, url: picture[i] }); } i.picture = arr; } if (_.isArray(filepath) && filepath.length > 0) { const arr = []; for (let i = 0; i < filepath.length; i++) { if (_.isString(filepath[i])) arr.push({ name: `file${i + 1}`, url: filepath[i] }); } i.filepath = arr; } await i.save(); } this.ctx.ok(); } } module.exports = HomeController;