liuyu 5 سال پیش
والد
کامیت
335906fc2b
3فایلهای تغییر یافته به همراه79 افزوده شده و 0 حذف شده
  1. 22 0
      app/controller/buff.js
  2. 1 0
      app/router.js
  3. 56 0
      app/service/buff.js

+ 22 - 0
app/controller/buff.js

@@ -0,0 +1,22 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 产品审核表管理
+class BuffController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.buff;
+  }
+
+  async userlist() {
+    const res = await this.service.userlist(this.ctx.query);
+    this.ctx.ok({ data: res });
+  }
+
+}
+
+module.exports = BuffController;

+ 1 - 0
app/router.js

@@ -7,6 +7,7 @@ module.exports = app => {
   const { router, controller } = app;
   router.get('/', controller.home.index);
 
+  router.get('/api/market/user/hwsxg', controller.buff.userlist);
   // 科技超市用户表设置路由
   router.post('user', '/api/market/user/uppasswd', controller.user.uppasswd);
   router.resources('user', '/api/market/user', controller.user); // index、create、show、destroy

+ 56 - 0
app/service/buff.js

@@ -0,0 +1,56 @@
+'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 BuffService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'user');
+    this.umodel = this.ctx.model.User;
+    this.emodel = this.ctx.model.Expertsuser;
+  }
+
+  async userlist(info) {
+    const { pid, code, skip, limit } = info;
+    let url = this.ctx.app.config.axios.auth.baseUrl + '?skip=' + skip + '&limit=' + limit;
+    if (pid) {
+      url = url + '&pid=' + pid;
+    }
+    if (code) {
+      url = url + '&code=' + code;
+    }
+    const res = await this.ctx.curl(url, {
+      method: 'get',
+      headers: {
+        'content-type': 'application/json',
+      },
+      dataType: 'json',
+    });
+    const resdata = res.data.data;
+    const data = [];
+    for (const elm of resdata) {
+      const newdata = { ...JSON.parse(JSON.stringify(elm)) };
+      if (elm.role === '2' || elm.role === '3') {
+        const user = await this.umodel.findById(elm.uid);
+        if (user) {
+          newdata.status = user.status;
+        }
+      } else if (elm.role === '6') {
+        const user = await this.emodel.findById(elm.uid);
+        if (user) {
+          newdata.status = user.status;
+        }
+      }
+      data.push(newdata);
+
+    }
+    return { data, total: res.data.total };
+  }
+
+}
+
+module.exports = BuffService;