| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 'use strict';
- var quick = require('quick-pomelo');
- var P = quick.Promise;
- var _ = require('lodash');
- var C = require('../../share/constant');
- var logger = quick.logger.getLogger('increase', __filename);
- // 构造方法
- var Controller = function (app) {
- this.app = app;
- this.userId = 100000;
- this.app.event.on('start_server', () => this.initAsync());
- };
- // 导出方法
- module.exports = function (app) {
- if (app.getServerType() == 'increaser') return new Controller(app);
- };
- // 原型对象
- var proto = Controller.prototype;
- // 初始计数
- proto.initAsync = function () {
- var goose = this.app.memdb.goose;
- return goose.transaction(function () {
- return goose.autoconn.collection('__increases__').findByIdReadOnly('player', 'userId')
- }, this.app.getServerId())
- .then((doc) => {
- this.userId = doc ? doc.userId : 100000;
- });
- };
- // 获取计数
- proto.newUserIdAsync = function () {
- this.userId += 1;
- var newId = this.userId;
- var self = this;
- var goose = this.app.memdb.goose;
- return goose.transaction(function () {
- return goose.autoconn.collection('__increases__').update('player', { $set: { userId: self.userId } }, { upsert: true });
- }, this.app.getServerId())
- .then(() => newId);
- };
|