|
@@ -1,37 +1,39 @@
|
|
|
package util
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
- "fmt"
|
|
|
- "jy/src/jfw/modules/publicapply/src/config"
|
|
|
- "jy/src/jfw/modules/publicapply/src/db"
|
|
|
- "regexp"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/config"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/db"
|
|
|
+ "net/http"
|
|
|
+ "regexp"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- . "app.yhyue.com/moapp/jybase/date"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
)
|
|
|
|
|
|
var ClearHtml = regexp.MustCompile("<[^>]*>")
|
|
|
|
|
|
-//加密
|
|
|
+// 加密
|
|
|
func EncodeId(sid string) string {
|
|
|
- if sid == "" {
|
|
|
- return ""
|
|
|
- }
|
|
|
- return encrypt.EncodeArticleId2ByCheck(sid)
|
|
|
+ if sid == "" {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ return encrypt.EncodeArticleId2ByCheck(sid)
|
|
|
}
|
|
|
|
|
|
-//解密
|
|
|
+// 解密
|
|
|
func DecodeId(eid string) string {
|
|
|
- if eid == "" {
|
|
|
- return ""
|
|
|
- }
|
|
|
- return encrypt.CommonDecodeArticle("content", eid)[0]
|
|
|
+ if eid == "" {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ return encrypt.CommonDecodeArticle("content", eid)[0]
|
|
|
}
|
|
|
|
|
|
//收藏列表
|
|
@@ -43,231 +45,249 @@ func DecodeId(eid string) string {
|
|
|
开始时间-结束时间:1622476800-1623859200
|
|
|
*/
|
|
|
type CollList struct {
|
|
|
- Pagenum int `json:"pagenum"` //页数
|
|
|
- Label string `json:"label"` //标签 用,分隔开
|
|
|
- SelectTime string `json:"selectTime"` //收藏时间
|
|
|
- Buyerclass string `json:"buyerclass"` //采购单位 用,分隔开
|
|
|
- BuyerPhone int `json:"buyerPhone"` //是否需要采购单位联系方式 1:需要 -1:不需要 0:未选中
|
|
|
- WinnerPhone int `json:"winnerPhone"` //是否需要中标单位联系方式 1:需要 -1:不需要 0:未选中
|
|
|
- Pagesize int `json:"pagesize"` //每页展示数量
|
|
|
+ Pagenum int `json:"pagenum"` //页数
|
|
|
+ Label string `json:"label"` //标签 用,分隔开
|
|
|
+ SelectTime string `json:"selectTime"` //收藏时间
|
|
|
+ Buyerclass string `json:"buyerclass"` //采购单位 用,分隔开
|
|
|
+ BuyerPhone int `json:"buyerPhone"` //是否需要采购单位联系方式 1:需要 -1:不需要 0:未选中
|
|
|
+ WinnerPhone int `json:"winnerPhone"` //是否需要中标单位联系方式 1:需要 -1:不需要 0:未选中
|
|
|
+ Pagesize int `json:"pagesize"` //每页展示数量
|
|
|
}
|
|
|
|
|
|
-//搜藏列表
|
|
|
+// 搜藏列表
|
|
|
func CollListSql(c *CollList, isPay bool, userid string) string {
|
|
|
- sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, db.DbConf.Bdcollection, userid)
|
|
|
- limit := config.BidCollConfig.FreeUserCollLimit
|
|
|
- //个人标签
|
|
|
- if c.Label != "" {
|
|
|
- i := 0
|
|
|
- sql += ` and `
|
|
|
- if labelArr := strings.Split(c.Label, ","); len(labelArr) > 0 {
|
|
|
- sql += `(`
|
|
|
- for _, v := range labelArr {
|
|
|
- i++
|
|
|
- labid := encrypt.SE.DecodeString(v)
|
|
|
- if i == len(labelArr) {
|
|
|
- sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid)`, labid)
|
|
|
- } else {
|
|
|
- sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid) or `, labid)
|
|
|
- }
|
|
|
- }
|
|
|
- sql += `)`
|
|
|
- }
|
|
|
- }
|
|
|
- now := time.Now()
|
|
|
- start, end := "", ""
|
|
|
- //收藏时间
|
|
|
- if c.SelectTime == "lately-7" { //最近7天
|
|
|
- start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
- } else if c.SelectTime == "lately-30" { //最近30天
|
|
|
- start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
- } else if c.SelectTime == "thisyear" { //去年
|
|
|
- start = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
- end = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Format(Date_Full_Layout))
|
|
|
- } else if len(strings.Split(c.SelectTime, "_")) == 2 {
|
|
|
- if c.SelectTime != "0_0" {
|
|
|
- starttime := strings.Split(c.SelectTime, "_")[0]
|
|
|
- startstamp, _ := strconv.Atoi(starttime)
|
|
|
- start = time.Unix(int64(startstamp), 0).Format(Date_Full_Layout)
|
|
|
- endtime := strings.Split(c.SelectTime, "_")[1]
|
|
|
- et, _ := strconv.ParseInt(endtime, 0, 64)
|
|
|
- etTime := time.Unix(et, 0)
|
|
|
- end = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
- }
|
|
|
- }
|
|
|
- if start != "" && end != "" {
|
|
|
- sql += ` and createdate >= '` + start + `' and createdate < '` + end + `'`
|
|
|
- } else if start != "" && end == "" {
|
|
|
- sql += ` and createdate >= '` + start + `'`
|
|
|
- } else if start == "" && end != "" {
|
|
|
- sql += ` and createdate < '` + end + `'`
|
|
|
- }
|
|
|
- if isPay {
|
|
|
+ sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, db.DbConf.Bdcollection, userid)
|
|
|
+ limit := config.BidCollConfig.FreeUserCollLimit
|
|
|
+ //个人标签
|
|
|
+ if c.Label != "" {
|
|
|
+ i := 0
|
|
|
+ sql += ` and `
|
|
|
+ if labelArr := strings.Split(c.Label, ","); len(labelArr) > 0 {
|
|
|
+ sql += `(`
|
|
|
+ for _, v := range labelArr {
|
|
|
+ i++
|
|
|
+ labid := encrypt.SE.DecodeString(v)
|
|
|
+ if i == len(labelArr) {
|
|
|
+ sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid)`, labid)
|
|
|
+ } else {
|
|
|
+ sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid) or `, labid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sql += `)`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ now := time.Now()
|
|
|
+ start, end := "", ""
|
|
|
+ //收藏时间
|
|
|
+ if c.SelectTime == "lately-7" { //最近7天
|
|
|
+ start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
+ } else if c.SelectTime == "lately-30" { //最近30天
|
|
|
+ start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
+ } else if c.SelectTime == "thisyear" { //去年
|
|
|
+ start = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
+ end = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Format(Date_Full_Layout))
|
|
|
+ } else if len(strings.Split(c.SelectTime, "_")) == 2 {
|
|
|
+ if c.SelectTime != "0_0" {
|
|
|
+ starttime := strings.Split(c.SelectTime, "_")[0]
|
|
|
+ startstamp, _ := strconv.Atoi(starttime)
|
|
|
+ start = time.Unix(int64(startstamp), 0).Format(Date_Full_Layout)
|
|
|
+ endtime := strings.Split(c.SelectTime, "_")[1]
|
|
|
+ et, _ := strconv.ParseInt(endtime, 0, 64)
|
|
|
+ etTime := time.Unix(et, 0)
|
|
|
+ end = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if start != "" && end != "" {
|
|
|
+ sql += ` and createdate >= '` + start + `' and createdate < '` + end + `'`
|
|
|
+ } else if start != "" && end == "" {
|
|
|
+ sql += ` and createdate >= '` + start + `'`
|
|
|
+ } else if start == "" && end != "" {
|
|
|
+ sql += ` and createdate < '` + end + `'`
|
|
|
+ }
|
|
|
+ if isPay {
|
|
|
|
|
|
- //采购单位 用,分隔开
|
|
|
- if c.Buyerclass != "" {
|
|
|
- i := 0
|
|
|
- sql += ` and buyerclass in (`
|
|
|
- if buyClassArr := strings.Split(c.Buyerclass, ","); len(buyClassArr) > 0 {
|
|
|
- for _, v := range buyClassArr {
|
|
|
- i++
|
|
|
- buyerclassid := fmt.Sprint(jy.PushMapping.Buyerclass[v])
|
|
|
- if i == len(buyClassArr) {
|
|
|
- sql += buyerclassid + `)`
|
|
|
- } else {
|
|
|
- sql += buyerclassid + ","
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //是否存在采购单位电话
|
|
|
- if c.BuyerPhone == 1 {
|
|
|
- sql += ` and buyerinfo = 1`
|
|
|
- } else if c.BuyerPhone == -1 {
|
|
|
- sql += ` and buyerinfo = 0`
|
|
|
- }
|
|
|
- //是否存在中标单位电话
|
|
|
- if c.WinnerPhone == 1 {
|
|
|
- sql += ` and winnerinfo = 1`
|
|
|
- } else if c.WinnerPhone == -1 {
|
|
|
- sql += ` and winnerinfo = 0`
|
|
|
- }
|
|
|
- limit = config.BidCollConfig.PayUserCollLimit
|
|
|
- }
|
|
|
- sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
|
|
|
- return sql
|
|
|
+ //采购单位 用,分隔开
|
|
|
+ if c.Buyerclass != "" {
|
|
|
+ i := 0
|
|
|
+ sql += ` and buyerclass in (`
|
|
|
+ if buyClassArr := strings.Split(c.Buyerclass, ","); len(buyClassArr) > 0 {
|
|
|
+ for _, v := range buyClassArr {
|
|
|
+ i++
|
|
|
+ buyerclassid := fmt.Sprint(jy.PushMapping.Buyerclass[v])
|
|
|
+ if i == len(buyClassArr) {
|
|
|
+ sql += buyerclassid + `)`
|
|
|
+ } else {
|
|
|
+ sql += buyerclassid + ","
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //是否存在采购单位电话
|
|
|
+ if c.BuyerPhone == 1 {
|
|
|
+ sql += ` and buyerinfo = 1`
|
|
|
+ } else if c.BuyerPhone == -1 {
|
|
|
+ sql += ` and buyerinfo = 0`
|
|
|
+ }
|
|
|
+ //是否存在中标单位电话
|
|
|
+ if c.WinnerPhone == 1 {
|
|
|
+ sql += ` and winnerinfo = 1`
|
|
|
+ } else if c.WinnerPhone == -1 {
|
|
|
+ sql += ` and winnerinfo = 0`
|
|
|
+ }
|
|
|
+ limit = config.BidCollConfig.PayUserCollLimit
|
|
|
+ }
|
|
|
+ sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
|
|
|
+ return sql
|
|
|
}
|
|
|
|
|
|
func ConfirmIntArr(arr []interface{}) []int {
|
|
|
- tmp := make([]int, 0)
|
|
|
- for _, v := range arr {
|
|
|
- tmp = append(tmp, qutil.IntAll(v))
|
|
|
- }
|
|
|
- return tmp
|
|
|
+ tmp := make([]int, 0)
|
|
|
+ for _, v := range arr {
|
|
|
+ tmp = append(tmp, qutil.IntAll(v))
|
|
|
+ }
|
|
|
+ return tmp
|
|
|
}
|
|
|
|
|
|
-//判断同一个数组是否重复
|
|
|
+// 判断同一个数组是否重复
|
|
|
func IsRepeat(slice1 []string) bool {
|
|
|
- m := make(map[string]int)
|
|
|
- for _, v := range slice1 {
|
|
|
- m[v]++
|
|
|
- if m[v] > 1 {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
+ m := make(map[string]int)
|
|
|
+ for _, v := range slice1 {
|
|
|
+ m[v]++
|
|
|
+ if m[v] > 1 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
-//判断数组是否包含
|
|
|
+// 判断数组是否包含
|
|
|
func IsContain(slice []string, s string) bool {
|
|
|
- for _, qq := range slice {
|
|
|
- if qq == s {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
+ for _, qq := range slice {
|
|
|
+ if qq == s {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
// jsonStr转map
|
|
|
func JsonToMap(jsonStr string) (map[string]interface{}, error) {
|
|
|
- m := map[string]interface{}{}
|
|
|
- err := json.Unmarshal([]byte(jsonStr), &m)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Unmarshal with error: %+v\n", err)
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- return m, nil
|
|
|
+ m := map[string]interface{}{}
|
|
|
+ err := json.Unmarshal([]byte(jsonStr), &m)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("Unmarshal with error: %+v\n", err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return m, nil
|
|
|
}
|
|
|
|
|
|
-//判断stringArr相等方法
|
|
|
+// 判断stringArr相等方法
|
|
|
func StringArrEqual(a, b []string) bool {
|
|
|
- if (len(a) == 0) != (len(b) == 0) {
|
|
|
- return false
|
|
|
- }
|
|
|
- if len(a) != len(b) {
|
|
|
- return false
|
|
|
- }
|
|
|
- for i := range a {
|
|
|
- if a[i] != b[i] {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
- return true
|
|
|
+ if (len(a) == 0) != (len(b) == 0) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if len(a) != len(b) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ for i := range a {
|
|
|
+ if a[i] != b[i] {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
-//获取频次信息:fre="周-1"(每周周一);"天-3":每三天一个周期;"日-3":每天三点;
|
|
|
+// 获取频次信息:fre="周-1"(每周周一);"天-3":每三天一个周期;"日-3":每天三点;
|
|
|
func GetFrequencyInfo(fre string) (string, bool, int) {
|
|
|
- if fre != "" && len(strings.Split(fre, "-")) > 1 {
|
|
|
- f := strings.Split(fre, "-")[0]
|
|
|
- d, _ := strconv.Atoi(strings.Split(fre, "-")[1])
|
|
|
- switch f {
|
|
|
- case "月":
|
|
|
- day := time.Now().Day()
|
|
|
- return fmt.Sprintf("nps_%s", time.Now().Month().String()), day == d, 31 * 24 * 60 * 60
|
|
|
- case "周":
|
|
|
- mi := ConvertWeekday(time.Now().Weekday().String())
|
|
|
- return fmt.Sprintf("nps_%s", WeekByDate(time.Now())), mi == d, 7 * 24 * 60 * 60
|
|
|
- case "日":
|
|
|
- day := time.Now().Day()
|
|
|
- hour := time.Now().Hour()
|
|
|
- return fmt.Sprintf("nps_%s", strconv.Itoa(day)), hour == d, 24 * 60 * 60
|
|
|
- case "天":
|
|
|
- return fmt.Sprintf("nps_%s", strings.Split(fre, "-")[1]), true, d * 24 * 60 * 60
|
|
|
- }
|
|
|
- }
|
|
|
- return "", false, 0
|
|
|
+ if fre != "" && len(strings.Split(fre, "-")) > 1 {
|
|
|
+ f := strings.Split(fre, "-")[0]
|
|
|
+ d, _ := strconv.Atoi(strings.Split(fre, "-")[1])
|
|
|
+ switch f {
|
|
|
+ case "月":
|
|
|
+ day := time.Now().Day()
|
|
|
+ return fmt.Sprintf("nps_%s", time.Now().Month().String()), day == d, 31 * 24 * 60 * 60
|
|
|
+ case "周":
|
|
|
+ mi := ConvertWeekday(time.Now().Weekday().String())
|
|
|
+ return fmt.Sprintf("nps_%s", WeekByDate(time.Now())), mi == d, 7 * 24 * 60 * 60
|
|
|
+ case "日":
|
|
|
+ day := time.Now().Day()
|
|
|
+ hour := time.Now().Hour()
|
|
|
+ return fmt.Sprintf("nps_%s", strconv.Itoa(day)), hour == d, 24 * 60 * 60
|
|
|
+ case "天":
|
|
|
+ return fmt.Sprintf("nps_%s", strings.Split(fre, "-")[1]), true, d * 24 * 60 * 60
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "", false, 0
|
|
|
}
|
|
|
|
|
|
-//获取当年第几周
|
|
|
+// 获取当年第几周
|
|
|
func WeekByDate(t time.Time) string {
|
|
|
- yearDay := t.YearDay()
|
|
|
- yearFirstDay := t.AddDate(0, 0, -yearDay+1)
|
|
|
- firstDayInWeek := int(yearFirstDay.Weekday())
|
|
|
+ yearDay := t.YearDay()
|
|
|
+ yearFirstDay := t.AddDate(0, 0, -yearDay+1)
|
|
|
+ firstDayInWeek := int(yearFirstDay.Weekday())
|
|
|
|
|
|
- //今年第一周有几天
|
|
|
- firstWeekDays := 1
|
|
|
- if firstDayInWeek != 0 {
|
|
|
- firstWeekDays = 7 - firstDayInWeek + 1
|
|
|
- }
|
|
|
- var week int
|
|
|
- if yearDay <= firstWeekDays {
|
|
|
- week = 1
|
|
|
- } else {
|
|
|
- week = (yearDay-firstWeekDays)/7 + 2
|
|
|
- }
|
|
|
- return fmt.Sprintf("%d-%d", t.Year(), week)
|
|
|
+ //今年第一周有几天
|
|
|
+ firstWeekDays := 1
|
|
|
+ if firstDayInWeek != 0 {
|
|
|
+ firstWeekDays = 7 - firstDayInWeek + 1
|
|
|
+ }
|
|
|
+ var week int
|
|
|
+ if yearDay <= firstWeekDays {
|
|
|
+ week = 1
|
|
|
+ } else {
|
|
|
+ week = (yearDay-firstWeekDays)/7 + 2
|
|
|
+ }
|
|
|
+ return fmt.Sprintf("%d-%d", t.Year(), week)
|
|
|
}
|
|
|
|
|
|
func ConvertWeekday(weekday string) int {
|
|
|
- _weekday := 0
|
|
|
- if weekday == "Sunday" {
|
|
|
- _weekday = 7
|
|
|
- } else if weekday == "Monday" {
|
|
|
- _weekday = 1
|
|
|
- } else if weekday == "Tuesday" {
|
|
|
- _weekday = 2
|
|
|
- } else if weekday == "Wednesday" {
|
|
|
- _weekday = 3
|
|
|
- } else if weekday == "Thursday" {
|
|
|
- _weekday = 4
|
|
|
- } else if weekday == "Friday" {
|
|
|
- _weekday = 5
|
|
|
- } else if weekday == "Saturday" {
|
|
|
- _weekday = 6
|
|
|
- }
|
|
|
- return _weekday
|
|
|
+ _weekday := 0
|
|
|
+ if weekday == "Sunday" {
|
|
|
+ _weekday = 7
|
|
|
+ } else if weekday == "Monday" {
|
|
|
+ _weekday = 1
|
|
|
+ } else if weekday == "Tuesday" {
|
|
|
+ _weekday = 2
|
|
|
+ } else if weekday == "Wednesday" {
|
|
|
+ _weekday = 3
|
|
|
+ } else if weekday == "Thursday" {
|
|
|
+ _weekday = 4
|
|
|
+ } else if weekday == "Friday" {
|
|
|
+ _weekday = 5
|
|
|
+ } else if weekday == "Saturday" {
|
|
|
+ _weekday = 6
|
|
|
+ }
|
|
|
+ return _weekday
|
|
|
}
|
|
|
|
|
|
-//map转结构体
|
|
|
+// map转结构体
|
|
|
func JsonUnmarshal(m interface{}, s interface{}) interface{} {
|
|
|
- var b []byte
|
|
|
- if v, ok := m.(string); ok {
|
|
|
- b = []byte(v)
|
|
|
- } else if v, ok := m.([]byte); ok {
|
|
|
- b = v
|
|
|
- } else {
|
|
|
- b, _ = json.Marshal(m)
|
|
|
- }
|
|
|
- json.Unmarshal(b, &s)
|
|
|
- return s
|
|
|
+ var b []byte
|
|
|
+ if v, ok := m.(string); ok {
|
|
|
+ b = []byte(v)
|
|
|
+ } else if v, ok := m.([]byte); ok {
|
|
|
+ b = v
|
|
|
+ } else {
|
|
|
+ b, _ = json.Marshal(m)
|
|
|
+ }
|
|
|
+ json.Unmarshal(b, &s)
|
|
|
+ return s
|
|
|
+}
|
|
|
+
|
|
|
+// SetCookieValue 更新cookie信息
|
|
|
+func SetCookieValue(rw http.ResponseWriter, name, val string, timeOut int) {
|
|
|
+ http.SetCookie(rw, func() *http.Cookie {
|
|
|
+ maxAge := timeOut //单位秒
|
|
|
+ expires := time.Now().Add(time.Duration(timeOut) * time.Second)
|
|
|
+ cookie := &http.Cookie{
|
|
|
+ Name: name,
|
|
|
+ Value: val,
|
|
|
+ Path: "/",
|
|
|
+ HttpOnly: false,
|
|
|
+ MaxAge: maxAge,
|
|
|
+ Expires: expires,
|
|
|
+ Domain: httpsession.Domain,
|
|
|
+ }
|
|
|
+ return cookie
|
|
|
+ }())
|
|
|
}
|