當前位置: 首頁>>代碼示例>>Golang>>正文


Golang utils.StrToFloat64函數代碼示例

本文整理匯總了Golang中github.com/c-darwin/dcoin-go/packages/utils.StrToFloat64函數的典型用法代碼示例。如果您正苦於以下問題:Golang StrToFloat64函數的具體用法?Golang StrToFloat64怎麽用?Golang StrToFloat64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了StrToFloat64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ChangeMoneyBackTime

func (c *Controller) ChangeMoneyBackTime() (string, error) {

	txType := "ChangeMoneyBackTime"
	txTypeId := utils.TypeInt(txType)
	timeNow := utils.Time()

	orderId := int64(utils.StrToFloat64(c.Parameters["order_id"]))
	days := int64(utils.StrToFloat64(c.Parameters["days"]))

	TemplateStr, err := makeTemplate("change_money_back_time", "changeMoneyBackTime", &changeMoneyBackTimePage{
		Alert:        c.Alert,
		Lang:         c.Lang,
		ShowSignData: c.ShowSignData,
		SignData:     "",
		UserId:       c.SessUserId,
		OrderId:      orderId,
		Days:         days,
		CountSignArr: c.CountSignArr,
		TimeNow:      timeNow,
		TxType:       txType,
		TxTypeId:     txTypeId})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:26,代碼來源:change_money_back_time.go

示例2: EWithdraw

func (c *Controller) EWithdraw() (string, error) {

	if c.SessUserId == 0 {
		return "", errors.New(c.Lang["sign_up_please"])
	}

	c.r.ParseForm()
	currencyId := utils.StrToInt64(c.r.FormValue("currency_id"))
	if !utils.CheckInputData(c.r.FormValue("amount"), "amount") {
		return "", fmt.Errorf("incorrect amount")
	}
	method := c.r.FormValue("method")
	if !utils.CheckInputData(method, "method") {
		return "", fmt.Errorf("incorrect method")
	}
	account := c.r.FormValue("account")
	if !utils.CheckInputData(account, "account") {
		return "", fmt.Errorf("incorrect account")
	}
	amount := utils.StrToFloat64(c.r.FormValue("amount"))

	curTime := utils.Time()

	// нужно проверить, есть ли нужная сумма на счету юзера
	userAmount := utils.EUserAmountAndProfit(c.SessUserId, currencyId)
	if userAmount < amount {
		return "", fmt.Errorf("%s (%f<%f)", c.Lang["not_enough_money"], userAmount, amount)
	}
	if method != "Dcoin" && currencyId < 1000 {
		return "", fmt.Errorf("incorrect method")
	}

	err := userLock(c.SessUserId)
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	err = c.ExecSql(`UPDATE e_wallets SET amount = ?, last_update = ? WHERE user_id = ? AND currency_id = ?`, userAmount-amount, curTime, c.SessUserId, currencyId)
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	var commission float64
	if method == "Dcoin" {
		commission = utils.StrToFloat64(c.EConfig["dc_commission"])
	} else if method == "Perfect-money" {
		commission = utils.StrToFloat64(c.EConfig["pm_commission"])
	}
	wdAmount := utils.ClearNull(utils.Float64ToStr(amount*(1-commission/100)), 2)

	err = c.ExecSql(`INSERT INTO e_withdraw (open_time, user_id, currency_id, account, amount, wd_amount, method) VALUES (?, ?, ?, ?, ?, ?, ?)`, curTime, c.SessUserId, currencyId, account, amount, wdAmount, method)
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	userUnlock(c.SessUserId)

	return utils.JsonAnswer(c.Lang["request_is_created"], "success").String(), nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:56,代碼來源:e_withdraw.go

示例3: ESaveOrder

func (c *Controller) ESaveOrder() (string, error) {

	if c.SessUserId == 0 {
		return "", errors.New(c.Lang["sign_up_please"])
	}
	c.r.ParseForm()
	sellCurrencyId := utils.StrToInt64(c.r.FormValue("sell_currency_id"))
	buyCurrencyId := utils.StrToInt64(c.r.FormValue("buy_currency_id"))
	amount := utils.StrToFloat64(c.r.FormValue("amount"))
	sellRate := utils.StrToFloat64(c.r.FormValue("sell_rate"))
	orderType := c.r.FormValue("type")
	// можно ли торговать такими валютами
	checkCurrency, err := c.Single("SELECT count(id) FROM e_currency WHERE id IN (?, ?)", sellCurrencyId, buyCurrencyId).Int64()
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	if checkCurrency != 2 {
		return "", errors.New("Currency error")
	}
	if orderType != "sell" && orderType != "buy" {
		return "", errors.New("Type error")
	}
	if amount == 0 {
		return "", errors.New(c.Lang["amount_error"])
	}
	if amount < 0.001 && sellCurrencyId < 1000 {
		return "", errors.New(strings.Replace(c.Lang["save_order_min_amount"], "[amount]", "0.001", -1))
	}
	if sellRate < 0.0001 {
		return "", errors.New(strings.Replace(c.Lang["save_order_min_price"], "[price]", "0.0001", -1))
	}
	reductionLock, err := utils.EGetReductionLock()
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	if reductionLock > 0 {
		return "", errors.New(strings.Replace(c.Lang["creating_orders_unavailable"], "[minutes]", "30", -1))
	}

	// нужно проверить, есть ли нужная сумма на счету юзера
	userAmountAndProfit := utils.EUserAmountAndProfit(c.SessUserId, sellCurrencyId)
	if userAmountAndProfit < amount {
		return "", errors.New(c.Lang["not_enough_money"] + " (" + utils.Float64ToStr(userAmountAndProfit) + "<" + utils.Float64ToStr(amount) + ")" + strings.Replace(c.Lang["add_funds_link"], "[currency]", "USD", -1))
	}

	err = NewForexOrder(c.SessUserId, amount, sellRate, sellCurrencyId, buyCurrencyId, orderType, utils.StrToMoney(c.EConfig["commission"]))
	if err != nil {
		return "", utils.ErrInfo(err)
	} else {
		return utils.JsonAnswer(c.Lang["order_created"], "success").String(), nil
	}

	return ``, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:54,代碼來源:e_save_order.go

示例4: SaveRaceCountry

func (c *Controller) SaveRaceCountry() (string, error) {

	if c.SessRestricted != 0 {
		return "", utils.ErrInfo(errors.New("Permission denied"))
	}

	c.r.ParseForm()
	race := int(utils.StrToFloat64(c.r.FormValue("race")))
	country := int(utils.StrToFloat64(c.r.FormValue("country")))
	err := c.ExecSql("UPDATE "+c.MyPrefix+"my_table SET race = ?, country = ?", race, country)
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return `{"error":"0"}`, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:15,代碼來源:save_race_country.go

示例5: EDelOrder

func (c *Controller) EDelOrder() (string, error) {

	c.r.ParseForm()
	orderId := utils.StrToInt64(c.r.FormValue("order_id"))

	// возвращаем сумму ордера на кошелек + возращаем комиссию.
	order, err := utils.DB.OneRow("SELECT amount, sell_currency_id FROM e_orders WHERE id  =  ? AND user_id  =  ? AND del_time  =  0 AND empty_time  =  0", orderId, c.SessUserId).String()
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	if len(order) == 0 {
		return "", utils.ErrInfo("order_id error")
	}
	sellCurrencyId := utils.StrToInt64(order["sell_currency_id"])
	amount := utils.StrToFloat64(order["amount"])

	amountAndCommission := utils.StrToFloat64(order["amount"]) / (1 - c.ECommission/100)
	// косиссия биржи
	commission := amountAndCommission - amount
	err = userLock(c.SessUserId)
	if err != nil {
		return "", err
	}

	// отмечаем, что ордер удален
	err = utils.DB.ExecSql("UPDATE e_orders SET del_time = ? WHERE id = ? AND user_id = ?", utils.Time(), orderId, c.SessUserId)
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	// возвращаем остаток ордера на кошель
	userAmount := utils.EUserAmountAndProfit(c.SessUserId, sellCurrencyId)
	err = utils.DB.ExecSql("UPDATE e_wallets SET amount = ?, last_update = ? WHERE user_id = ? AND currency_id = ?", userAmount+amountAndCommission, utils.Time(), c.SessUserId, sellCurrencyId)
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	// вычитаем комиссию биржи
	userAmount = utils.EUserAmountAndProfit(1, sellCurrencyId)
	err = utils.DB.ExecSql("UPDATE e_wallets SET amount = ?, last_update = ? WHERE user_id = 1 AND currency_id = ?", userAmount-commission, utils.Time(), sellCurrencyId)
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	userUnlock(c.SessUserId)

	return ``, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:48,代碼來源:e_del_order.go

示例6: DelCfProject

func (c *Controller) DelCfProject() (string, error) {

	var err error

	txType := "DelCfProject"
	txTypeId := utils.TypeInt(txType)
	timeNow := utils.Time()

	delId := int64(utils.StrToFloat64(c.Parameters["del_id"]))
	projectCurrencyName, err := c.Single("SELECT project_currency_name FROM cf_projects WHERE id =  ?", delId).String()
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	TemplateStr, err := makeTemplate("del_cf_project", "delCfProject", &DelCfProjectPage{
		Alert:               c.Alert,
		Lang:                c.Lang,
		CountSignArr:        c.CountSignArr,
		ShowSignData:        c.ShowSignData,
		SignData:            fmt.Sprintf(`%d,%d,%d,%d`, txTypeId, timeNow, c.SessUserId, delId),
		UserId:              c.SessUserId,
		TimeNow:             timeNow,
		TxType:              txType,
		TxTypeId:            txTypeId,
		DelId:               delId,
		ProjectCurrencyName: projectCurrencyName})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:31,代碼來源:del_cf_project.go

示例7: RepaymentCredit

func (c *Controller) RepaymentCredit() (string, error) {

	txType := "RepaymentCredit"
	txTypeId := utils.TypeInt(txType)
	timeNow := time.Now().Unix()

	creditId := utils.Round(utils.StrToFloat64(c.Parameters["credit_id"]), 0)

	TemplateStr, err := makeTemplate("repayment_credit", "repaymentCredit", &repaymentCreditPage{
		Alert:        c.Alert,
		Lang:         c.Lang,
		CountSignArr: c.CountSignArr,
		ShowSignData: c.ShowSignData,
		UserId:       c.SessUserId,
		TimeNow:      timeNow,
		TxType:       txType,
		TxTypeId:     txTypeId,
		SignData:     "",
		CreditId:     creditId,
		CurrencyList: c.CurrencyList})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:25,代碼來源:repayment_credit.go

示例8: ChangeCreditor

func (c *Controller) ChangeCreditor() (string, error) {

	txType := "ChangeCreditor"
	txTypeId := utils.TypeInt(txType)
	timeNow := time.Now().Unix()

	creditId := utils.Round(utils.StrToFloat64(c.Parameters["credit_id"]), 0)
	log.Debug("creditId", creditId)

	TemplateStr, err := makeTemplate("change_creditor", "changeCreditor", &changeCreditorPage{
		Alert:        c.Alert,
		Lang:         c.Lang,
		CountSignArr: c.CountSignArr,
		ShowSignData: c.ShowSignData,
		UserId:       c.SessUserId,
		TimeNow:      timeNow,
		TxType:       txType,
		TxTypeId:     txTypeId,
		SignData:     "",
		CreditId:     creditId})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:25,代碼來源:change_creditor.go

示例9: MoneyBackRequest

func (c *Controller) MoneyBackRequest() (string, error) {

	txType := "MoneyBackRequest"
	txTypeId := utils.TypeInt(txType)
	timeNow := utils.Time()

	orderId := int64(utils.StrToFloat64(c.Parameters["order_id"]))
	order, err := c.OneRow("SELECT * FROM orders WHERE id  =  ?", orderId).String()
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	TemplateStr, err := makeTemplate("money_back_request", "moneyBackRequest", &moneyBackRequestPage{
		Alert:        c.Alert,
		Lang:         c.Lang,
		ShowSignData: c.ShowSignData,
		SignData:     "",
		UserId:       c.SessUserId,
		OrderId:      orderId,
		Order:        order,
		CountSignArr: c.CountSignArr,
		TimeNow:      timeNow,
		TxType:       txType,
		TxTypeId:     txTypeId})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:29,代碼來源:money_back_request.go

示例10: DelCfFunding

func (c *Controller) DelCfFunding() (string, error) {

	var err error

	txType := "DelCfFunding"
	txTypeId := utils.TypeInt(txType)
	timeNow := utils.Time()

	delId := int64(utils.StrToFloat64(c.Parameters["del_id"]))

	TemplateStr, err := makeTemplate("del_cf_funding", "delCfFunding", &DelCfFundingPage{
		Alert:        c.Alert,
		Lang:         c.Lang,
		CountSignArr: c.CountSignArr,
		ShowSignData: c.ShowSignData,
		SignData:     fmt.Sprintf(`%d,%d,%d,%d`, txTypeId, timeNow, c.SessUserId, delId),
		UserId:       c.SessUserId,
		TimeNow:      timeNow,
		TxType:       txType,
		TxTypeId:     txTypeId,
		DelId:        delId})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:26,代碼來源:del_cf_funding.go

示例11: MiningPromisedAmount

func (c *Controller) MiningPromisedAmount() (string, error) {

	txType := "Mining"
	txTypeId := utils.TypeInt(txType)
	timeNow := time.Now().Unix()
	amount := utils.StrToMoney(c.Parameters["amount"])
	amount = math.Floor(amount*100) / 100
	promisedAmountId := int64(utils.StrToFloat64(c.Parameters["promised_amount_id"]))
	log.Debug("c.Parameters[promised_amount_id]):", c.Parameters["promised_amount_id"])
	log.Debug("promisedAmountId:", promisedAmountId)
	TemplateStr, err := makeTemplate("mining_promised_amount", "miningPromisedAmount", &miningPromisedAmountPage{
		Alert:            c.Alert,
		Lang:             c.Lang,
		CountSignArr:     c.CountSignArr,
		ShowSignData:     c.ShowSignData,
		UserId:           c.SessUserId,
		TimeNow:          timeNow,
		TxType:           txType,
		TxTypeId:         txTypeId,
		SignData:         fmt.Sprintf("%v,%v,%v,%v,%v", txTypeId, timeNow, c.SessUserId, promisedAmountId, amount),
		Amount:           amount,
		PromisedAmountId: promisedAmountId})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:27,代碼來源:mining_promised_amount.go

示例12: ChangePromisedAmount

func (c *Controller) ChangePromisedAmount() (string, error) {

	txType := "ChangePromisedAmount"
	txTypeId := utils.TypeInt(txType)
	timeNow := time.Now().Unix()
	promisedAmountId := int64(utils.StrToFloat64(c.Parameters["promised_amount_id"]))
	amount := c.Parameters["amount"]

	TemplateStr, err := makeTemplate("change_promised_amount", "changePromisedAmount", &changePromisedAmountPage{
		Alert:            c.Alert,
		Lang:             c.Lang,
		CountSignArr:     c.CountSignArr,
		ShowSignData:     c.ShowSignData,
		UserId:           c.SessUserId,
		TimeNow:          timeNow,
		TxType:           txType,
		TxTypeId:         txTypeId,
		SignData:         fmt.Sprintf("%v,%v,%v,%v,%v", txTypeId, timeNow, c.SessUserId, promisedAmountId, amount),
		PromisedAmountId: promisedAmountId,
		Amount:           amount})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:25,代碼來源:change_promised_amount.go

示例13: NewPhoto

func (c *Controller) NewPhoto() (string, error) {

	c.r.ParseForm()

	userId := int64(utils.StrToFloat64(c.r.FormValue("user_id")))

	data, err := c.OneRow("SELECT photo_block_id, photo_max_miner_id, miners_keepers FROM miners_data WHERE user_id = ?", userId).String()
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	// получим ID майнеров, у которых лежат фото нужного нам юзера
	minersIds := utils.GetMinersKeepers(data["photo_block_id"], data["photo_max_miner_id"], data["miners_keepers"], true)

	// берем 1 случайный из 10-и ID майнеров
	k := utils.RandInt(0, len(minersIds))
	minerId := minersIds[k]
	host, err := c.Single("SELECT http_host FROM miners_data WHERE miner_id  =  ?", minerId).String()
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	result, err := json.Marshal(map[string]string{"face": host + "public/face_" + utils.Int64ToStr(userId) + ".jpg", "profile": host + "public/profile_" + utils.Int64ToStr(userId) + ".jpg"})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return string(result), nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:28,代碼來源:new_photo.go

示例14: AddCfProjectData

func (c *Controller) AddCfProjectData() (string, error) {

	var err error

	txType := "CfProjectData"
	txTypeId := utils.TypeInt(txType)
	timeNow := utils.Time()

	projectId := int64(utils.StrToFloat64(c.Parameters["projectId"]))
	id := int64(utils.StrToFloat64(c.Parameters["id"]))
	cfData := make(map[string]string)
	if id > 0 {
		log.Debug("id:", id)
		cfData, err = c.OneRow("SELECT * FROM cf_projects_data WHERE id = ?", id).String()
		if err != nil {
			return "", utils.ErrInfo(err)
		}
		projectId = utils.StrToInt64(cfData["project_id"])
	}

	cfCurrencyName, err := c.Single("SELECT project_currency_name FROM cf_projects WHERE id  =  ?", projectId).String()
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	CfLng, err := c.GetAllCfLng()
	log.Debug("CfData", cfData)
	TemplateStr, err := makeTemplate("add_cf_project_data", "addCfProjectData", &AddCfProjectDataPage{
		Alert:          c.Alert,
		Lang:           c.Lang,
		CountSignArr:   c.CountSignArr,
		ShowSignData:   c.ShowSignData,
		UserId:         c.SessUserId,
		TimeNow:        timeNow,
		TxType:         txType,
		TxTypeId:       txTypeId,
		ProjectId:      projectId,
		Id:             id,
		CfData:         cfData,
		CfCurrencyName: cfCurrencyName,
		CfLng:          CfLng})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:46,代碼來源:add_cf_project_data.go

示例15: CfCatalog

func (c *Controller) CfCatalog() (string, error) {

	var err error
	log.Debug("CfCatalog")

	categoryId := utils.Int64ToStr(int64(utils.StrToFloat64(c.Parameters["category_id"])))
	log.Debug("categoryId", categoryId)
	var curCategory string
	addSql := ""
	if categoryId != "0" {
		addSql = `AND category_id = ` + categoryId
		curCategory = c.Lang["cf_category_"+categoryId]
	}

	cfUrl := ""

	projects := make(map[string]map[string]string)
	cfProjects, err := c.GetAll(`
			SELECT cf_projects.id, lang_id, blurb_img, country, city, currency_id, end_time, amount
			FROM cf_projects
			LEFT JOIN cf_projects_data ON  cf_projects_data.project_id = cf_projects.id
			WHERE del_block_id = 0 AND
						 end_time > ? AND
						 lang_id = ?
						`+addSql+`
			ORDER BY funders DESC
			LIMIT 100
			`, 100, utils.Time(), c.LangInt)
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	for _, data := range cfProjects {
		CfProjectData, err := c.GetCfProjectData(utils.StrToInt64(data["id"]), utils.StrToInt64(data["end_time"]), c.LangInt, utils.StrToFloat64(data["amount"]), cfUrl)
		if err != nil {
			return "", utils.ErrInfo(err)
		}
		for k, v := range CfProjectData {
			data[k] = v
		}
		projects[data["id"]] = data
	}

	cfCategory := utils.MakeCfCategories(c.Lang)

	TemplateStr, err := makeTemplate("cf_catalog", "cfCatalog", &cfCatalogPage{
		Lang:         c.Lang,
		CfCategory:   cfCategory,
		CurrencyList: c.CurrencyList,
		CurCategory:  curCategory,
		Projects:     projects,
		UserId:       c.SessUserId,
		CategoryId:   categoryId,
		CfUrl:        cfUrl})
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return TemplateStr, nil
}
開發者ID:dzyk,項目名稱:dcoin-go,代碼行數:58,代碼來源:cf_catalog.go


注:本文中的github.com/c-darwin/dcoin-go/packages/utils.StrToFloat64函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。