'use strict'; const Service = require('egg').Service; const _ = require("lodash"); class ExportDataService extends Service { async index(params) { let { ctx } = this let modelLocal = ctx.model[params.model] let subType = params.subType let whereOther = params["$where"] let paramsLocal = _.omit(params, ["subType", "url", "model", "$where"]) let paramsLocalInfoAgg = { ...paramsLocal, isExit: 1 } let msgObj = { exportS6: "成功导出S6订单", exportxiaoshou: "成功导出销售订单", } if (whereOther === "this.zuigaocaigoujia > this.xiaoshoujine") { paramsLocalInfoAgg["$expr"] = { "$gt": ["$zuigaocaigoujia", "$xiaoshoujine"] } } else if (whereOther === "this.pinmingxuanxiang.length>1") { paramsLocalInfoAgg["$expr"] = { "$gt": [{ "$size": "$pinmingxuanxiang" }, 1] } } let res = await modelLocal.aggregate([{ $match: paramsLocalInfoAgg, }, { $sort: { update_at: -1 } }]).exec() let returnData = { hasError: false, msg: msgObj[subType], subType, list: res } return returnData } } module.exports = ExportDataService;