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 }