/
views_advertising.go
72 lines (58 loc) · 1.66 KB
/
views_advertising.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package marketplace
import (
"fmt"
"github.com/bobanderson-malibu/dotfree/dot-free-market/modules/apis"
"github.com/bobanderson-malibu/dotfree/dot-free-market/modules/util"
"github.com/gocraft/web"
"net/http"
)
func (c *Context) ViewListAdvertisings(w web.ResponseWriter, r *web.Request) {
c.Advertisings = FindAdvertisingByStore(c.ViewUserStore.Uuid)
println("!!!")
println(len(c.Advertisings))
c.AdvertisingCost = MARKETPLACE_SETTINGS.AdvertisingCost
items := FindItemsForStore(c.ViewUserStore.Uuid)
c.ViewItems = items.ViewItems(c.ViewUser.Language)
c.USDBTCRate = GetCurrencyRate("BTC", "USD")
util.RenderTemplate(w, "advertising/list", c)
}
func (c *Context) AddAdvertisingsPOST(w web.ResponseWriter, r *web.Request) {
var (
count = 1000
comment = r.FormValue("text")
itemUuid = r.FormValue("item")
priceUSD = MARKETPLACE_SETTINGS.AdvertisingCost
)
c.USDBTCRate = GetCurrencyRate("BTC", "USD")
price := priceUSD / c.USDBTCRate
userWallets := c.ViewUser.User.FindUserBitcoinWallets()
if userWallets.Balance().Balance < price {
c.Error = fmt.Sprintf("Please deposit %f BTC to your onsite wallet.", price)
c.ViewListAdvertisings(w, r)
return
}
addr, err := apis.GenerateBTCAddress("advertising")
if err != nil {
c.Error = err.Error()
c.ViewListAdvertisings(w, r)
return
}
_, err = userWallets.Send(addr, price)
if err != nil {
c.Error = err.Error()
c.ViewListAdvertisings(w, r)
return
}
err = CreateAdvertising(comment, count, itemUuid)
if err != nil {
c.Error = err.Error()
c.ViewListAdvertisings(w, r)
return
}
http.Redirect(
w,
r.Request,
"/store-admin/"+c.ViewStore.Storename+"/advertisings",
302,
)
}