|
@@ -28,12 +28,20 @@ type Tenant struct {
|
|
|
PassKey string `gorm:"type:varchar(10)" json:"passKey"` //租户登录Key
|
|
|
LoginDisplayName string `gorm:"type:varchar(60)" json:"loginDisplayName"` //登录页面显示名称
|
|
|
ContactEmail string `gorm:"type:varchar(255)" json:"contactEmail"` //联系邮箱
|
|
|
+ CityCode string `gorm:"type:varchar(6)" json:"cityCode"` //城市行政编码
|
|
|
+ CityName string `gorm:"type:varchar(255)" json:"cityName"` //城市名称
|
|
|
+ CityLng float64 `gorm:"type:double(18, 14)" json:"cityLng"` //经度
|
|
|
+ CityLat float64 `gorm:"type:double(18, 14)" json:"cityLat"` //经度
|
|
|
}
|
|
|
|
|
|
func (Tenant) TableName() string {
|
|
|
return "tenant"
|
|
|
}
|
|
|
|
|
|
+func (c *Tenant) Get() error {
|
|
|
+ return Db.Model(&c).Where("id = ?", c.ID).Find(&c).Error
|
|
|
+}
|
|
|
+
|
|
|
func (c *Tenant) GetTenant() error {
|
|
|
return Db.Model(&c).Where("tenant_id = ?", c.TenantId).Find(&c).Error
|
|
|
}
|
|
@@ -42,20 +50,43 @@ func (c *Tenant) GetTenantByPasskey() error {
|
|
|
return Db.Model(&c).Where("pass_key = ?", c.PassKey).Find(&c).Error
|
|
|
}
|
|
|
|
|
|
-// 租户位置信息
|
|
|
-type TenantCode struct {
|
|
|
- ID int64 `gorm:"primary_key" json:"id"` //编号
|
|
|
- TenantId string `gorm:"type:varchar(12)" json:"tenantId"` //租户id
|
|
|
- CityCode string `gorm:"type:varchar(6)" json:"cityCode"` //城市行政编码
|
|
|
- CityName string `gorm:"type:varchar(255)" json:"cityName"` //城市名称
|
|
|
- CityLng float64 `gorm:"type:double(18, 14)" json:"cityLng"` //经度
|
|
|
- CityLat float64 `gorm:"type:double(18, 14)" json:"cityLat"` //经度
|
|
|
+func (c *Tenant) IsExist() bool {
|
|
|
+ var count int
|
|
|
+ _ = Db.Model(&c).Where("pass_key = ?", c.PassKey).Count(&c).Error
|
|
|
+ return count > 0
|
|
|
}
|
|
|
|
|
|
-func (TenantCode) TableName() string {
|
|
|
- return "tenant_code"
|
|
|
+func (c *Tenant) GetTenants(offset, limit int) ([]Tenant, error) {
|
|
|
+ var tenants []Tenant
|
|
|
+ db := Db.Model(&c)
|
|
|
+ if c.TenantId != "" {
|
|
|
+ db = db.Where("tenant_id like ?", "%"+c.TenantId+"%")
|
|
|
+ }
|
|
|
+ if c.TenantName != "" {
|
|
|
+ db = db.Where("tenant_name like ?", "%"+c.TenantName+"%")
|
|
|
+ }
|
|
|
+ if c.Linkman != "" {
|
|
|
+ db = db.Where("linkman like ?", "%"+c.Linkman+"%")
|
|
|
+ }
|
|
|
+ err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&tenants).Error
|
|
|
+ return tenants, err
|
|
|
}
|
|
|
|
|
|
-func (c *TenantCode) GetTenantCode() error {
|
|
|
- return Db.Model(&c).Where("tenant_id = ?", c.TenantId).Find(&c).Error
|
|
|
+func (c *Tenant) Save() error {
|
|
|
+ return Db.Model(&c).Save(&c).Error
|
|
|
+}
|
|
|
+
|
|
|
+func (c *Tenant) Update() error {
|
|
|
+ return Db.Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
|
|
|
+}
|
|
|
+
|
|
|
+func (c *Tenant) GetAll() ([]Tenant, error) {
|
|
|
+ var tenants []Tenant
|
|
|
+ err := Db.Model(&c).Find(&tenants).Error
|
|
|
+ return tenants, err
|
|
|
+}
|
|
|
+
|
|
|
+func (c *Tenant) Remove() error {
|
|
|
+ return Db.Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
|
|
|
+ "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
|
|
|
}
|