|
@@ -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("删除失败")
|
|
|
+ }
|
|
|
+}
|