Esempio n. 1
0
func (c *ContentController) Post() {
	openid := getContentCookie(c)
	op := c.Input().Get("op")
	beego.Debug("post op :---------------", op)
	switch op {
	case "help":
		id_s := c.Input().Get("id")
		if len(openid) != 0 && len(id_s) != 0 {
			post, err := models.GetOnePost(id_s)
			if err != nil {
				beego.Error(err)
			}
			_, err = models.AddPosthelp(post.Id, openid, 1)
			if err != nil {
				beego.Error(err)
			} else {
				if post.Label == 1 {
					err = models.AddWxUserMoney(post.OpenId, 1)
					if err != nil {
						beego.Error(err)
					} else {
						_, err = models.AddUserMoneyRecord(post.OpenId, MONEY_BELIKE_SUM, MONEY_BELIKE)
					}
				}
				url := "/content?op=con&id=" + id_s
				c.Redirect(url, 302)
				return
			}
		}
		c.TplName = "content.html"
		break
	}
	c.TplName = "content.html"
}
func (c *AdminImportUserController) Get() {
	op := c.Input().Get("op")
	if op == "import" {
		beego.Debug("AdminImportUserController get import")
		openid := c.Input().Get("openid")
		errcode, token := getToken()
		if errcode == 0 && len(openid) != 0 {
			user, err := getWxUser(openid, token)
			if err == nil {
				if user.ErrCode == 0 {
					err = models.AddWxUserInfo(user)
					if err != nil {
						beego.Error(err)
					} else {
						err = models.AddWxUserMoney(user.OpenId, 4)
						if err != nil {
							beego.Error(err)
						} else {
							_, err = models.AddUserMoneyRecord(user.OpenId, MONEY_SUBSCRIBE_SUM, MONEY_SUBSCRIBE)
						}
					}

				}
			}
		}
		url := "/admin/importuser"
		c.Redirect(url, 302)
		return
	}
	wxusers, err := models.GetAllWxUsers()
	if err != nil {
		beego.Error("err :", err)
	}
	// var wxusermap map[string]int64
	wxusermap := make(map[string]int64)
	for i := 0; i < len(wxusers); i++ {
		wxusermap[wxusers[i].OpenId] = wxusers[i].Id
	}

	errcode, token := getToken()
	beego.Debug("errcode :", errcode, "token :", token)
	if errcode == 0 {
		openids := getWxUserList(token, c)
		importUsers := make([]*ImportUser, len(openids))
		for i := 0; i < len(openids); i++ {
			importUser := &ImportUser{OpenId: openids[i]}
			if _, ok := wxusermap[openids[i]]; ok {
				//存在
				importUser.IsImport = true
			}
			// beego.Debug(" openids ", i, importUser)
			importUsers[i] = importUser
		}
		c.Data["ImportUsers"] = importUsers
	}
	c.TplName = "adminimportuser.html"
}
func (c *AdminUpUserMoneyController) Post() {
	id := c.Input().Get("id")
	op := c.Input().Get("op")
	beego.Debug("op :", op)
	switch op {
	case "up":
		beego.Debug("op  ok")
		if len(id) != 0 {
			user, err := models.GetOneWxUserInfoId(id)
			if err != nil {
				beego.Error(err)
			} else {
				moneytype := c.Input().Get("moneytype")
				if len(moneytype) != 0 {
					addmoney := int64(0)
					if moneytype == "1" {
						addmoney = MONEY_SUBSCRIBE_SUM
					} else if moneytype == "2" {
						addmoney = MONEY_EXAMINE_SUM
					} else if moneytype == "3" {
						addmoney = MONEY_BELIKE_SUM
					}
					err = models.AddWxUserMoney(user.OpenId, addmoney)
					moneytype_i, err := strconv.ParseInt(moneytype, 10, 64)
					if err != nil {
						beego.Debug("err :", err)
					}
					_, err = models.AddUserMoneyRecord(user.OpenId, addmoney, moneytype_i)
					if err != nil {
						beego.Error(err)
					}
				}
			}
		}
		c.Redirect("/admin/wxuserlist", 302)
		return
	}
	c.TplName = "adminupusermoney.html"
}
Esempio n. 4
0
func (c *AdminExchangeController) Get() {
	bool, username := chackAccount(c.Ctx)
	if bool {
		c.Data["isUser"] = bool
		c.Data["User"] = username
	} else {
		c.Redirect("/admin", 302)
		return
	}
	op := c.Input().Get("op")
	switch op {
	case "state":
		id := c.Input().Get("id")
		if len(id) == 0 {
			break
		}
		err := models.UpdateUorderState(id, 1)
		if err != nil {
			beego.Debug(err)
		} else {
			uoder, err := models.GetOneUorder(id)

			if err != nil {
				beego.Error(err)
			} else {
				com, err := models.GetOneCommodity1(uoder.CommodityId)
				if err != nil {
					beego.Error(err)
				} else {
					err = models.ConsumeWxUserMoney(uoder.OpenId, com.Money)
					if err != nil {
						beego.Error(err)
					} else {
						models.AddUserMoneyRecord(uoder.OpenId, com.Money, MONEY_EXCHANGE)
						if err != nil {
							beego.Error(err)
						} else {
						}
					}
				}
			}
		}
		c.Redirect("/admin/exchange", 302)
		return
	case "state1":
		id := c.Input().Get("id")
		if len(id) == 0 {
			break
		}
		err := models.UpdateUorderState(id, 0)
		if err != nil {
			beego.Debug(err)
		} else {

		}
		c.Redirect("/admin/exchange", 302)
		return
	}

	uorders, err := models.GetAllUorders()
	if err != nil {
		beego.Error(err)
	}
	var showOrders []models.ShowOrder
	for i := 0; i < len(uorders); i++ {
		com, err := models.GetOneCommodity1(uorders[i].CommodityId)
		if err != nil {
			beego.Error(err)
		} else {
			obj := models.ShowOrder{Id: uorders[i].Id, OpenId: uorders[i].OpenId, CommodityId: uorders[i].CommodityId,
				State: uorders[i].State, CreateTime: uorders[i].CreateTime, Time: uorders[i].Time,
				ExchangeTime: uorders[i].ExchangeTime, Time1: uorders[i].Time1, Commodity: com}
			user, err := models.GetOneWxUserInfo(uorders[i].OpenId)
			if err != nil {
				beego.Debug(err)
			} else {
				obj.NickeName = user.NickeName
				obj.HeadImgurl = user.HeadImgurl
			}
			showOrders = append(showOrders, obj)
		}

	}
	// beego.Debug("ShowOrders :", showOrders)
	c.Data["ShowOrders"] = showOrders
	c.TplName = "adminexchange.html"
}