-
Notifications
You must be signed in to change notification settings - Fork 0
/
goods.go
82 lines (71 loc) · 1.54 KB
/
goods.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
73
74
75
76
77
78
79
80
81
82
/**
* Copyright 2014 @ z3q.net.
* name :
* author : jarryliu
* date : 2014-02-11 21:15
* description :
* history :
*/
package format
import (
"go2o/src/core/infrastructure"
"go2o/src/core/variable"
"strconv"
"strings"
)
var (
imageServe string
noPicUrl string
picCfgLoaded bool
)
//todo: not used
// 格式化商品编号,不足位用0补齐
func FormatGoodsNo(d int) string {
const l int = 6
s := strconv.Itoa(d)
sl := len(s)
if sl >= 6 {
return s
}
return strings.Repeat("0", l-sl) + s
}
// 获取商品图片地址
func GetGoodsImageUrl(image string) string {
if !picCfgLoaded {
ctx := infrastructure.GetApp()
if len(imageServe) == 0 {
imageServe = ctx.Config().GetString(variable.ImageServer)
}
if len(noPicUrl) == 0 {
noPicUrl = imageServe + "/" + ctx.Config().GetString(variable.NoPicPath)
}
picCfgLoaded = true
}
if len(image) == 0 {
return noPicUrl
}
if strings.HasPrefix(image, "http://") || strings.HasPrefix(image, "https://") {
return image
}
return imageServe + "/" + image
}
// 获取资源地址
func GetResUrl(image string) string {
if !picCfgLoaded {
ctx := infrastructure.GetApp()
if len(imageServe) == 0 {
imageServe = ctx.Config().GetString(variable.ImageServer)
}
if len(noPicUrl) == 0 {
noPicUrl = imageServe + "/" + ctx.Config().GetString(variable.NoPicPath)
}
picCfgLoaded = true
}
if len(image) == 0 {
return noPicUrl
}
if strings.HasPrefix(image, "http://") || strings.HasPrefix(image, "https://") {
return image
}
return imageServe + "/" + image
}