123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- class ApplymmoneyService extends CrudService {
- constructor(ctx) {
- super(ctx, 'apply_mmoney');
- this.model = this.ctx.model.Applymmoney;
- }
- async getAmlist(data) {
- const match = {};
- if (data.region) {
- match.status = data.region;
- }
- if (data.jg_id) {
- match.jgid = data.jg_id;
- }
- const skip = Number.parseInt(data.skip) || 1;
- const limit = Number.parseInt(data.limit) || 10;
- const totalres = await this.model.aggregate([
- { $match: match },
- { $project: { jgid:1,qyid:1,mid:{$toObjectId: '$mid'},status:1} },
- { $lookup: {
- from: 'manage_money',
- localField: 'mid',
- foreignField: '_id',
- as: 'mmnew' } },
- { $unwind: '$mmnew' },
- { $lookup: {
- from: 'company',
- localField: 'qyid',
- foreignField: 'uid',
- as: 'companynew' } },
- { $unwind: '$companynew' },
- { $project: { _id: 1,status: 1, jgid: 1, mmtitle: '$mmnew.title',companyname:'$companynew.company_name'} },
- { $count:'total'}
- ]);
- let total=0
- if(totalres.length>0){
- total= totalres[0].total;
- }
- const res = await this.model.aggregate([
- { $match: match },
- { $project: { jgid:1,qyid:1,mid:{$toObjectId: '$mid'},status:1} },
- { $lookup: {
- from: 'manage_money',
- localField: 'mid',
- foreignField: '_id',
- as: 'mmnew' } },
- { $unwind: '$mmnew' },
- { $lookup: {
- from: 'company',
- localField: 'qyid',
- foreignField: 'uid',
- as: 'companynew' } },
- { $unwind: '$companynew' },
- { $project: { _id: 1,status: 1, jgid: 1, mmtitle: '$mmnew.title',companyname:'$companynew.company_name',buymin:'$mmnew.buymin'} },
- { $skip: (skip - 1) * limit},
- { $limit: limit },
- ]);
- const newres = {res,total};
- return newres;
- }
- async getOne(data) {
- const match = {};
- if (data.mid) {
- match._id = ObjectId(data.mid);
- }
- const res = await this.model.aggregate([
- { $match: match },
- { $project: { jgid:1,qyid:1,mid:{$toObjectId: '$mid'},status:1} },
- { $lookup: {
- from: 'manage_money',
- localField: 'mid',
- foreignField: '_id',
- as: 'mmnew' } },
- { $unwind: '$mmnew' },
- { $lookup: {
- from: 'company',
- localField: 'qyid',
- foreignField: 'uid',
- as: 'companynew' } },
- { $unwind: '$companynew' },
- { $project: { _id: 1,status: 1, jgid: 1, mmtitle: '$mmnew.title',rate:'$mmnew.rate',min_time:'$mmnew.min_time',max_time:'$mmnew.max_time',buymin:'$mmnew.buymin',
- companyname:'$companynew.company_name'} }
- ]);
- return res;
- }
- async getChangefollow(data) {
- const changeres = await this.model.findById(data.mid);
- if(data.status=='0'){ //前台传0 说明当前信息未关注 点击应该为想关注的操作
- changeres.status = '1';
- }else{
- changeres.status = '0'; //取消关注
- }
- const res = await changeres.save();
- return res;
- }
- async getBeforecreat(data) {
- let finalres={};
- const res = await this.model.find({"qyid":data.qyid,"mid":data.mid});
- if(res.length>0){
- finalres.status = 'ERROR';//说明已经申请过了
- }else{
- finalres.status = 'SUCCESS';//说明可以继续申请
- }
- return finalres;
- }
- }
- module.exports = ApplymmoneyService;
|