123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- package model
- import (
- "encoding/json"
- "strconv"
- xtime "go-common/library/time"
- )
- // Banners struct
- type Banners struct {
- Banner map[int][]*Banner
- Version string
- }
- // Banner struct
- type Banner struct {
- ID int `json:"id"`
- ParentID int `json:"-"`
- Plat int8 `json:"-"`
- Module string `json:"-"`
- Position string `json:"-"`
- Title string `json:"title"`
- Image string `json:"image"`
- Hash string `json:"hash"`
- URI string `json:"uri"`
- Goto string `json:"-"`
- Value string `json:"-"`
- Param string `json:"-"`
- Channel string `json:"-"`
- Build int `json:"-"`
- Condition string `json:"-"`
- Area string `json:"-"`
- Rank int `json:"-"`
- Rule string `json:"-"`
- Type int8 `json:"-"`
- Start xtime.Time `json:"stime"`
- End xtime.Time `json:"-"`
- MTime xtime.Time `json:"-"`
- ResourceID int `json:"resource_id"`
- RequestId string `json:"request_id,omitempty"`
- CreativeId int `json:"creative_id,omitempty"`
- SrcId int `json:"src_id,omitempty"`
- IsAd bool `json:"is_ad"`
- IsAdReplace bool `json:"-"`
- IsAdLoc bool `json:"is_ad_loc,omitempty"`
- CmMark int `json:"cm_mark"`
- AdCb string `json:"ad_cb,omitempty"`
- ShowUrl string `json:"show_url,omitempty"`
- ClickUrl string `json:"click_url,omitempty"`
- ClientIp string `json:"client_ip,omitempty"`
- Index int `json:"index"`
- ServerType int `json:"server_type"`
- Extra json.RawMessage `json:"extra"`
- CreativeType int `json:"creative_type"`
- }
- // JSONBanner bilibili_assignment rule
- type JSONBanner struct {
- Area string `json:"area"`
- Hash string `json:"hash"`
- Build int `json:"build"`
- Condition string `json:"cond"`
- Channel string `json:"channel"`
- CreativeType int `json:"creative_type"`
- }
- // Limit limit
- type Limit struct {
- Rule string `json:"-"`
- }
- // JSONLimit limit
- type JSONLimit struct {
- Limit int `json:"limit"`
- Resrc []string `json:"resrc"`
- }
- // BannerChange change banner
- func (b *Banner) BannerChange() {
- var tmp *JSONBanner
- if err := json.Unmarshal([]byte(b.Rule), &tmp); err == nil {
- b.Area = tmp.Area
- b.Build = tmp.Build
- b.Condition = tmp.Condition
- if tmp.Channel == "" {
- b.Channel = "*"
- } else {
- b.Channel = tmp.Channel
- }
- b.Hash = tmp.Hash
- b.CreativeType = tmp.CreativeType
- }
- switch b.Plat {
- case 1: // resource iphone
- b.Plat = PlatIPhone
- case 2: // resource android
- b.Plat = PlatAndroid
- case 3: // resource pad
- b.Plat = PlatIPad
- case 4: // resource iphoneg
- b.Plat = PlatIPhoneI
- case 5: // resource androidg
- b.Plat = PlatAndroidG
- case 6: // resource padg
- b.Plat = PlatIPadI
- case 8: // resource androidi
- b.Plat = PlatAndroidI
- }
- if b.Value == "" {
- return
- }
- switch b.Type {
- case 7:
- if b.Plat == PlatIPhone || b.Plat == PlatAndroid || b.Plat == PlatIPad || b.Plat == PlatIPhoneI || b.Plat == PlatAndroidG || b.Plat == PlatIPadI || b.Plat == PlatAndroidI {
- b.URI = "bilibili://pegasus/channel/" + b.Value + "/"
- } else {
- b.URI = "http://www.bilibili.com/tag/" + b.Value
- }
- case 6:
- //GotoAv
- b.URI = "bilibili://video/" + b.Value
- case 4:
- //GotoLive
- if b.Plat == PlatIPad {
- b.URI = "bilibili://player/live/" + b.Value
- } else {
- b.URI = "bilibili://live/" + b.Value
- }
- case 3:
- //GotoBangumi
- b.URI = "bilibili://bangumi/season/" + b.Value
- case 5:
- //GotoGame
- b.URI = "bilibili://game/" + b.Value
- case 2:
- //GotoWeb
- b.URI = b.Value
- }
- }
- // LimitChange change limit
- func (l *Limit) LimitChange() (data map[int]int) {
- data = map[int]int{}
- var (
- tmp = &JSONLimit{}
- err error
- resid int
- )
- if err = json.Unmarshal([]byte(l.Rule), tmp); err != nil {
- return
- }
- l.Rule = ""
- for _, residstr := range tmp.Resrc {
- resid, err = strconv.Atoi(residstr)
- if err != nil {
- return
- }
- data[resid] = tmp.Limit
- }
- return
- }
|