admin_user.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* indent size: 2 */
  2. module.exports = app => {
  3. const DataTypes = app.Sequelize;
  4. const Model = app.model.define('AdminUser', {
  5. admin_id: {
  6. type: DataTypes.INTEGER(10).UNSIGNED,
  7. primaryKey: true,
  8. autoIncrement: true
  9. },
  10. username: {
  11. type: DataTypes.STRING(20)
  12. },
  13. password: {
  14. type: DataTypes.STRING(255)
  15. },
  16. role_id: {
  17. type: DataTypes.INTEGER(10).UNSIGNED
  18. },
  19. admin_status: {
  20. type: DataTypes.INTEGER(1).UNSIGNED
  21. },
  22. login_ip: {
  23. type: DataTypes.STRING(15)
  24. },
  25. login_time: {
  26. type: DataTypes.DATE,
  27. get() {
  28. let logintime = this.getDataValue('login_time');
  29. if('0000-00-00 00:00:00' == logintime) return '';
  30. return logintime;
  31. }
  32. },
  33. login_count:{
  34. type:DataTypes.INTEGER(1).UNSIGNED
  35. },
  36. admin_token: {
  37. type: DataTypes.STRING(255)
  38. },
  39. admin_code: {
  40. type: DataTypes.CHAR(6)
  41. },
  42. other_auth: {
  43. type: DataTypes.STRING(255)
  44. },
  45. action_user: {
  46. type: DataTypes.INTEGER(1).UNSIGNED
  47. },
  48. update_time: {
  49. type: DataTypes.TIME
  50. },
  51. create_time: {
  52. type: DataTypes.DATE
  53. }
  54. },
  55. {
  56. tableName: 'szj_admin_user'
  57. });
  58. Model.associate = function() {
  59. //关联角色表
  60. Model.belongsTo(app.model.Roles,{foreignKey:'role_id',targetKey:'role_id',as:'role'});
  61. }
  62. //同步:没有就新建,有就不变
  63. Model.sync();
  64. return Model;
  65. };