|
@@ -0,0 +1,98 @@
|
|
|
+package utility
|
|
|
+
|
|
|
+import (
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "context"
|
|
|
+ "fmt"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "github.com/gogf/gf/v2/net/ghttp"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
+ "reflect"
|
|
|
+ "regexp"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+// ConversionMoney 金额格式化
|
|
|
+func ConversionMoney(i_money interface{}) string {
|
|
|
+ if i_money == nil {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ m := ""
|
|
|
+ if reflect.TypeOf(i_money).Name() == "float64" {
|
|
|
+ m = strconv.FormatFloat(gconv.Float64(i_money), 'f', -1, 64)
|
|
|
+ } else {
|
|
|
+ m = gconv.String(i_money)
|
|
|
+ }
|
|
|
+ if m == "" {
|
|
|
+ return m
|
|
|
+ }
|
|
|
+ m_arr := strings.Split(m, ".")
|
|
|
+ m_1 := m_arr[0]
|
|
|
+ len_m1 := len([]rune(m_1))
|
|
|
+ if len_m1 >= 9 {
|
|
|
+ m = m_1[0:len_m1-8] + "." + m_1[len_m1-8:len_m1-6] + "亿元"
|
|
|
+ } else if len_m1 >= 5 {
|
|
|
+ m = m_1[0:len_m1-4] + "." + m_1[len_m1-4:len_m1-2] + "万元"
|
|
|
+ } else {
|
|
|
+ if len(m_arr) == 1 {
|
|
|
+ return m + ".00元"
|
|
|
+ }
|
|
|
+ m_2 := m_arr[1]
|
|
|
+ if len([]rune(m_2)) > 1 {
|
|
|
+ m_2 = m_2[0:2]
|
|
|
+ } else {
|
|
|
+ m_2 = m_2[0:1] + "0"
|
|
|
+ }
|
|
|
+ m = m_1 + "." + m_2 + "元"
|
|
|
+ }
|
|
|
+ return m
|
|
|
+}
|
|
|
+
|
|
|
+var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
|
|
|
+
|
|
|
+func GetCommonRenderPatch(agent, value string) string {
|
|
|
+ if IsMobile(agent) {
|
|
|
+ return fmt.Sprintf("mobile/%s", value)
|
|
|
+ }
|
|
|
+ return fmt.Sprintf("pc/%s", value)
|
|
|
+}
|
|
|
+
|
|
|
+func IsMobile(agent string) bool {
|
|
|
+ if mobileReg.MatchString(agent) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+func EncodeId(sid string) string {
|
|
|
+ if sid == "" || sid == "-" { //不存在的id为-
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ return encrypt.EncodeArticleId2ByCheck(sid)
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeId(eid string) string {
|
|
|
+ if eid == "" {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ return encrypt.DecodeArticleId2ByCheck(eid)[0]
|
|
|
+}
|
|
|
+
|
|
|
+// JySessionLoginEd 是否已经登录
|
|
|
+func JySessionLoginEd(r *ghttp.Request) bool {
|
|
|
+ val := r.Cookie.Get("SESSIONID")
|
|
|
+ if val.IsNil() {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ sessionId := val.String()
|
|
|
+ if sessionId == "" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if gVal, _ := g.Redis("session").Get(context.Background(), sessionId); !gVal.IsEmpty() {
|
|
|
+ if gconv.String(gVal.Map()["userId"]) != "" {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|