scrm-go

material_service.go 915B

123456789101112131415161718192021222324252627
  1. package wechat_service
  2. import (
  3. "SCRM/models"
  4. "SCRM/service"
  5. )
  6. func SaveMaterial(m *models.WechatMedias) (err error) {
  7. err = service.PatientWriteDB().Save(m).Error
  8. return err
  9. }
  10. func FindMeterialsByMediaIDs(orgID int64, mediaType string, mediaIDs []string) (medias []models.WechatMedias, err error) {
  11. err = service.PatientReadDB().Model(&models.WechatMedias{}).Where("media_id IN (?) and user_org_id=? AND msgtype=? and media_status=1", mediaIDs, orgID, mediaType).Limit(len(mediaIDs)).Find(&medias).Error
  12. return
  13. }
  14. func GetPageMaterials(orgID, page, limit int64, mediaType string) (medias []*models.WechatMedias, total int64, err error) {
  15. db := service.PatientReadDB().Model(&models.WechatMedias{}).Where("user_org_id=? and msgtype=? and media_status=1", orgID, mediaType)
  16. offset := (page - 1) * limit
  17. err = db.Count(&total).Order("id desc").Offset(offset).Limit(limit).Find(&medias).Error
  18. return
  19. }