package wechat_service import ( "SCRM/models" "SCRM/service" "time" "github.com/jinzhu/gorm" ) //GetMenusByOrgID 通过user_org_id(机构ID)取信息 func GetMenusByOrgID(orgID int64) (*models.AuthorizationButtons, error) { var button models.AuthorizationButtons err := service.PatientReadDB().Where("user_org_id=?", orgID).Order("id desc").First(&button).Error if err == gorm.ErrRecordNotFound { return nil, nil } if err != nil { return nil, err } return &button, nil } func GetOrgMenusWithMsgs(orgID int64) (*Buttons, error) { var button Buttons err := service.PatientReadDB().Where("user_org_id=?", orgID).Order("id desc").Preload("Messages", "user_org_id=? AND message_msg_type='event' AND message_msg_event='click' AND message_status=1", orgID).First(&button).Error if err == gorm.ErrRecordNotFound { return nil, nil } if err != nil { return nil, err } return &button, nil } type Buttons struct { ID int64 `gorm:"column:id" json:"id"` UserOrgID int64 `gorm:"column:user_org_id" json:"user_org_id"` ButtonFileds string `gorm:"column:button_fileds" json:"button_fileds"` CreatedTime int64 `gorm:"column:created_time" json:"created_time"` UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"` ButtonStatus int64 `gorm:"column:button_status" json:"button_status"` SendStatus int64 `gorm:"column:send_status" json:"send_status"` Messages []*models.AuthorizationMessageManagements `gorm:"ForeignKey:user_org_id;association_foreignkey:user_org_id" json:"messages"` } func (Buttons) TableName() string { return "sgj_patient_authorization_buttons" } func SaveButtons(menu *Buttons) (err error) { tx := service.PatientWriteDB().Begin() err = tx.Model(&models.AuthorizationMessageManagements{}).Where("user_org_id=? AND message_msg_type='event' AND message_msg_event='click'", menu.UserOrgID).Update(map[string]interface{}{"MessageStatus": 2, "UpdatedTime": time.Now().Unix()}).Error if err != nil { tx.Rollback() return } err = tx.Save(menu).Error tx.Commit() return } func DeleteButton(orgID, id int64) (err error) { err = service.PatientWriteDB().Model(&models.AuthorizationButtons{}).Where("id=? and user_org_id=?", id, orgID).Update(map[string]interface{}{"ButtonStatus": 2, "UpdatedTime": time.Now().Unix()}).Error return }