|
@@ -1,6 +1,10 @@
|
|
|
package models
|
|
|
|
|
|
-import "time"
|
|
|
+import (
|
|
|
+ "eta_gn/eta_api/global"
|
|
|
+ "eta_gn/eta_api/utils"
|
|
|
+ "time"
|
|
|
+)
|
|
|
|
|
|
type ClassifyVisible struct {
|
|
|
ClassifyVisibleId int `gorm:"column:classify_visible_id;primary_key"`
|
|
@@ -8,3 +12,36 @@ type ClassifyVisible struct {
|
|
|
AdminId int `gorm:"column:admin_id"`
|
|
|
CreateTime time.Time `gorm:"column:create_time"`
|
|
|
}
|
|
|
+
|
|
|
+func (ClassifyVisible) TableName() string {
|
|
|
+ return "classify_visible"
|
|
|
+}
|
|
|
+
|
|
|
+func UpdateClassifyVisible(parentId, classifyId int, adminIds []int) (err error) {
|
|
|
+ tx := global.DmSQL["rddp"].Begin()
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tx.Commit()
|
|
|
+ }()
|
|
|
+ err = tx.Table(ClassifyVisible{}.TableName()).Where("classify_id =?", parentId).Delete(&ClassifyVisible{}).Error
|
|
|
+ insertList := make([]ClassifyVisible, 0, len(adminIds))
|
|
|
+ for _, adminId := range adminIds {
|
|
|
+ classifyVisible := ClassifyVisible{
|
|
|
+ ClassifyId: classifyId,
|
|
|
+ AdminId: adminId,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ }
|
|
|
+ insertList = append(insertList, classifyVisible)
|
|
|
+ }
|
|
|
+ err = tx.CreateInBatches(insertList, utils.MultiAddNum).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetClassifyVisibleUserIdByClassifyId(classifyId int) (classifyVisibles []int, err error) {
|
|
|
+ db := global.DmSQL["rddp"]
|
|
|
+ err = db.Table(ClassifyVisible{}.TableName()).Where("classify_id =?", classifyId).Pluck("admin_id", &classifyVisibles).Error
|
|
|
+ return
|
|
|
+}
|