コード例 #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
			}
		}
	}
}