guhongwei %!s(int64=2) %!d(string=hai) anos
pai
achega
2057746e5f

+ 5 - 0
app/controller/.notice.js

@@ -41,6 +41,7 @@ module.exports = {
         send_name: "send_name",
         send_name: "send_name",
         send_time: "send_time",
         send_time: "send_time",
         type: "type",
         type: "type",
+        user_id: "user_id",
         "meta.createdAt@start": "meta.createdAt@start",
         "meta.createdAt@start": "meta.createdAt@start",
         "meta.createdAt@end": "meta.createdAt@end",
         "meta.createdAt@end": "meta.createdAt@end",
       },
       },
@@ -56,4 +57,8 @@ module.exports = {
       count: true,
       count: true,
     },
     },
   },
   },
+  updateRead: {
+    params: ["!id"],
+    requestBody: ["user_id", "status", "receive_user"],
+  },
 };
 };

+ 61 - 1
app/service/notice.js

@@ -1,14 +1,74 @@
 'use strict';
 'use strict';
 const { CrudService } = require('naf-framework-mongoose-free/lib/service');
 const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { isNullOrUndefined, trimData } = require('naf-core').Util;
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const _ = require('lodash');
 const assert = require('assert');
 const assert = require('assert');
+const { ObjectId } = require('mongoose').Types;
 
 
 // 通知通告
 // 通知通告
 class NoticeService extends CrudService {
 class NoticeService extends CrudService {
   constructor(ctx) {
   constructor(ctx) {
-    super(ctx, "notice");
+    super(ctx, 'notice');
     this.model = this.ctx.model.Notice;
     this.model = this.ctx.model.Notice;
+    this.usermodel = this.ctx.model.User;
+  }
+  async query({ user_id, ...query }, { skip = 0, limit = 0 } = {}) {
+    const condition = { ...query };
+    if (user_id) condition.receive_user = { $elemMatch: { user_id } };
+    const data = await this.model
+      .find(condition)
+      .skip(parseInt(skip))
+      .limit(parseInt(limit));
+    if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
+    return data;
+  }
+  async create(body) {
+    const { type } = body;
+    const user = await this.usermodel.find();
+    let userList = user.filter(i => i.type !== '0');
+    if (type !== '3') {
+      if (type === '0') {
+        for (const val of userList) {
+          body.receive_user.push({
+            user_id: val._id,
+            user_name: val.nickname,
+            status: '0',
+          });
+        }
+      } else if (type === '1') {
+        userList = userList.filter(i => i.type === '1');
+        for (const val of userList) {
+          body.receive_user.push({
+            user_id: val._id,
+            user_name: val.nickname,
+            status: '0',
+          });
+        }
+      } else if (type === '2') {
+        userList = userList.filter(i => i.type === '2');
+        for (const val of userList) {
+          body.receive_user.push({
+            user_id: val._id,
+            user_name: val.nickname,
+            status: '0',
+          });
+        }
+      }
+    }
+    await this.model.create(body);
+  }
+  // 修改
+  async updateRead({ id, user_id, status }) {
+    const data = await this.model.findById(id);
+    if (!data) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    const receive_user = [];
+    for (const val of data.receive_user) {
+      if (val.user_id == user_id) val.status = status;
+      receive_user.push(val);
+    }
+    data.receive_user = receive_user;
+    await data.save();
   }
   }
 }
 }
 
 

+ 2 - 1
app/service/team.js

@@ -20,7 +20,8 @@ class TeamService extends CrudService {
   }
   }
   // 用户所在团队列表
   // 用户所在团队列表
   async userteams({ user_id } = {}) {
   async userteams({ user_id } = {}) {
-    const res = await this.model.find({ members: { $elemMatch: { user_id: user_id } } });
+    const condition = { members: { $elemMatch: { user_id } } };
+    const res = await this.model.find(condition);
     if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
     if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
     return res;
     return res;
   }
   }

+ 2 - 1
app/service/user.js

@@ -35,7 +35,8 @@ class UserService extends CrudService {
     const data = await this.model.findById(id);
     const data = await this.model.findById(id);
     if (!data) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
     if (!data) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
     data.password = { secret: password };
     data.password = { secret: password };
-    await data.save();
+    console.log(data);
+    // await data.save();
   }
   }
 }
 }
 
 

+ 3 - 2
app/z_router/notice.js

@@ -1,9 +1,10 @@
 'use strict';
 'use strict';
 // 路由配置
 // 路由配置
-const rkey = "notice";
-const ckey = "notice";
+const rkey = 'notice';
+const ckey = 'notice';
 const keyZh = '通知通告';
 const keyZh = '通知通告';
 const routes = [
 const routes = [
+  { method: 'post', path: `${rkey}/read/:id`, controller: `${ckey}.updateRead`, name: `${ckey}UpdateRead`, zh: `修改${keyZh}已读` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
   { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },

+ 1 - 1
config/config.default.js

@@ -75,7 +75,7 @@ module.exports = appInfo => {
   // 数据库设置
   // 数据库设置
   config.dbName = 'courtAdmin';
   config.dbName = 'courtAdmin';
   config.mongoose = {
   config.mongoose = {
-    url: `mongodb://101.36.221.66:27017/${config.dbName}`,
+    url: `mongodb://101.36.221.66:27017/${config.dbName}`, // 101.36.221.66
     options: {
     options: {
       user: 'admin',
       user: 'admin',
       pass: 'admin',
       pass: 'admin',