1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 'use strict';
- /**
- * 项目操作日志-数据模型
- *
- * @author ellisran
- * @date 2021/01/12
- * @version
- */
- module.exports = app => {
- class projectLog extends app.BaseService {
- constructor(ctx) {
- super(ctx);
- this.tableName = 'project_log';
- }
- /**
- * 创建登录日志
- * @return {Boolean} 日志是否创建成功
- * @param {Number} type - 登录类型
- * @param {Number} status - 是否显示记录
- */
- async addProjectLog(transaction, type, status, msg, tid = 0) {
- const { ctx } = this;
- const ipMsg = await ctx.helper.getUserIPMsg();
- const payload = {
- uid: ctx.session.sessionUser.accountId,
- pid: ctx.session.sessionProject.id,
- tid: ctx.tender.id ? ctx.tender.id : tid,
- type,
- status,
- msg,
- };
- this._.assign(payload, ipMsg);
- return await transaction.insert(this.tableName, payload);
- }
- /**
- * 获取操作日志
- * @param {Number} pid - 项目id
- * @param {Number} type - 类型
- * @return {Promise<Array>} 日志数组
- */
- async getLogs(pid, type = 0) {
- const typeSql = parseInt(type) !== 0 ? ' AND A.`type` = ' + type : '';
- const sql = 'SELECT A.*, B.`name` as `username`, B.`mobile` FROM ?? as A LEFT JOIN ?? as B ON A.`uid` = B.`id` WHERE A.`pid` = ?' + typeSql + ' AND TO_DAYS(NOW()) - TO_DAYS(A.`create_time`) <= 30 ORDER BY A.`id` DESC';
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, pid];
- return await this.db.query(sql, sqlParam);
- }
- }
- return projectLog;
- };
|