authorization_service.go 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package wechat_service
  2. import (
  3. "SCRM/models"
  4. "SCRM/service"
  5. "github.com/jinzhu/gorm"
  6. )
  7. //GetAuthorizationByOnlyAppID 通过appid取信息
  8. func GetAuthorizationByOnlyAppID(appid string) (*models.PatientAuthorizations, error) {
  9. var authorizationinfo models.PatientAuthorizations
  10. var err error
  11. err = service.PatientReadDB().Model(&models.PatientAuthorizations{}).Where("authorizer_appid=? and authorizer_status=1", appid).First(&authorizationinfo).Error
  12. if err == gorm.ErrRecordNotFound {
  13. return nil, nil
  14. }
  15. if err != nil {
  16. return nil, err
  17. }
  18. return &authorizationinfo, nil
  19. }
  20. //GetAuthorizationByAppID 通过appid取信息
  21. func GetAuthorizationByAppID(orgID int64, appid string) (*models.PatientAuthorizations, error) {
  22. var authorizationinfo models.PatientAuthorizations
  23. var err error
  24. err = service.PatientReadDB().Model(&models.PatientAuthorizations{}).Where(" user_org_id=? and authorizer_appid=? and authorizer_status=1", orgID, appid).First(&authorizationinfo).Error
  25. if err == gorm.ErrRecordNotFound {
  26. return nil, nil
  27. }
  28. if err != nil {
  29. return nil, err
  30. }
  31. return &authorizationinfo, nil
  32. }
  33. //GetAuthorizationByOrgID 通过orgid取信息
  34. func GetAuthorizationByOrgID(orgID int64) (*models.PatientAuthorizations, error) {
  35. var authorizationinfo models.PatientAuthorizations
  36. var err error
  37. err = service.PatientReadDB().Model(&models.PatientAuthorizations{}).Where("user_org_id=?", orgID).First(&authorizationinfo).Error
  38. if err == gorm.ErrRecordNotFound {
  39. return nil, nil
  40. }
  41. if err != nil {
  42. return nil, err
  43. }
  44. return &authorizationinfo, nil
  45. }
  46. func SaveWechatComponentVerifyTicket(id int64, componentVerifyTicket string) (err error) {
  47. err = service.PatientWriteDB().Model(&models.WechatComponents{}).Where("id=?", id).Update(map[string]interface{}{"ComponentVerifyTicket": componentVerifyTicket}).Error
  48. return
  49. }
  50. func SaveWechatComponentInfoByMap(id int64, info map[string]interface{}) (err error) {
  51. err = service.PatientWriteDB().Model(&models.WechatComponents{}).Where("id=?", id).Update(info).Error
  52. return
  53. }
  54. func SaveAuthorizerStatusByAppID(appID string, status int64) (err error) {
  55. err = service.PatientWriteDB().Model(&models.PatientAuthorizations{}).Where("authorizer_appid=?", appID).Update(map[string]interface{}{"AuthorizerStatus": status}).Error
  56. return
  57. }
  58. func SaveAuthorizationInfo(authorization *models.PatientAuthorizations) (err error) {
  59. err = service.PatientWriteDB().Model(&models.PatientAuthorizations{}).Save(&authorization).Error
  60. return
  61. }
  62. func GetAuthorizations() (mps []*models.PatientAuthorizations, err error) {
  63. err = service.PatientReadDB().Where("authorizer_status = 1").Find(&mps).Error
  64. return
  65. }