12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package common
- import (
- "app.yhyue.com/moapp/MessageCenter/entity"
- "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
- "app.yhyue.com/moapp/MessageCenter/util"
- "fmt"
- "log"
- "strconv"
- "strings"
- )
- func FindUserBuoyMsg(this *message.FindUserBuoyMsgReq) *message.FindUserBuoyMsgRes {
- var err error
- data := message.FindUserBuoyMsgRes{}
- res := entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT * FROM message WHERE receive_userid = "%s" and isdel = 1 and appid = %s and isRead =0 and show_buoy = 1 and show_content != "" ORDER BY createtime DESC LIMIT 0,%d`, this.UserId, this.Appid, int(this.PageSize)))
- //log.Println("数据:", res)
- if res != nil && len(*res) > 0 {
- for _, v := range *res {
- _id := util.Int64All(v["id"])
- id := strconv.FormatInt(_id, 10)
- links2 := util.ObjToString((v["link"]))
- link2, androidUrl2, iosUrl2, weChatUrl2 := LinkSplit(links2)
- data.Data = append(data.Data, &message.BuoyMessages{
- Id: id,
- BuoyDetail: util.ObjToString(v["show_content"]),
- PcUrl: link2,
- AndroidUrl: androidUrl2,
- IosUrl: iosUrl2,
- WeChatUrl: weChatUrl2,
- })
- }
- }
- if err == nil {
- data.Code = 0
- data.Message = "查询成功"
- } else {
- data.Code = 1
- data.Message = "查询失败"
- }
- return &data
- }
- func LinkSplit(url string) (link, androidUrl, iosUrl, weChatUrl string) {
- if url != "" {
- arr := strings.Split(url, ",")
- if len(arr) == 4 {
- link = arr[0]
- androidUrl = arr[1]
- iosUrl = arr[2]
- weChatUrl = arr[3]
- } else {
- if len(arr) > 0 {
- link = arr[0]
- } else {
- link = ""
- }
- androidUrl = ""
- iosUrl = ""
- weChatUrl = ""
- }
- }
- return link, androidUrl, iosUrl, weChatUrl
- }
- func ClearUnreadMsg(in *message.ClearUnreadMsgReq) error {
- if in.Userid != "" {
- query := map[string]interface{}{
- "receive_userid": in.Userid,
- "appid": in.AppId,
- "isdel": 1,
- "isRead": 0,
- }
- //更新服务未读数
- if !entity.Mysql.Update("message", query, map[string]interface{}{"isRead": 1}) {
- log.Println("更新服务未读数失败")
- }
- }
- //更新私信未读数
- if in.PositionId > 0 {
- sQuery := map[string]interface{}{
- "my_position_id": in.PositionId,
- "ent_id": in.EntId,
- }
- if !entity.Mysql.Update("socialize_summary", sQuery, map[string]interface{}{"unread": 0}) {
- log.Println("更新私信未读数失败")
- }
- }
- return nil
- }
|