Parcourir la source

改为gomod 代码提交 企业认证走广告位

wangkaiyue il y a 1 an
Parent
commit
bd755aa11e

+ 0 - 0
src/config.json → config.json


+ 14 - 0
db.json

@@ -0,0 +1,14 @@
+{
+  "mongodb": {
+    "main": {
+      "address": "192.168.3.206:27080",
+      "size": 10,
+      "dbName": "qfw"
+    }
+  },
+  "redis": {
+    "main": {
+      "address": "other=192.168.3.149:1712"
+    }
+  }
+}

+ 14 - 0
main.go

@@ -0,0 +1,14 @@
+package main
+
+import (
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	_ "commercialService/service/a"
+	_ "commercialService/service/action"
+	"commercialService/service/config"
+	"net/http"
+)
+
+func main() {
+	mux1 := http.NewServeMux()
+	xweb.RunBase(":"+config.Sysconfig.Webport, mux1)
+}

+ 2 - 3
src/service/a/init.go → service/a/init.go

@@ -1,10 +1,9 @@
 package init
 
 import (
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
 	"time"
-
-	"github.com/go-xweb/httpsession"
-	"github.com/go-xweb/xweb"
 )
 
 func init() {

+ 144 - 0
service/action/customer.go

@@ -0,0 +1,144 @@
+package action
+
+import (
+	qu "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"app.yhyue.com/moapp/jybase/redis"
+	"app.yhyue.com/moapp/jypkg/public"
+	"commercialService/service/config"
+	"encoding/json"
+	"fmt"
+	"strings"
+	"time"
+)
+
+type Action struct {
+	*xweb.Action
+	info xweb.Mapper `xweb:"/customer/info"`
+}
+
+func init() {
+	xweb.AddAction(&Action{})
+}
+
+func (a *Action) Info() {
+	module := a.GetString("module")
+	rMap := map[string]interface{}{}
+	switch module {
+	case "tripartiteAuth":
+		AdCode := fmt.Sprintf("ad_%s", module)
+		obj := redis.Get("other", AdCode)
+		var adInfo []AdInfo
+		if obj != nil {
+			adInfo = Handle(obj.([]interface{}), a.Request.Host)
+		} else {
+			res, ok := public.MQFW.FindOneByField("ad", `{"s_code":"`+AdCode+`"}`, `{"a_son":1,"l_modifydate":1}`)
+			if ok && res != nil && (*res)["a_son"] != nil {
+				res, ok := public.MQFW.FindOneByField("ad", `{"s_code":"`+AdCode+`"}`, `{"a_son":1}`)
+				if ok && res != nil && (*res)["a_son"] != nil {
+					son := (*res)["a_son"].([]interface{})
+					if len(son) > 0 {
+						redis.Put("other", AdCode, son, int(GetLastTime()))
+					}
+					adInfo = Handle(son, a.Request.Host)
+				}
+			}
+		}
+		if len(adInfo) > 0 {
+			rMap = map[string]interface{}{
+				"phone":     adInfo[0].S_remark,
+				"wxCodeImg": adInfo[0].S_pic,
+			}
+		}
+	default:
+		if data := config.Sysconfig.Info[module]; data != nil {
+			if m := qu.ObjToMap(data); m != nil {
+				rMap = *m
+			}
+		}
+	}
+	a.ServeJson(map[string]interface{}{
+		"data":       rMap,
+		"error_msg":  "",
+		"erros_code": 0,
+	})
+}
+
+// 获取当天剩余时间
+var (
+	timeOut int64 = 24 * 60 * 60
+)
+
+func GetLastTime() int64 {
+	t := time.Now()
+	midnight := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, t.Location())
+	if midnight.After(t) {
+		return midnight.Unix() - t.Unix()
+	}
+	return timeOut
+}
+
+// AdInfo 广告信息
+type AdInfo struct {
+	S_link   string `json:"s_link"`   //广告位跳转链接
+	S_pic    string `json:"s_pic"`    //广告位弹窗
+	S_remark string `json:"s_remark"` //备注
+	S_picalt string `json:"s_picalt"` //图片ALT
+	S_id     string `json:"s_id"`     //广告标识id
+	O_extend struct {
+		Linktype  string `json:"linktype"`  //是否外部链接
+		Height    string `json:"height"`    //高度
+		Width     string `json:"width"`     //宽度
+		StartTime string `json:"startTime"` //开始时间
+		EndTime   string `json:"endTime"`   //结束时间
+		IosHref   string `json:"iosHref"`   //根据客户端不同 是否访问不同地址
+		Theme     string `json:"theme"`     // 主题样式
+		Title     string `json:"title"`     //标题
+		Power     string `json:"power"`     // 权限判断
+		Tab       string `json:"tab"`       // tab切换
+	} `json:"o_extend"` //拓展属性
+	S_script string `json:"s_script"` //脚本
+}
+
+// Handle 广告位信息处理
+func Handle(data []interface{}, host string) []AdInfo {
+	var res = []AdInfo{}
+	if len(data) > 0 {
+		AdInfo_Arr := []AdInfo{}
+		bytes, err := json.Marshal(data)
+		if err != nil {
+			return res
+		}
+		json.Unmarshal(bytes, &AdInfo_Arr)
+		if len(AdInfo_Arr) > 0 {
+			now := time.Now()
+			for _, v := range AdInfo_Arr {
+				//log.Println(v.S_id, "---", host, "----", strings.Contains(host, v.S_id))
+				if v.S_id != "" && host != "" {
+					//根据不同环境区分广告位信息 v.S_id 填充内容, 例:app-i2;app-a1
+					if !strings.Contains(host, v.S_id) {
+						continue
+					}
+				}
+				if v.O_extend.StartTime != "" && len(strings.Split(v.O_extend.StartTime, "-")) == 6 {
+					if thisTime, err := time.ParseInLocation("2006-01-02-15-04-05", v.O_extend.StartTime, time.Local); err == nil {
+						//广告还未开始
+						if thisTime.Unix() > now.Unix() {
+							continue
+						}
+					}
+				}
+				if v.O_extend.EndTime != "" && len(strings.Split(v.O_extend.EndTime, "-")) == 6 {
+					if thisTime, err := time.ParseInLocation("2006-01-02-15-04-05", v.O_extend.EndTime, time.Local); err == nil {
+						//广告已经结束
+						if thisTime.Unix() < now.Unix() {
+							continue
+						}
+					}
+				}
+				res = append(res, v)
+			}
+		}
+	}
+	return res
+}

+ 2 - 2
src/service/config/config.go → service/config/config.go

@@ -1,7 +1,7 @@
 package config
 
 import (
-	"qfw/util"
+	qutil "app.yhyue.com/moapp/jybase/common"
 )
 
 type config struct {
@@ -14,5 +14,5 @@ var (
 )
 
 func init() {
-	util.ReadConfig(&Sysconfig)
+	qutil.ReadConfig(&Sysconfig)
 }

+ 0 - 16
src/main.go

@@ -1,16 +0,0 @@
-package main
-
-import (
-	"net/http"
-	_ "service/a"
-	_ "service/action"
-	"service/config"
-	_ "service/filter"
-
-	"github.com/go-xweb/xweb"
-)
-
-func main() {
-	mux1 := http.NewServeMux()
-	xweb.RunBase(":"+config.Sysconfig.Webport, mux1)
-}

+ 0 - 35
src/service/action/customer.go

@@ -1,35 +0,0 @@
-package action
-
-import (
-	qu "qfw/util"
-	"service/config"
-
-	"github.com/go-xweb/xweb"
-)
-
-type Action struct {
-	*xweb.Action
-	info xweb.Mapper `xweb:"/customer/info"`
-}
-
-func init() {
-	xweb.AddAction(&Action{})
-}
-
-func (a *Action) Info() {
-	module := a.GetString("module")
-	data := config.Sysconfig.Info[module]
-	ret := map[string]interface{}{
-		"data":       nil,
-		"error_msg":  "暂未找到模块",
-		"erros_code": -1,
-	}
-	if data != nil {
-		ret = map[string]interface{}{
-			"data":       qu.ObjToMap(data),
-			"error_msg":  "",
-			"erros_code": 0,
-		}
-	}
-	a.ServeJson(ret)
-}

+ 0 - 7
src/service/filter/filter.go

@@ -1,7 +0,0 @@
-package filter
-
-import "github.com/go-xweb/xweb"
-
-func init() {
-	xweb.AddFilter(&sessionfilter{App: xweb.RootApp()})
-}

+ 0 - 22
src/service/filter/sessionfilter.go

@@ -1,22 +0,0 @@
-package filter
-
-import (
-	"net/http"
-
-	"github.com/go-xweb/xweb"
-)
-
-//登录限制
-type sessionfilter struct {
-	App *xweb.App
-}
-
-//继承过滤器方法
-func (l *sessionfilter) Do(w http.ResponseWriter, req *http.Request) bool {
-	//session := l.App.SessionManager.Session(req, w)
-	//if session.Get("userId") == nil {
-	//	R.ServeJson(w, req, &Result{Error_code_1001, Error_msg_1001, nil})
-	//	return false
-	//}
-	return true
-}