Documentation
¶
Index ¶
- Constants
- func CreateProject(c *gin.Context)
- func DeleteProject(c *gin.Context)
- func GetProject(c *gin.Context)
- func ListMyProjects(c *gin.Context)
- func ListProjectReceivers(c *gin.Context)
- func ListProjects(c *gin.Context)
- func ListReceiveHistory(c *gin.Context)
- func ListReceiveHistoryChart(c *gin.Context)
- func ListTags(c *gin.Context)
- func ProjectCreateRateLimitMiddleware() gin.HandlerFunc
- func ProjectCreatorPermMiddleware() gin.HandlerFunc
- func ProjectItemsKey(projectID string) string
- func ReceiveProjectMiddleware() gin.HandlerFunc
- func ReportProject(c *gin.Context)
- func SetProjectToContext(c *gin.Context, project *Project)
- func UpdateProject(c *gin.Context)
- type CreateProjectRequestBody
- type DistributionType
- type GetProjectResponseData
- type ListProjectReceiversRequest
- type ListProjectsRequest
- type ListProjectsResponse
- type ListProjectsResponseData
- type ListProjectsResponseDataResult
- type ListReceiveHistoryChartRequest
- type ListReceiveHistoryChartResponse
- type ListReceiveHistoryRequest
- type ListReceiveHistoryResponse
- type ListReceiveHistoryResponseData
- type ListReceiveHistoryResponseDataResult
- type ListTagsResponse
- type Project
- func (p *Project) CheckSameIPReceived(ctx context.Context, ip string) (bool, error)
- func (p *Project) CreateItems(ctx context.Context, tx *gorm.DB, items []string, userName string, ...) error
- func (p *Project) CreateItemsWithFilter(ctx context.Context, tx *gorm.DB, items []string, enableFilter bool) error
- func (p *Project) Exact(tx *gorm.DB, id string, isNormal bool) error
- func (p *Project) FulfillForReceiver(ctx context.Context, tx *gorm.DB, item *ProjectItem, receiverID uint64, ...) error
- func (p *Project) GetFilteredItemsCount(ctx context.Context, tx *gorm.DB, items []string, enableFilter bool) (int64, error)
- func (p *Project) GetReceivedItem(ctx context.Context, userID uint64) (*ProjectItem, error)
- func (p *Project) GetTags(tx *gorm.DB) ([]string, error)
- func (p *Project) HasStock(ctx context.Context) (bool, error)
- func (p *Project) IsPaid() bool
- func (p *Project) IsReceivable(ctx context.Context, now time.Time, user *oauth.User, ip string) error
- func (p *Project) ItemsKey() string
- func (p *Project) PrepareReceive(ctx context.Context, userName string) (uint64, error)
- func (p *Project) RefreshTags(tx *gorm.DB, tags []string) error
- func (p *Project) SameIPCacheKey(ip string) string
- func (p *Project) Stock(ctx context.Context) (int64, error)
- func (p *Project) ValidateRequirement(user *oauth.User) error
- type ProjectItem
- type ProjectReport
- type ProjectRequest
- type ProjectResponse
- type ProjectStatus
- type ProjectTag
- type ProjectWithTags
- type ProjectsPage
- type ReceiveHistoryChartPoint
- type ReportProjectRequestBody
- type TopicResponse
- type TopicTag
- type UpdateProjectRequestBody
Constants ¶
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 = "请先在账户设置中配置支付凭据" )
const (
ProjectObjKey = "project_obj"
)
Variables ¶
This section is empty.
Functions ¶
func CreateProject ¶
CreateProject @Tags project @Accept json @Produce json @Param project body CreateProjectRequestBody true "项目信息" @Success 200 {object} ProjectResponse @Router /api/v1/projects [post]
func DeleteProject ¶
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 ¶
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 ¶
ListMyProjects @Tags project @Param request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects/mine [get]
func ListProjectReceivers ¶
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 ¶
ListProjects @Tags project @Param request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects [get]
func ListReceiveHistory ¶
ListReceiveHistory @Tags project @Param request query ListReceiveHistoryRequest true "request query" @Produce json @Success 200 {object} ListReceiveHistoryResponse @Router /api/v1/projects/received [get]
func ListReceiveHistoryChart ¶
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 ¶
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
ProjectItemsKey 包级别的 Redis key 构造函数,便于不持有 Project 实例时拼接 key。
func ReceiveProjectMiddleware ¶
func ReceiveProjectMiddleware() gin.HandlerFunc
func ReportProject ¶
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 ¶
SetProjectToContext 将Project对象存储到Context中
func UpdateProject ¶
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 ListProjectsRequest ¶
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 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 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 ¶
GetProjectFromContext 从Context中获取Project对象
func (*Project) CheckSameIPReceived ¶
func (*Project) CreateItems ¶
func (*Project) CreateItemsWithFilter ¶
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 (*Project) GetReceivedItem ¶
func (*Project) IsReceivable ¶
func (*Project) PrepareReceive ¶
func (*Project) SameIPCacheKey ¶
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"`
}
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 ProjectWithTags ¶
ProjectWithTags 返回项目及其标签
type ProjectsPage ¶
type ProjectsPage struct {
Total int64
Items []ProjectWithTags
}
ProjectsPage 返回分页的项目列表及其标签
type ReportProjectRequestBody ¶
type ReportProjectRequestBody struct {
Reason string `json:"reason" binding:"required,min=1,max=255"`
}
type TopicResponse ¶
type UpdateProjectRequestBody ¶
type UpdateProjectRequestBody struct {
ProjectRequest
ProjectItems []string `json:"project_items" binding:"dive,min=1,max=1024"`
EnableFilter bool `json:"enable_filter"`
}