Exemplo n.º 1
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"
}
Exemplo 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)
}