area.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const { DataTypes } = require('sequelize');
  2. const connect = require('./connect');
  3. /*
  4. type: DataTypes.STRING,
  5. allowNull: false,
  6. defaultValue:'',
  7. comment: '名',
  8. */
  9. const model = connect.define(
  10. __filename.slice(__dirname.length + 1).replace('.js', ''),
  11. {
  12. id: {
  13. type: DataTypes.INTEGER,
  14. autoIncrement: true,
  15. primaryKey: true,
  16. comment: 'id',
  17. },
  18. name: {
  19. type: DataTypes.STRING,
  20. allowNull: false,
  21. comment: '地区名',
  22. },
  23. cityId: {
  24. type: DataTypes.INTEGER,
  25. allowNull: false,
  26. defaultValue: 0,
  27. comment: '市id ',
  28. },
  29. provinceId: {
  30. type: DataTypes.INTEGER,
  31. allowNull: false,
  32. defaultValue: 0,
  33. comment: '省id ',
  34. },
  35. type: {
  36. type: DataTypes.INTEGER,
  37. allowNull: false,
  38. comment: '1省2市3地区',
  39. },
  40. pinyin: {
  41. type: DataTypes.STRING,
  42. defaultValue: '',
  43. comment: '首字母',
  44. },
  45. },
  46. {
  47. comment: '地区',
  48. hooks: {
  49. beforeFind(option) {
  50. if (!option.order) {
  51. option.order = [['id', 'ASC']];
  52. }
  53. },
  54. },
  55. },
  56. {
  57. indexes: [
  58. {
  59. fields: ['type', 'province_id'],
  60. },
  61. {
  62. fields: ['type', 'city_id'],
  63. },
  64. ],
  65. }
  66. );
  67. module.exports = model;