ad

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2023 License: GPL-2.0 Imports: 2 Imported by: 0

README

广告模块

需求

全站可分广告位组,每个组可添加广告位。 每个广告位。管理员可设默认的广告, 每个商户可以绑定自己的广告。 每个商户最多可添加一定数量的广告。广告位不限制广告类型。 可图片、文字、轮播图等

组和广告位暂时只能由管理员操作。同时广告需增加展现次数,点击次数等。

说明

广告为独立模块,不限于merchant使用, 所有AdUser均可。

todo

广告用户功能, 当多个角色使用广告建立一个广告用户表, 生成广告用户编号。 还可生成开关广告功能。

Documentation

Overview

*

  • Copyright 2015 @ 56x.net.
  • name : IAdvertisement
  • author : jarryliu
  • date : -- :
  • description :
  • history :

*

  • Copyright 2015 @ 56x.net.
  • name : ad_gallery
  • author : jarryliu
  • date : -- :
  • description :
  • history :

Index

Constants

View Source
const (
	// 文字广告
	TypeText = 1
	// 图片广告
	TypeImage = 2
	// 图片轮播广告
	TypeSwiper = 3
)

Variables

View Source
var (
	ErrInternalDisallow = domain.NewError(
		"err_internal_disallow", "不允许修改系统内置广告")

	ErrNoSuchAd = domain.NewError(
		"err_no_such_ad", "广告不存在")

	ErrNoSuchAdGroup = domain.NewError(
		"err_no_such_ad_group", "广告位分组不存在")

	ErrNotEmptyGroup = domain.NewError(
		"err_ad_not_empty_ad_group", "广告位分组包含广告位,无法删除")

	ErrNoSuchAdPosition = domain.NewError(
		"err_no_such_ad_position", "广告位不存在")

	ErrNotOpened = domain.NewError(
		"err_position_not_opened", "广告未开放")
	ErrUserPositionIsBind = domain.NewError(
		"err_ad_user_position_is_bind", "该广告位已绑定其他广告")
	ErrAdType = domain.NewError(
		"err_ad_type", "请选择广告类型")

	ErrDisallowModifyAdType = domain.NewError(
		"err_disallow_modify_ad_type", "广告创建后不允许修改类型")

	ErrKeyExists = domain.NewError(
		"err_key_exists", "广告位KEY已存在")

	ErrAdUsed = domain.NewError(
		"err_ad_used", " 无法删除已投放的广告")
)

Functions

This section is empty.

Types

type Ad struct {
	// 编号
	Id int64 `db:"id" auto:"yes" pk:"yes"`

	//广告用户编号
	UserId int64 `db:"user_id"`

	// 名称
	Name string `db:"name"`

	// 广告类型
	AdType int `db:"type_id"`

	// 展现次数
	ShowTimes int `db:"show_times" json:"-"`

	// 点击次数
	ClickTimes int `db:"click_times" json:"-"`

	// 展现天数
	ShowDays int `db:"show_days" json:"-"`

	// 修改时间
	UpdateTime int64 `db:"update_time" json:"-"`
}

广告

type AdDto

type AdDto struct {
	Id     int64       `json:"id"`
	AdType int         `json:"type"`
	Data   interface{} `json:"data"`
}

广告数据传输对象

type AdUserSet

type AdUserSet struct {
	// 编号
	Id int64 `db:"id"`

	// 广告位编号
	PosId int64 `db:"pos_id"`

	//广告用户编号
	AdUserId int64 `db:"user_id"`

	// 广告编号
	AdId int64 `db:"ad_id"`
}

广告用户设置

type HyperLink struct {
	Id      int64  `db:"id" auto:"yes" pk:"yes"`
	AdId    int64  `db:"ad_id"`
	Title   string `db:"title"`
	LinkUrl string `db:"link_url"`
}

超链接

type IAd

type IAd interface {
	// 获取领域对象编号
	GetDomainId() int64
	// 是否为系统发布的广告
	System() bool
	// 广告类型
	Type() int
	// 广告名称
	Name() string
	// 设置值
	SetValue(*Ad) error
	// 获取值
	GetValue() *Ad
	// 保存广告
	Save() (int64, error)
	// 增加展现次数
	AddShowTimes(times int) error
	// 增加展现次数
	AddClickTimes(times int) error
	// 增加展现次数
	AddShowDays(times int) error
	// 转换为数据传输对象
	Dto() *AdDto
}

IAd 广告接口

type IAdPosition

type IAdPosition interface {
	GetAggregateRootId() int64
	SetValue(v *Position) error
	Save() error
	// 设置广告
	PutAd(adId int64) error
	GetValue() Position
}

IAdPosition 广告位

type IAdRepo

type IAdRepo interface {
	// 获取广告管理器
	GetAdManager() IAdvertisementManager

	// 获取广告分组
	GetPosition(id int64) IAdPosition

	// 根据KEY获取广告位
	GetAdPositionByKey(key string) *Position

	// 根据ID获取广告位
	GetAdPositionById(adPosId int64) *Position

	// 获取广告位
	GetAdPositionsByGroupId(adGroupId int64) []*Position

	// 删除广告位
	DeleteAdPosition(id int64) error

	// 保存广告位
	SaveAdPosition(a *Position) (int64, error)

	// 设置用户的广告
	SetUserAd(adUserId, posId, adId int64) error

	// 根据名称获取广告编号
	GetIdByName(mchId int64, name string) int

	// 保存广告值
	SaveAdValue(*Ad) (int64, error)

	// GetTextAdData  获取超链接广告数据
	GetTextAdData(adId int64) *HyperLink

	// SaveTextAdData  保存超链接广告数据
	SaveTextAdData(value *HyperLink) (int64, error)

	// SaveImageAdData  保存广告图片
	SaveImageAdData(*Image) (int64, error)

	// GetAd  获取广告
	GetAd(id int64) *Ad

	// GetAdByKey 根据KEY获取广告
	GetAdByKey(userId int64, key string) *Ad

	// GetSwiperAd 获取轮播广告
	GetSwiperAd(adId int64) SwiperAd

	// GetSwiperAdImage 获取图片项
	GetSwiperAdImage(adId, id int64) *Image

	// DeleteSwiperAdImage 删除图片项
	DeleteSwiperAdImage(adId, id int64) error

	// DeleteAd 删除广告
	DeleteAd(mchId, adId int64) error

	// DeleteImageAdData 删除广告的图片数据
	DeleteImageAdData(adId int64) error

	// DeleteTextAdData 删除广告的文字数据
	DeleteTextAdData(adId int64) error

	// GetGroups 获取广告分组
	GetGroups() []string
	CreateAdPosition(v *Position) IAdPosition
	QueryAdList(keyword string, size int) []*Ad
	// GetPositions 获取所有广告位
	GetPositions() []*Position
}

广告仓储

type IAdvertisementManager

type IAdvertisementManager interface {
	// 根据编号获取广告位
	GetPosition(id int64) IAdPosition
	// 根据KEY获取广告位
	GetPositionByKey(key string) *Position
	// 根据广告位KEY获取默认广告
	GetAdByPositionKey(key string) IAd
	// 获取用户的广告管理
	GetUserAd(adUserId int64) IUserAd
	// 获取广告分组
	GetGroups() []string
	// QueryAd 查询广告列表
	QueryAd(keyword string, size int) []*Ad
}

IAdvertisementManager 广告管理

type IGalleryAd

type IGalleryAd interface {
	// 获取广告数据
	GetAdValue() SwiperAd

	// 获取可用的广告数据
	GetEnabledAdValue() SwiperAd

	// 保存广告图片
	SaveImage(v *Image) (int64, error)

	// 获取图片项
	GetImage(id int64) *Image

	// 删除图片项
	DeleteItem(id int64) error
}

轮播广告

type IHyperLinkAd

type IHyperLinkAd interface {
	SetData(v *HyperLink) error
}

文本广告

type IImageAd

type IImageAd interface {
	SetData(v *Image) error
}

图片广告

type IUserAd

type IUserAd interface {
	// 获取聚合根标识
	GetAggregateRootId() int64
	// 删除广告
	DeleteAd(adId int64) error
	//获取广告关联的广告位
	GetAdPositionsByAdId(adId int64) []*Position
	// 根据编号获取广告
	GetById(id int64) IAd
	// 根据KEY获取广告
	GetByPositionKey(key string) IAd
	// 创建广告对象
	CreateAd(*Ad) IAd
	// 设置广告
	SetAd(posId, adId int64) error
	QueryAdvertisement(keys []string) map[string]IAd
}

IUserAd 商户广告聚合根

type Image

type Image struct {
	// 图片编号
	Id int64 `db:"id" auto:"yes" pk:"yes"`

	// 广告编号
	AdId int64 `db:"ad_id"`

	// 图片标题
	Title string `db:"title"`

	// 链接
	LinkUrl string `db:"link_url"`

	// 图片地址
	ImageUrl string `db:"image_url"`

	// 排列序号
	SortNum int `db:"sort_num"`

	// 是否启用
	Enabled int `db:"enabled"`
}

广告图片

type Position

type Position struct {
	// 编号
	Id int64 `db:"id" auto:"yes" pk:"yes"`
	// 引用键
	Key string `db:"key"`
	// 名称
	Name string `db:"name"`
	// 分组名称
	GroupName string `db:"group_name"`
	//todo:广告位类型限制
	// 广告类型限制,0为无限制
	TypeLimit int `db:"-"` //`db:"type_limit"`
	// 标志
	Flag int `db:"flag"`
	// 是否开放给外部
	Opened int `db:"opened"`
	// 是否启用
	Enabled int `db:"enabled"`
	// 默认广告编号
	PutAdId int64 `db:"put_aid"`
}

Position 广告位

type SwiperAd

type SwiperAd []*Image

轮播广告图片集合

func (SwiperAd) Len

func (v SwiperAd) Len() int

func (SwiperAd) Less

func (v SwiperAd) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (SwiperAd) Swap

func (v SwiperAd) Swap(i, j int)

Swap swaps the elements with indexes i and j.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL