123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- '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 IntelligentFollowService extends CrudService {
- constructor(ctx) {
- super(ctx, 'intelligent_follow');
- this.model = this.ctx.model.IntelligentFollow;
- this.dmodel = this.ctx.model.IntelligentDocking;
- }
- // 已完成列表
- async getFinishList(data) {
- const match = {};
- if (data.userid) { // 金融机构ID---管理员
- match.uid = data.userid;
- } else {
- if (data.uid) { // 金融机构ID---客户经理
- match.uuid = data.uid;
- }
- }
- match.creditStatus = '1';
- const skip = Number.parseInt(data.skip) || 1;
- const limit = Number.parseInt(data.limit) || 10;
- const total = await this.model.countDocuments(match);
- const res = await this.model.aggregate([
- { $match: match },
- { $project: { intelligentId: { $toObjectId: '$intelligentId' }, creditStatus: 1, savetime: '$meta.createdAt' } },
- { $lookup: {
- from: 'intelligent_docking',
- localField: 'intelligentId',
- foreignField: '_id',
- as: 'intelligent' } },
- { $unwind: '$intelligent' },
- { $skip: (skip - 1) * limit },
- { $limit: limit },
- { $sort: { savetime: -1 } },
- ]);
- const newres = { res, total };
- return newres;
- }
- // 关注列表
- async getFollowList(data) {
- const match = {};
- if (data.userid) { // 金融机构ID---客户经理
- match.uuid = data.userid;
- }
- if (data.creditStatus) {
- match.creditStatus = data.creditStatus;
- } else {
- match.creditStatus = { $ne: '1' };
- }
- const skip = Number.parseInt(data.skip) || 1;
- const limit = Number.parseInt(data.limit) || 10;
- const total = await this.model.countDocuments(match);
- const res = await this.model.aggregate([
- { $match: match },
- { $project: { intelligentId: { $toObjectId: '$intelligentId' }, creditStatus: 1, savetime: '$meta.createdAt' } },
- { $lookup: {
- from: 'intelligent_docking',
- localField: 'intelligentId',
- foreignField: '_id',
- as: 'intelligent' } },
- { $unwind: '$intelligent' },
- { $skip: (skip - 1) * limit },
- { $limit: limit },
- { $sort: { savetime: -1 } },
- ]);
- const newres = { res, total };
- return newres;
- }
- // 授信接口
- async getCredit(data) {
- const { id, money, creditStatus, senhemessage, jindiaomessage, sxcpname, sxhowlong, sxcplilue } = data;// id:关注ID money:授信额度 orcredit:状态,senhemessage:审核备注,jindiaomessage:尽调备注
- const now = new Date();
- const nowtime = now.getTime();// 当前时间戳(授信时间)
- const intelligentFollow = await this.model.findById(id);
- if (creditStatus == '1' || creditStatus == '3') {
- const xuqiuId = intelligentFollow.intelligentId;
- const xuqiuData = await this.dmodel.findById(xuqiuId);
- xuqiuData.status = '1';
- await xuqiuData.save();
- }
- if (senhemessage) {
- intelligentFollow.senhemessage = senhemessage;
- }
- if (jindiaomessage) {
- intelligentFollow.jindiaomessage = jindiaomessage;
- }
- if (money) {
- intelligentFollow.credit_money = parseInt(money);
- }
- if (sxcpname) {
- intelligentFollow.sxcpname = sxcpname;
- }
- if (sxhowlong) {
- intelligentFollow.sxhowlong = sxhowlong;
- }
- if (sxcplilue) {
- intelligentFollow.sxcplilue = sxcplilue;
- }
- // 状态
- intelligentFollow.creditStatus = creditStatus;
- const creattime = new Date(intelligentFollow.meta.createdAt).getTime();// 创建时间时的时间戳
- const accept_time = parseInt(nowtime) - parseInt(creattime);// 授理时间(授信时间-创建时间)
- intelligentFollow.accept_time = parseInt(accept_time);
- intelligentFollow.credit_time = parseInt(nowtime);
- const res = await intelligentFollow.save();
- return res;
- }
- // 关注前接口
- async getBeforFollow(data) {
- const { xqid, userid } = data;// 需求ID,金融机构ID
- const match = {};
- if (userid) { // 金融机构ID
- match.uid = userid;
- }
- if (xqid) { // 需求ID
- match.intelligentId = xqid;
- }
- const result = {};
- const res = await this.model.find(match);
- if (res.length > 0) {
- result.finstatus = 'SUCCESS';
- } else {
- result.finstatus = 'ERROR';
- }
- return result;
- }
- // 金融机构关注需求
- async getFollow(data) {
- const { xqid, cid, userid, uuid } = data;// 需求ID,金融机构ID,客户经理id
- const newdata = {};
- newdata.intelligentId = xqid;
- newdata.cid = cid;
- newdata.uid = userid;
- newdata.uuid = uuid;
- newdata.creditStatus = '0';
- newdata.credit_money = 0;
- newdata.accept_time = 0;
- newdata.credit_time = 0;
- console.log('new =============', newdata);
- const res = await this.model.create(newdata);
- console.dir(this.dmodel);
- const qy = await this.dmodel.findById(xqid);
- this.ctx.service.viewnews.insertViewNews('银企对接需求信息', '您有新的银企对接需求被关注,请查看需求列表', qy.uid);
- return res;
- }
- }
- module.exports = IntelligentFollowService;
|