Ejemplo n.º 1
0
func (this *WithdrawRouter) Post() {
	// Get Data session: addr, authen
	d := this.GetSession("Data")
	var addr, authen, amount_str string
	if d == nil {
		this.SetSession("Error", ERROR_CAPTCHA)
		this.fail()
	}
	this.DelSession("Data")

	Data := d.([]string)
	addr = Data[0]
	authen = Data[1]
	amount_str = Data[2]

	// Validate user input authen
	if this.Input().Get("authen") != authen {
		this.SetSession("Error", ERROR_CAPTCHA)
		this.fail()
		return
	}

	// Get User session
	u := this.GetSession("_User")
	if u == nil {
		this.Ctx.Redirect(302, "/login")
		return
	}
	User := u.(Session_User)

	// Get User Address and Send BTC to User
	userAddr := models.AddressByUid(User.Uid)
	if userAddr == "" {
		this.SetSession("Error", ERROR_DB)
		this.fail()
		return
	}

	amount, _ := strconv.ParseFloat(amount_str, 64)
	_, err := models.SendBTC(userAddr, addr, "提现"+amount_str+"BTC", amount-Tx_Fee)
	if err != nil {
		this.SetSession("Error", ERROR_CANTSENDBTC)
		this.fail()
		return
	}

	// Update DB
	if !models.WithdrawRequest(User.Uid, amount, addr) {
		this.SetSession("Error", ERROR_DB)
		this.fail()
		return
	}

	this.succ()
}
Ejemplo n.º 2
0
func (this *GameRouter) postData(Type string, id, uid int) {
	// Validate Bet amount
	amount_str := this.Input().Get("amount")
	if !models.ValidBetamount(amount_str) {
		this.SetSession("Error", ERROR_INVALIDINPUT)
		this.fail(id)
		return
	}

	// Validate if balance is enough
	amount, _ := strconv.ParseFloat(amount_str, 64)
	if !models.UserBalanceEnough(uid, amount) {
		this.SetSession("Error", ERROR_BALANCENOTENOUGH)
		this.fail(id)
		return
	}

	// Submit Post
	switch Type {
	case "AorB":
		// Validate radio input
		sliceAorB := []interface{}{"A_Win", "B_Win"}
		AorB := this.Input().Get("AorB")
		if !In_slice(AorB, sliceAorB) {
			this.SetSession("Error", ERROR_INVALIDINPUT)
			this.fail(id)
			return
		}

		// Send BTC to betaddress
		Type := " 主队赢"
		if AorB != "A_Win" {
			Type = " 客队赢"
		}
		user := models.UserByUid(uid)
		note := time.Now().Format(layout) + " 赛事ID:" + strconv.Itoa(id) + Type
		txhash, err := models.SendBTC(user.Btcaddress, BetAddr, note, amount)
		if err != nil {
			this.SetSession("Error", ERROR_CANTSENDBTC)
			this.fail(id)
			return
		}

		// Change database
		if !models.PlaceBet(id, uid, AorB, txhash, amount) {
			this.SetSession("Error", ERROR_DB)
			this.fail(id)
			return
		}

	case "OddEven":
		sliceOddEven := []interface{}{"Odd", "Even"}
		OddEven := this.Input().Get("OddEven")

		if !In_slice(OddEven, sliceOddEven) {
			this.SetSession("Error", ERROR_INVALIDINPUT)
			this.fail(id)
			return
		}

		// Send BTC to betaddress
		Type := " 单数总比分"
		if OddEven != "Odd" {
			Type = " 双数总比分"
		}
		user := models.UserByUid(uid)
		note := time.Now().Format(layout) + " 赛事ID:" + strconv.Itoa(id) + Type
		txhash, err := models.SendBTC(user.Btcaddress, BetAddr, note, amount)
		if err != nil {
			this.SetSession("Error", ERROR_CANTSENDBTC)
			this.fail(id)
			return
		}

		// Change database
		if !models.PlaceBet(id, uid, OddEven, txhash, amount) {
			this.SetSession("Error", ERROR_DB)
			this.fail(id)
			return
		}

	case "LargeSmall":
		sliceLargeSmall := []interface{}{"Large", "Small"}
		LargeSmall := this.Input().Get("LargeSmall")

		if !In_slice(LargeSmall, sliceLargeSmall) {
			this.SetSession("Error", ERROR_INVALIDINPUT)
			this.fail(id)
			return
		}

		// Send BTC to betaddress
		Type := " 大分"
		if LargeSmall != "Large" {
			Type = " 小分"
		}
		user := models.UserByUid(uid)
		note := time.Now().Format(layout) + " 赛事ID:" + strconv.Itoa(id) + Type
		txhash, err := models.SendBTC(user.Btcaddress, BetAddr, note, amount)
		if err != nil {
			this.SetSession("Error", ERROR_CANTSENDBTC)
			this.fail(id)
			return
		}

		// Change database
		if !models.PlaceBet(id, uid, LargeSmall, txhash, amount) {
			this.SetSession("Error", ERROR_DB)
			this.fail(id)
			return
		}

	}

	this.succ(id)
}