Esempio n. 1
0
// @router /weixin/bindOrderNumber [get,post]
func (this *WeixinPageController) BindOrderNumber() {
	var userID string
	if this.GetString("userID") != "" {
		userID = this.GetString("userID")
		this.Data["userID"] = this.GetString("userID")
	}

	method := strings.ToLower(this.Ctx.Request.Method)
	switch method {
	case "get":
		this.TplNames = "weixin/bindOrderNumber.tpl"
	case "post":
		this.TplNames = "weixin/bindOrderNumberResult.tpl"
		if order_suffix := this.GetString("order_suffix"); len(order_suffix) == 4 {
			// cache.GlobalCache.Put(order_suffix, "20141114134433", 60)
			cacheKey := "ON:" + order_suffix
			if cache.GlobalCache.IsExist(cacheKey) {
				order_prefix := cache.GlobalCache.Get(cacheKey)
				cache.GlobalCache.Delete(cacheKey)

				var orderPair models.FixOrderPair
				orderPair.UserId = userID
				if err := models.Orm.Read(&orderPair, "UserId"); err != nil {
					orderPair.OrderNumber = order_prefix.(string) + "-" + order_suffix
					if _, err := models.Orm.Insert(&orderPair); err != nil {
						log.Println(err.Error())
						return
					}
				} else {
					orderPair.OrderNumber = order_prefix.(string) + "-" + order_suffix
					if _, err := models.Orm.Update(&orderPair, "OrderNumber"); err != nil {
						log.Println(err.Error())
						return
					}
				}
				this.Data["success"] = "success"
				this.Data["orderNumber"] = orderPair.OrderNumber
				this.Data["orderShortNumber"] = order_prefix.(string)[6:10] + order_suffix
				return
			}
		}
	}
}
Esempio n. 2
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()
}