示例#1
0
// @router /api/manage/weixin/message/getMessageList [post]
func (this *MessageController) GetMessageList() {
	this.CheckAvaliable("消息查看")
	lastID, _ := this.GetInt("lastID")
	size, _ := this.GetInt("size")
	if size == 0 {
		size = 25
	}
	cond := orm.NewCondition()

	if lastID > 0 {
		cond = cond.And("Id__lt", lastID)
	}

	var messageList []models.Message
	if _, err := models.Orm.QueryTable("message").SetCond(cond).OrderBy("-Id").Limit(size).All(&messageList); err == nil {
		var messageExList []models.MessageEx = make([]models.MessageEx, len(messageList))
		for i, v := range messageList {
			var user models.FollowUser
			user.UserId = v.UserId
			models.Orm.Read(&user, "UserId")
			messageExList[i] = models.MessageEx{Message: v, User: user}
			messageExList[i].CreateOnFmt = v.CreateOn.Format("2006-01-02 15:04:05")
		}
		this.Data["json"] = &messageExList
	} else {
		beego.Error(err.Error())
	}

	this.ServeJson()
}
示例#2
0
func handleEventMsg(w http.ResponseWriter, msg []byte) {
	var message EventMessage
	if err := xml.Unmarshal(msg, &message); err != nil {
		log.Println(err.Error())
		return
	}

	user := models.FollowUser{
		UserId:      message.FromUserName,
		UserName:    "",
		NickName:    "",
		Description: "",
	}

	var ret []byte
	//订阅
	if message.Event == "subscribe" {
		var feedback TextMessage
		var option models.Option
		option.Key = "follow_feedback_text"
		if err := models.Orm.Read(&option, "Key"); err == nil {
			feedback.Content = option.Value
		} else {
			feedback.Content = "欢迎关注贝贝科技生活馆,您有什么想和小贝说的呢?"
		}
		feedback.FromUserName = message.ToUserName
		feedback.ToUserName = message.FromUserName
		feedback.MsgType = MSG_TYPE_TEXT
		ret, _ = xml.Marshal(feedback)

		user.FollowOn = time.Now()

		if created, _, err := models.Orm.ReadOrCreate(&user, "UserId"); err == nil {
			if !created {
				user.FollowOn = time.Now()
				models.Orm.Update(&user)
			} else {
			}
		} else {
			log.Println(err.Error())
		}

	} else if message.Event == "unsubscribe" { //退订
		user.UnFollowOn = time.Now()
		if created, _, err := models.Orm.ReadOrCreate(&user, "UserId"); err == nil {
			if !created {
				user.UnFollowOn = time.Now()
				models.Orm.Update(&user)
			} else {
			}
		} else {
			log.Println(err.Error())
		}
	}
	w.Write(ret)
}
// @router /weixin/user [get]
func (this *WeixinPageController) UserInfo() {
	this.TplNames = "weixin/userInfo.tpl"
	if userID := this.GetString("userID"); userID != "" {
		var user models.FollowUser
		user.UserId = userID
		if err := models.Orm.Read(&user, "UserId"); err != nil {
			log.Println(err.Error())
		} else {
			this.Data["User"] = &user
		}
	}
}
示例#4
0
func handleTextMsg(w http.ResponseWriter, msg []byte) {
	var message TextMessage
	if err := xml.Unmarshal(msg, &message); err != nil {
		log.Println(err.Error())
		return
	}

	user := models.FollowUser{
		UserId:      message.FromUserName,
		UserName:    "",
		NickName:    "",
		Description: "",
	}

	//将msg存入数据库
	var db_msg models.Message
	db_msg.UserId = message.FromUserName
	db_msg.Content = message.Content
	db_msg.MsgType = message.MsgType
	db_msg.MsgId = message.MsgId

	if _, err := models.Orm.Insert(&db_msg); err != nil {
		log.Println(err.Error())
	}

	user.LastMessageOn = time.Now()

	if created, _, err := models.Orm.ReadOrCreate(&user, "UserId"); err == nil {
		if !created {
			user.LastMessageOn = time.Now()
			models.Orm.Update(&user)
		} else {
		}
	} else {
		log.Println(err.Error())
	}

	//

	switch {
	default:
		makeDefaultContent(&message)
	}

	message.FromUserName, message.ToUserName = message.ToUserName, message.FromUserName
	ret, _ := xml.Marshal(message)
	w.Write(ret)
}
示例#5
0
// @router /api/manage/weixin/fix/getOrderBindedUser [post]
func (this *FixOrderController) GetOrderBindedUser() {
	this.CheckAvaliable("订单管理")
	var followUser models.FollowUser
	if orderNumber := this.GetString("orderNumber"); orderNumber != "" {
		var pair models.FixOrderPair
		pair.OrderNumber = orderNumber
		if err := models.Orm.Read(&pair, "OrderNumber"); err != nil {
			log.Println(err.Error())
		} else {
			followUser.UserId = pair.UserId
			if err := models.Orm.Read(&followUser, "UserId"); err != nil {
				log.Println(err.Error())
			} else {
				models.Orm.Delete(&pair)
			}
		}
	}
	this.Data["json"] = &followUser

	this.ServeJson()
}