applymmoney.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class ApplymmoneyService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'apply_mmoney');
  10. this.model = this.ctx.model.Applymmoney;
  11. }
  12. async getAmlist(data) {
  13. const match = {};
  14. if (data.region) {
  15. match.status = data.region;
  16. }
  17. if (data.jg_id) {
  18. match.jgid = data.jg_id;
  19. }
  20. const skip = Number.parseInt(data.skip) || 1;
  21. const limit = Number.parseInt(data.limit) || 10;
  22. const totalres = await this.model.aggregate([
  23. { $match: match },
  24. { $project: { jgid:1,qyid:1,mid:{$toObjectId: '$mid'},status:1} },
  25. { $lookup: {
  26. from: 'manage_money',
  27. localField: 'mid',
  28. foreignField: '_id',
  29. as: 'mmnew' } },
  30. { $unwind: '$mmnew' },
  31. { $lookup: {
  32. from: 'company',
  33. localField: 'qyid',
  34. foreignField: 'uid',
  35. as: 'companynew' } },
  36. { $unwind: '$companynew' },
  37. { $project: { _id: 1,status: 1, jgid: 1, mmtitle: '$mmnew.title',companyname:'$companynew.company_name'} },
  38. { $count:'total'}
  39. ]);
  40. let total=0
  41. if(totalres.length>0){
  42. total= totalres[0].total;
  43. }
  44. const res = await this.model.aggregate([
  45. { $match: match },
  46. { $project: { jgid:1,qyid:1,mid:{$toObjectId: '$mid'},status:1} },
  47. { $lookup: {
  48. from: 'manage_money',
  49. localField: 'mid',
  50. foreignField: '_id',
  51. as: 'mmnew' } },
  52. { $unwind: '$mmnew' },
  53. { $lookup: {
  54. from: 'company',
  55. localField: 'qyid',
  56. foreignField: 'uid',
  57. as: 'companynew' } },
  58. { $unwind: '$companynew' },
  59. { $project: { _id: 1,status: 1, jgid: 1, mmtitle: '$mmnew.title',companyname:'$companynew.company_name',buymin:'$mmnew.buymin'} },
  60. { $skip: (skip - 1) * limit},
  61. { $limit: limit },
  62. ]);
  63. const newres = {res,total};
  64. return newres;
  65. }
  66. async getOne(data) {
  67. const match = {};
  68. if (data.mid) {
  69. match._id = ObjectId(data.mid);
  70. }
  71. const res = await this.model.aggregate([
  72. { $match: match },
  73. { $project: { jgid:1,qyid:1,mid:{$toObjectId: '$mid'},status:1} },
  74. { $lookup: {
  75. from: 'manage_money',
  76. localField: 'mid',
  77. foreignField: '_id',
  78. as: 'mmnew' } },
  79. { $unwind: '$mmnew' },
  80. { $lookup: {
  81. from: 'company',
  82. localField: 'qyid',
  83. foreignField: 'uid',
  84. as: 'companynew' } },
  85. { $unwind: '$companynew' },
  86. { $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',
  87. companyname:'$companynew.company_name'} }
  88. ]);
  89. return res;
  90. }
  91. async getChangefollow(data) {
  92. const changeres = await this.model.findById(data.mid);
  93. if(data.status=='0'){ //前台传0 说明当前信息未关注 点击应该为想关注的操作
  94. changeres.status = '1';
  95. }else{
  96. changeres.status = '0'; //取消关注
  97. }
  98. const res = await changeres.save();
  99. return res;
  100. }
  101. async getBeforecreat(data) {
  102. let finalres={};
  103. const res = await this.model.find({"qyid":data.qyid,"mid":data.mid});
  104. if(res.length>0){
  105. finalres.status = 'ERROR';//说明已经申请过了
  106. }else{
  107. finalres.status = 'SUCCESS';//说明可以继续申请
  108. }
  109. return finalres;
  110. }
  111. }
  112. module.exports = ApplymmoneyService;