const { DataTypes } = require('sequelize'); const connect = require('./connect'); const { dateFormat } = require('../../utils'); /* type: DataTypes.STRING, allowNull: false, defaultValue:'', comment: '名', */ function format(m) { m.payAt && (m.payAt = dateFormat(m.payAt)); } const model = connect.define( __filename.slice(__dirname.length + 1).replace('.js', ''), { id: { type: DataTypes.STRING, primaryKey: true, comment: 'id', }, title: { type: DataTypes.STRING, allowNull: false, comment: '课程', }, detailimg: { type: DataTypes.STRING, allowNull: false, comment: '课程', }, recordId: { type: DataTypes.INTEGER, comment: '录播讲师', }, cid: { type: DataTypes.INTEGER, allowNull: false, comment: '课程id', }, price: { type: DataTypes.DECIMAL(10, 2), allowNull: false, comment: '支付价格', }, discount: { type: DataTypes.CHAR(5), defaultValue: '', comment: '折扣价格', }, code: { type: DataTypes.CHAR(6), defaultValue: '', comment: '邀请码', }, uid: { type: DataTypes.INTEGER, allowNull: false, comment: '用户id', }, payAt: { type: DataTypes.DATE, comment: '支付时间', }, status: { type: DataTypes.INTEGER, defaultValue: 0, comment: '0为支付1亿支付2渠道', }, channel: { type: DataTypes.INTEGER, defaultValue: 0, comment: '0在线支付2渠道', }, }, { comment: '订单', hooks: { beforeFind(option) { if (!option.order) { option.order = [['id', 'desc']]; } }, afterFind(m) { m && (Array.isArray(m) ? m.forEach(item => format(item)) : format(m)); }, }, } ); module.exports = model;