You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
746 B

  1. package datas
  2. import (
  3. "gin-vue-admin/global"
  4. "github.com/gookit/color"
  5. "time"
  6. "gin-vue-admin/model"
  7. "gorm.io/gorm"
  8. )
  9. var Customers = []model.ExaCustomer{
  10. {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"},
  11. }
  12. func InitExaCustomer(db *gorm.DB) (err error) {
  13. return db.Transaction(func(tx *gorm.DB) error {
  14. if tx.Where("id IN ? ", []int{1}).Find(&[]model.ExaCustomer{}).RowsAffected == 1 {
  15. color.Danger.Println("exa_customers表的初始数据已存在!")
  16. return nil
  17. }
  18. if err := tx.Create(&Customers).Error; err != nil { // 遇到错误时回滚事务
  19. return err
  20. }
  21. return nil
  22. })
  23. }