users.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* indent size: 2 */
  2. // eslint-disable-next-line strict
  3. module.exports = app => {
  4. const DataTypes = app.Sequelize;
  5. const Model = app.model.define('Users', {
  6. user_id: {
  7. type: DataTypes.INTEGER(10).UNSIGNED,
  8. allowNull: false,
  9. primaryKey: true,
  10. autoIncrement: true,
  11. },
  12. nickname: {
  13. type: DataTypes.STRING(255),
  14. allowNull: true,
  15. },
  16. account_name: {
  17. type: DataTypes.STRING(255),
  18. allowNull: true,
  19. },
  20. openid: {
  21. type: DataTypes.STRING(255),
  22. allowNull: true,
  23. },
  24. /* new_openid: {
  25. type: DataTypes.STRING(128),
  26. allowNull: true,
  27. },
  28. ori_openid: {
  29. type: DataTypes.STRING(128),
  30. allowNull: true,
  31. },*/
  32. unionid: {
  33. type: DataTypes.STRING(255),
  34. allowNull: true,
  35. },
  36. password: {
  37. type: DataTypes.STRING(255),
  38. allowNull: true,
  39. },
  40. money: {
  41. type: DataTypes.FLOAT,
  42. allowNull: true,
  43. },
  44. commission: {
  45. type: DataTypes.FLOAT,
  46. allowNull: true,
  47. },
  48. intergral: {
  49. type: DataTypes.INTEGER(10).UNSIGNED,
  50. allowNull: true,
  51. },
  52. headimgurl: {
  53. type: DataTypes.STRING(255),
  54. allowNull: true,
  55. },
  56. login_time: {
  57. type: DataTypes.DATE,
  58. allowNull: true,
  59. },
  60. city: {
  61. type: DataTypes.STRING(255),
  62. allowNull: true,
  63. },
  64. province: {
  65. type: DataTypes.STRING(255),
  66. allowNull: true,
  67. },
  68. country: {
  69. type: DataTypes.STRING(255),
  70. allowNull: true,
  71. },
  72. sex: {
  73. type: DataTypes.CHAR(1),
  74. allowNull: true,
  75. },
  76. subscribe: {
  77. type: DataTypes.INTEGER(1).UNSIGNED,
  78. allowNull: true,
  79. },
  80. update_ttime: {
  81. type: DataTypes.TIME,
  82. },
  83. create_time: {
  84. type: DataTypes.DATE,
  85. allowNull: true,
  86. },
  87. is_proxy: {
  88. type: DataTypes.INTEGER(1).UNSIGNED,
  89. allowNull: true,
  90. },
  91. is_employee: {
  92. type: DataTypes.INTEGER(1).UNSIGNED,
  93. allowNull: true,
  94. },
  95. is_office: {
  96. type: DataTypes.INTEGER(1).UNSIGNED,
  97. allowNull: true,
  98. },
  99. is_family: {
  100. type: DataTypes.INTEGER(1).UNSIGNED,
  101. allowNull: true,
  102. },
  103. partner_id: {
  104. type: DataTypes.INTEGER(11),
  105. allowNull: true,
  106. },
  107. }, {
  108. tableName: 'szj_users',
  109. });
  110. Model.associate = function() {
  111. // 关联地址表
  112. Model.hasMany(app.model.Address, { foreignKey: 'user_id', targetKey: 'user_id', as: 'address' });
  113. // 关联购物车表
  114. Model.hasMany(app.model.Carts, { foreignKey: 'user_id', targetKey: 'user_id', as: 'carts' });
  115. // 关联收藏表
  116. Model.hasMany(app.model.Collects, { foreignKey: 'user_id', targetKey: 'user_id', as: 'collects' });
  117. // 关联代理认证申请
  118. Model.hasOne(app.model.ProxyApplyLogs, { foreignKey: 'user_id', targetKey: 'user_id', as: 'proxyApplyLogs' });
  119. // Model.hasOne(app.model.RelUserInviter, { foreignKey: 'user_id', targetKey: 'user_id', as: 'relUser' });
  120. };
  121. // 同步:没有就新建,有就不变
  122. Model.sync();
  123. return Model;
  124. };