companyidentify.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 CompanyidentifyService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'company_identify');
  10. this.model = this.ctx.model.Companyidentify;
  11. this.cmodel = this.ctx.model.Company;
  12. this.umodel = this.ctx.model.Companyuser;
  13. this.pmodel = this.ctx.model.Profession;
  14. this.dmodel = this.ctx.model.Dictionary;
  15. }
  16. // 重写创建方法
  17. async create(data) {
  18. const { uid, company_name, reg_num, type, address, business, capital, establish_date, valid_period, person, opening_bank } = data;
  19. assert(company_name && reg_num && type && address && business && capital && establish_date && valid_period && person && opening_bank, '缺少部分信息项');
  20. const res = await this.model.create(data);
  21. // 给用户发送消息告知注册成功
  22. this.ctx.service.viewnews.insertViewNews('认证成功', '恭喜您认证成功', res._id);
  23. return res;
  24. }
  25. // 修改企业认证信息表的状态
  26. async status({ id }, { status }) {
  27. // 根据id查询企业认证信息表的数据
  28. const companyidentify = await this.model.findById(id);
  29. // 如果修改状态为1(审核通过)
  30. if (status === '1') {
  31. // 将企业认证信息表中的部分字段提取出来,创建用户对应的企业信息表
  32. // const newdata = _.pick(companyidentify, [ 'uid', 'company_name', 'introduction', 'registered_addr', 'business_addr', 'profession_one', 'profession_two', 'profession_three', 'profession_four' ]);
  33. const newdata = _.pick(companyidentify, [ 'uid', 'company_name', 'reg_num', 'type', 'address', 'business', 'capital', 'establish_date', 'valid_period', 'person' ]);
  34. // 将企业用户表中的权限改为1(认证)
  35. const companyuser = await this.umodel.findById(companyidentify.uid);
  36. companyuser.roles = '1';
  37. await companyuser.save();
  38. // 给用户发送消息告知认证通过
  39. this.ctx.service.viewnews.insertViewNews('认证成功', '恭喜您通过了企业认证,您现在可以体验平台更多功能', companyidentify.uid);
  40. // 增加月报
  41. const financeinfo = [];
  42. const now_date = new Date();
  43. const year = now_date.getFullYear();
  44. const month = [ '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12' ];
  45. for (const elm of month) {
  46. const report_time = year + '-' + elm + '月报';
  47. const status = '0';
  48. const fidata = { report_time, status };
  49. financeinfo.push(fidata);
  50. }
  51. // 增加年报
  52. const yeardata = { report_time: year + '年报', status: '0' };
  53. financeinfo.push(yeardata);
  54. newdata.finance_info = financeinfo;
  55. await this.cmodel.create(newdata);
  56. }
  57. companyidentify.status = status;
  58. await companyidentify.save();
  59. }
  60. async fetch({ id }) {
  61. const companyidentify = await this.model.findById(id);
  62. if (companyidentify.profession_one) {
  63. const profession_one = await this.pmodel.findOne({
  64. code: companyidentify.profession_one,
  65. });
  66. companyidentify.profession_one = profession_one.name;
  67. }
  68. if (companyidentify.profession_two) {
  69. const profession_two = await this.pmodel.findOne({
  70. code: companyidentify.profession_two,
  71. });
  72. companyidentify.profession_two = profession_two.name;
  73. }
  74. if (companyidentify.profession_three) {
  75. const profession_three = await this.pmodel.findOne({
  76. code: companyidentify.profession_three,
  77. });
  78. companyidentify.profession_three = profession_three.name;
  79. }
  80. if (companyidentify.profession_four) {
  81. const profession_four = await this.pmodel.findOne({
  82. code: companyidentify.profession_four,
  83. });
  84. companyidentify.profession_four = profession_four.name;
  85. }
  86. if (companyidentify.belong_addr_city) {
  87. const belong_addr_city = await this.dmodel.findOne({
  88. code: companyidentify.belong_addr_city,
  89. });
  90. companyidentify.belong_addr_city = belong_addr_city.name;
  91. }
  92. if (companyidentify.belong_addr_city) {
  93. const belong_addr_area = await this.dmodel.findOne({
  94. code: companyidentify.belong_addr_area,
  95. });
  96. companyidentify.belong_addr_area = belong_addr_area.name;
  97. }
  98. return companyidentify;
  99. }
  100. }
  101. module.exports = CompanyidentifyService;