Skip to content

Commit

Permalink
Merge branch 'release/v1.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Apr 28, 2024
2 parents b3853b8 + 72acfe2 commit 71164ee
Show file tree
Hide file tree
Showing 20 changed files with 568 additions and 1 deletion.
22 changes: 22 additions & 0 deletions enum/audienceStatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package enum

// AudienceStatusEnum 类型
type AudienceStatus Enum[int]

func (e AudienceStatus) Values() []AudienceStatus {
return []AudienceStatus{
{0, "基本属性"},
{1, "自定义人群"},
{1025, "已转化用户"},
{2, "设备属性"},
{4, "商圈地域"},
}
}
func (e *AudienceStatus) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = AudienceStatus(v)
return nil
}
21 changes: 21 additions & 0 deletions enum/bsType.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package enum

// BsType 该字段仅支持用于Filter中筛选数据使用。
type BsType Enum[int]

func (e BsType) Values() []BsType {
return []BsType{
{1, "通报告"},
{3, "商品报告"},
{7, "信息流RTA"},
}
}

func (e *BsType) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = BsType(v)
return nil
}
27 changes: 27 additions & 0 deletions enum/deepConvertType.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package enum

// DeepConvertType 深度转化
type DeepConvertType Enum[int]

func (e DeepConvertType) Values() []DeepConvertType {
return []DeepConvertType{
{10, "商品支付成功"},
{25, "注册"},
{26, "付费"},
{27, "客户自定义"},
{28, "次日留存"},
{42, "授信"},
{45, "商品下单成功"},
{53, "订单核对成功"},
{54, "收货成功"},
}
}

func (e *DeepConvertType) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = DeepConvertType(v)
return nil
}
21 changes: 21 additions & 0 deletions enum/device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package enum

// Device 推广设备
type Device Enum[int]

func (e Device) Values() []Device {
return []Device{
{0, "计算机"},
{1, "移动设备"},
}
}

// UnmarshalJSON implement json Unmarshal interface
func (e *Device) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = Device(v)
return nil
}
78 changes: 78 additions & 0 deletions enum/enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package enum

import (
"strconv"
)

type Enum[T int | int64] struct {
key T
value string
}

func EnumFromKey[T int | int64](key T) Enum[T] {
return Enum[T]{key: key}
}

func (e Enum[T]) Key() T {
return e.key
}

func (e Enum[T]) Value() string {
return e.value
}

func (e Enum[T]) String() string {
return e.value
}

func (e *Enum[T]) SetKey(key T) {
e.key = key
}

func (e *Enum[T]) SetValue(value string) {
e.value = value
}

func (e Enum[T]) Values() []Enum[T] {
return nil
}

type IEnum[T int | int64] interface {
Values() []Enum[T]
Key() T
Value() string
}

// UnmarshalJSON implement json Unmarshal interface
func UnmarshalJSON[T int | int64](b []byte) (Enum[T], error) {
if b[0] == '"' && b[len(b)-1] == '"' {
b = b[1 : len(b)-1]
}
str := string(b)
var x Enum[T]
values := x.Values()
var found bool
if i, err := strconv.ParseInt(str, 10, 64); err != nil {
for _, val := range values {
if val.Value() == str {
x = val
found = true
break
}
}
} else {
key := T(i)
for _, val := range values {
if val.Key() == key {
x = val
found = true
break
}
}
}
if !found {
(&x).SetKey(-1)
(&x).SetValue(str)
}
return x, nil
}
24 changes: 24 additions & 0 deletions enum/feedFlowType.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package enum

// FeedFlowType
type FeedFlowType Enum[int]

func (e FeedFlowType) Values() []FeedFlowType {
return []FeedFlowType{
{1, "百度信息流"},
{2, "贴吧"},
{3, "好看视频"},
{4, "百度小说"},
{5, "百青藤"},
{6, "默认"},
}
}

func (e *FeedFlowType) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = FeedFlowType(v)
return nil
}
31 changes: 31 additions & 0 deletions enum/feedMaterialStyle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package enum

// FeedMaterialStyle 该字段仅支持用于Filter中筛选数据使用。
type FeedMaterialStyle Enum[int]

func (e FeedMaterialStyle) Values() []FeedMaterialStyle {
return []FeedMaterialStyle{
{0, "全部"},
{1, "单图"},
{10, "互动图"},
{100, "程序化"},
{16, "开屏视频"},
{2, "三图"},
{20, "全部视频"},
{3, "大图"},
{5, "橱窗"},
{6, "开屏图片"},
{7, "横幅"},
{8, "横版视频"},
{9, "竖版视频"},
}
}

func (e *FeedMaterialStyle) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = FeedMaterialStyle(v)
return nil
}
26 changes: 26 additions & 0 deletions enum/feedSubject.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package enum

// FeedSubjectEnum 该字段仅支持用于Filter中筛选数据使用。
type FeedSubject Enum[int]

func (e FeedSubject) Values() []FeedSubject {
return []FeedSubject{
{0, "全部"},
{1, "网站链接"},
{2, "应用推广(ios)"},
{3, "应用推广(android)"},
{4, "小程序"},
{5, "商品目录"},
{6, "门店推广"},
{7, "电商店铺"},
}
}

func (e *FeedSubject) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = FeedSubject(v)
return nil
}
25 changes: 25 additions & 0 deletions enum/marketingTarget.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package enum

// MarketingTarget 营销目标
type MarketingTarget Enum[int]

func (e MarketingTarget) Values() []MarketingTarget {
return []MarketingTarget{
{0, "站链接"},
{1, "应用推广"},
{2, "门店推广"},
{3, "推广营销活动"},
{4, "电商店铺推广"},
{5, "商品目录"},
}
}

// UnmarshalJSON implement json Unmarshal interface
func (e *MarketingTarget) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = MarketingTarget(v)
return nil
}
24 changes: 24 additions & 0 deletions enum/mixWmatch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package enum

// MixWmatchEnum 匹配模式
type MixWmatch Enum[int]

func (e MixWmatch) Values() []MixWmatch {
return []MixWmatch{
{0, "智能匹配"},
{127, "分匹配出价"},
{16, "智能匹配核心词"},
{17, "短语匹配"},
{48, "精确匹配"},
}
}

// UnmarshalJSON implement json Unmarshal interface
func (e *MixWmatch) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = MixWmatch(v)
return nil
}
59 changes: 59 additions & 0 deletions enum/ocpcTransType.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package enum

// OcpcTransType 目标转化
type OcpcTransType Enum[int]

func (e OcpcTransType) Values() []OcpcTransType {
return []OcpcTransType{
{1, "咨询按钮点击"},
{10, "购买成功"},
{1000, "销售线索"},
{11, "注册"},
{12, "沟通"},
{13, "下单"},
{14, "订单提交成功"},
{17, "三句话咨询"},
{18, "留线索"},
{19, "一句话咨询"},
{2, "电话按钮点击"},
{20, "深度页面访问"},
{25, "注册"},
{26, "付费"},
{3, "表单提交成功"},
{30, "电话拨通"},
{35, "微信复制按钮点击"},
{4, "APP激活"},
{41, "申请"},
{42, "授信"},
{45, "商品下单成功"},
{46, "加入购物车"},
{47, "商品收藏"},
{48, "商品详情页"},
{5, "表单按钮点击"},
{55, "完件"},
{57, "店铺调起"},
{6, "下载(预约)按钮点击"},
{67, "微信按钮调起点击"},
{68, "粉丝关注成功"},
{71, "应用调起"},
{78, "店铺停留"},
{79, "微信加粉成功"},
{80, "直播间成单"},
{82, "直播间观看"},
{83, "直播间商品按钮点击"},
{84, "直播间停留"},
{85, "直播间评论"},
{86, "直播间打赏"},
{87, "直播间购物袋点击"},
{999999, "多目标转化"},
}
}

func (e *OcpcTransType) UnmarshalJSON(b []byte) error {
v, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = OcpcTransType(v)
return nil
}
22 changes: 22 additions & 0 deletions enum/picScale.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package enum

// PicScale 图片比例
type PicScale Enum[int]

func (e PicScale) Values() []PicScale {
return []PicScale{
{1, "1:1"},
{2, "1.61:1"},
{3, "3:1"},
{4, "1.77:1"},
}
}

func (e *PicScale) UnmarshalJSON(b []byte) error {
value, err := UnmarshalJSON[int](b)
if err != nil {
return err
}
*e = PicScale(value)
return nil
}
Loading

0 comments on commit 71164ee

Please sign in to comment.