Browse Source

pasture: 账号下发

Yi 1 year ago
parent
commit
fb48b82a91
3 changed files with 54 additions and 5 deletions
  1. 7 5
      models/group_data.go
  2. 35 0
      models/pasture.go
  3. 12 0
      module/group.go

+ 7 - 5
models/group_data.go

@@ -117,11 +117,13 @@ type SprinkleStatisticsDataList struct {
 }
 
 type AccountDistributionRequest struct {
-	Account   string `json:"account"`
-	UserName  string `json:"user_name"`
-	Password  string `json:"password"`
-	Phone     string `json:"phone"`
-	PastureId int32  `json:"pasture_id"`
+	Account     string `json:"account"`
+	UserName    string `json:"user_name"`
+	Password    string `json:"password"`
+	Phone       string `json:"phone"`
+	PastureId   int32  `json:"pasture_id"`
+	PastureName string `json:"pasture_name"`
+	Address     string `json:"address"`
 }
 
 type CategoryRequest struct {

+ 35 - 0
models/pasture.go

@@ -0,0 +1,35 @@
+package models
+
+type Pasture struct {
+	PastureId   int64  `xorm:"pastureid"`
+	PastureCode string `xorm:"pasture_Code"`
+	PastureName string `xorm:"pasture_Name"`
+	GroupsId    int64  `xorm:"groupsid"`
+	User        string `xorm:"user"`
+	Note        string `xorm:"note"`
+	Enable      int32  `xorm:"enable"`
+	Emp         string `xorm:"emp"`
+	Address     string `xorm:"address"`
+	Phone       string `xorm:"phone"`
+	IsGroups    int32  `xorm:"isgroups"`
+}
+
+func (p *Pasture) TableName() string {
+	return "pasture"
+}
+
+func NewPasture(pastureId int64, pastureName, address, managerUser, phone string) *Pasture {
+	return &Pasture{
+		PastureId:   pastureId,
+		PastureCode: "",
+		PastureName: pastureName,
+		GroupsId:    0,
+		User:        managerUser,
+		Note:        "",
+		Enable:      1,
+		Emp:         managerUser,
+		Address:     address,
+		Phone:       phone,
+		IsGroups:    0,
+	}
+}

+ 12 - 0
module/group.go

@@ -174,6 +174,18 @@ func AccountDistribution(req *models.AccountDistributionRequest) error {
 		return err
 	}
 
+	pastureData := &models.Pasture{}
+	if err = session.Table(new(models.Pasture).TableName()).Where("pastureid = ?", req.PastureId).Find(pastureData); err != nil {
+		return err
+	}
+
+	if pastureData.PastureId <= 0 {
+		newPasture := models.NewPasture(int64(req.PastureId), req.PastureName, req.Address, req.UserName, req.Phone)
+		if _, err = session.Table(new(models.Pasture).TableName()).Insert(newPasture); err != nil {
+			return err
+		}
+	}
+
 	// 创建新的超级管理员角色
 	newRole := models.NewDefaultRole(int64(req.PastureId))
 	if _, err = session.Table(new(models.Role).TableName()).Insert(newRole); err != nil {