Example #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()
}
Example #2
0
func (this *UserRouter) setData(sec string) {
	switch sec {
	case "Deposit":
		// User Addr
		this.Data["Addr"] = models.AddressByUid(User.Uid)

		// User All deposit
		userDeposit := models.DepositByUid(User.Uid)
		this.Data["UserDeposit"] = userDeposit

		// All time deposit
		var allTimeDeposit float64
		for _, v := range userDeposit {
			allTimeDeposit += v.Amount
		}
		this.Data["AllTimeDeposit"] = allTimeDeposit

		// Current Balance
		this.Data["Balance"] = models.UserByUid(User.Uid).Balance

	case "Withdraw":
		// Withdraw error from POST
		e := this.GetSession("Error")
		if e != nil {
			this.DelSession("Error")
			this.Data["Error"] = GetError(e)
		}

		// User All withdraw
		userWithdraw := models.WithdrawByUid(User.Uid)
		this.Data["UserWithdraw"] = userWithdraw

		//xsrf
		this.Data["xsrf"] = template.HTML(this.XsrfFormHtml())
	case "Refer":
		// Username -> Refer Address
		this.Data["Username"] = User.Username

		// User Bet amount and profit of this month
		betAmount, betProfit := models.UserBetAmountProfit(User.Uid)
		this.Data["betAmount"] = betAmount
		this.Data["betProfit"] = betProfit

		// Find all referee
		userRefer := models.UserByReferral(User.Username)
		this.Data["Count"] = len(userRefer)

		// Calculate all referees' bet info
		type temp struct {
			Uid       int
			Betamount float64
			Profit    float64
		}
		var userData []temp
		for _, v := range userRefer {
			betamount, profit := models.UserBetAmountProfit(v.Id)
			userData = append(userData, temp{Uid: v.Id, Betamount: betamount, Profit: profit})
		}
		this.Data["UserData"] = userData

		// Calculate ReferFee
		var referFee float64
		for _, v := range userData {
			if v.Profit < 0 {
				fee := math.Floor(0.00188*float64(len(userRefer))*100000000) / 10000000
				referFee -= v.Profit * fee
			}
		}
		this.Data["ReferFee"] = referFee

	case "Allbet":
		bets := models.UserBets(User.Uid)
		this.Data["BetCount"] = len(bets)
		this.Data["UserAllBets"] = bets

	}
	this.TplNames = "user_" + sec + ".tpl"
}