project

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoPermission       = "无权限"
	AlreadyReceived    = "已有用户领取,不允许删除"
	TimeTooEarly       = "未到开启时间"
	TimeTooLate        = "已经结束"
	TrustLevelNotMatch = "社区等级未达标,需要信任等级 %d"
	UnknownError       = "未知异常"
	ScoreNotEnough     = "社区分数未达标,需要分数 %d"
	SameIPReceived     = "已有相同IP领取"
	NoStock            = "无库存"
	NotFound           = "项目不存在"
	AlreadyReported    = "已举报过当前项目"
	RequirementsFailed = "未达到项目发起者设置的条件"
	TooManyRequests    = "创建项目太频繁,请稍后再试"
	// Payment 相关
	InvalidPrice         = "金额必须大于等于 0"
	InvalidPriceDecimals = "金额最多保留 2 位小数"
	PriceTooLarge        = "金额超出允许范围"
	PriceOnlyOneForEach  = "仅一码一用分发支持设置金额"
	PaymentDisabled      = "平台支付功能未启用"
	CreatorNotConfigured = "请先在账户设置中配置支付凭据"
)
View Source
const (
	ProjectObjKey = "project_obj"
)

Variables

This section is empty.

Functions

func CreateProject

func CreateProject(c *gin.Context)

CreateProject @Tags project @Accept json @Produce json @Param project body CreateProjectRequestBody true "项目信息" @Success 200 {object} ProjectResponse @Router /api/v1/projects [post]

func DeleteProject

func DeleteProject(c *gin.Context)

DeleteProject @Tags project @Accept json @Produce json @Param id path string true "项目ID" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id} [delete]

func GetProject

func GetProject(c *gin.Context)

GetProject @Tags project @Summary 获取指定项目信息 (Get specific project information) @Description 获取指定项目所有信息以及领取情况 (Get all information and claim status for a specific project) @Produce json @Param id path string true "项目ID (Project ID)" @Success 200 {object} ProjectResponse{data=GetProjectResponseData} @Router /api/v1/projects/{id} [get]

func ListMyProjects

func ListMyProjects(c *gin.Context)

ListMyProjects @Tags project @Param request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects/mine [get]

func ListProjectReceivers

func ListProjectReceivers(c *gin.Context)

ListProjectReceivers @Tags project @Accept json @Produce json @Param id path string true "项目ID (Project ID)" @Param request query ListProjectReceiversRequest true "request query" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id}/receivers [get]

func ListProjects

func ListProjects(c *gin.Context)

ListProjects @Tags project @Param request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects [get]

func ListReceiveHistory

func ListReceiveHistory(c *gin.Context)

ListReceiveHistory @Tags project @Param request query ListReceiveHistoryRequest true "request query" @Produce json @Success 200 {object} ListReceiveHistoryResponse @Router /api/v1/projects/received [get]

func ListReceiveHistoryChart

func ListReceiveHistoryChart(c *gin.Context)

ListReceiveHistoryChart @Tags project @Param request query ListReceiveHistoryChartRequest true "request query" @Produce json @Success 200 {object} ListReceiveHistoryChartResponse @Router /api/v1/projects/received/chart [get]

func ListTags

func ListTags(c *gin.Context)

ListTags @Tags project @Accept json @Produce json @Success 200 {object} ListTagsResponse @Router /api/v1/tags [get]

func ProjectCreateRateLimitMiddleware

func ProjectCreateRateLimitMiddleware() gin.HandlerFunc

func ProjectCreatorPermMiddleware

func ProjectCreatorPermMiddleware() gin.HandlerFunc

func ProjectItemsKey added in v1.2.3

func ProjectItemsKey(projectID string) string

ProjectItemsKey 包级别的 Redis key 构造函数,便于不持有 Project 实例时拼接 key。

func ReceiveProjectMiddleware

func ReceiveProjectMiddleware() gin.HandlerFunc

func ReportProject

func ReportProject(c *gin.Context)

ReportProject @Tags project @Accept json @Produce json @Param id path string true "项目ID" @Param project body ReportProjectRequestBody true "举报信息" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id}/report [post]

func SetProjectToContext

func SetProjectToContext(c *gin.Context, project *Project)

SetProjectToContext 将Project对象存储到Context中

func UpdateProject

func UpdateProject(c *gin.Context)

UpdateProject @Tags project @Accept json @Produce json @Param id path string true "项目ID" @Param project body UpdateProjectRequestBody true "项目信息" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id} [put]

Types

type CreateProjectRequestBody

type CreateProjectRequestBody struct {
	ProjectRequest
	DistributionType DistributionType `json:"distribution_type" binding:"oneof=0 1"`
	ProjectItems     []string         `json:"project_items" binding:"required,min=1,dive,min=1,max=1024"`
	TopicId          uint64           `json:"topic_id" binding:"omitempty,gt=0"`
}

type DistributionType

type DistributionType int8
const (
	DistributionTypeOneForEach DistributionType = iota
	DistributionTypeLottery
	DistributionTypeInvite
)

type GetProjectResponseData

type GetProjectResponseData struct {
	Project             `json:",inline"` // 内嵌所有 Project 字段
	CreatorUsername     string           `json:"creator_username"`
	CreatorNickname     string           `json:"creator_nickname"`
	Tags                []string         `json:"tags"`
	AvailableItemsCount int64            `json:"available_items_count"`
	IsReceived          bool             `json:"is_received"`
	ReceivedContent     string           `json:"received_content"`
}

type ListProjectReceiversRequest

type ListProjectReceiversRequest struct {
	Current int    `json:"current" form:"current" binding:"min=1"`
	Size    int    `json:"size" form:"size" binding:"min=1,max=100"`
	Search  string `json:"search" form:"search" binding:"max=1024"`
}

type ListProjectsRequest

type ListProjectsRequest struct {
	Current int      `json:"current" form:"current" binding:"min=1"`
	Size    int      `json:"size" form:"size" binding:"min=1,max=100"`
	Tags    []string `json:"tags" form:"tags" binding:"dive,min=1,max=16"`
}

type ListProjectsResponse

type ListProjectsResponse struct {
	ErrorMsg string                    `json:"error_msg"`
	Data     *ListProjectsResponseData `json:"data"`
}

type ListProjectsResponseData

type ListProjectsResponseData struct {
	Total   int64                             `json:"total"`
	Results *[]ListProjectsResponseDataResult `json:"results"`
}

func ListMyProjectsWithTags

func ListMyProjectsWithTags(ctx context.Context, creatorID uint64, offset, limit int, tags []string) (*ListProjectsResponseData, error)

ListMyProjectsWithTags 查询我创建的项目列表及其标签

func ListProjectsWithTags

func ListProjectsWithTags(ctx context.Context, offset, limit int, tags []string, currentUser *oauth.User) (*ListProjectsResponseData, error)

ListProjectsWithTags 查询未结束的项目列表及其标签

type ListProjectsResponseDataResult

type ListProjectsResponseDataResult struct {
	ID                string            `json:"id"`
	Name              string            `json:"name"`
	Description       string            `json:"description"`
	DistributionType  DistributionType  `json:"distribution_type"`
	TotalItems        int64             `json:"total_items"`
	StartTime         time.Time         `json:"start_time"`
	EndTime           time.Time         `json:"end_time"`
	MinimumTrustLevel oauth.TrustLevel  `json:"minimum_trust_level"`
	AllowSameIP       bool              `json:"allow_same_ip"`
	RiskLevel         int8              `json:"risk_level"`
	HideFromExplore   bool              `json:"hide_from_explore"`
	Price             decimal.Decimal   `json:"price"`
	Tags              utils.StringArray `json:"tags"`
	CreatedAt         time.Time         `json:"created_at"`
}

type ListReceiveHistoryChartRequest

type ListReceiveHistoryChartRequest struct {
	Day int `json:"day" form:"day" binding:"min=1,max=180"`
}

type ListReceiveHistoryChartResponse

type ListReceiveHistoryChartResponse struct {
	ErrorMsg string                     `json:"error_msg"`
	Data     []ReceiveHistoryChartPoint `json:"data"`
}

type ListReceiveHistoryRequest

type ListReceiveHistoryRequest struct {
	Current int    `json:"current" form:"current" binding:"min=1"`
	Size    int    `json:"size" form:"size" binding:"min=1,max=100"`
	Search  string `json:"search" form:"search" binding:"max=255"`
}

type ListReceiveHistoryResponse

type ListReceiveHistoryResponse struct {
	ErrorMsg string                         `json:"error_msg"`
	Data     ListReceiveHistoryResponseData `json:"data"`
}

type ListReceiveHistoryResponseData

type ListReceiveHistoryResponseData struct {
	Total   int64                                  `json:"total"`
	Results []ListReceiveHistoryResponseDataResult `json:"results"`
}

type ListReceiveHistoryResponseDataResult

type ListReceiveHistoryResponseDataResult struct {
	ProjectID              string     `json:"project_id"`
	ProjectName            string     `json:"project_name"`
	ProjectCreator         string     `json:"project_creator"`
	ProjectCreatorNickname string     `json:"project_creator_nickname"`
	Content                string     `json:"content"`
	ReceivedAt             *time.Time `json:"received_at"`
}

type ListTagsResponse

type ListTagsResponse struct {
	ErrorMsg string   `json:"error_msg"`
	Data     []string `json:"data"`
}

type Project

type Project struct {
	ID                string           `json:"id" gorm:"primaryKey;size:64"`
	Name              string           `json:"name" gorm:"size:32"`
	Description       string           `json:"description" gorm:"size:1024"`
	DistributionType  DistributionType `json:"distribution_type"`
	TotalItems        int64            `json:"total_items"`
	StartTime         time.Time        `json:"start_time"`
	EndTime           time.Time        `json:"end_time" gorm:"index:idx_projects_end_completed_trust_risk,priority:1"`
	MinimumTrustLevel oauth.TrustLevel `json:"minimum_trust_level" gorm:"index:idx_projects_end_completed_trust_risk,priority:4"`
	AllowSameIP       bool             `json:"allow_same_ip"`
	RiskLevel         int8             `json:"risk_level" gorm:"index:idx_projects_end_completed_trust_risk,priority:5"`
	CreatorID         uint64           `json:"creator_id" gorm:"index"`
	IsCompleted       bool             `json:"is_completed" gorm:"index:idx_projects_end_completed_trust_risk,priority:2"`
	Status            ProjectStatus    `json:"status" gorm:"default:0;index;index:idx_projects_end_completed_trust_risk,priority:3"`
	ReportCount       uint8            `json:"report_count" gorm:"default:0"`
	HideFromExplore   bool             `json:"hide_from_explore" gorm:"default:false"`
	Price             decimal.Decimal  `json:"price" gorm:"type:decimal(10,2);default:0;not null"`
	Creator           oauth.User       `json:"-" gorm:"foreignKey:CreatorID"`
	CreatedAt         time.Time        `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt         time.Time        `json:"updated_at" gorm:"autoUpdateTime"`
}

func GetProjectFromContext

func GetProjectFromContext(c *gin.Context) (*Project, bool)

GetProjectFromContext 从Context中获取Project对象

func (*Project) CheckSameIPReceived

func (p *Project) CheckSameIPReceived(ctx context.Context, ip string) (bool, error)

func (*Project) CreateItems

func (p *Project) CreateItems(ctx context.Context, tx *gorm.DB, items []string, userName string, topicId uint64) error

func (*Project) CreateItemsWithFilter

func (p *Project) CreateItemsWithFilter(ctx context.Context, tx *gorm.DB, items []string, enableFilter bool) error

func (*Project) Exact

func (p *Project) Exact(tx *gorm.DB, id string, isNormal bool) error

func (*Project) FulfillForReceiver added in v1.2.3

func (p *Project) FulfillForReceiver(ctx context.Context, tx *gorm.DB, item *ProjectItem, receiverID uint64, clientIP string) error

FulfillForReceiver 执行领取结算事务:将 item 标记为已领取、库存耗尽则标记项目完成、 若不允许同 IP 领取则写 Redis SetNX 锁、抽奖模式从 Redis HDel 用户。 由免费领取与付费回调两条路径共用;失败时上游需决定是否回退 itemID。

func (*Project) GetFilteredItemsCount

func (p *Project) GetFilteredItemsCount(ctx context.Context, tx *gorm.DB, items []string, enableFilter bool) (int64, error)

func (*Project) GetReceivedItem

func (p *Project) GetReceivedItem(ctx context.Context, userID uint64) (*ProjectItem, error)

func (*Project) GetTags

func (p *Project) GetTags(tx *gorm.DB) ([]string, error)

GetTags retrieves all tags associated with the project.

func (*Project) HasStock

func (p *Project) HasStock(ctx context.Context) (bool, error)

func (*Project) IsPaid added in v1.2.3

func (p *Project) IsPaid() bool

IsPaid 是否为付费项目

func (*Project) IsReceivable

func (p *Project) IsReceivable(ctx context.Context, now time.Time, user *oauth.User, ip string) error

func (*Project) ItemsKey

func (p *Project) ItemsKey() string

func (*Project) PrepareReceive

func (p *Project) PrepareReceive(ctx context.Context, userName string) (uint64, error)

func (*Project) RefreshTags

func (p *Project) RefreshTags(tx *gorm.DB, tags []string) error

func (*Project) SameIPCacheKey

func (p *Project) SameIPCacheKey(ip string) string

func (*Project) Stock

func (p *Project) Stock(ctx context.Context) (int64, error)

func (*Project) ValidateRequirement added in v1.2.3

func (p *Project) ValidateRequirement(user *oauth.User) error

type ProjectItem

type ProjectItem struct {
	ID         uint64      `json:"id" gorm:"primaryKey,autoIncrement"`
	ProjectID  string      `json:"project_id" gorm:"size:64;index;uniqueIndex:idx_project_receiver"`
	Project    Project     `json:"-" gorm:"foreignKey:ProjectID"`
	ReceiverID *uint64     `json:"receiver_id" gorm:"index;uniqueIndex:idx_project_receiver"`
	Receiver   *oauth.User `json:"-" gorm:"foreignKey:ReceiverID"`
	Content    string      `json:"content" gorm:"size:1024"`
	CreatedAt  time.Time   `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt  time.Time   `json:"updated_at" gorm:"autoUpdateTime"`
	ReceivedAt *time.Time  `json:"received_at" gorm:"index"`
}

func (*ProjectItem) Exact

func (p *ProjectItem) Exact(tx *gorm.DB, id uint64) error

type ProjectReport

type ProjectReport struct {
	ID         uint64    `json:"id" gorm:"primaryKey,autoIncrement"`
	ProjectID  string    `json:"project_id" gorm:"size:64;index;uniqueIndex:idx_project_reporter"`
	ReporterID uint64    `json:"reporter_id" gorm:"index;uniqueIndex:idx_project_reporter"`
	Reason     string    `json:"reason" gorm:"size:255"`
	CreatedAt  time.Time `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt  time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}

type ProjectRequest

type ProjectRequest struct {
	Name              string           `json:"name" binding:"required,min=1,max=32"`
	Description       string           `json:"description" binding:"max=1024"`
	ProjectTags       []string         `json:"project_tags" binding:"dive,min=1,max=16"`
	StartTime         time.Time        `json:"start_time" binding:"required"`
	EndTime           time.Time        `json:"end_time" binding:"required,gtfield=StartTime"`
	MinimumTrustLevel oauth.TrustLevel `json:"minimum_trust_level" binding:"oneof=0 1 2 3 4"`
	AllowSameIP       bool             `json:"allow_same_ip"`
	RiskLevel         int8             `json:"risk_level" binding:"min=0,max=100"`
	HideFromExplore   bool             `json:"hide_from_explore"`
	Price             decimal.Decimal  `json:"price"`
}

type ProjectResponse

type ProjectResponse struct {
	ErrorMsg string      `json:"error_msg"`
	Data     interface{} `json:"data"`
}

type ProjectStatus

type ProjectStatus uint8
const (
	ProjectStatusNormal ProjectStatus = iota
	ProjectStatusHidden
	ProjectStatusViolation
)

type ProjectTag

type ProjectTag struct {
	ID        uint64  `json:"id" gorm:"primaryKey,autoIncrement"`
	ProjectID string  `json:"project_id" gorm:"size:64;index;uniqueIndex:idx_project_tag"`
	Project   Project `json:"-" gorm:"foreignKey:ProjectID"`
	Tag       string  `json:"tag" gorm:"size:16;index;uniqueIndex:idx_project_tag"`
}

type ProjectWithTags

type ProjectWithTags struct {
	Project
	Tags string `gorm:"column:tags"`
}

ProjectWithTags 返回项目及其标签

type ProjectsPage

type ProjectsPage struct {
	Total int64
	Items []ProjectWithTags
}

ProjectsPage 返回分页的项目列表及其标签

type ReceiveHistoryChartPoint

type ReceiveHistoryChartPoint struct {
	Date  string `json:"date"`
	Label string `json:"label"`
	Count int64  `json:"count"`
}

type ReportProjectRequestBody

type ReportProjectRequestBody struct {
	Reason string `json:"reason" binding:"required,min=1,max=255"`
}

type TopicResponse

type TopicResponse struct {
	HighestPostNumber uint       `json:"highest_post_number"`
	Tags              []TopicTag `json:"tags"`
	Closed            bool       `json:"closed"`
}

type TopicTag

type TopicTag struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

type UpdateProjectRequestBody

type UpdateProjectRequestBody struct {
	ProjectRequest
	ProjectItems []string `json:"project_items" binding:"dive,min=1,max=1024"`
	EnableFilter bool     `json:"enable_filter"`
}

Jump to

Keyboard shortcuts

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