1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { ObjectId } = require('mongoose').Types;
- const assert = require('assert');
- // 套餐
- class SetService extends CrudService {
- constructor(ctx) {
- super(ctx, 'set');
- this.model = this.ctx.model.Set;
- this.xzqh = this.ctx.model.Xzqh;
- this.provinceList = [ '110000', '120000', '310000', '500000', '150000', '450000', '640000', '650000', '540000', '810000', '820000' ];
- }
- /**
- * 将数组的id换成对应的套餐名称
- * @param {Array} list card数组
- */
- async changeName(list) {
- const ids = list.map(i => ObjectId(i.set));
- const setList = await this.model.find({ _id: ids });
- list = list.map(i => {
- const res = setList.find(f => ObjectId(f._id).equals(i.set));
- if (res) i.set = res.title;
- return i;
- });
- return list;
- }
- /**
- *
- * @param {Object} condition 查询条件
- * @property province 省份代码
- */
- async range(condition) {
- const { contact, ...others } = condition;
- assert(contact, '缺少城市范围');
- if (this.provinceList.includes(contact)) {
- others.contact = contact;
- } else {
- const xzqh = await this.xzqh.find({ pcode: contact });
- others.contact = xzqh.map(i => i.code);
- }
- const res = await this.model.find(others);
- return res;
- }
- }
- module.exports = SetService;
|