cgserver 12.3.6 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/lib/Framework/Config/_error_.js +33 -24
  2. package/dist/lib/Framework/Database/Mongo/MongoBaseService.js +151 -128
  3. package/dist/lib/Framework/Database/Mongo/MongoManager.js +18 -561
  4. package/dist/lib/Framework/Decorator/JsonAuthorityValidate.js +1 -5
  5. package/dist/lib/Framework/Logic/Log.js +20 -5
  6. package/dist/lib/Framework/Server/WebServer/Controller/MongoBaseUserController.js +11 -25
  7. package/dist/lib/Framework/Server/WebServer/Controller/MysqlBaseUserController.js +0 -26
  8. package/dist/lib/Framework/Service/MongoAccountService.js +53 -116
  9. package/dist/lib/Framework/Service/MongoCacheService.js +20 -19
  10. package/dist/lib/Framework/Service/MongoUserService.js +39 -77
  11. package/dist/lib/Framework/Service/MysqlUserService.js +3 -12
  12. package/dist/lib/Framework/Service/ini.js +4 -10
  13. package/dist/lib/Framework/global.js +0 -2
  14. package/dist/lib/Framework/index_export_.js +2 -21
  15. package/dist/types/Framework/Config/_error_.d.ts +28 -92
  16. package/dist/types/Framework/Database/Mongo/MongoBaseService.d.ts +35 -113
  17. package/dist/types/Framework/Database/Mongo/MongoManager.d.ts +4 -145
  18. package/dist/types/Framework/Decorator/JsonAuthorityValidate.d.ts +1 -2
  19. package/dist/types/Framework/Logic/Log.d.ts +5 -5
  20. package/dist/types/Framework/Server/WebServer/Controller/MongoBaseUserController.d.ts +4 -8
  21. package/dist/types/Framework/Server/WebServer/Controller/MysqlBaseUserController.d.ts +0 -4
  22. package/dist/types/Framework/Service/MongoAccountService.d.ts +15 -17
  23. package/dist/types/Framework/Service/MongoCacheService.d.ts +5 -4
  24. package/dist/types/Framework/Service/MongoUserService.d.ts +14 -26
  25. package/dist/types/Framework/Service/MysqlUserService.d.ts +2 -4
  26. package/dist/types/Framework/Service/ini.d.ts +3 -8
  27. package/dist/types/Framework/global.d.ts +0 -1
  28. package/dist/types/Framework/index_export_.d.ts +5 -12
  29. package/package.json +2 -1
  30. package/dist/lib/Framework/Database/Mongo/MongoServiceManager.js +0 -52
  31. package/dist/lib/Framework/Decorator/AdminValidate.js +0 -18
  32. package/dist/lib/Framework/Decorator/AuthorityValidate.js +0 -22
  33. package/dist/lib/Framework/Decorator/CreatorValidate.js +0 -18
  34. package/dist/lib/Framework/Decorator/JsonCreatorValidate.js +0 -18
  35. package/dist/types/Framework/Database/Mongo/MongoServiceManager.d.ts +0 -13
  36. package/dist/types/Framework/Decorator/AdminValidate.d.ts +0 -1
  37. package/dist/types/Framework/Decorator/AuthorityValidate.d.ts +0 -2
  38. package/dist/types/Framework/Decorator/CreatorValidate.d.ts +0 -1
  39. package/dist/types/Framework/Decorator/JsonCreatorValidate.d.ts +0 -1
@@ -4,16 +4,13 @@ exports.MongoBaseUserController = void 0;
4
4
  const BaseController_1 = require("./BaseController");
5
5
  const FrameworkConfig_1 = require("../../../Config/FrameworkConfig");
6
6
  const MongoCacheService_1 = require("../../../Service/MongoCacheService");
7
- const ini_1 = require("../../../Service/ini");
8
7
  const CacheTool_1 = require("../../../Logic/CacheTool");
9
8
  const RedisManager_1 = require("../../../Database/Redis/RedisManager");
10
- const MongoServiceManager_1 = require("../../../Database/Mongo/MongoServiceManager");
11
9
  class MongoBaseUserController extends BaseController_1.BaseController {
12
10
  _user_session_id = "user_session_id";
13
11
  _self_user = null;
14
12
  _user = null; //网页内容的所属,比如,查看别人的博客,那这个信息就是作者的
15
13
  _session_id = null;
16
- _userser = null;
17
14
  get selfUser() {
18
15
  return this._self_user;
19
16
  }
@@ -23,23 +20,14 @@ class MongoBaseUserController extends BaseController_1.BaseController {
23
20
  get isLogin() {
24
21
  return this._self_user && true;
25
22
  }
26
- get isCreator() {
27
- return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Creator);
28
- }
29
- get isAdmin() {
30
- return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Admin || this._self_user.role_group == ini_1.ERoleGroup.Creator);
31
- }
32
- get isProxy() {
33
- return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Proxy);
34
- }
35
- get isCommon() {
36
- return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Common);
23
+ get userService() {
24
+ throw new Error("请重写userService方法");
37
25
  }
38
26
  async init() {
39
- this._userser = MongoServiceManager_1.gMongoServiceMgr.getService("user");
27
+ let userSer = this.userService;
40
28
  this._engine.cfg.session_type = this._engine.cfg.session_type || FrameworkConfig_1.ESessionType.Cache;
41
29
  this._session_id = this._request.getCookie(this._user_session_id) || this._request.params.session_id || this._request.postData.session_id;
42
- let userId = -1;
30
+ let userId = "";
43
31
  if (this._session_id) {
44
32
  let user = await this._getUserBySession(this._session_id);
45
33
  if (!user) {
@@ -53,8 +41,8 @@ class MongoBaseUserController extends BaseController_1.BaseController {
53
41
  }
54
42
  }
55
43
  let params = this._request.params;
56
- if (params.userId && params.userId != userId + "") {
57
- this._user = (await this._userser.getById(params.userId));
44
+ if (params.userId && params.userId != userId) {
45
+ this._user = (await this.userService.findById(params.userId));
58
46
  }
59
47
  else {
60
48
  //不是别人的信息就查看自己的
@@ -66,8 +54,6 @@ class MongoBaseUserController extends BaseController_1.BaseController {
66
54
  if (!session) {
67
55
  return user;
68
56
  }
69
- //每次强制从cache中先找,提高效率
70
- //if(this._engine.cfg.session_type==ESessionType.Cache)
71
57
  {
72
58
  user = CacheTool_1.gCacheTool.get(this._session_id);
73
59
  }
@@ -75,15 +61,15 @@ class MongoBaseUserController extends BaseController_1.BaseController {
75
61
  return user;
76
62
  }
77
63
  if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
78
- let user_id = +(await RedisManager_1.gRedisMgr.redis.get(this._session_id)).toString();
79
- if (user_id > 0) {
80
- user = (await this._userser.getById(user_id));
64
+ let user_id = (await RedisManager_1.gRedisMgr.redis.get(this._session_id)).toString();
65
+ if (user_id) {
66
+ user = (await this.userService.findById(user_id));
81
67
  }
82
68
  }
83
69
  else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
84
70
  let user_id = (await MongoCacheService_1.gMongoCacheSer.getData(this._session_id)) || -1;
85
71
  if (user_id > 0) {
86
- user = (await this._userser.getById(user_id));
72
+ user = (await this.userService.findById(user_id));
87
73
  }
88
74
  }
89
75
  if (user) {
@@ -146,7 +132,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
146
132
  async _update_session() {
147
133
  }
148
134
  async update_user(user_id) {
149
- let user = (await this._userser.getById(user_id));
135
+ let user = (await this.userService.findById(user_id));
150
136
  if (this._user && this._user.id == user.id) {
151
137
  this._user = user;
152
138
  }
@@ -4,8 +4,6 @@ exports.MysqlBaseUserController = void 0;
4
4
  const BaseController_1 = require("./BaseController");
5
5
  const MysqlUserService_1 = require("../../../Service/MysqlUserService");
6
6
  const FrameworkConfig_1 = require("../../../Config/FrameworkConfig");
7
- const MongoCacheService_1 = require("../../../Service/MongoCacheService");
8
- const ini_1 = require("../../../Service/ini");
9
7
  const CacheTool_1 = require("../../../Logic/CacheTool");
10
8
  const RedisManager_1 = require("../../../Database/Redis/RedisManager");
11
9
  class MysqlBaseUserController extends BaseController_1.BaseController {
@@ -22,18 +20,6 @@ class MysqlBaseUserController extends BaseController_1.BaseController {
22
20
  get isLogin() {
23
21
  return this._self_user && true;
24
22
  }
25
- get isCreator() {
26
- return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Creator);
27
- }
28
- get isAdmin() {
29
- return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Admin || this._self_user.role_group == ini_1.ERoleGroup.Creator);
30
- }
31
- get isProxy() {
32
- return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Proxy);
33
- }
34
- get isCommon() {
35
- return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Common);
36
- }
37
23
  async init() {
38
24
  this._engine.cfg.session_type = this._engine.cfg.session_type || FrameworkConfig_1.ESessionType.Cache;
39
25
  this._session_id = this._request.getCookie(this._user_session_id) || this._request.params.session_id || this._request.postData.session_id;
@@ -78,12 +64,6 @@ class MysqlBaseUserController extends BaseController_1.BaseController {
78
64
  user = (await MysqlUserService_1.GUserSer.getById(user_id));
79
65
  }
80
66
  }
81
- else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
82
- let user_id = (await MongoCacheService_1.gMongoCacheSer.getData(this._session_id)) || -1;
83
- if (user_id > 0) {
84
- user = (await MysqlUserService_1.GUserSer.getById(user_id));
85
- }
86
- }
87
67
  if (user) {
88
68
  this._login(user);
89
69
  }
@@ -97,9 +77,6 @@ class MysqlBaseUserController extends BaseController_1.BaseController {
97
77
  else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
98
78
  RedisManager_1.gRedisMgr.redis.del(this._session_id);
99
79
  }
100
- else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
101
- MongoCacheService_1.gMongoCacheSer.deleteOne({ key: this._session_id });
102
- }
103
80
  this._session_id = null;
104
81
  }
105
82
  this._response.clearCookie(this._user_session_id);
@@ -133,9 +110,6 @@ class MysqlBaseUserController extends BaseController_1.BaseController {
133
110
  RedisManager_1.gRedisMgr.redis.expire(this._session_id, time);
134
111
  });
135
112
  }
136
- else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
137
- MongoCacheService_1.gMongoCacheSer.addData(this._session_id, user.id, new Date(Date.now() + time * 1000));
138
- }
139
113
  this._self_user = user;
140
114
  }
141
115
  /**
@@ -1,31 +1,38 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoAccountService = exports.MongoAccountModel = void 0;
6
+ exports.MongoAccountService = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
4
8
  const _error_1 = require("../Config/_error_");
5
9
  const MongoBaseService_1 = require("../Database/Mongo/MongoBaseService");
6
- const MongoManager_1 = require("../Database/Mongo/MongoManager");
7
- const MongoServiceManager_1 = require("../Database/Mongo/MongoServiceManager");
8
10
  const CacheTool_1 = require("../Logic/CacheTool");
9
11
  const QQTool_1 = require("../ThirdParty/QQTool");
10
12
  const WechatTool_1 = require("../ThirdParty/WechatTool");
11
13
  const ini_1 = require("./ini");
12
- class MongoAccountModel extends MongoManager_1.MongoBaseModel {
13
- id = -1;
14
- phone = "";
15
- email = "";
16
- name = "";
17
- password = "";
18
- unionid = ""; //第三方
19
- openid = "";
20
- create_time = -1;
21
- create_ip = "";
22
- login_time = -1;
23
- login_ip = "";
24
- from = 0;
25
- state = ini_1.EAccountState.Waitting;
26
- }
27
- exports.MongoAccountModel = MongoAccountModel;
28
14
  class MongoAccountService extends MongoBaseService_1.MongoBaseService {
15
+ get userService() {
16
+ throw new Error("请重写userService方法");
17
+ }
18
+ constructor(extaccountdef) {
19
+ const accountSchema = new mongoose_1.default.Schema({ ...{
20
+ phone: { type: String, default: "" },
21
+ email: { type: String, default: "" },
22
+ name: { type: String, default: "" },
23
+ password: { type: String, default: "" },
24
+ unionid: { type: String, default: "" }, // 第三方唯一标识
25
+ openid: { type: String, default: "" }, // 第三方开放ID
26
+ create_time: { type: Date, default: new Date() },
27
+ create_ip: { type: String, default: "" },
28
+ login_time: { type: Date, default: new Date() },
29
+ login_ip: { type: String, default: "" },
30
+ from: { type: Number, default: ini_1.EAccountFrom.Guest }, // 来源
31
+ state: { type: Number, default: ini_1.EAccountState.Waitting } // 状态
32
+ }, ...extaccountdef });
33
+ super('account', accountSchema);
34
+ let userService = this.userService;
35
+ }
29
36
  /**
30
37
  * 注册新账号
31
38
  * @param unionid
@@ -33,52 +40,44 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
33
40
  * @param ip
34
41
  * @param from
35
42
  */
36
- async add(unionid, openid, ip, from) {
37
- let account = new this._t_type();
43
+ async add(key, pass, ip, from) {
44
+ let account = {};
38
45
  switch (from) {
39
46
  case ini_1.EAccountFrom.WeChat:
40
47
  case ini_1.EAccountFrom.QQ:
41
48
  case ini_1.EAccountFrom.Apple:
42
49
  case ini_1.EAccountFrom.Google:
43
50
  {
44
- account.unionid = unionid;
45
- account.openid = openid;
51
+ account.unionid = key;
52
+ account.openid = pass;
46
53
  break;
47
54
  }
48
55
  case ini_1.EAccountFrom.Email:
49
56
  {
50
- account.email = unionid;
51
- account.password = openid;
57
+ account.email = key;
58
+ account.password = pass;
52
59
  break;
53
60
  }
54
61
  case ini_1.EAccountFrom.Phone:
55
62
  case ini_1.EAccountFrom.QuickPhone:
56
63
  {
57
- account.phone = unionid;
58
- account.password = openid;
64
+ account.phone = key;
65
+ account.password = pass;
59
66
  break;
60
67
  }
61
68
  case ini_1.EAccountFrom.Name:
62
69
  case ini_1.EAccountFrom.Guest:
63
70
  {
64
- account.name = unionid;
65
- account.password = openid;
71
+ account.name = key;
72
+ account.password = pass;
66
73
  break;
67
74
  }
68
75
  }
69
- account.create_time = Date.now();
70
76
  account.create_ip = ip;
71
- account.login_time = Date.now();
72
77
  account.login_ip = ip;
73
78
  account.from = from;
74
- account.state = ini_1.EAccountState.Waitting;
75
- account.id = await this.getNextId();
76
79
  let sr = await this.insert(account);
77
- if (sr.errcode) {
78
- return null;
79
- }
80
- account._id = sr.rs.insertedId;
81
- return account;
80
+ return sr.model;
82
81
  }
83
82
  /**
84
83
  * 通过第三方信息获取账号
@@ -149,8 +148,8 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
149
148
  return rs;
150
149
  }
151
150
  if (force_user) {
152
- let userser = MongoServiceManager_1.gMongoServiceMgr.getService("user");
153
- let user = await userser.getByAccountId(account.id);
151
+ let userser = this.userService;
152
+ let user = await userser.findOne({ account_id: account.id });
154
153
  if (!user) {
155
154
  switch (from) {
156
155
  case ini_1.EAccountFrom.QQ:
@@ -210,7 +209,7 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
210
209
  user = await userser.add(account.id, extra_info.nickname, extra_info.sex, extra_info.logo);
211
210
  }
212
211
  else {
213
- user = await userser.add(account.id, null, null, null);
212
+ user = await userser.add(account.id);
214
213
  }
215
214
  if (!user) {
216
215
  this.deleteOne({ id: account.id });
@@ -228,112 +227,50 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
228
227
  rs.is_new = true;
229
228
  }
230
229
  }
231
- account.login_time = Date.now();
230
+ account.login_time = new Date();
232
231
  account.login_ip = ip;
233
- this.updateOne({ id: account.id }, { login_time: account.login_time, login_ip: account.login_ip });
232
+ await account.save();
234
233
  rs.account = account;
235
234
  return rs;
236
235
  }
237
- async _login(unionid, openid, from) {
238
- unionid += "";
239
- openid += "";
236
+ async _login(key, pass, from) {
237
+ key += "";
238
+ pass += "";
240
239
  let rs = { errcode: null, account: null };
241
240
  if (from == ini_1.EAccountFrom.QQ
242
241
  || from == ini_1.EAccountFrom.WeChat
243
242
  || from == ini_1.EAccountFrom.Apple
244
243
  || from == ini_1.EAccountFrom.Google) {
245
- rs.account = await this.getByThird(unionid, openid);
244
+ rs.account = await this.getByThird(key, pass);
246
245
  }
247
246
  else if (from == ini_1.EAccountFrom.QuickPhone) {
248
- let key = "phone_code_" + unionid;
249
- let code = CacheTool_1.gCacheTool.get(key);
250
- if (!code || code != openid) {
247
+ let _phone_key = "phone_code_" + key;
248
+ let code = CacheTool_1.gCacheTool.get(_phone_key);
249
+ if (!code || code != pass) {
251
250
  rs.errcode = _error_1.EErrorCode.Wrong_Phone_Code;
252
251
  return rs;
253
252
  }
254
- rs.account = await this.getByPhone(unionid);
253
+ rs.account = await this.getByPhone(key);
255
254
  }
256
255
  else if (from == ini_1.EAccountFrom.Phone) {
257
- rs.account = await this.findOne({ phone: unionid, password: openid });
256
+ rs.account = await this.findOne({ phone: key, password: pass });
258
257
  if (!rs.account) {
259
258
  rs.errcode = _error_1.EErrorCode.Login_Failed;
260
259
  }
261
260
  }
262
261
  else if (from == ini_1.EAccountFrom.Email) {
263
- rs.account = await this.findOne({ email: unionid, password: openid });
262
+ rs.account = await this.findOne({ email: key, password: pass });
264
263
  if (!rs.account) {
265
264
  rs.errcode = _error_1.EErrorCode.Login_Failed;
266
265
  }
267
266
  }
268
267
  else if (from == ini_1.EAccountFrom.Name || from == ini_1.EAccountFrom.Guest) {
269
- rs.account = await this.findOne({ name: unionid, password: openid });
268
+ rs.account = await this.findOne({ name: key, password: pass });
270
269
  if (!rs.account && from == ini_1.EAccountFrom.Name) {
271
270
  rs.errcode = _error_1.EErrorCode.Login_Failed;
272
271
  }
273
272
  }
274
273
  return rs;
275
274
  }
276
- async register(type, key, password, ip, extra) {
277
- let rs = { user: null, errcode: null };
278
- extra = extra || {};
279
- let am = new this._t_type();
280
- switch (type) {
281
- case ini_1.EAccountFrom.Phone:
282
- {
283
- am.phone = key;
284
- let temp = await this.findOne({ phone: key }, { id: 1 });
285
- if (temp) {
286
- rs.errcode = _error_1.EErrorCode.Account_Phone_Exist;
287
- return rs;
288
- }
289
- break;
290
- }
291
- case ini_1.EAccountFrom.Email:
292
- {
293
- am.email = key;
294
- let temp = await this.findOne({ email: key }, { id: 1 });
295
- if (temp) {
296
- rs.errcode = _error_1.EErrorCode.Account_Email_Exist;
297
- return rs;
298
- }
299
- break;
300
- }
301
- case ini_1.EAccountFrom.Name:
302
- {
303
- am.name = key;
304
- let temp = await this.findOne({ name: key }, { id: 1 });
305
- if (temp) {
306
- rs.errcode = _error_1.EErrorCode.Account_Name_Exist;
307
- return rs;
308
- }
309
- break;
310
- }
311
- default:
312
- {
313
- rs.errcode = _error_1.EErrorCode.Account_Type_Error;
314
- return rs;
315
- }
316
- }
317
- am.password = password;
318
- am.create_time = Date.now();
319
- am.create_ip = ip;
320
- am.login_time = Date.now();
321
- am.login_ip = ip;
322
- am.id = await this.getNextId();
323
- let rs_am = await this.insert(am);
324
- if (!rs_am.rs.insertedId) {
325
- rs.errcode = _error_1.EErrorCode.Mysql_Error;
326
- return rs;
327
- }
328
- let userser = MongoServiceManager_1.gMongoServiceMgr.getService("user");
329
- let user = await userser.add(am.id, extra.nickname, extra.sex, extra.logo);
330
- if (!user) {
331
- this.deleteOne({ id: am.id });
332
- rs.errcode = _error_1.EErrorCode.User_Create_Failed;
333
- return rs;
334
- }
335
- rs.user = user;
336
- return rs;
337
- }
338
275
  }
339
276
  exports.MongoAccountService = MongoAccountService;
@@ -1,20 +1,24 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gMongoCacheSer = exports.MongoCacheService = exports.MongoCacheModel = void 0;
6
+ exports.gMongoCacheSer = exports.MongoCacheService = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
4
8
  const MongoBaseService_1 = require("../Database/Mongo/MongoBaseService");
5
- const MongoManager_1 = require("../Database/Mongo/MongoManager");
6
- //暂时就用这个了,反正没啥用户
7
- class MongoCacheModel extends MongoManager_1.MongoBaseModel {
8
- key = "";
9
- data = null;
10
- expireAt = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000);
11
- }
12
- exports.MongoCacheModel = MongoCacheModel;
9
+ let mongoCacheSchema = new mongoose_1.default.Schema({
10
+ key: { type: String, required: true },
11
+ data: { type: Object, required: true },
12
+ expireAt: { type: Date, default: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), require: true }
13
+ });
13
14
  /**
14
15
  * mongo版本的缓存服务
15
16
  * 可以用来缓存kv数据
16
17
  */
17
18
  class MongoCacheService extends MongoBaseService_1.MongoBaseService {
19
+ constructor() {
20
+ super("cache", mongoCacheSchema);
21
+ }
18
22
  async getData(key) {
19
23
  let cm = await this.findOne({ key: key });
20
24
  if (!cm) {
@@ -25,17 +29,14 @@ class MongoCacheService extends MongoBaseService_1.MongoBaseService {
25
29
  }
26
30
  return cm.data;
27
31
  }
28
- async addData(key, data, expireAt = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000)) {
29
- let mcm = new MongoCacheModel();
30
- mcm.key = key;
31
- mcm.data = data;
32
- mcm.expireAt = expireAt;
33
- let rs = await this.updateOne({ key: mcm.key }, mcm, { upsert: true });
34
- if (rs.rs.upsertedCount <= 0) {
35
- return null;
32
+ async addData(key, data, expireAt) {
33
+ let m = { key: key, data: data };
34
+ if (expireAt) {
35
+ m.expireAt = expireAt;
36
36
  }
37
- return mcm;
37
+ let rs = await this.insert(m);
38
+ return rs.model;
38
39
  }
39
40
  }
40
41
  exports.MongoCacheService = MongoCacheService;
41
- exports.gMongoCacheSer = new MongoCacheService("cache", MongoCacheModel);
42
+ exports.gMongoCacheSer = new MongoCacheService();
@@ -15,12 +15,6 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
18
  var __importStar = (this && this.__importStar) || (function () {
25
19
  var ownKeys = function(o) {
26
20
  ownKeys = Object.getOwnPropertyNames || function (o) {
@@ -38,92 +32,60 @@ var __importStar = (this && this.__importStar) || (function () {
38
32
  return result;
39
33
  };
40
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
41
38
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.MongoUserService = exports.MongoUserModel = void 0;
39
+ exports.MongoUserService = void 0;
43
40
  const _ = __importStar(require("underscore"));
44
41
  const MongoBaseService_1 = require("../Database/Mongo/MongoBaseService");
45
- const MongoManager_1 = require("../Database/Mongo/MongoManager");
42
+ const mongoose_1 = __importDefault(require("mongoose"));
46
43
  const ini_1 = require("./ini");
47
- const SyncCall_1 = require("../Decorator/SyncCall");
48
- class MongoUserModel extends MongoManager_1.MongoBaseModel {
49
- id = -1;
50
- account_id = -1;
51
- nickname = "";
52
- sex = -1;
53
- logo = "";
54
- state = 0;
55
- role_group = 4;
56
- role = 0;
57
- phone = "";
58
- wechat = "";
59
- qq = "";
60
- email = "";
61
- about = "";
62
- pre_user_id = -1;
63
- exp = 0;
64
- level = 1; //等级
65
- vip_exp = 0;
66
- vip_level = 0; //等级
67
- is_robot = 0;
68
- create_time = 0;
69
- }
70
- exports.MongoUserModel = MongoUserModel;
71
44
  //暂时不实例化,方便重写
72
45
  class MongoUserService extends MongoBaseService_1.MongoBaseService {
73
- async _createNewUser(account_id, nickname, sex, logo, group) {
74
- group = group || ini_1.ERoleGroup.Common;
75
- let um = new this._t_type();
76
- um.account_id = account_id;
77
- um.nickname = nickname;
78
- if (!um.nickname || um.nickname.length == 0) {
79
- um.nickname = "noname";
46
+ constructor(extuserdef) {
47
+ const userSchema = new mongoose_1.default.Schema({ ...{
48
+ _id: { type: Number },
49
+ account_id: { type: String, index: { unique: true } },
50
+ state: { type: Number, default: ini_1.EUserState.Normal },
51
+ is_robot: { type: Boolean, default: false },
52
+ create_time: { type: Date, default: Date.now },
53
+ login_time: { type: Date, default: Date.now },
54
+ create_ip: { type: String, default: "" },
55
+ login_ip: { type: String, default: "" },
56
+ nickname: { type: String, default: "noname" },
57
+ logo: { type: String, default: "" },
58
+ sex: { type: Number, default: 0 }
59
+ }, ...extuserdef }, { id: false });
60
+ userSchema.virtual('id').get(function () {
61
+ return this._id;
62
+ });
63
+ super('user', userSchema);
64
+ }
65
+ async add(account_id, nickname, sex, logo) {
66
+ let m = {};
67
+ m.account_id = account_id;
68
+ if (nickname) {
69
+ m.nickname = nickname;
70
+ }
71
+ if (sex !== undefined) {
72
+ m.sex = sex;
73
+ }
74
+ if (logo) {
75
+ m.logo = logo;
80
76
  }
81
- um.sex = sex || 0;
82
- um.logo = logo || "";
83
- um.account_id = account_id;
84
- um.state = 0;
85
- um.role_group = group;
86
- um.role = 0;
87
- um.create_time = Date.now();
88
77
  //随机userid
89
78
  let id = 0;
90
79
  do {
91
- id = _.random(1000000, 9999999);
80
+ id = _.random(10000000, 99999999);
92
81
  let p = await this.findOne({ id: id }, { id: 1 });
93
82
  if (!p) {
94
83
  break;
95
84
  }
96
85
  } while (true);
97
- um.id = id;
98
- return um;
99
- }
100
- async add(account_id, nickname, sex, logo, group) {
101
- let um = await this._createNewUser(account_id, nickname, sex, logo, group);
102
- let rs = await this.insert(um);
103
- if (rs.errcode || !rs.rs.insertedId) {
104
- return null;
105
- }
106
- um._id = rs.rs.insertedId;
107
- return um;
108
- }
109
- async getByAccountId(account_id) {
110
- let pm = await this.findOne({ account_id: account_id });
111
- return pm;
112
- }
113
- async updateBaseInfoByAccount(account_id, nickname, sex, logo) {
114
- let model = {
115
- nickname: nickname,
116
- sex: sex,
117
- logo: logo
118
- };
119
- let sr = await this.updateOne({ account_id: account_id }, model);
120
- if (sr.errcode) {
121
- return "更新失败";
122
- }
123
- return;
86
+ m._id = id;
87
+ let rs = await this.insert(m);
88
+ return rs.model;
124
89
  }
125
90
  }
126
91
  exports.MongoUserService = MongoUserService;
127
- __decorate([
128
- SyncCall_1.SyncCall
129
- ], MongoUserService.prototype, "_createNewUser", null);
@@ -148,8 +148,7 @@ class MysqlUserService extends MysqlBaseService_1.MysqlBaseService {
148
148
  super(type);
149
149
  exports.GUserSer = this;
150
150
  }
151
- async _createNewUser(account_id, nickname, sex, logo, group) {
152
- group = group || ini_1.ERoleGroup.Common;
151
+ async _createNewUser(account_id, nickname, sex, logo) {
153
152
  let um = new this._t_type();
154
153
  um.account_id = account_id;
155
154
  um.nickname = nickname;
@@ -160,7 +159,6 @@ class MysqlUserService extends MysqlBaseService_1.MysqlBaseService {
160
159
  um.logo = logo || "";
161
160
  um.account_id = account_id;
162
161
  um.state = ini_1.EUserState.Waitting;
163
- um.role_group = group;
164
162
  um.role = 0;
165
163
  //随机userid
166
164
  let id = 0;
@@ -181,21 +179,14 @@ class MysqlUserService extends MysqlBaseService_1.MysqlBaseService {
181
179
  }
182
180
  return;
183
181
  }
184
- async add(account_id, nickname, sex, logo, group) {
185
- let um = await this._createNewUser(account_id, nickname, sex, logo, group);
182
+ async add(account_id, nickname, sex, logo) {
183
+ let um = await this._createNewUser(account_id, nickname, sex, logo);
186
184
  let sr = await this.insert(um);
187
185
  if (sr.error || sr.queryResult.length <= 0) {
188
186
  return null;
189
187
  }
190
188
  return um;
191
189
  }
192
- async updateRoleGroup(user_id, role_group) {
193
- let sr = await this.updateProperty("role_group=?", "id=?", [role_group, user_id]);
194
- if (sr.error && sr.execResult.affectedRows <= 0) {
195
- return "更新失败";
196
- }
197
- return;
198
- }
199
190
  async getByAccountId(account_id) {
200
191
  let pm = await this.get(null, "account_id=?", [account_id]);
201
192
  return pm;