Bläddra i källkod

wip:项目初始化

wangkaiyue 1 år sedan
förälder
incheckning
360c51e868

+ 3 - 0
internal/cmd/cmd.go

@@ -17,6 +17,9 @@ var (
 		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
 			s := g.Server()
 			s.Group("/", func(group *ghttp.RouterGroup) {
+				group.GET("/hello", func(r *ghttp.Request) {
+					r.Response.Write("hello world")
+				}) //地区、行业首页
 				group.GET("/", controller.IndexTransfer)           //地区、行业首页
 				group.GET("/index.html", controller.IndexTransfer) //地区、行业首页
 

+ 0 - 0
resource/staticres/css/.gitkeep


+ 0 - 0
resource/staticres/images/.gitkeep


+ 0 - 0
resource/staticres/js/.gitkeep


+ 0 - 0
resource/template/.gitkeep


+ 0 - 0
resource/template/mobile/.gitkeep


+ 0 - 0
utility/.gitkeep


+ 46 - 0
utility/db.go

@@ -0,0 +1,46 @@
+package utility
+
+import (
+	m "app.yhyue.com/moapp/jybase/mongodb"
+	"context"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gctx"
+)
+
+type (
+	mgoConf struct {
+		Address         string
+		Size            int
+		DbName          string
+		ReplSet         string
+		UserName        string
+		Password        string
+		Collection      string
+		Collection_back string
+	}
+)
+
+var (
+	mongdbConf mgoConf
+	Mgo        m.MongodbSim
+)
+
+func init() {
+	initCtx := gctx.New()
+	if err := g.Cfg().MustGet(initCtx, "mongodb").Struct(&mongdbConf); err != nil {
+		panic(err)
+	}
+	Mgo = m.MongodbSim{
+		MongodbAddr: mongdbConf.Address,
+		Size:        mongdbConf.Size,
+		DbName:      mongdbConf.DbName,
+		UserName:    mongdbConf.UserName,
+		Password:    mongdbConf.Password,
+		ReplSet:     mongdbConf.ReplSet,
+	}
+	Mgo.InitPool()
+
+	if err := g.Cfg().MustGet(context.Background(), "entMongodb").Struct(&mongdbConf); err != nil {
+		panic(err)
+	}
+}

+ 98 - 0
utility/util.go

@@ -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
+}