123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package wechat_service
-
- import (
- "SCRM/models"
- "SCRM/service"
- "time"
-
- "github.com/jinzhu/gorm"
- )
-
- //GetTextReplyMessagesByKey 通过关键词搜索 user_org_id(机构ID)取信息
- func GetTextReplyMessagesByKey(userOrgID int64, keywrods string) (messages []*models.AuthorizationMessageManagements, err error) {
- if len(keywrods) == 0 {
- return
- }
-
- likekey := "%" + keywrods + "%"
- err = service.PatientReadDB().Where("user_org_id=? AND message_msg_type='text' AND message_status=1 AND ((message_key_name LIKE ? AND message_key_type=1) OR (message_key_name = ? AND message_key_type=2))", userOrgID, likekey, keywrods).Order("id desc").Find(&messages).Error
- return
- }
-
- //GetOrgSubscribeReplyMessages 通过user_org_id(机构ID)取信息
- func GetOrgSubscribeReplyMessages(orgID int64) (*models.AuthorizationMessageManagements, error) {
-
- var message models.AuthorizationMessageManagements
-
- err := service.PatientReadDB().Where("user_org_id=? AND message_msg_type='event' AND message_msg_event='subscribe' AND message_status=1", orgID).First(&message).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
- if err != nil {
- return nil, err
- }
- return &message, nil
-
- }
-
- //GetClickButtonReplyMessagesByOrgID 通过user_org_id(机构ID)取信息
- func GetClickButtonReplyMessagesByOrgID(orgID int64, key string) (*models.AuthorizationMessageManagements, error) {
- var message models.AuthorizationMessageManagements
- err := service.PatientReadDB().Where("user_org_id=? AND message_msg_type='event' AND message_msg_event='click' AND message_key_name=? AND message_status=1", orgID, key).First(&message).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
- if err != nil {
- return nil, err
- }
- return &message, nil
- }
-
- func GetOrgAllClickMessages(orgID int64) (messages []*models.AuthorizationMessageManagements, err error) {
- err = service.PatientReadDB().Where("user_org_id=? AND message_msg_type='event' AND message_msg_event='click'", orgID).Find(&messages).Error
- return
- }
-
- func SaveMessage(m *models.AuthorizationMessageManagements) (err error) {
- err = service.PatientWriteDB().Save(m).Error
- return
- }
-
- func GetPageKeyWordMessages(orgID, page, limit int64, search string) (messages []*models.AuthorizationMessageManagements, total int64, err error) {
- db := service.PatientReadDB().Model(&models.AuthorizationMessageManagements{}).Where("user_org_id=? and message_msg_type='text' and message_status=1", orgID)
-
- if len(search) > 0 {
- searchKey := "%" + search + "%"
- db = db.Where("message_key_name LIKE ?", searchKey)
- }
- offset := (page - 1) * limit
-
- err = db.Count(&total).Order("id desc").Offset(offset).Limit(limit).Find(&messages).Error
-
- return
- }
-
- //GetMessageByID 通过ID取信息
- func GetMessageByID(orgID, id int64) (*models.AuthorizationMessageManagements, error) {
- var message models.AuthorizationMessageManagements
- err := service.PatientReadDB().Where("id=? and user_org_id=? and message_status=1", id, orgID).First(&message).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
- if err != nil {
- return nil, err
- }
- return &message, nil
- }
-
- func DeleteMessages(orgID int64, ids []int64) (err error) {
- if len(ids) == 1 {
- err = service.PatientWriteDB().Model(&models.AuthorizationMessageManagements{}).Where("id =? and user_org_id =?", ids[0], orgID).Update(map[string]interface{}{"MessageStatus": 2, "UpdatedTime": time.Now().Unix()}).Error
- } else {
- err = service.PatientWriteDB().Model(&models.AuthorizationMessageManagements{}).Where("id IN (?) and user_org_id =?", ids, orgID).Update(map[string]interface{}{"MessageStatus": 2, "UpdatedTime": time.Now().Unix()}).Error
- }
- return
- }
|