companyidentify.js 3.9 KB

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