material.go
1.06 KB
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
package models
import (
"database/sql"
"strings"
db "client/icesimba.ad/database"
)
type Material struct {
Type int64 `json:"type"`
Src string `json:"src"`
}
type material struct {
Type sql.NullInt64
Src sql.NullString
}
func (sell *SellPlan) QueryMaterialByAdId() (out []Material, err error) {
sqlQu := "SELECT material_type,material_src FROM ice_ad_material WHERE ad_id=?"
rows, err := db.SqlDB.Query(
sqlQu,
sell.AdId,
)
materialNull := material{}
for rows.Next() {
err = rows.Scan(
&materialNull.Type,
&materialNull.Src,
)
if err != nil {
continue
}
mater := Material{}
if materialNull.Type.Valid {
mater.Type = materialNull.Type.Int64
}
if materialNull.Src.Valid {
srcUrl := materialNull.Src.String
if strings.Index(srcUrl, "http") == 0 {
mater.Src = srcUrl
} else {
urlHost := "http://iceplay.oss-cn-beijing.aliyuncs.com"
if !strings.Contains(srcUrl, "/") || strings.Index(srcUrl, "/") != 0 {
urlHost = urlHost + "/"
}
mater.Src = urlHost + srcUrl
}
}
out = append(out, mater)
}
return
}