12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 'use strict';
- const Subscription = require('egg').Subscription;
- class dayUsers extends Subscription {
-
-
- static get schedule() {
- return {
-
-
-
- cron: '0 58 23 * * *',
- type: 'all',
- };
- }
-
- async subscribe() {
- const that = this;
- const seq = that.app.Sequelize;
- const tmpTime = that.app.szjcomo.time();
- const transaction = await that.app.model.transaction();
- try {
- const users = await that.app.model.Users.findAll({
- where: { update_ttime: { [seq.Op.between]: [ `${that.app.szjcomo.date('Y-m-d', tmpTime)} 00:00:00`, `${that.app.szjcomo.date('Y-m-d', tmpTime)} 23:59:59` ] } },
- order: [[ 'update_ttime', 'asc' ]],
- attributes: [ 'user_id', 'nickname', 'headimgurl', 'login_time', 'update_ttime', 'is_employee' ],
- });
- const result = JSON.parse(JSON.stringify(users));
-
- const datas = await result.map(item => {
- return Object.assign(item, {
- create_time: that.app.szjcomo.date('Y-m-d H:i:s'),
- });
- });
- await that.app.model.UserLoginLogs.bulkCreate(datas, { transaction });
- transaction.commit();
- } catch (e) {
- console.log(e);
- if (transaction) {
- transaction.rollback();
- }
- }
- }
- }
- module.exports = dayUsers;
|