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
}
func (c *Controller) WalletsListCfProject() (string, error) {

	var err error
	c.r.ParseForm()

	projectId := utils.StrToInt64(c.r.FormValue("project_id"))
	if projectId == 0 {
		return "", errors.New("projectId == 0")
	}
	cfProject, err := c.OneRow("SELECT id, amount, currency_id, end_time FROM cf_projects WHERE del_block_id = 0 AND id  =  ?", projectId).String()
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	//id, endTime, langId int64, amount float64, levelUp string
	CfProjectData, err := c.GetCfProjectData(projectId, utils.StrToInt64(cfProject["end_time"]), c.LangInt, utils.StrToFloat64(cfProject["amount"]), "")
	for k, v := range CfProjectData {
		cfProject[k] = v
	}

	// сколько у нас есть DC данной валюты
	wallet, err := c.OneRow("SELECT amount, currency_id,  last_update FROM wallets WHERE user_id  =  ? AND currency_id  =  ?", c.SessUserId, cfProject["currency_id"]).String()
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	if len(wallet) > 0 {
		amount := utils.StrToMoney(wallet["amount"])
		profit, err := c.CalcProfitGen(utils.StrToInt64(wallet["currency_id"]), amount, c.SessUserId, utils.StrToInt64(wallet["last_update"]), time.Now().Unix(), "wallet")
		if err != nil {
			return "", utils.ErrInfo(err)
		}
		amount += profit
		amount = math.Floor(utils.Round(amount, 3)*100) / 100
		forexOrdersAmount, err := c.Single("SELECT sum(amount) FROM forex_orders WHERE user_id  =  ? AND sell_currency_id  =  ? AND del_block_id  =  0", c.SessUserId, wallet["currency_id"]).Float64()
		if err != nil {
			return "", utils.ErrInfo(err)
		}
		amount -= forexOrdersAmount
		cfProject["wallet_amount"] = utils.Float64ToStrPct(amount)
	} else {
		cfProject["wallet_amount"] = "0"
	}

	cfProject["currency"] = c.CurrencyList[utils.StrToInt64(cfProject["currency_id"])]

	newmap := make(map[string]interface{})
	for k, v := range cfProject {
		newmap[k] = v
	}

	// наличие описаний
	newmap["lang"], err = c.GetMap("SELECT id,  lang_id FROM cf_projects_data	WHERE project_id = ?", "id", "lang_id", projectId)
	if err != nil {
		return "", utils.ErrInfo(err)
	}

	result, err := json.Marshal(newmap)
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	return string(result), nil
}
Exemple #3
0
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
}
Exemple #4
0
func AjaxE(w http.ResponseWriter, r *http.Request) {
	defer func() {
		if r := recover(); r != nil {
			log.Error("ajax Recovered", r)
			panic(r)
		}
	}()
	log.Debug("AjaxE")
	w.Header().Set("Content-type", "text/html")

	sess, err := globalSessions.SessionStart(w, r)
	if err != nil {
		log.Error("%v", err)
		return
	}
	defer sess.SessionRelease(w)
	sessUserId := GetSessEUserId(sess)
	log.Debug("sessUserId", sessUserId)

	c := new(Controller)
	c.r = r
	c.w = w
	c.sess = sess
	c.SessUserId = sessUserId

	if utils.DB == nil || utils.DB.DB == nil {
		log.Error("utils.DB == nil")
		w.Write([]byte("DB == nil"))
		return
	}
	c.DCDB = utils.DB

	c.Parameters, err = c.GetParameters()
	log.Debug("parameters=", c.Parameters)

	lang := GetLang(w, r, c.Parameters)
	log.Debug("lang", lang)
	c.Lang = globalLangReadOnly[lang]
	c.LangInt = int64(lang)
	if lang == 42 {
		c.TimeFormat = "2006-01-02 15:04:05"
	} else {
		c.TimeFormat = "2006-02-01 15:04:05"
	}

	r.ParseForm()
	controllerName := r.FormValue("controllerName")
	log.Debug("controllerName=", controllerName)

	html := ""

	c.EConfig, err = c.GetMap(`SELECT * FROM e_config`, "name", "value")
	if err != nil {
		log.Error("%v", err)
	}
	c.EURL = c.EConfig["domain"]
	if len(c.EURL) == 0 {
		eHost, err := c.Single(`SELECT http_host FROM config`).String()
		if err != nil {
			log.Error("%v", err)
		}
		eHost += c.EConfig["catalog"]
		c.EURL = eHost
	} else {
		c.EURL = "http://" + c.EURL + "/"
	}
	c.ECommission = utils.StrToMoney(c.EConfig["commission"])
	// валюты
	c.CurrencyList, err = c.GetCurrencyList(false)
	if err != nil {
		log.Error("%v", err)
	}
	if ok, _ := regexp.MatchString(`^(?i)EPayeerSign|EGatePayeer|EDelOrder|EWithdraw|EGetBalance|ESaveOrder|ESignUp|ELogin|ELogout|ESignLogin|ECheckSign|ERedirect|EInfo|EData|EGatePm|EGateIk$`, controllerName); !ok {
		html = "Access denied 0"
	} else {
		if ok, _ := regexp.MatchString(`^(?i)EPayeerSign|ESaveOrder|ESignUp|ELogin|ESignLogin|ECheckSign|ERedirect|EInfo|EData|EGatePm|EGateIk|EGatePayeer$`, controllerName); !ok && c.SessUserId <= 0 {
			html = "Access denied 1"
		} else {
			// вызываем контроллер в зависимости от шаблона
			log.Debug("controllerName %s", controllerName)
			html, err = CallController(c, controllerName)
			log.Debug("html %s", html)
			if err != nil {
				log.Error("ajax error: %v", err)
			}
		}
	}
	w.Write([]byte(html))

}