浏览代码

wip:p540 留资配置文案

fuwencai 7 月之前
父节点
当前提交
5247926138
共有 4 个文件被更改,包括 138 次插入1 次删除
  1. 64 0
      src/entity/copywritingConfig.go
  2. 7 1
      src/filter/sessionfilter.go
  3. 39 0
      src/service/action/copywritingConfig.go
  4. 28 0
      src/test/p540.http

+ 64 - 0
src/entity/copywritingConfig.go

@@ -0,0 +1,64 @@
+package entity
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/redis"
+	"errors"
+	"fmt"
+	. "salesLeads/src/config"
+	"strings"
+)
+
+const (
+	saleLeadConfigCacheKey   = "saleLeadConfig_%s"
+	saleLeadConfigCacheRedis = "newother"
+)
+
+// GetConfig 查询留资文案配置
+func GetConfig(codes []string) (configData map[string]interface{}) {
+	configData = map[string]interface{}{}
+	args := []string{}
+	selectCode := []interface{}{}
+	for i := 0; i < len(codes); i++ {
+		// 查缓存
+		content := redis.Get(saleLeadConfigCacheRedis, fmt.Sprintf(saleLeadConfigCacheKey, codes[i]))
+		if content != nil {
+			cMap := common.ObjToMap(content)
+			if cMap != nil && len(*cMap) > 0 {
+				configData[codes[i]] = *cMap
+			} else {
+				args = append(args, "?")
+				selectCode = append(selectCode, codes[i])
+			}
+		} else {
+			args = append(args, "?")
+			selectCode = append(selectCode, codes[i])
+		}
+	}
+	q := fmt.Sprintf("select `code`,title,subtitle,button_confirm,button_cancel from sales_leads_config where `code` in (%s)", strings.Join(args, ","))
+	rs := Mysql.SelectBySql(q, selectCode...)
+	// 格式化
+	if rs != nil && len(*rs) > 0 {
+		for i := 0; i < len(*rs); i++ {
+			code := common.ObjToString((*rs)[i]["code"])
+			tmp := map[string]interface{}{
+				"title":          common.ObjToString((*rs)[i]["title"]),
+				"subtitle":       common.ObjToString((*rs)[i]["subtitle"]),
+				"button_confirm": common.ObjToString((*rs)[i]["button_confirm"]),
+				"button_cancel":  common.ObjToString((*rs)[i]["button_cancel"]),
+			}
+			configData[code] = tmp
+			redis.Put(saleLeadConfigCacheRedis, fmt.Sprintf(saleLeadConfigCacheKey, codes[i]), tmp, -1)
+		}
+	}
+	return
+}
+
+// DelConfig 删除留资文案配置
+func DelConfig(codes string) error {
+	if redis.Del(saleLeadConfigCacheRedis, fmt.Sprintf(saleLeadConfigCacheKey, codes)) {
+		return nil
+	} else {
+		return errors.New("删除失败")
+	}
+}

+ 7 - 1
src/filter/sessionfilter.go

@@ -21,7 +21,13 @@ func (l *sessionfilter) Do(w http.ResponseWriter, req *http.Request) bool {
 	if strings.Contains(rul, "/salesLeads/official/notLogin") {
 		return true
 	}
-	if strings.Contains(rul, "/salesLeads/sampleReport") {
+	if strings.Contains(rul, "/salesLeads/official/notLogin") {
+		return true
+	}
+	if strings.Contains(rul, "/salesLeads/getConfig") {
+		return true
+	}
+	if strings.Contains(rul, "/salesLeads/delCache") {
 		return true
 	}
 	if session.Get("userId") == nil {

+ 39 - 0
src/service/action/copywritingConfig.go

@@ -0,0 +1,39 @@
+package action
+
+import (
+	"app.yhyue.com/moapp/jybase/api"
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"encoding/json"
+	"salesLeads/src/entity"
+)
+
+type Config struct {
+	*xweb.Action
+	getConfig xweb.Mapper `xweb:"/getConfig"`     //获取留资信息
+	delConfig xweb.Mapper `xweb:"/delCache/(.*)"` //清除留资缓存配置
+}
+
+func init() {
+	xweb.AddAction(&Config{})
+}
+
+type RequestMsg struct {
+	Codes []string `json:"codes"` // 留资source
+}
+
+func (c *Config) GetConfig() {
+	defer common.Catch()
+	reqMsg := new(RequestMsg)
+	if json.Unmarshal(c.Body(), &reqMsg) == nil && len(reqMsg.Codes) > 0 {
+		codes := entity.GetConfig(reqMsg.Codes)
+		c.ServeJson(api.Result{Data: codes})
+		return
+	}
+	c.ServeJson(api.Result{Data: map[string]interface{}{}})
+}
+
+func (c *Config) DelConfig(code string) {
+	defer common.Catch()
+	c.ServeJson(api.NewResult(nil, entity.DelConfig(code)))
+}

+ 28 - 0
src/test/p540.http

@@ -0,0 +1,28 @@
+POST http://localhost:8881/salesLeads/getConfig
+Content-Type: application/json
+
+{
+  "codes": ["jylab_see500_plus","source_code2"]
+}
+
+###
+#{
+#  "error_code": 0,
+#  "error_msg": "",
+#  "data": {
+#    "source_code1":
+#      {
+#        "title": "这是一个标题文案1",
+#        "subtitle": "这是一个副标题文案2",
+#      },
+#    "source_code2":
+#      {
+#        "title": "这是一个标题文案2",
+#        "subtitle": "这是一个副标题文案2",
+#      }
+#}
+#}
+###
+POST http://localhost:8881/salesLeads/delCache/jylab_see500_plus
+Content-Type: application/json
+