scrm-go

menu_service.go 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package wechat_service
  2. import (
  3. "SCRM/models"
  4. "SCRM/service"
  5. "time"
  6. "github.com/jinzhu/gorm"
  7. )
  8. //GetMenusByOrgID 通过user_org_id(机构ID)取信息
  9. func GetMenusByOrgID(orgID int64) (*models.AuthorizationButtons, error) {
  10. var button models.AuthorizationButtons
  11. err := service.PatientReadDB().Where("user_org_id=?", orgID).Order("id desc").First(&button).Error
  12. if err == gorm.ErrRecordNotFound {
  13. return nil, nil
  14. }
  15. if err != nil {
  16. return nil, err
  17. }
  18. return &button, nil
  19. }
  20. func GetOrgMenusWithMsgs(orgID int64) (*Buttons, error) {
  21. var button Buttons
  22. 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
  23. if err == gorm.ErrRecordNotFound {
  24. return nil, nil
  25. }
  26. if err != nil {
  27. return nil, err
  28. }
  29. return &button, nil
  30. }
  31. type Buttons struct {
  32. ID int64 `gorm:"column:id" json:"id"`
  33. UserOrgID int64 `gorm:"column:user_org_id" json:"user_org_id"`
  34. ButtonFileds string `gorm:"column:button_fileds" json:"button_fileds"`
  35. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  36. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  37. ButtonStatus int64 `gorm:"column:button_status" json:"button_status"`
  38. SendStatus int64 `gorm:"column:send_status" json:"send_status"`
  39. Messages []*models.AuthorizationMessageManagements `gorm:"ForeignKey:user_org_id;association_foreignkey:user_org_id" json:"messages"`
  40. }
  41. func (Buttons) TableName() string {
  42. return "sgj_patient_authorization_buttons"
  43. }
  44. func SaveButtons(menu *Buttons) (err error) {
  45. tx := service.PatientWriteDB().Begin()
  46. 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
  47. if err != nil {
  48. tx.Rollback()
  49. return
  50. }
  51. err = tx.Save(menu).Error
  52. tx.Commit()
  53. return
  54. }
  55. func DeleteButton(orgID, id int64) (err error) {
  56. 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
  57. return
  58. }