Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b6d0c89aa1 | |||
| 27986044a1 | |||
| 197fed7d12 | |||
| f452f80100 | |||
| 1022160ff8 | |||
| 82eff47f38 | |||
| d351b50066 |
@@ -0,0 +1,48 @@
|
|||||||
|
syntax = "v1"
|
||||||
|
|
||||||
|
info (
|
||||||
|
title: "invite admin API"
|
||||||
|
desc: "API for ppanel"
|
||||||
|
author: "Tension"
|
||||||
|
email: "tension@ppanel.com"
|
||||||
|
version: "0.0.1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
GetInviteManageListRequest {
|
||||||
|
Page int `form:"page"`
|
||||||
|
Size int `form:"size"`
|
||||||
|
Search string `form:"search"`
|
||||||
|
InviterId int64 `form:"inviter_id"`
|
||||||
|
InviteeId int64 `form:"invitee_id"`
|
||||||
|
}
|
||||||
|
InviteManageRecord {
|
||||||
|
InviterId int64 `json:"inviter_id"`
|
||||||
|
InviterIdentifier string `json:"inviter_identifier"`
|
||||||
|
InviteeId int64 `json:"invitee_id"`
|
||||||
|
InviteeIdentifier string `json:"invitee_identifier"`
|
||||||
|
InviteeAvatar string `json:"invitee_avatar"`
|
||||||
|
InviteeEnable bool `json:"invitee_enable"`
|
||||||
|
InvitedAt int64 `json:"invited_at"`
|
||||||
|
OrderCount int64 `json:"order_count"`
|
||||||
|
HasPurchased bool `json:"has_purchased"`
|
||||||
|
InviterCommission int64 `json:"inviter_commission"`
|
||||||
|
InviterGiftDays int64 `json:"inviter_gift_days"`
|
||||||
|
InviteeGiftDays int64 `json:"invitee_gift_days"`
|
||||||
|
}
|
||||||
|
GetInviteManageListResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []InviteManageRecord `json:"list"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@server (
|
||||||
|
prefix: v1/admin/invite
|
||||||
|
group: admin/invite
|
||||||
|
middleware: AuthMiddleware
|
||||||
|
)
|
||||||
|
service ppanel {
|
||||||
|
@doc "Get invite manage list"
|
||||||
|
@handler GetInviteManageList
|
||||||
|
get /list (GetInviteManageListRequest) returns (GetInviteManageListResponse)
|
||||||
|
}
|
||||||
@@ -46,6 +46,7 @@ type (
|
|||||||
SpeedLimit int64 `json:"speed_limit"`
|
SpeedLimit int64 `json:"speed_limit"`
|
||||||
DeviceLimit int64 `json:"device_limit"`
|
DeviceLimit int64 `json:"device_limit"`
|
||||||
Quota int64 `json:"quota"`
|
Quota int64 `json:"quota"`
|
||||||
|
NewUserOnly *bool `json:"new_user_only"`
|
||||||
Nodes []int64 `json:"nodes"`
|
Nodes []int64 `json:"nodes"`
|
||||||
NodeTags []string `json:"node_tags"`
|
NodeTags []string `json:"node_tags"`
|
||||||
NodeGroupIds []int64 `json:"node_group_ids,omitempty"`
|
NodeGroupIds []int64 `json:"node_group_ids,omitempty"`
|
||||||
@@ -74,6 +75,7 @@ type (
|
|||||||
SpeedLimit int64 `json:"speed_limit"`
|
SpeedLimit int64 `json:"speed_limit"`
|
||||||
DeviceLimit int64 `json:"device_limit"`
|
DeviceLimit int64 `json:"device_limit"`
|
||||||
Quota int64 `json:"quota"`
|
Quota int64 `json:"quota"`
|
||||||
|
NewUserOnly *bool `json:"new_user_only"`
|
||||||
Nodes []int64 `json:"nodes"`
|
Nodes []int64 `json:"nodes"`
|
||||||
NodeTags []string `json:"node_tags"`
|
NodeTags []string `json:"node_tags"`
|
||||||
NodeGroupIds []int64 `json:"node_group_ids,omitempty"`
|
NodeGroupIds []int64 `json:"node_group_ids,omitempty"`
|
||||||
@@ -175,4 +177,3 @@ service ppanel {
|
|||||||
@handler ResetAllSubscribeToken
|
@handler ResetAllSubscribeToken
|
||||||
post /reset_all_token returns (ResetAllSubscribeTokenResponse)
|
post /reset_all_token returns (ResetAllSubscribeTokenResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+45
-1
@@ -23,10 +23,12 @@ type (
|
|||||||
SubscribeId *int64 `form:"subscribe_id,omitempty"`
|
SubscribeId *int64 `form:"subscribe_id,omitempty"`
|
||||||
UserSubscribeId *int64 `form:"user_subscribe_id,omitempty"`
|
UserSubscribeId *int64 `form:"user_subscribe_id,omitempty"`
|
||||||
ShortCode string `form:"short_code,omitempty"`
|
ShortCode string `form:"short_code,omitempty"`
|
||||||
|
DeviceId *int64 `form:"device_id,omitempty"`
|
||||||
FamilyJoined *bool `form:"family_joined,omitempty"`
|
FamilyJoined *bool `form:"family_joined,omitempty"`
|
||||||
FamilyStatus string `form:"family_status,omitempty"`
|
FamilyStatus string `form:"family_status,omitempty"`
|
||||||
FamilyOwnerUserId *int64 `form:"family_owner_user_id,omitempty"`
|
FamilyOwnerUserId *int64 `form:"family_owner_user_id,omitempty"`
|
||||||
FamilyId *int64 `form:"family_id,omitempty"`
|
FamilyId *int64 `form:"family_id,omitempty"`
|
||||||
|
SortOrder string `form:"sort_order,omitempty"`
|
||||||
}
|
}
|
||||||
// GetUserListResponse
|
// GetUserListResponse
|
||||||
GetUserListResponse {
|
GetUserListResponse {
|
||||||
@@ -134,6 +136,40 @@ type (
|
|||||||
List []UserDevice `json:"list"`
|
List []UserDevice `json:"list"`
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
}
|
}
|
||||||
|
GetAdminUserInviteStatsRequest {
|
||||||
|
UserId int64 `form:"user_id" validate:"required"`
|
||||||
|
}
|
||||||
|
GetAdminUserInviteStatsResponse {
|
||||||
|
InviteCount int64 `json:"invite_count"`
|
||||||
|
TotalCommission int64 `json:"total_commission"`
|
||||||
|
CurrentCommission int64 `json:"current_commission"`
|
||||||
|
ReferralPercentage uint8 `json:"referral_percentage"`
|
||||||
|
OnlyFirstPurchase bool `json:"only_first_purchase"`
|
||||||
|
}
|
||||||
|
GetAdminUserInviteListRequest {
|
||||||
|
Page int `form:"page"`
|
||||||
|
Size int `form:"size"`
|
||||||
|
UserId int64 `form:"user_id" validate:"required"`
|
||||||
|
Search string `form:"search,omitempty"`
|
||||||
|
Enable *bool `form:"enable,omitempty"`
|
||||||
|
UserIdSearch int64 `form:"user_id_search,omitempty"`
|
||||||
|
}
|
||||||
|
AdminInvitedUser {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
Identifier string `json:"identifier"`
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
OrderCount int64 `json:"order_count"`
|
||||||
|
HasPurchased bool `json:"has_purchased"`
|
||||||
|
InviterCommission int64 `json:"inviter_commission"`
|
||||||
|
InviterGiftDays int64 `json:"inviter_gift_days"`
|
||||||
|
InviteeGiftDays int64 `json:"invitee_gift_days"`
|
||||||
|
}
|
||||||
|
GetAdminUserInviteListResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []AdminInvitedUser `json:"list"`
|
||||||
|
}
|
||||||
CreateUserSubscribeRequest {
|
CreateUserSubscribeRequest {
|
||||||
UserId int64 `json:"user_id"`
|
UserId int64 `json:"user_id"`
|
||||||
ExpiredAt int64 `json:"expired_at"`
|
ExpiredAt int64 `json:"expired_at"`
|
||||||
@@ -149,7 +185,7 @@ type (
|
|||||||
ExpiredAt int64 `json:"expired_at"`
|
ExpiredAt int64 `json:"expired_at"`
|
||||||
Upload int64 `json:"upload"`
|
Upload int64 `json:"upload"`
|
||||||
Download int64 `json:"download"`
|
Download int64 `json:"download"`
|
||||||
SpeedLimit *int64 `json:"speed_limit,omitempty"`
|
SpeedLimit *int64 `json:"speed_limit,omitempty" validate:"omitempty,gte=0"`
|
||||||
TrafficLimit *string `json:"traffic_limit,omitempty"`
|
TrafficLimit *string `json:"traffic_limit,omitempty"`
|
||||||
}
|
}
|
||||||
GetUserLoginLogsRequest {
|
GetUserLoginLogsRequest {
|
||||||
@@ -318,6 +354,14 @@ service ppanel {
|
|||||||
@handler GetUserSubscribeTrafficLogs
|
@handler GetUserSubscribeTrafficLogs
|
||||||
get /subscribe/traffic_logs (GetUserSubscribeTrafficLogsRequest) returns (GetUserSubscribeTrafficLogsResponse)
|
get /subscribe/traffic_logs (GetUserSubscribeTrafficLogsRequest) returns (GetUserSubscribeTrafficLogsResponse)
|
||||||
|
|
||||||
|
@doc "Get admin user invite stats"
|
||||||
|
@handler GetAdminUserInviteStats
|
||||||
|
get /invite/stats (GetAdminUserInviteStatsRequest) returns (GetAdminUserInviteStatsResponse)
|
||||||
|
|
||||||
|
@doc "Get admin user invite list"
|
||||||
|
@handler GetAdminUserInviteList
|
||||||
|
get /invite/list (GetAdminUserInviteListRequest) returns (GetAdminUserInviteListResponse)
|
||||||
|
|
||||||
@doc "Get user subcribe devices"
|
@doc "Get user subcribe devices"
|
||||||
@handler GetUserSubscribeDevices
|
@handler GetUserSubscribeDevices
|
||||||
get /subscribe/device (GetUserSubscribeDevicesRequest) returns (GetUserSubscribeDevicesResponse)
|
get /subscribe/device (GetUserSubscribeDevicesRequest) returns (GetUserSubscribeDevicesResponse)
|
||||||
|
|||||||
+2
-3
@@ -111,7 +111,7 @@ type (
|
|||||||
|
|
||||||
@server (
|
@server (
|
||||||
prefix: v1/server
|
prefix: v1/server
|
||||||
group: server
|
group: node/server
|
||||||
middleware: ServerMiddleware
|
middleware: ServerMiddleware
|
||||||
)
|
)
|
||||||
service ppanel {
|
service ppanel {
|
||||||
@@ -138,11 +138,10 @@ service ppanel {
|
|||||||
|
|
||||||
@server (
|
@server (
|
||||||
prefix: v2/server
|
prefix: v2/server
|
||||||
group: server
|
group: node/server
|
||||||
)
|
)
|
||||||
service ppanel {
|
service ppanel {
|
||||||
@doc "Get Server Protocol Config"
|
@doc "Get Server Protocol Config"
|
||||||
@handler QueryServerProtocolConfig
|
@handler QueryServerProtocolConfig
|
||||||
get /:server_id (QueryServerConfigRequest) returns (QueryServerConfigResponse)
|
get /:server_id (QueryServerConfigRequest) returns (QueryServerConfigResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
syntax = "v1"
|
||||||
|
|
||||||
|
info (
|
||||||
|
title: "ppanel API"
|
||||||
|
desc: "API for ppanel"
|
||||||
|
author: "Tension"
|
||||||
|
email: "tension@ppanel.com"
|
||||||
|
version: "0.0.1"
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
"common.api"
|
||||||
|
"node/node.api"
|
||||||
|
"auth/auth.api"
|
||||||
|
"admin/system.api"
|
||||||
|
"admin/user.api"
|
||||||
|
"admin/auth.api"
|
||||||
|
"admin/server.api"
|
||||||
|
"admin/subscribe.api"
|
||||||
|
"admin/payment.api"
|
||||||
|
"admin/coupon.api"
|
||||||
|
"admin/redemption.api"
|
||||||
|
"admin/order.api"
|
||||||
|
"admin/ticket.api"
|
||||||
|
"admin/announcement.api"
|
||||||
|
"admin/document.api"
|
||||||
|
"admin/tool.api"
|
||||||
|
"admin/console.api"
|
||||||
|
"admin/log.api"
|
||||||
|
"admin/ads.api"
|
||||||
|
"admin/marketing.api"
|
||||||
|
"admin/application.api"
|
||||||
|
"admin/promo.api"
|
||||||
|
"admin/invite.api"
|
||||||
|
"admin/group.api"
|
||||||
|
"public/user.api"
|
||||||
|
"public/subscribe.api"
|
||||||
|
"public/redemption.api"
|
||||||
|
"public/recovery.api"
|
||||||
|
"public/order.api"
|
||||||
|
"public/announcement.api"
|
||||||
|
"public/ticket.api"
|
||||||
|
"public/payment.api"
|
||||||
|
"public/document.api"
|
||||||
|
"public/file.api"
|
||||||
|
"public/portal.api"
|
||||||
|
"public/iap.api"
|
||||||
|
)
|
||||||
+13
-13
@@ -201,21 +201,22 @@ type (
|
|||||||
GrowthRate string `json:"growth_rate"`
|
GrowthRate string `json:"growth_rate"`
|
||||||
PaidGrowthRate string `json:"paid_growth_rate"`
|
PaidGrowthRate string `json:"paid_growth_rate"`
|
||||||
}
|
}
|
||||||
GetInviteSalesRequest {
|
GetInviteRecordsRequest {
|
||||||
Page int `form:"page"`
|
Page int `form:"page"`
|
||||||
Size int `form:"size"`
|
Size int `form:"size"`
|
||||||
StartTime int64 `form:"start_time"`
|
StartTime int64 `form:"start_time"`
|
||||||
EndTime int64 `form:"end_time"`
|
EndTime int64 `form:"end_time"`
|
||||||
}
|
}
|
||||||
InvitedUserSale {
|
InviteRecord {
|
||||||
Amount float64 `json:"amount"`
|
Role string `json:"role"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
PeerHash string `json:"peer_hash"`
|
||||||
UserHash string `json:"user_hash"`
|
GiftDays int64 `json:"gift_days"`
|
||||||
ProductName string `json:"product_name"`
|
OrderNo string `json:"order_no"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
}
|
}
|
||||||
GetInviteSalesResponse {
|
GetInviteRecordsResponse {
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
List []InvitedUserSale `json:"list"`
|
List []InviteRecord `json:"list"`
|
||||||
}
|
}
|
||||||
GetSubscribeStatusRequest {
|
GetSubscribeStatusRequest {
|
||||||
Email string `form:"email" json:"email" validate:"omitempty,email"`
|
Email string `form:"email" json:"email" validate:"omitempty,email"`
|
||||||
@@ -397,9 +398,9 @@ service ppanel {
|
|||||||
@handler GetAgentRealtime
|
@handler GetAgentRealtime
|
||||||
get /agent_realtime (GetAgentRealtimeRequest) returns (GetAgentRealtimeResponse)
|
get /agent_realtime (GetAgentRealtimeRequest) returns (GetAgentRealtimeResponse)
|
||||||
|
|
||||||
@doc "Get Invite Sales"
|
@doc "Get Invite Records"
|
||||||
@handler GetInviteSales
|
@handler GetInviteRecords
|
||||||
get /invite_sales (GetInviteSalesRequest) returns (GetInviteSalesResponse)
|
get /invite_records (GetInviteRecordsRequest) returns (GetInviteRecordsResponse)
|
||||||
|
|
||||||
@doc "Get Subscribe Status"
|
@doc "Get Subscribe Status"
|
||||||
@handler GetSubscribeStatus
|
@handler GetSubscribeStatus
|
||||||
@@ -424,4 +425,3 @@ service ppanel {
|
|||||||
@handler DeviceWsConnect
|
@handler DeviceWsConnect
|
||||||
get /device_ws_connect
|
get /device_ws_connect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+27
-15
@@ -160,15 +160,17 @@ type (
|
|||||||
OnlyRealDevice bool `json:"only_real_device"`
|
OnlyRealDevice bool `json:"only_real_device"`
|
||||||
}
|
}
|
||||||
RegisterConfig {
|
RegisterConfig {
|
||||||
StopRegister bool `json:"stop_register"`
|
StopRegister bool `json:"stop_register"`
|
||||||
EnableTrial bool `json:"enable_trial"`
|
EnableTrial bool `json:"enable_trial"`
|
||||||
TrialSubscribe int64 `json:"trial_subscribe"`
|
EnableTrialEmailWhitelist bool `json:"enable_trial_email_whitelist"`
|
||||||
TrialTime int64 `json:"trial_time"`
|
TrialSubscribe int64 `json:"trial_subscribe"`
|
||||||
TrialTimeUnit string `json:"trial_time_unit"`
|
TrialTime int64 `json:"trial_time"`
|
||||||
EnableIpRegisterLimit bool `json:"enable_ip_register_limit"`
|
TrialTimeUnit string `json:"trial_time_unit"`
|
||||||
IpRegisterLimit int64 `json:"ip_register_limit"`
|
TrialEmailDomainWhitelist string `json:"trial_email_domain_whitelist"`
|
||||||
IpRegisterLimitDuration int64 `json:"ip_register_limit_duration"`
|
EnableIpRegisterLimit bool `json:"enable_ip_register_limit"`
|
||||||
DeviceLimit int64 `json:"device_limit"`
|
IpRegisterLimit int64 `json:"ip_register_limit"`
|
||||||
|
IpRegisterLimitDuration int64 `json:"ip_register_limit_duration"`
|
||||||
|
DeviceLimit int64 `json:"device_limit"`
|
||||||
}
|
}
|
||||||
VerifyConfig {
|
VerifyConfig {
|
||||||
CaptchaType string `json:"captcha_type"` // local or turnstile
|
CaptchaType string `json:"captcha_type"` // local or turnstile
|
||||||
@@ -226,10 +228,11 @@ type (
|
|||||||
CurrencySymbol string `json:"currency_symbol"`
|
CurrencySymbol string `json:"currency_symbol"`
|
||||||
}
|
}
|
||||||
SubscribeDiscount {
|
SubscribeDiscount {
|
||||||
Quantity int64 `json:"quantity"`
|
Quantity int64 `json:"quantity"`
|
||||||
Discount float64 `json:"discount"`
|
Discount float64 `json:"discount"`
|
||||||
MapApple string `json:"map_apple"`
|
NewUserOnly bool `json:"new_user_only"`
|
||||||
Promo *SubscribePromo `json:"promo"`
|
MapApple string `json:"map_apple"`
|
||||||
|
Promo *SubscribePromo `json:"promo"`
|
||||||
}
|
}
|
||||||
PromoPrice {
|
PromoPrice {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
@@ -293,6 +296,7 @@ type (
|
|||||||
SpeedLimit int64 `json:"speed_limit"`
|
SpeedLimit int64 `json:"speed_limit"`
|
||||||
DeviceLimit int64 `json:"device_limit"`
|
DeviceLimit int64 `json:"device_limit"`
|
||||||
Quota int64 `json:"quota"`
|
Quota int64 `json:"quota"`
|
||||||
|
NewUserOnly bool `json:"new_user_only"`
|
||||||
Nodes []int64 `json:"nodes"`
|
Nodes []int64 `json:"nodes"`
|
||||||
NodeTags []string `json:"node_tags"`
|
NodeTags []string `json:"node_tags"`
|
||||||
NodeGroupIds []int64 `json:"node_group_ids,omitempty"`
|
NodeGroupIds []int64 `json:"node_group_ids,omitempty"`
|
||||||
@@ -462,6 +466,8 @@ type (
|
|||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
GiftAmount int64 `json:"gift_amount"`
|
GiftAmount int64 `json:"gift_amount"`
|
||||||
Discount int64 `json:"discount"`
|
Discount int64 `json:"discount"`
|
||||||
|
PromoRuleId int64 `json:"promo_rule_id"`
|
||||||
|
PromoDiscount int64 `json:"promo_discount"`
|
||||||
Coupon string `json:"coupon"`
|
Coupon string `json:"coupon"`
|
||||||
CouponDiscount int64 `json:"coupon_discount"`
|
CouponDiscount int64 `json:"coupon_discount"`
|
||||||
Commission int64 `json:"commission,omitempty"`
|
Commission int64 `json:"commission,omitempty"`
|
||||||
@@ -484,6 +490,8 @@ type (
|
|||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
GiftAmount int64 `json:"gift_amount"`
|
GiftAmount int64 `json:"gift_amount"`
|
||||||
Discount int64 `json:"discount"`
|
Discount int64 `json:"discount"`
|
||||||
|
PromoRuleId int64 `json:"promo_rule_id"`
|
||||||
|
PromoDiscount int64 `json:"promo_discount"`
|
||||||
Coupon string `json:"coupon"`
|
Coupon string `json:"coupon"`
|
||||||
CouponDiscount int64 `json:"coupon_discount"`
|
CouponDiscount int64 `json:"coupon_discount"`
|
||||||
Commission int64 `json:"commission,omitempty"`
|
Commission int64 `json:"commission,omitempty"`
|
||||||
@@ -557,10 +565,13 @@ type (
|
|||||||
}
|
}
|
||||||
UserSubscribe {
|
UserSubscribe {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
|
IdStr string `json:"id_str"`
|
||||||
UserId int64 `json:"user_id"`
|
UserId int64 `json:"user_id"`
|
||||||
OrderId int64 `json:"order_id"`
|
OrderId int64 `json:"order_id"`
|
||||||
SubscribeId int64 `json:"subscribe_id"`
|
SubscribeId int64 `json:"subscribe_id"`
|
||||||
Subscribe Subscribe `json:"subscribe"`
|
Subscribe Subscribe `json:"subscribe"`
|
||||||
|
NodeGroupId int64 `json:"node_group_id"`
|
||||||
|
NodeGroupName string `json:"node_group_name"`
|
||||||
StartTime int64 `json:"start_time"`
|
StartTime int64 `json:"start_time"`
|
||||||
ExpireTime int64 `json:"expire_time"`
|
ExpireTime int64 `json:"expire_time"`
|
||||||
FinishedAt int64 `json:"finished_at"`
|
FinishedAt int64 `json:"finished_at"`
|
||||||
@@ -906,8 +917,9 @@ type (
|
|||||||
Sandbox *bool `json:"sandbox,omitempty"`
|
Sandbox *bool `json:"sandbox,omitempty"`
|
||||||
}
|
}
|
||||||
AttachAppleTransactionResponse {
|
AttachAppleTransactionResponse {
|
||||||
ExpiresAt int64 `json:"expires_at"`
|
ExpiresAt int64 `json:"expires_at"`
|
||||||
Tier string `json:"tier"`
|
Tier string `json:"tier"`
|
||||||
|
ExistingOrderNo string `json:"existing_order_no,omitempty"`
|
||||||
}
|
}
|
||||||
RestoreAppleTransactionsRequest {
|
RestoreAppleTransactionsRequest {
|
||||||
Transactions []string `json:"transactions" validate:"required"`
|
Transactions []string `json:"transactions" validate:"required"`
|
||||||
|
|||||||
@@ -128,6 +128,10 @@ curl -X PUT 'https://bucket.s3.ap-east-1.amazonaws.com/...' \
|
|||||||
说明:
|
说明:
|
||||||
|
|
||||||
- `Content-Type` 需和 `init` 返回的 `headers.Content-Type` 一致
|
- `Content-Type` 需和 `init` 返回的 `headers.Content-Type` 一致
|
||||||
|
- 允许的 `Content-Type` 由服务端 `S3.AllowedContentTypes` 配置控制,默认包含:
|
||||||
|
- 压缩包:`application/zip`、`application/x-zip-compressed`、`application/gzip`、`application/x-gzip`
|
||||||
|
- 通用文件:`application/octet-stream`、`text/plain`、`application/json`
|
||||||
|
- 图片:`image/jpeg`、`image/jpg`、`image/png`、`image/webp`、`image/gif`、`image/heic`、`image/heif`、`image/bmp`
|
||||||
- `upload_url` 有过期时间,通常 300 秒
|
- `upload_url` 有过期时间,通常 300 秒
|
||||||
- 成功时 S3 常见返回 `200` 或 `204`
|
- 成功时 S3 常见返回 `200` 或 `204`
|
||||||
|
|
||||||
@@ -164,11 +168,13 @@ curl -X POST 'https://tapi.hifast.biz/v1/public/file/upload/complete' \
|
|||||||
- 如果请求带了 `X-App-Id`,就按现有逻辑验签
|
- 如果请求带了 `X-App-Id`,就按现有逻辑验签
|
||||||
- 如果没有 `X-App-Id`,仍按旧逻辑放行
|
- 如果没有 `X-App-Id`,仍按旧逻辑放行
|
||||||
- 如果要给该接口加签,签名时必须对原始 multipart body 计算 `BODY_SHA256`
|
- 如果要给该接口加签,签名时必须对原始 multipart body 计算 `BODY_SHA256`
|
||||||
|
- 允许的 `Content-Type` 与预签名三段式一致;multipart 文件字段未显式携带 `Content-Type` 时,服务端会基于文件内容嗅探常见类型。
|
||||||
|
|
||||||
## 常见错误码
|
## 常见错误码
|
||||||
|
|
||||||
- `200`: 成功
|
- `200`: 成功
|
||||||
- `400`: 参数错误
|
- `400`: 参数错误
|
||||||
|
- `400 content_type is not allowed`: 文件 `Content-Type` 不在 `S3.AllowedContentTypes` 白名单内
|
||||||
- `40008`: 缺少签名头
|
- `40008`: 缺少签名头
|
||||||
- `40009`: 签名已过期
|
- `40009`: 签名已过期
|
||||||
- `40010`: 签名无效
|
- `40010`: 签名无效
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ S3:
|
|||||||
UsePathStyle: false
|
UsePathStyle: false
|
||||||
PresignExpireSeconds: 300
|
PresignExpireSeconds: 300
|
||||||
MaxUploadSize: 104857600
|
MaxUploadSize: 104857600
|
||||||
AllowedContentTypes: "application/zip,application/x-zip-compressed,application/gzip,application/x-gzip,application/octet-stream,text/plain,application/json"
|
AllowedContentTypes: "application/zip,application/x-zip-compressed,application/gzip,application/x-gzip,application/octet-stream,text/plain,application/json,image/jpeg,image/jpg,image/png,image/webp,image/gif,image/heic,image/heif,image/bmp"
|
||||||
|
|
||||||
device:
|
device:
|
||||||
enable: true # 开启设备加密通信
|
enable: true # 开启设备加密通信
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ module github.com/perfect-panel/server
|
|||||||
|
|
||||||
go 1.24
|
go 1.24
|
||||||
|
|
||||||
|
replace github.com/zeromicro/go-zero => ./internal/gozero
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f
|
github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f
|
||||||
github.com/alibabacloud-go/darabonba-openapi v0.1.18
|
github.com/alibabacloud-go/darabonba-openapi v0.1.18
|
||||||
@@ -33,6 +35,7 @@ require (
|
|||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.8.1
|
||||||
github.com/stripe/stripe-go/v81 v81.1.0
|
github.com/stripe/stripe-go/v81 v81.1.0
|
||||||
github.com/twilio/twilio-go v1.23.11
|
github.com/twilio/twilio-go v1.23.11
|
||||||
|
github.com/zeromicro/go-zero v0.0.0
|
||||||
go.opentelemetry.io/otel v1.29.0
|
go.opentelemetry.io/otel v1.29.0
|
||||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
|
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
|
||||||
@@ -53,6 +56,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||||
github.com/Masterminds/sprig/v3 v3.3.0
|
github.com/Masterminds/sprig/v3 v3.3.0
|
||||||
github.com/aws/aws-sdk-go-v2 v1.41.7
|
github.com/aws/aws-sdk-go-v2 v1.41.7
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.32.17
|
github.com/aws/aws-sdk-go-v2/config v1.32.17
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4
|
|||||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
|
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||||
github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f h1:RDkg3pyE1qGbBpRWmvSN9RNZC5nUrOaEPiEpEb8y2f0=
|
github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f h1:RDkg3pyE1qGbBpRWmvSN9RNZC5nUrOaEPiEpEb8y2f0=
|
||||||
github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f/go.mod h1:zA7AF9RTfpluCfz0omI4t5KCMaWHUMicsZoMccnaT44=
|
github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f/go.mod h1:zA7AF9RTfpluCfz0omI4t5KCMaWHUMicsZoMccnaT44=
|
||||||
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
|
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
|
||||||
@@ -264,6 +266,7 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
|
|||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
|
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
|
||||||
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
|
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
|
||||||
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
|
|||||||
@@ -1,5 +1,35 @@
|
|||||||
-- Purpose: Rollback user-level speed limit overrides from user_subscribe
|
SET @traffic_limit_exists = (
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
|
AND TABLE_NAME = 'user_subscribe'
|
||||||
|
AND COLUMN_NAME = 'traffic_limit'
|
||||||
|
);
|
||||||
|
|
||||||
ALTER TABLE `user_subscribe`
|
SET @traffic_limit_sql = IF(
|
||||||
DROP COLUMN IF EXISTS `traffic_limit`,
|
@traffic_limit_exists = 1,
|
||||||
DROP COLUMN IF EXISTS `speed_limit`;
|
'ALTER TABLE `user_subscribe` DROP COLUMN `traffic_limit`',
|
||||||
|
'SELECT 1'
|
||||||
|
);
|
||||||
|
|
||||||
|
PREPARE traffic_limit_stmt FROM @traffic_limit_sql;
|
||||||
|
EXECUTE traffic_limit_stmt;
|
||||||
|
DEALLOCATE PREPARE traffic_limit_stmt;
|
||||||
|
|
||||||
|
SET @speed_limit_exists = (
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
|
AND TABLE_NAME = 'user_subscribe'
|
||||||
|
AND COLUMN_NAME = 'speed_limit'
|
||||||
|
);
|
||||||
|
|
||||||
|
SET @speed_limit_sql = IF(
|
||||||
|
@speed_limit_exists = 1,
|
||||||
|
'ALTER TABLE `user_subscribe` DROP COLUMN `speed_limit`',
|
||||||
|
'SELECT 1'
|
||||||
|
);
|
||||||
|
|
||||||
|
PREPARE speed_limit_stmt FROM @speed_limit_sql;
|
||||||
|
EXECUTE speed_limit_stmt;
|
||||||
|
DEALLOCATE PREPARE speed_limit_stmt;
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
-- Purpose: Add user-level speed limit overrides to user_subscribe
|
SET @speed_limit_exists = (
|
||||||
|
|
||||||
SET @column_exists = (
|
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM INFORMATION_SCHEMA.COLUMNS
|
FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
WHERE TABLE_SCHEMA = DATABASE()
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
@@ -8,17 +6,17 @@ SET @column_exists = (
|
|||||||
AND COLUMN_NAME = 'speed_limit'
|
AND COLUMN_NAME = 'speed_limit'
|
||||||
);
|
);
|
||||||
|
|
||||||
SET @sql = IF(
|
SET @speed_limit_sql = IF(
|
||||||
@column_exists = 0,
|
@speed_limit_exists = 0,
|
||||||
'ALTER TABLE `user_subscribe` ADD COLUMN `speed_limit` int NOT NULL DEFAULT 0 COMMENT ''User-level speed limit override (Mbps, 0=use plan default)'' AFTER `upload`',
|
'ALTER TABLE `user_subscribe` ADD COLUMN `speed_limit` BIGINT NOT NULL DEFAULT 0 COMMENT ''User-level speed limit override (Mbps), 0 uses plan-level'' AFTER `upload`',
|
||||||
'SELECT ''Column speed_limit already exists in user_subscribe table'''
|
'SELECT 1'
|
||||||
);
|
);
|
||||||
|
|
||||||
PREPARE stmt FROM @sql;
|
PREPARE speed_limit_stmt FROM @speed_limit_sql;
|
||||||
EXECUTE stmt;
|
EXECUTE speed_limit_stmt;
|
||||||
DEALLOCATE PREPARE stmt;
|
DEALLOCATE PREPARE speed_limit_stmt;
|
||||||
|
|
||||||
SET @column_exists = (
|
SET @traffic_limit_exists = (
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM INFORMATION_SCHEMA.COLUMNS
|
FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
WHERE TABLE_SCHEMA = DATABASE()
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
@@ -26,12 +24,12 @@ SET @column_exists = (
|
|||||||
AND COLUMN_NAME = 'traffic_limit'
|
AND COLUMN_NAME = 'traffic_limit'
|
||||||
);
|
);
|
||||||
|
|
||||||
SET @sql = IF(
|
SET @traffic_limit_sql = IF(
|
||||||
@column_exists = 0,
|
@traffic_limit_exists = 0,
|
||||||
'ALTER TABLE `user_subscribe` ADD COLUMN `traffic_limit` text DEFAULT NULL COMMENT ''User-level traffic limit rules override (JSON, NULL=use plan default)'' AFTER `speed_limit`',
|
'ALTER TABLE `user_subscribe` ADD COLUMN `traffic_limit` TEXT DEFAULT NULL COMMENT ''User-level traffic limit override (JSON), NULL uses plan-level'' AFTER `speed_limit`',
|
||||||
'SELECT ''Column traffic_limit already exists in user_subscribe table'''
|
'SELECT 1'
|
||||||
);
|
);
|
||||||
|
|
||||||
PREPARE stmt FROM @sql;
|
PREPARE traffic_limit_stmt FROM @traffic_limit_sql;
|
||||||
EXECUTE stmt;
|
EXECUTE traffic_limit_stmt;
|
||||||
DEALLOCATE PREPARE stmt;
|
DEALLOCATE PREPARE traffic_limit_stmt;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ type S3Config struct {
|
|||||||
UsePathStyle bool `yaml:"UsePathStyle" default:"false"`
|
UsePathStyle bool `yaml:"UsePathStyle" default:"false"`
|
||||||
PresignExpireSeconds int64 `yaml:"PresignExpireSeconds" default:"300"`
|
PresignExpireSeconds int64 `yaml:"PresignExpireSeconds" default:"300"`
|
||||||
MaxUploadSize int64 `yaml:"MaxUploadSize" default:"104857600"`
|
MaxUploadSize int64 `yaml:"MaxUploadSize" default:"104857600"`
|
||||||
AllowedContentTypes string `yaml:"AllowedContentTypes" default:"application/zip,application/x-zip-compressed,application/gzip,application/x-gzip,application/octet-stream,text/plain,application/json"`
|
AllowedContentTypes string `yaml:"AllowedContentTypes" default:"application/zip,application/x-zip-compressed,application/gzip,application/x-gzip,application/octet-stream,text/plain,application/json,image/jpeg,image/jpg,image/png,image/webp,image/gif,image/heic,image/heif,image/bmp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RedisConfig struct {
|
type RedisConfig struct {
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package logx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Logger interface {
|
||||||
|
Error(...any)
|
||||||
|
Errorf(string, ...any)
|
||||||
|
Info(...any)
|
||||||
|
Infof(string, ...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
type logger struct{}
|
||||||
|
|
||||||
|
func WithContext(context.Context) Logger {
|
||||||
|
return logger{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger) Error(v ...any) {
|
||||||
|
log.Print(v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger) Errorf(format string, v ...any) {
|
||||||
|
log.Printf(format, v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger) Info(v ...any) {
|
||||||
|
log.Print(v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger) Infof(format string, v ...any) {
|
||||||
|
log.Printf(format, v...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
module github.com/zeromicro/go-zero
|
||||||
|
|
||||||
|
go 1.24
|
||||||
|
|
||||||
|
require github.com/gin-gonic/gin v1.10.0
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package httpx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Parse(r *http.Request, v any) error {
|
||||||
|
if r.Body == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
if err := decoder.Decode(v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrorCtx(_ context.Context, w http.ResponseWriter, err error) {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
func OkJsonCtx(_ context.Context, w http.ResponseWriter, v any) {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
_ = json.NewEncoder(w).Encode(v)
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package rest
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
type Middleware = gin.HandlerFunc
|
||||||
|
|
||||||
|
type Route struct {
|
||||||
|
Method string
|
||||||
|
Path string
|
||||||
|
Handler gin.HandlerFunc
|
||||||
|
Middlewares []Middleware
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteOption func(*routeOptions)
|
||||||
|
|
||||||
|
type routeOptions struct {
|
||||||
|
prefix string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
router *gin.Engine
|
||||||
|
optionalAuth Middleware
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerOption func(*Server)
|
||||||
|
|
||||||
|
func NewServer(router *gin.Engine, opts ...ServerOption) *Server {
|
||||||
|
server := &Server{router: router}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(server)
|
||||||
|
}
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithOptionalAuth(middleware Middleware) ServerOption {
|
||||||
|
return func(server *Server) {
|
||||||
|
server.optionalAuth = middleware
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithMiddlewares(middlewares []Middleware, routes ...Route) []Route {
|
||||||
|
for i := range routes {
|
||||||
|
routes[i].Middlewares = append(routes[i].Middlewares, middlewares...)
|
||||||
|
}
|
||||||
|
return routes
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithPrefix(prefix string) RouteOption {
|
||||||
|
return func(opts *routeOptions) {
|
||||||
|
opts.prefix = prefix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithJwt(_ string) RouteOption {
|
||||||
|
return func(_ *routeOptions) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) AddRoutes(routes []Route, opts ...RouteOption) {
|
||||||
|
options := routeOptions{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(&options)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, route := range routes {
|
||||||
|
handlers := append([]gin.HandlerFunc{}, route.Middlewares...)
|
||||||
|
if server.optionalAuth != nil && options.prefix == "/v1/public/subscribe" && route.Path == "/list" && len(handlers) > 0 {
|
||||||
|
handlers[0] = server.optionalAuth
|
||||||
|
}
|
||||||
|
handlers = append(handlers, route.Handler)
|
||||||
|
server.router.Handle(route.Method, options.prefix+route.Path, handlers...)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package invite
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/invite"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get invite manage list
|
||||||
|
func GetInviteManageListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.GetInviteManageListRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
if err := svcCtx.Validate(&req); err != nil {
|
||||||
|
result.ParamErrorResult(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := invite.NewGetInviteManageListLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.GetInviteManageList(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/user"
|
"github.com/perfect-panel/server/internal/logic/admin/user"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
@@ -18,9 +21,25 @@ func UpdateUserSubscribeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context)
|
|||||||
result.ParamErrorResult(c, validateErr)
|
result.ParamErrorResult(c, validateErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err := validateUpdateUserSubscribeTrafficLimit(&req); err != nil {
|
||||||
|
result.ParamErrorResult(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
l := user.NewUpdateUserSubscribeLogic(c.Request.Context(), svcCtx)
|
l := user.NewUpdateUserSubscribeLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.UpdateUserSubscribe(&req)
|
err := l.UpdateUserSubscribe(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateUpdateUserSubscribeTrafficLimit(req *types.UpdateUserSubscribeRequest) error {
|
||||||
|
if req.TrafficLimit == nil || *req.TrafficLimit == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var rules []types.TrafficLimit
|
||||||
|
if err := json.Unmarshal([]byte(*req.TrafficLimit), &rules); err != nil {
|
||||||
|
return errors.New("traffic_limit must be a valid JSON array")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUpdateUserSubscribeHandlerRejectsInvalidLimits(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
body string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "negative speed limit",
|
||||||
|
body: `{"user_subscribe_id":1,"subscribe_id":1,"traffic":0,"expired_at":4102444800000,"upload":0,"download":0,"speed_limit":-1}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid traffic limit json",
|
||||||
|
body: `{"user_subscribe_id":1,"subscribe_id":1,"traffic":0,"expired_at":4102444800000,"upload":0,"download":0,"traffic_limit":"not-json"}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
router := gin.New()
|
||||||
|
router.PUT("/v1/admin/user/subscribe", UpdateUserSubscribeHandler(&svc.ServiceContext{}))
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPut, "/v1/admin/user/subscribe", bytes.NewBufferString(tt.body))
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
|
||||||
|
router.ServeHTTP(rec, req)
|
||||||
|
|
||||||
|
if rec.Code != http.StatusOK {
|
||||||
|
t.Fatalf("expected HTTP 200, got %d", rec.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code uint32 `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
|
||||||
|
t.Fatalf("unmarshal response: %v", err)
|
||||||
|
}
|
||||||
|
if resp.Code != xerr.InvalidParams {
|
||||||
|
t.Fatalf("expected code %d, got %d (%s)", xerr.InvalidParams, resp.Code, resp.Msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
authHandler "github.com/perfect-panel/server/internal/handler/auth"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckCodeLegacyHandler(svcCtx *svc.ServiceContext) gin.HandlerFunc {
|
||||||
|
return authHandler.CheckCodeLegacyV1Handler(svcCtx)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
authHandler "github.com/perfect-panel/server/internal/handler/auth"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckCodeLegacyV2Handler(svcCtx *svc.ServiceContext) gin.HandlerFunc {
|
||||||
|
return authHandler.CheckCodeLegacyV2Handler(svcCtx)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package common
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package common
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
serverhandler "github.com/perfect-panel/server/internal/handler/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetServerConfigHandler(svcCtx *svc.ServiceContext) gin.HandlerFunc {
|
||||||
|
return serverhandler.GetServerConfigHandler(svcCtx)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
serverhandler "github.com/perfect-panel/server/internal/handler/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetServerUserListHandler(svcCtx *svc.ServiceContext) gin.HandlerFunc {
|
||||||
|
return serverhandler.GetServerUserListHandler(svcCtx)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
serverhandler "github.com/perfect-panel/server/internal/handler/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PushOnlineUsersHandler(svcCtx *svc.ServiceContext) gin.HandlerFunc {
|
||||||
|
return serverhandler.PushOnlineUsersHandler(svcCtx)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
serverhandler "github.com/perfect-panel/server/internal/handler/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func QueryServerProtocolConfigHandler(svcCtx *svc.ServiceContext) gin.HandlerFunc {
|
||||||
|
return serverhandler.QueryServerProtocolConfigHandler(svcCtx)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
serverhandler "github.com/perfect-panel/server/internal/handler/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ServerPushStatusHandler(svcCtx *svc.ServiceContext) gin.HandlerFunc {
|
||||||
|
return serverhandler.ServerPushStatusHandler(svcCtx)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
serverhandler "github.com/perfect-panel/server/internal/handler/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ServerPushUserTrafficHandler(svcCtx *svc.ServiceContext) gin.HandlerFunc {
|
||||||
|
return serverhandler.ServerPushUserTrafficHandler(svcCtx)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package apple
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package apple
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package apple
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package apple
|
||||||
+5
-5
@@ -8,10 +8,10 @@ import (
|
|||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get invite sales data
|
// Get invite gift records
|
||||||
func GetInviteSalesHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
func GetInviteRecordsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
var req types.GetInviteSalesRequest
|
var req types.GetInviteRecordsRequest
|
||||||
if err := c.ShouldBind(&req); err != nil {
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
result.ParamErrorResult(c, err)
|
result.ParamErrorResult(c, err)
|
||||||
return
|
return
|
||||||
@@ -23,8 +23,8 @@ func GetInviteSalesHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewGetInviteSalesLogic(c.Request.Context(), svcCtx)
|
l := user.NewGetInviteRecordsLogic(c.Request.Context(), svcCtx)
|
||||||
resp, err := l.GetInviteSales(&req)
|
resp, err := l.GetInviteRecords(&req)
|
||||||
result.HttpResult(c, resp, err)
|
result.HttpResult(c, resp, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2331
-1198
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,203 @@
|
|||||||
|
package invite
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
modellog "github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Benefits struct {
|
||||||
|
OrderCount int64
|
||||||
|
HasPurchased bool
|
||||||
|
InviterCommission int64
|
||||||
|
InviterGiftDays int64
|
||||||
|
InviteeGiftDays int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type InviteRelation struct {
|
||||||
|
InviteeId int64
|
||||||
|
InviterId int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type paidOrderRow struct {
|
||||||
|
UserId int64 `gorm:"column:user_id"`
|
||||||
|
OrderNo string `gorm:"column:order_no"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type systemLogRow struct {
|
||||||
|
ObjectID int64 `gorm:"column:object_id"`
|
||||||
|
Content string `gorm:"column:content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NormalizePage(page, size int) (int, int) {
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
if size < 1 {
|
||||||
|
size = 10
|
||||||
|
}
|
||||||
|
if size > 100 {
|
||||||
|
size = 100
|
||||||
|
}
|
||||||
|
return page, size
|
||||||
|
}
|
||||||
|
|
||||||
|
func QueryBenefits(ctx context.Context, db *gorm.DB, relations []InviteRelation) (map[int64]Benefits, error) {
|
||||||
|
result := make(map[int64]Benefits, len(relations))
|
||||||
|
if len(relations) == 0 {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
inviteeIds := make([]int64, 0, len(relations))
|
||||||
|
inviteeToInviter := make(map[int64]int64, len(relations))
|
||||||
|
for _, relation := range relations {
|
||||||
|
inviteeIds = append(inviteeIds, relation.InviteeId)
|
||||||
|
inviteeToInviter[relation.InviteeId] = relation.InviterId
|
||||||
|
result[relation.InviteeId] = Benefits{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var orderCounts []struct {
|
||||||
|
UserId int64 `gorm:"column:user_id"`
|
||||||
|
Cnt int64 `gorm:"column:cnt"`
|
||||||
|
}
|
||||||
|
if err := db.WithContext(ctx).
|
||||||
|
Table("`order`").
|
||||||
|
Select("user_id, COUNT(*) as cnt").
|
||||||
|
Where("user_id IN ? AND status IN ?", inviteeIds, []int{2, 5}).
|
||||||
|
Group("user_id").
|
||||||
|
Scan(&orderCounts).Error; err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "count invitee paid orders failed: %v", err)
|
||||||
|
}
|
||||||
|
for _, row := range orderCounts {
|
||||||
|
benefit := result[row.UserId]
|
||||||
|
benefit.OrderCount = row.Cnt
|
||||||
|
benefit.HasPurchased = row.Cnt > 0
|
||||||
|
result[row.UserId] = benefit
|
||||||
|
}
|
||||||
|
|
||||||
|
var paidOrders []paidOrderRow
|
||||||
|
if err := db.WithContext(ctx).
|
||||||
|
Table("`order`").
|
||||||
|
Select("user_id, order_no").
|
||||||
|
Where("user_id IN ? AND status IN ?", inviteeIds, []int{2, 5}).
|
||||||
|
Scan(&paidOrders).Error; err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query invitee paid orders failed: %v", err)
|
||||||
|
}
|
||||||
|
if len(paidOrders) == 0 {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
orderNos := make([]string, 0, len(paidOrders))
|
||||||
|
orderToInvitee := make(map[string]int64, len(paidOrders))
|
||||||
|
inviterIds := make([]int64, 0, len(relations))
|
||||||
|
inviteeAndInviterSet := make(map[int64]struct{}, len(relations)*2)
|
||||||
|
for _, order := range paidOrders {
|
||||||
|
orderNos = append(orderNos, order.OrderNo)
|
||||||
|
orderToInvitee[order.OrderNo] = order.UserId
|
||||||
|
}
|
||||||
|
for _, relation := range relations {
|
||||||
|
inviterIds = append(inviterIds, relation.InviterId)
|
||||||
|
inviteeAndInviterSet[relation.InviteeId] = struct{}{}
|
||||||
|
inviteeAndInviterSet[relation.InviterId] = struct{}{}
|
||||||
|
}
|
||||||
|
inviteeAndInviterIds := make([]int64, 0, len(inviteeAndInviterSet))
|
||||||
|
for userId := range inviteeAndInviterSet {
|
||||||
|
inviteeAndInviterIds = append(inviteeAndInviterIds, userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := fillCommissionBenefits(ctx, db, result, orderToInvitee, inviteeToInviter, orderNos, inviterIds); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := fillGiftBenefits(ctx, db, result, orderToInvitee, inviteeToInviter, orderNos, inviteeAndInviterIds); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fillCommissionBenefits(ctx context.Context, db *gorm.DB, benefits map[int64]Benefits, orderToInvitee map[string]int64, inviteeToInviter map[int64]int64, orderNos []string, inviterIds []int64) error {
|
||||||
|
var rows []systemLogRow
|
||||||
|
if err := db.WithContext(ctx).
|
||||||
|
Table("system_logs").
|
||||||
|
Select("object_id, content").
|
||||||
|
Where("type = ? AND object_id IN ? AND JSON_UNQUOTE(JSON_EXTRACT(content, '$.order_no')) IN ? AND JSON_EXTRACT(content, '$.type') IN ?", modellog.TypeCommission.Uint8(), inviterIds, orderNos, []int{int(modellog.CommissionTypePurchase), int(modellog.CommissionTypeRenewal)}).
|
||||||
|
Scan(&rows).Error; err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query invite commission logs failed: %v", err)
|
||||||
|
}
|
||||||
|
for _, row := range rows {
|
||||||
|
content := modellog.Commission{}
|
||||||
|
if err := content.Unmarshal([]byte(row.Content)); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
inviteeId, ok := orderToInvitee[content.OrderNo]
|
||||||
|
if !ok || inviteeToInviter[inviteeId] != row.ObjectID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
benefit := benefits[inviteeId]
|
||||||
|
benefit.InviterCommission += content.Amount
|
||||||
|
benefits[inviteeId] = benefit
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fillGiftBenefits(ctx context.Context, db *gorm.DB, benefits map[int64]Benefits, orderToInvitee map[string]int64, inviteeToInviter map[int64]int64, orderNos []string, userIds []int64) error {
|
||||||
|
var rows []systemLogRow
|
||||||
|
if err := db.WithContext(ctx).
|
||||||
|
Table("system_logs").
|
||||||
|
Select("object_id, content").
|
||||||
|
Where("type = ? AND object_id IN ? AND JSON_UNQUOTE(JSON_EXTRACT(content, '$.order_no')) IN ?", modellog.TypeGift.Uint8(), userIds, orderNos).
|
||||||
|
Scan(&rows).Error; err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query invite gift logs failed: %v", err)
|
||||||
|
}
|
||||||
|
for _, row := range rows {
|
||||||
|
content := modellog.Gift{}
|
||||||
|
if err := content.Unmarshal([]byte(row.Content)); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if content.Type != modellog.GiftTypeIncrease {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
inviteeId, ok := orderToInvitee[content.OrderNo]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
benefit := benefits[inviteeId]
|
||||||
|
switch row.ObjectID {
|
||||||
|
case inviteeToInviter[inviteeId]:
|
||||||
|
benefit.InviterGiftDays += content.Amount
|
||||||
|
case inviteeId:
|
||||||
|
benefit.InviteeGiftDays += content.Amount
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
benefits[inviteeId] = benefit
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func QueryIdentifiers(ctx context.Context, db *gorm.DB, userIds []int64) (map[int64]string, error) {
|
||||||
|
identifiers := make(map[int64]string, len(userIds))
|
||||||
|
if len(userIds) == 0 {
|
||||||
|
return identifiers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type identifierRow struct {
|
||||||
|
UserId int64 `gorm:"column:user_id"`
|
||||||
|
Identifier string `gorm:"column:identifier"`
|
||||||
|
}
|
||||||
|
var rows []identifierRow
|
||||||
|
if err := db.WithContext(ctx).
|
||||||
|
Table("user_auth_methods uam").
|
||||||
|
Select("uam.user_id, uam.auth_identifier as identifier").
|
||||||
|
Joins("JOIN (SELECT user_id, MIN(id) AS id FROM user_auth_methods WHERE user_id IN ? GROUP BY user_id) first_uam ON first_uam.id = uam.id", userIds).
|
||||||
|
Scan(&rows).Error; err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query user identifiers failed: %v", err)
|
||||||
|
}
|
||||||
|
for _, row := range rows {
|
||||||
|
identifiers[row.UserId] = row.Identifier
|
||||||
|
}
|
||||||
|
return identifiers, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package invite
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetInviteManageListLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetInviteManageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInviteManageListLogic {
|
||||||
|
return &GetInviteManageListLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetInviteManageListLogic) GetInviteManageList(req *types.GetInviteManageListRequest) (resp *types.GetInviteManageListResponse, err error) {
|
||||||
|
req.Page, req.Size = NormalizePage(req.Page, req.Size)
|
||||||
|
|
||||||
|
type inviteRow struct {
|
||||||
|
InviteeId int64 `gorm:"column:invitee_id"`
|
||||||
|
InviteeAvatar string `gorm:"column:invitee_avatar"`
|
||||||
|
InviteeEnable bool `gorm:"column:invitee_enable"`
|
||||||
|
InvitedAt int64 `gorm:"column:invited_at"`
|
||||||
|
InviterId int64 `gorm:"column:inviter_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
baseQuery := applyInviteManageFilters(l.svcCtx.DB.WithContext(l.ctx).
|
||||||
|
Table("user invitee").
|
||||||
|
Where("invitee.referer_id > 0 AND invitee.deleted_at IS NULL"), req)
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
if err = baseQuery.Count(&total).Error; err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "count invite manage records failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []inviteRow
|
||||||
|
if err = applyInviteManageFilters(l.svcCtx.DB.WithContext(l.ctx).
|
||||||
|
Table("user invitee").
|
||||||
|
Select("invitee.id as invitee_id, invitee.avatar as invitee_avatar, invitee.enable as invitee_enable, UNIX_TIMESTAMP(invitee.created_at) as invited_at, invitee.referer_id as inviter_id").
|
||||||
|
Where("invitee.referer_id > 0 AND invitee.deleted_at IS NULL"), req).
|
||||||
|
Order("invitee.created_at DESC").
|
||||||
|
Limit(req.Size).
|
||||||
|
Offset((req.Page - 1) * req.Size).
|
||||||
|
Scan(&rows).Error; err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query invite manage records failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
relations := make([]InviteRelation, 0, len(rows))
|
||||||
|
userIds := make([]int64, 0, len(rows)*2)
|
||||||
|
for _, row := range rows {
|
||||||
|
relations = append(relations, InviteRelation{InviteeId: row.InviteeId, InviterId: row.InviterId})
|
||||||
|
userIds = append(userIds, row.InviteeId, row.InviterId)
|
||||||
|
}
|
||||||
|
|
||||||
|
benefits, err := QueryBenefits(l.ctx, l.svcCtx.DB, relations)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
identifiers, err := QueryIdentifiers(l.ctx, l.svcCtx.DB, userIds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]types.InviteManageRecord, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
benefit := benefits[row.InviteeId]
|
||||||
|
list = append(list, types.InviteManageRecord{
|
||||||
|
InviterId: row.InviterId,
|
||||||
|
InviterIdentifier: identifiers[row.InviterId],
|
||||||
|
InviteeId: row.InviteeId,
|
||||||
|
InviteeIdentifier: identifiers[row.InviteeId],
|
||||||
|
InviteeAvatar: row.InviteeAvatar,
|
||||||
|
InviteeEnable: row.InviteeEnable,
|
||||||
|
InvitedAt: row.InvitedAt,
|
||||||
|
OrderCount: benefit.OrderCount,
|
||||||
|
HasPurchased: benefit.HasPurchased,
|
||||||
|
InviterCommission: benefit.InviterCommission,
|
||||||
|
InviterGiftDays: benefit.InviterGiftDays,
|
||||||
|
InviteeGiftDays: benefit.InviteeGiftDays,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.GetInviteManageListResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyInviteManageFilters(db *gorm.DB, req *types.GetInviteManageListRequest) *gorm.DB {
|
||||||
|
if req.InviterId > 0 {
|
||||||
|
db = db.Where("invitee.referer_id = ?", req.InviterId)
|
||||||
|
}
|
||||||
|
if req.InviteeId > 0 {
|
||||||
|
db = db.Where("invitee.id = ?", req.InviteeId)
|
||||||
|
}
|
||||||
|
if req.Search != "" {
|
||||||
|
search := "%" + req.Search + "%"
|
||||||
|
db = db.Where(
|
||||||
|
"(EXISTS (SELECT 1 FROM user_auth_methods inviter_auth WHERE inviter_auth.user_id = invitee.referer_id AND inviter_auth.auth_identifier LIKE ?) OR EXISTS (SELECT 1 FROM user_auth_methods invitee_auth WHERE invitee_auth.user_id = invitee.id AND invitee_auth.auth_identifier LIKE ?))",
|
||||||
|
search,
|
||||||
|
search,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return db
|
||||||
|
}
|
||||||
@@ -3,11 +3,13 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
adminInvite "github.com/perfect-panel/server/internal/logic/admin/invite"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/logger"
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
"github.com/perfect-panel/server/pkg/xerr"
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetAdminUserInviteListLogic struct {
|
type GetAdminUserInviteListLogic struct {
|
||||||
@@ -25,15 +27,7 @@ func NewGetAdminUserInviteListLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetAdminUserInviteListLogic) GetAdminUserInviteList(req *types.GetAdminUserInviteListRequest) (resp *types.GetAdminUserInviteListResponse, err error) {
|
func (l *GetAdminUserInviteListLogic) GetAdminUserInviteList(req *types.GetAdminUserInviteListRequest) (resp *types.GetAdminUserInviteListResponse, err error) {
|
||||||
if req.Page < 1 {
|
req.Page, req.Size = adminInvite.NormalizePage(req.Page, req.Size)
|
||||||
req.Page = 1
|
|
||||||
}
|
|
||||||
if req.Size < 1 {
|
|
||||||
req.Size = 10
|
|
||||||
}
|
|
||||||
if req.Size > 100 {
|
|
||||||
req.Size = 100
|
|
||||||
}
|
|
||||||
|
|
||||||
type InvitedUser struct {
|
type InvitedUser struct {
|
||||||
Id int64 `gorm:"column:id"`
|
Id int64 `gorm:"column:id"`
|
||||||
@@ -44,19 +38,19 @@ func (l *GetAdminUserInviteListLogic) GetAdminUserInviteList(req *types.GetAdmin
|
|||||||
}
|
}
|
||||||
|
|
||||||
var total int64
|
var total int64
|
||||||
baseQuery := l.svcCtx.DB.WithContext(l.ctx).
|
baseQuery := applyAdminUserInviteFilters(l.svcCtx.DB.WithContext(l.ctx).
|
||||||
Table("user u").
|
Table("user u").
|
||||||
Where("u.referer_id = ? AND u.deleted_at IS NULL", req.UserId)
|
Where("u.referer_id = ? AND u.deleted_at IS NULL", req.UserId), req)
|
||||||
|
|
||||||
if err = baseQuery.Count(&total).Error; err != nil {
|
if err = baseQuery.Count(&total).Error; err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "count invited users failed: %v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "count invited users failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rows []InvitedUser
|
var rows []InvitedUser
|
||||||
err = l.svcCtx.DB.WithContext(l.ctx).
|
err = applyAdminUserInviteFilters(l.svcCtx.DB.WithContext(l.ctx).
|
||||||
Table("user u").
|
Table("user u").
|
||||||
Select("u.id, u.avatar, u.enable, UNIX_TIMESTAMP(u.created_at) as created_at, COALESCE((SELECT uam.auth_identifier FROM user_auth_methods uam WHERE uam.user_id = u.id ORDER BY uam.id ASC LIMIT 1), '') as identifier").
|
Select("u.id, u.avatar, u.enable, UNIX_TIMESTAMP(u.created_at) as created_at, COALESCE((SELECT uam.auth_identifier FROM user_auth_methods uam WHERE uam.user_id = u.id ORDER BY uam.id ASC LIMIT 1), '') as identifier").
|
||||||
Where("u.referer_id = ? AND u.deleted_at IS NULL", req.UserId).
|
Where("u.referer_id = ? AND u.deleted_at IS NULL", req.UserId), req).
|
||||||
Order("u.created_at DESC").
|
Order("u.created_at DESC").
|
||||||
Limit(req.Size).
|
Limit(req.Size).
|
||||||
Offset((req.Page - 1) * req.Size).
|
Offset((req.Page - 1) * req.Size).
|
||||||
@@ -65,14 +59,29 @@ func (l *GetAdminUserInviteListLogic) GetAdminUserInviteList(req *types.GetAdmin
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query invited users failed: %v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query invited users failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
relations := make([]adminInvite.InviteRelation, 0, len(rows))
|
||||||
|
for _, r := range rows {
|
||||||
|
relations = append(relations, adminInvite.InviteRelation{InviteeId: r.Id, InviterId: req.UserId})
|
||||||
|
}
|
||||||
|
benefits, err := adminInvite.QueryBenefits(l.ctx, l.svcCtx.DB, relations)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
list := make([]types.AdminInvitedUser, 0, len(rows))
|
list := make([]types.AdminInvitedUser, 0, len(rows))
|
||||||
for _, r := range rows {
|
for _, r := range rows {
|
||||||
|
benefit := benefits[r.Id]
|
||||||
list = append(list, types.AdminInvitedUser{
|
list = append(list, types.AdminInvitedUser{
|
||||||
Id: r.Id,
|
Id: r.Id,
|
||||||
Avatar: r.Avatar,
|
Avatar: r.Avatar,
|
||||||
Identifier: r.Identifier,
|
Identifier: r.Identifier,
|
||||||
Enable: r.Enable,
|
Enable: r.Enable,
|
||||||
CreatedAt: r.CreatedAt,
|
CreatedAt: r.CreatedAt,
|
||||||
|
OrderCount: benefit.OrderCount,
|
||||||
|
HasPurchased: benefit.HasPurchased,
|
||||||
|
InviterCommission: benefit.InviterCommission,
|
||||||
|
InviterGiftDays: benefit.InviterGiftDays,
|
||||||
|
InviteeGiftDays: benefit.InviteeGiftDays,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,3 +90,16 @@ func (l *GetAdminUserInviteListLogic) GetAdminUserInviteList(req *types.GetAdmin
|
|||||||
List: list,
|
List: list,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyAdminUserInviteFilters(db *gorm.DB, req *types.GetAdminUserInviteListRequest) *gorm.DB {
|
||||||
|
if req.Search != "" {
|
||||||
|
db = db.Where("EXISTS (SELECT 1 FROM user_auth_methods uam WHERE uam.user_id = u.id AND uam.auth_identifier LIKE ?)", "%"+req.Search+"%")
|
||||||
|
}
|
||||||
|
if req.Enable != nil {
|
||||||
|
db = db.Where("u.enable = ?", *req.Enable)
|
||||||
|
}
|
||||||
|
if req.UserIdSearch > 0 {
|
||||||
|
db = db.Where("u.id = ?", req.UserIdSearch)
|
||||||
|
}
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/model/group"
|
"github.com/perfect-panel/server/internal/model/group"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
@@ -36,6 +37,13 @@ func (l *GetUserSubscribeByIdLogic) GetUserSubscribeById(req *types.GetUserSubsc
|
|||||||
}
|
}
|
||||||
var subscribeDetails types.UserSubscribeDetail
|
var subscribeDetails types.UserSubscribeDetail
|
||||||
tool.DeepCopy(&subscribeDetails, sub)
|
tool.DeepCopy(&subscribeDetails, sub)
|
||||||
|
subscribeDetails.SpeedLimit = sub.SpeedLimit
|
||||||
|
if sub.TrafficLimit != nil && *sub.TrafficLimit != "" {
|
||||||
|
_ = json.Unmarshal([]byte(*sub.TrafficLimit), &subscribeDetails.TrafficLimit)
|
||||||
|
}
|
||||||
|
if sub.Subscribe != nil {
|
||||||
|
subscribeDetails.PlanSpeedLimit = sub.Subscribe.SpeedLimit
|
||||||
|
}
|
||||||
|
|
||||||
// 填充分组名
|
// 填充分组名
|
||||||
if sub.NodeGroupId > 0 {
|
if sub.NodeGroupId > 0 {
|
||||||
@@ -47,7 +55,17 @@ func (l *GetUserSubscribeByIdLogic) GetUserSubscribeById(req *types.GetUserSubsc
|
|||||||
|
|
||||||
// Calculate speed limit status
|
// Calculate speed limit status
|
||||||
if sub.Subscribe != nil && sub.Status == 1 {
|
if sub.Subscribe != nil && sub.Status == 1 {
|
||||||
result := speedlimit.Calculate(l.ctx, l.svcCtx.DB, sub.UserId, sub.Id, sub.Subscribe.SpeedLimit, sub.Subscribe.TrafficLimit)
|
baseSpeed := sub.Subscribe.SpeedLimit
|
||||||
|
if sub.SpeedLimit > 0 {
|
||||||
|
baseSpeed = sub.SpeedLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
trafficLimit := sub.Subscribe.TrafficLimit
|
||||||
|
if sub.TrafficLimit != nil && *sub.TrafficLimit != "" {
|
||||||
|
trafficLimit = *sub.TrafficLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
result := speedlimit.Calculate(l.ctx, l.svcCtx.DB, sub.UserId, sub.Id, baseSpeed, trafficLimit)
|
||||||
subscribeDetails.EffectiveSpeed = result.EffectiveSpeed
|
subscribeDetails.EffectiveSpeed = result.EffectiveSpeed
|
||||||
subscribeDetails.IsThrottled = result.IsThrottled
|
subscribeDetails.IsThrottled = result.IsThrottled
|
||||||
subscribeDetails.ThrottleRule = result.ThrottleRule
|
subscribeDetails.ThrottleRule = result.ThrottleRule
|
||||||
|
|||||||
@@ -39,22 +39,32 @@ func (l *UpdateUserSubscribeLogic) UpdateUserSubscribe(req *types.UpdateUserSubs
|
|||||||
} else {
|
} else {
|
||||||
userSub.Status = 1
|
userSub.Status = 1
|
||||||
}
|
}
|
||||||
|
speedLimit := userSub.SpeedLimit
|
||||||
|
if req.SpeedLimit != nil {
|
||||||
|
speedLimit = *req.SpeedLimit
|
||||||
|
}
|
||||||
|
trafficLimit := userSub.TrafficLimit
|
||||||
|
if req.TrafficLimit != nil {
|
||||||
|
trafficLimit = req.TrafficLimit
|
||||||
|
}
|
||||||
|
|
||||||
err = l.svcCtx.UserModel.UpdateSubscribe(l.ctx, &user.Subscribe{
|
err = l.svcCtx.UserModel.UpdateSubscribe(l.ctx, &user.Subscribe{
|
||||||
Id: userSub.Id,
|
Id: userSub.Id,
|
||||||
UserId: userSub.UserId,
|
UserId: userSub.UserId,
|
||||||
OrderId: userSub.OrderId,
|
OrderId: userSub.OrderId,
|
||||||
SubscribeId: req.SubscribeId,
|
SubscribeId: req.SubscribeId,
|
||||||
StartTime: userSub.StartTime,
|
StartTime: userSub.StartTime,
|
||||||
ExpireTime: time.UnixMilli(req.ExpiredAt),
|
ExpireTime: time.UnixMilli(req.ExpiredAt),
|
||||||
Traffic: req.Traffic,
|
Traffic: req.Traffic,
|
||||||
Download: req.Download,
|
Download: req.Download,
|
||||||
Upload: req.Upload,
|
Upload: req.Upload,
|
||||||
Token: userSub.Token,
|
SpeedLimit: speedLimit,
|
||||||
UUID: userSub.UUID,
|
TrafficLimit: trafficLimit,
|
||||||
Status: userSub.Status,
|
Token: userSub.Token,
|
||||||
NodeGroupId: userSub.NodeGroupId,
|
UUID: userSub.UUID,
|
||||||
GroupLocked: userSub.GroupLocked,
|
Status: userSub.Status,
|
||||||
|
NodeGroupId: userSub.NodeGroupId,
|
||||||
|
GroupLocked: userSub.GroupLocked,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
package common
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package common
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package common
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package common
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package server
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package server
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package server
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package server
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package server
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package server
|
||||||
@@ -80,7 +80,7 @@ func validateInitRequest(svcCtx *svc.ServiceContext, bizType, fileName, contentT
|
|||||||
allowed := allowedContentTypeSet(svcCtx.Config.S3.AllowedContentTypes)
|
allowed := allowedContentTypeSet(svcCtx.Config.S3.AllowedContentTypes)
|
||||||
if len(allowed) > 0 {
|
if len(allowed) > 0 {
|
||||||
if _, ok := allowed[strings.ToLower(strings.TrimSpace(contentType))]; !ok {
|
if _, ok := allowed[strings.ToLower(strings.TrimSpace(contentType))]; !ok {
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), "content_type is not allowed")
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "content_type is not allowed"), "content_type is not allowed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"mime/multipart"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/config"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/pkg/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testAllowedContentTypes = "application/zip,application/x-zip-compressed,application/gzip,application/x-gzip,application/octet-stream,text/plain,application/json,image/jpeg,image/jpg,image/png,image/webp,image/gif,image/heic,image/heif,image/bmp"
|
||||||
|
|
||||||
|
type testMultipartFile struct {
|
||||||
|
*strings.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (testMultipartFile) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateInitRequestAllowedContentTypes(t *testing.T) {
|
||||||
|
svcCtx := &svc.ServiceContext{
|
||||||
|
Config: config.Config{
|
||||||
|
S3: config.S3Config{
|
||||||
|
Enable: true,
|
||||||
|
MaxUploadSize: 1024,
|
||||||
|
AllowedContentTypes: testAllowedContentTypes,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
S3Store: &storage.S3Store{},
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
contentType string
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{name: "allow jpeg", contentType: "image/jpeg"},
|
||||||
|
{name: "allow png", contentType: "image/png"},
|
||||||
|
{name: "allow webp", contentType: "image/webp"},
|
||||||
|
{name: "reject unknown", contentType: "application/x-sh", wantErr: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
err := validateInitRequest(svcCtx, "app-package", "demo.bin", tt.contentType, 10)
|
||||||
|
if tt.wantErr {
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error, got nil")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "content_type is not allowed") {
|
||||||
|
t.Fatalf("expected content type error, got %v", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected nil error, got %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSniffContentTypeDetectsCommonImages(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
data string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{name: "jpeg", data: "\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01", want: "image/jpeg"},
|
||||||
|
{name: "png", data: "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR", want: "image/png"},
|
||||||
|
{name: "webp", data: "RIFF\x1a\x00\x00\x00WEBPVP8 \x0e\x00\x00\x00", want: "image/webp"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
file := testMultipartFile{Reader: strings.NewReader(tt.data)}
|
||||||
|
got, err := sniffContentType(&multipart.FileHeader{}, file)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected nil error, got %v", err)
|
||||||
|
}
|
||||||
|
if got != tt.want {
|
||||||
|
t.Fatalf("expected %q, got %q", tt.want, got)
|
||||||
|
}
|
||||||
|
if pos, err := file.Seek(0, 1); err != nil || pos != 0 {
|
||||||
|
t.Fatalf("expected reader reset to start, pos=%d err=%v", pos, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package apple
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package apple
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package apple
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package apple
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
logmodel "github.com/perfect-panel/server/internal/model/log"
|
||||||
|
ordermodel "github.com/perfect-panel/server/internal/model/order"
|
||||||
|
"github.com/perfect-panel/server/internal/model/user"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/constant"
|
||||||
|
"github.com/perfect-panel/server/pkg/hash"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
inviteRecordRoleInviter = "inviter"
|
||||||
|
inviteRecordRoleInvitee = "invitee"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetInviteRecordsLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
type inviteRecordLog struct {
|
||||||
|
Id int64 `gorm:"column:id"`
|
||||||
|
ObjectId int64 `gorm:"column:object_id"`
|
||||||
|
Content string `gorm:"column:content"`
|
||||||
|
CreatedAt int64 `gorm:"column:created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type inviteGiftContent struct {
|
||||||
|
OrderNo string `json:"order_no"`
|
||||||
|
Amount int64 `json:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type parsedInviteRecordLog struct {
|
||||||
|
log inviteRecordLog
|
||||||
|
content inviteGiftContent
|
||||||
|
}
|
||||||
|
|
||||||
|
type inviteOrderUser struct {
|
||||||
|
OrderNo string `gorm:"column:order_no"`
|
||||||
|
UserId int64 `gorm:"column:user_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get invite gift records
|
||||||
|
func NewGetInviteRecordsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInviteRecordsLogic {
|
||||||
|
return &GetInviteRecordsLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetInviteRecordsLogic) GetInviteRecords(req *types.GetInviteRecordsRequest) (resp *types.GetInviteRecordsResponse, err error) {
|
||||||
|
u, ok := l.ctx.Value(constant.CtxKeyUser).(*user.User)
|
||||||
|
if !ok {
|
||||||
|
l.Errorw("[GetInviteRecords] user not found in context")
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "Invalid Access")
|
||||||
|
}
|
||||||
|
|
||||||
|
normalizeInviteRecordsPagination(req)
|
||||||
|
|
||||||
|
query := l.svcCtx.DB.WithContext(l.ctx).
|
||||||
|
Table("system_logs").
|
||||||
|
Where("type = ? AND object_id = ?", logmodel.TypeGift.Uint8(), u.Id).
|
||||||
|
Where("JSON_VALID(content) = 1").
|
||||||
|
Where("JSON_UNQUOTE(JSON_EXTRACT(content, '$.remark')) = ?", "邀请赠送")
|
||||||
|
if req.StartTime > 0 {
|
||||||
|
query = query.Where("created_at >= FROM_UNIXTIME(?)", req.StartTime)
|
||||||
|
}
|
||||||
|
if req.EndTime > 0 {
|
||||||
|
query = query.Where("created_at <= FROM_UNIXTIME(?)", req.EndTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
if err = query.Count(&total).Error; err != nil {
|
||||||
|
l.Errorw("[GetInviteRecords] count logs failed",
|
||||||
|
logger.Field("error", err.Error()),
|
||||||
|
logger.Field("user_id", u.Id))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "count logs failed: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var logs []inviteRecordLog
|
||||||
|
if err = query.
|
||||||
|
Select("id, object_id, content, CAST(UNIX_TIMESTAMP(created_at) * 1000 AS SIGNED) AS created_at").
|
||||||
|
Order("created_at DESC, id DESC").
|
||||||
|
Limit(req.Size).
|
||||||
|
Offset((req.Page - 1) * req.Size).
|
||||||
|
Scan(&logs).Error; err != nil {
|
||||||
|
l.Errorw("[GetInviteRecords] query logs failed",
|
||||||
|
logger.Field("error", err.Error()),
|
||||||
|
logger.Field("user_id", u.Id))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query logs failed: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
parsedLogs, orderNos := l.parseInviteRecordContents(logs)
|
||||||
|
if len(logs) == 0 || len(parsedLogs) == 0 {
|
||||||
|
return &types.GetInviteRecordsResponse{Total: total, List: []types.InviteRecord{}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
orders, err := l.queryInviteRecordOrders(orderNos)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[GetInviteRecords] query orders failed",
|
||||||
|
logger.Field("error", err.Error()),
|
||||||
|
logger.Field("user_id", u.Id))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query orders failed: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]types.InviteRecord, 0, len(parsedLogs))
|
||||||
|
for _, parsed := range parsedLogs {
|
||||||
|
content := parsed.content
|
||||||
|
logItem := parsed.log
|
||||||
|
record := types.InviteRecord{
|
||||||
|
Role: inviteRecordRoleInviter,
|
||||||
|
GiftDays: content.Amount,
|
||||||
|
OrderNo: content.OrderNo,
|
||||||
|
CreatedAt: logItem.CreatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
if orderInfo, ok := orders[content.OrderNo]; ok {
|
||||||
|
peerId := orderInfo.UserId
|
||||||
|
if orderInfo.UserId == u.Id {
|
||||||
|
record.Role = inviteRecordRoleInvitee
|
||||||
|
peerId = u.RefererId
|
||||||
|
}
|
||||||
|
if peerId > 0 {
|
||||||
|
record.PeerHash = hash.InvitePeerHash(peerId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list = append(list, record)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.GetInviteRecordsResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeInviteRecordsPagination(req *types.GetInviteRecordsRequest) {
|
||||||
|
if req.Page < 1 {
|
||||||
|
req.Page = 1
|
||||||
|
}
|
||||||
|
if req.Size < 1 {
|
||||||
|
req.Size = 10
|
||||||
|
}
|
||||||
|
if req.Size > 100 {
|
||||||
|
req.Size = 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetInviteRecordsLogic) parseInviteRecordContents(logs []inviteRecordLog) ([]parsedInviteRecordLog, []string) {
|
||||||
|
parsedLogs := make([]parsedInviteRecordLog, 0, len(logs))
|
||||||
|
orderNos := make([]string, 0, len(logs))
|
||||||
|
for _, logItem := range logs {
|
||||||
|
var content inviteGiftContent
|
||||||
|
if err := json.Unmarshal([]byte(logItem.Content), &content); err != nil {
|
||||||
|
l.Infow("[GetInviteRecords] parse content failed",
|
||||||
|
logger.Field("error", err.Error()),
|
||||||
|
logger.Field("log_id", logItem.Id))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parsedLogs = append(parsedLogs, parsedInviteRecordLog{log: logItem, content: content})
|
||||||
|
if content.OrderNo != "" {
|
||||||
|
orderNos = append(orderNos, content.OrderNo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parsedLogs, orderNos
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetInviteRecordsLogic) queryInviteRecordOrders(orderNos []string) (map[string]inviteOrderUser, error) {
|
||||||
|
orders := make(map[string]inviteOrderUser, len(orderNos))
|
||||||
|
if len(orderNos) == 0 {
|
||||||
|
return orders, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var orderData []inviteOrderUser
|
||||||
|
err := l.svcCtx.DB.WithContext(l.ctx).
|
||||||
|
Model(&ordermodel.Order{}).
|
||||||
|
Select("order_no, user_id").
|
||||||
|
Where("order_no IN ?", orderNos).
|
||||||
|
Scan(&orderData).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range orderData {
|
||||||
|
orders[item.OrderNo] = item
|
||||||
|
}
|
||||||
|
return orders, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/DATA-DOG/go-sqlmock"
|
||||||
|
modeluser "github.com/perfect-panel/server/internal/model/user"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/constant"
|
||||||
|
"github.com/perfect-panel/server/pkg/hash"
|
||||||
|
"gorm.io/driver/mysql"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetInviteRecordsInviter(t *testing.T) {
|
||||||
|
svcCtx, mock, cleanup := newInviteRecordsTestSvc(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
mock.ExpectQuery("count(*)").
|
||||||
|
WithArgs(34, int64(100), "邀请赠送").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(1))
|
||||||
|
mock.ExpectQuery("SELECT id, object_id, content").
|
||||||
|
WithArgs(34, int64(100), "邀请赠送", 10).
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"id", "object_id", "content", "created_at"}).
|
||||||
|
AddRow(1, 100, `{"order_no":"order-1","amount":7,"remark":"邀请赠送"}`, 1779934580000))
|
||||||
|
mock.ExpectQuery("SELECT order_no, user_id FROM `order`").
|
||||||
|
WithArgs("order-1").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"order_no", "user_id"}).AddRow("order-1", 200))
|
||||||
|
|
||||||
|
resp, err := NewGetInviteRecordsLogic(inviteRecordsContext(100, 0), svcCtx).GetInviteRecords(&types.GetInviteRecordsRequest{Page: 1, Size: 10})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetInviteRecords returned error: %v", err)
|
||||||
|
}
|
||||||
|
assertInviteRecordResponse(t, resp, types.InviteRecord{
|
||||||
|
Role: inviteRecordRoleInviter,
|
||||||
|
PeerHash: hash.InvitePeerHash(200),
|
||||||
|
GiftDays: 7,
|
||||||
|
OrderNo: "order-1",
|
||||||
|
CreatedAt: 1779934580000,
|
||||||
|
})
|
||||||
|
assertInviteRecordsExpectations(t, mock)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetInviteRecordsInvitee(t *testing.T) {
|
||||||
|
svcCtx, mock, cleanup := newInviteRecordsTestSvc(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
mock.ExpectQuery("count(*)").
|
||||||
|
WithArgs(34, int64(200), "邀请赠送").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(1))
|
||||||
|
mock.ExpectQuery("SELECT id, object_id, content").
|
||||||
|
WithArgs(34, int64(200), "邀请赠送", 10).
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"id", "object_id", "content", "created_at"}).
|
||||||
|
AddRow(2, 200, `{"order_no":"order-2","amount":7,"remark":"邀请赠送"}`, 1779934590000))
|
||||||
|
mock.ExpectQuery("SELECT order_no, user_id FROM `order`").
|
||||||
|
WithArgs("order-2").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"order_no", "user_id"}).AddRow("order-2", 200))
|
||||||
|
|
||||||
|
resp, err := NewGetInviteRecordsLogic(inviteRecordsContext(200, 100), svcCtx).GetInviteRecords(&types.GetInviteRecordsRequest{Page: 1, Size: 10})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetInviteRecords returned error: %v", err)
|
||||||
|
}
|
||||||
|
assertInviteRecordResponse(t, resp, types.InviteRecord{
|
||||||
|
Role: inviteRecordRoleInvitee,
|
||||||
|
PeerHash: hash.InvitePeerHash(100),
|
||||||
|
GiftDays: 7,
|
||||||
|
OrderNo: "order-2",
|
||||||
|
CreatedAt: 1779934590000,
|
||||||
|
})
|
||||||
|
assertInviteRecordsExpectations(t, mock)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetInviteRecordsMissingOrderReturnsDirtyRecord(t *testing.T) {
|
||||||
|
svcCtx, mock, cleanup := newInviteRecordsTestSvc(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
mock.ExpectQuery("count(*)").
|
||||||
|
WithArgs(34, int64(100), "邀请赠送").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(1))
|
||||||
|
mock.ExpectQuery("SELECT id, object_id, content").
|
||||||
|
WithArgs(34, int64(100), "邀请赠送", 10).
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"id", "object_id", "content", "created_at"}).
|
||||||
|
AddRow(3, 100, `{"order_no":"missing-order","amount":7,"remark":"邀请赠送"}`, 1779934600000))
|
||||||
|
mock.ExpectQuery("SELECT order_no, user_id FROM `order`").
|
||||||
|
WithArgs("missing-order").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"order_no", "user_id"}))
|
||||||
|
|
||||||
|
resp, err := NewGetInviteRecordsLogic(inviteRecordsContext(100, 0), svcCtx).GetInviteRecords(&types.GetInviteRecordsRequest{Page: 1, Size: 10})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetInviteRecords returned error: %v", err)
|
||||||
|
}
|
||||||
|
assertInviteRecordResponse(t, resp, types.InviteRecord{
|
||||||
|
Role: inviteRecordRoleInviter,
|
||||||
|
GiftDays: 7,
|
||||||
|
OrderNo: "missing-order",
|
||||||
|
CreatedAt: 1779934600000,
|
||||||
|
})
|
||||||
|
assertInviteRecordsExpectations(t, mock)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newInviteRecordsTestSvc(t *testing.T) (*svc.ServiceContext, sqlmock.Sqlmock, func()) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
sqlDB, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherFunc(func(expectedSQL, actualSQL string) error {
|
||||||
|
if strings.Contains(actualSQL, expectedSQL) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("actual sql %q does not contain %q", actualSQL, expectedSQL)
|
||||||
|
})))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("create sqlmock: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := gorm.Open(mysql.New(mysql.Config{Conn: sqlDB, SkipInitializeWithVersion: true}), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
_ = sqlDB.Close()
|
||||||
|
t.Fatalf("open gorm db: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &svc.ServiceContext{DB: db}, mock, func() {
|
||||||
|
_ = sqlDB.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func inviteRecordsContext(userId, refererId int64) context.Context {
|
||||||
|
return context.WithValue(context.Background(), constant.CtxKeyUser, &modeluser.User{
|
||||||
|
Id: userId,
|
||||||
|
RefererId: refererId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertInviteRecordResponse(t *testing.T, resp *types.GetInviteRecordsResponse, want types.InviteRecord) {
|
||||||
|
t.Helper()
|
||||||
|
if resp == nil {
|
||||||
|
t.Fatal("response is nil")
|
||||||
|
}
|
||||||
|
if resp.Total != 1 {
|
||||||
|
t.Fatalf("Total = %d, want 1", resp.Total)
|
||||||
|
}
|
||||||
|
if len(resp.List) != 1 {
|
||||||
|
t.Fatalf("len(List) = %d, want 1", len(resp.List))
|
||||||
|
}
|
||||||
|
if got := resp.List[0]; got != want {
|
||||||
|
t.Fatalf("record = %+v, want %+v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertInviteRecordsExpectations(t *testing.T, mock sqlmock.Sqlmock) {
|
||||||
|
t.Helper()
|
||||||
|
if err := mock.ExpectationsWereMet(); err != nil {
|
||||||
|
t.Fatalf("unmet sql expectations: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
package user
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"hash/fnv"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/model/user"
|
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
|
||||||
"github.com/perfect-panel/server/internal/types"
|
|
||||||
"github.com/perfect-panel/server/pkg/constant"
|
|
||||||
"github.com/perfect-panel/server/pkg/logger"
|
|
||||||
"github.com/perfect-panel/server/pkg/xerr"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GetInviteSalesLogic struct {
|
|
||||||
logger.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGetInviteSalesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInviteSalesLogic {
|
|
||||||
return &GetInviteSalesLogic{
|
|
||||||
Logger: logger.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *GetInviteSalesLogic) GetInviteSales(req *types.GetInviteSalesRequest) (resp *types.GetInviteSalesResponse, err error) {
|
|
||||||
// 1. Get current user
|
|
||||||
u, ok := l.ctx.Value(constant.CtxKeyUser).(*user.User)
|
|
||||||
if !ok {
|
|
||||||
l.Errorw("[GetInviteSales] user not found in context")
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "Invalid Access")
|
|
||||||
}
|
|
||||||
userId := u.Id
|
|
||||||
|
|
||||||
// 2. Count total sales
|
|
||||||
var totalSales int64
|
|
||||||
db := l.svcCtx.DB.WithContext(l.ctx).
|
|
||||||
Table("`order` o").
|
|
||||||
Joins("JOIN user u ON o.user_id = u.id").
|
|
||||||
Where("u.referer_id = ? AND o.status IN ?", userId, []int{2, 5})
|
|
||||||
|
|
||||||
if req.StartTime > 0 {
|
|
||||||
db = db.Where("o.updated_at >= FROM_UNIXTIME(?)", req.StartTime)
|
|
||||||
}
|
|
||||||
if req.EndTime > 0 {
|
|
||||||
db = db.Where("o.updated_at <= FROM_UNIXTIME(?)", req.EndTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.Count(&totalSales).Error
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[GetInviteSales] count sales failed",
|
|
||||||
logger.Field("error", err.Error()),
|
|
||||||
logger.Field("user_id", userId))
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError),
|
|
||||||
"count sales failed: %v", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Pagination
|
|
||||||
if req.Page < 1 {
|
|
||||||
req.Page = 1
|
|
||||||
}
|
|
||||||
if req.Size < 1 {
|
|
||||||
req.Size = 10
|
|
||||||
}
|
|
||||||
if req.Size > 100 {
|
|
||||||
req.Size = 100
|
|
||||||
}
|
|
||||||
offset := (req.Page - 1) * req.Size
|
|
||||||
|
|
||||||
// 4. Get sales data
|
|
||||||
type OrderWithUser struct {
|
|
||||||
Amount int64 `gorm:"column:amount"`
|
|
||||||
UpdatedAt int64 `gorm:"column:updated_at"`
|
|
||||||
UserId int64 `gorm:"column:user_id"`
|
|
||||||
ProductName string `gorm:"column:product_name"`
|
|
||||||
Quantity int64 `gorm:"column:quantity"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var orderData []OrderWithUser
|
|
||||||
query := l.svcCtx.DB.WithContext(l.ctx).
|
|
||||||
Table("`order` o").
|
|
||||||
Select("o.amount, CAST(UNIX_TIMESTAMP(o.updated_at) * 1000 AS SIGNED) as updated_at, u.id as user_id, s.name as product_name, o.quantity").
|
|
||||||
Joins("JOIN user u ON o.user_id = u.id").
|
|
||||||
Joins("LEFT JOIN subscribe s ON o.subscribe_id = s.id").
|
|
||||||
Where("u.referer_id = ? AND o.status IN ?", userId, []int{2, 5}) // status 2: Active, 5: Finished
|
|
||||||
|
|
||||||
if req.StartTime > 0 {
|
|
||||||
query = query.Where("o.updated_at >= FROM_UNIXTIME(?)", req.StartTime)
|
|
||||||
}
|
|
||||||
if req.EndTime > 0 {
|
|
||||||
query = query.Where("o.updated_at <= FROM_UNIXTIME(?)", req.EndTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = query.Order("o.updated_at DESC").
|
|
||||||
Limit(req.Size).
|
|
||||||
Offset(offset).
|
|
||||||
Scan(&orderData).Error
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[GetInviteSales] query sales failed",
|
|
||||||
logger.Field("error", err.Error()),
|
|
||||||
logger.Field("user_id", userId))
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError),
|
|
||||||
"query sales failed: %v", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. Get sales list
|
|
||||||
const HashSalt = "ppanel_invite_sales_v1" // Fixed Key
|
|
||||||
var list []types.InvitedUserSale
|
|
||||||
for _, order := range orderData {
|
|
||||||
// Calculate unique numeric hash (FNV-64a)
|
|
||||||
h := fnv.New64a()
|
|
||||||
h.Write([]byte(HashSalt))
|
|
||||||
h.Write([]byte(strconv.FormatInt(order.UserId, 10)))
|
|
||||||
// Truncate to 10 digits using modulo 10^10
|
|
||||||
hashVal := h.Sum64() % 10000000000
|
|
||||||
userHashStr := fmt.Sprintf("%010d", hashVal)
|
|
||||||
|
|
||||||
// Format product name: prefer subscribe name, fallback to quantity-based label
|
|
||||||
productName := order.ProductName
|
|
||||||
if productName == "" {
|
|
||||||
productName = fmt.Sprintf("%d天VPN服务", order.Quantity)
|
|
||||||
if order.Quantity <= 0 {
|
|
||||||
productName = "VPN服务"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
list = append(list, types.InvitedUserSale{
|
|
||||||
Amount: float64(order.Amount) / 100.0, // Convert cents to dollars
|
|
||||||
UpdatedAt: order.UpdatedAt,
|
|
||||||
UserHash: userHashStr,
|
|
||||||
ProductName: productName,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.GetInviteSalesResponse{
|
|
||||||
Total: totalSales,
|
|
||||||
List: list,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
@@ -307,14 +307,24 @@ func (l *GetServerUserListLogic) canUseExpiredNodeGroup(userSub *user.Subscribe,
|
|||||||
|
|
||||||
// calculateEffectiveSpeedLimit 计算用户的实际限速值(考虑按量限速规则)
|
// calculateEffectiveSpeedLimit 计算用户的实际限速值(考虑按量限速规则)
|
||||||
func (l *GetServerUserListLogic) calculateEffectiveSpeedLimit(sub *subscribe.Subscribe, userSub *user.Subscribe) int64 {
|
func (l *GetServerUserListLogic) calculateEffectiveSpeedLimit(sub *subscribe.Subscribe, userSub *user.Subscribe) int64 {
|
||||||
|
baseSpeed := sub.SpeedLimit
|
||||||
|
if userSub.SpeedLimit > 0 {
|
||||||
|
baseSpeed = userSub.SpeedLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
trafficLimit := sub.TrafficLimit
|
||||||
|
if userSub.TrafficLimit != nil && *userSub.TrafficLimit != "" {
|
||||||
|
trafficLimit = *userSub.TrafficLimit
|
||||||
|
}
|
||||||
|
|
||||||
result := speedlimit.CalculateWithCache(
|
result := speedlimit.CalculateWithCache(
|
||||||
l.ctx.Request.Context(),
|
l.ctx.Request.Context(),
|
||||||
l.svcCtx.Redis,
|
l.svcCtx.Redis,
|
||||||
l.svcCtx.DB,
|
l.svcCtx.DB,
|
||||||
userSub.UserId,
|
userSub.UserId,
|
||||||
userSub.Id,
|
userSub.Id,
|
||||||
sub.SpeedLimit,
|
baseSpeed,
|
||||||
sub.TrafficLimit,
|
trafficLimit,
|
||||||
30*time.Second,
|
30*time.Second,
|
||||||
)
|
)
|
||||||
return result.EffectiveSpeed
|
return result.EffectiveSpeed
|
||||||
|
|||||||
@@ -23,25 +23,27 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SubscribeDetails struct {
|
type SubscribeDetails struct {
|
||||||
Id int64 `gorm:"primarykey"`
|
Id int64 `gorm:"primarykey"`
|
||||||
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
||||||
User *User `gorm:"foreignKey:UserId;references:Id"`
|
User *User `gorm:"foreignKey:UserId;references:Id"`
|
||||||
OrderId int64 `gorm:"index:idx_order_id;not null;comment:Order ID"`
|
OrderId int64 `gorm:"index:idx_order_id;not null;comment:Order ID"`
|
||||||
SubscribeId int64 `gorm:"index:idx_subscribe_id;not null;comment:Subscription ID"`
|
SubscribeId int64 `gorm:"index:idx_subscribe_id;not null;comment:Subscription ID"`
|
||||||
Subscribe *subscribe.Subscribe `gorm:"foreignKey:SubscribeId;references:Id"`
|
Subscribe *subscribe.Subscribe `gorm:"foreignKey:SubscribeId;references:Id"`
|
||||||
NodeGroupId int64 `gorm:"index:idx_node_group_id;not null;default:0;comment:Node Group ID (single ID)"`
|
NodeGroupId int64 `gorm:"index:idx_node_group_id;not null;default:0;comment:Node Group ID (single ID)"`
|
||||||
StartTime time.Time `gorm:"default:CURRENT_TIMESTAMP(3);not null;comment:Subscription Start Time"`
|
StartTime time.Time `gorm:"default:CURRENT_TIMESTAMP(3);not null;comment:Subscription Start Time"`
|
||||||
ExpireTime time.Time `gorm:"default:NULL;comment:Subscription Expire Time"`
|
ExpireTime time.Time `gorm:"default:NULL;comment:Subscription Expire Time"`
|
||||||
FinishedAt *time.Time `gorm:"default:NULL;comment:Finished Time"`
|
FinishedAt *time.Time `gorm:"default:NULL;comment:Finished Time"`
|
||||||
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
||||||
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
||||||
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
||||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
SpeedLimit int64 `gorm:"default:0;comment:User-level speed limit override (Mbps), 0 uses plan-level"`
|
||||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
TrafficLimit *string `gorm:"type:text;default:null;comment:User-level traffic limit override (JSON), NULL uses plan-level"`
|
||||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired; 4: Cancelled"`
|
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||||
Note string `gorm:"type:varchar(500);default:'';comment:User note for subscription"`
|
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired; 4: Cancelled"`
|
||||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
Note string `gorm:"type:varchar(500);default:'';comment:User note for subscription"`
|
||||||
|
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||||
|
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubscribeLogFilterParams struct {
|
type SubscribeLogFilterParams struct {
|
||||||
|
|||||||
@@ -101,10 +101,10 @@ type Subscribe struct {
|
|||||||
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
||||||
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
||||||
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
||||||
SpeedLimit int64 `gorm:"default:0;comment:User-level speed limit override (Mbps, 0=use plan default)"`
|
|
||||||
TrafficLimit string `gorm:"type:text;default:null;comment:User-level traffic limit rules override (JSON)"`
|
|
||||||
ExpiredDownload int64 `gorm:"default:0;comment:Expired period download traffic (bytes)"`
|
ExpiredDownload int64 `gorm:"default:0;comment:Expired period download traffic (bytes)"`
|
||||||
ExpiredUpload int64 `gorm:"default:0;comment:Expired period upload traffic (bytes)"`
|
ExpiredUpload int64 `gorm:"default:0;comment:Expired period upload traffic (bytes)"`
|
||||||
|
SpeedLimit int64 `gorm:"default:0;comment:User-level speed limit override (Mbps), 0 uses plan-level"`
|
||||||
|
TrafficLimit *string `gorm:"type:text;default:null;comment:User-level traffic limit override (JSON), NULL uses plan-level"`
|
||||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired 4: Deducted 5: stopped"`
|
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired 4: Deducted 5: stopped"`
|
||||||
|
|||||||
+6
-1
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/perfect-panel/server/internal/handler"
|
"github.com/perfect-panel/server/internal/handler"
|
||||||
"github.com/perfect-panel/server/internal/middleware"
|
"github.com/perfect-panel/server/internal/middleware"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
@@ -64,7 +65,11 @@ func initServer(svc *svc.ServiceContext) *gin.Engine {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// register handlers
|
// register handlers
|
||||||
handler.RegisterHandlers(r, svc)
|
svc.AuthMiddleware = middleware.AuthMiddleware(svc)
|
||||||
|
svc.OptionalAuthMiddleware = middleware.OptionalAuthMiddleware(svc)
|
||||||
|
svc.DeviceMiddleware = middleware.DeviceMiddleware(svc)
|
||||||
|
svc.ServerMiddleware = middleware.ServerMiddleware(svc)
|
||||||
|
handler.RegisterHandlers(rest.NewServer(r, rest.WithOptionalAuth(svc.OptionalAuthMiddleware)), svc)
|
||||||
r.StaticFile("/order-recovery.html", "./public/order-recovery.html")
|
r.StaticFile("/order-recovery.html", "./public/order-recovery.html")
|
||||||
// register subscribe handler
|
// register subscribe handler
|
||||||
handler.RegisterSubscribeHandlers(r, svc)
|
handler.RegisterSubscribeHandlers(r, svc)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/model/client"
|
"github.com/perfect-panel/server/internal/model/client"
|
||||||
"github.com/perfect-panel/server/internal/model/node"
|
"github.com/perfect-panel/server/internal/model/node"
|
||||||
"github.com/perfect-panel/server/internal/model/redemption"
|
"github.com/perfect-panel/server/internal/model/redemption"
|
||||||
@@ -71,11 +72,15 @@ type ServiceContext struct {
|
|||||||
AnnouncementModel announcement.Model
|
AnnouncementModel announcement.Model
|
||||||
IAPAppleTransactionModel iapapple.Model
|
IAPAppleTransactionModel iapapple.Model
|
||||||
|
|
||||||
Restart func() error
|
Restart func() error
|
||||||
TelegramBot *tgbotapi.BotAPI
|
TelegramBot *tgbotapi.BotAPI
|
||||||
NodeMultiplierManager *nodeMultiplier.Manager
|
NodeMultiplierManager *nodeMultiplier.Manager
|
||||||
AuthLimiter *limit.PeriodLimit
|
AuthLimiter *limit.PeriodLimit
|
||||||
DeviceManager *device.DeviceManager
|
DeviceManager *device.DeviceManager
|
||||||
|
AuthMiddleware gin.HandlerFunc
|
||||||
|
OptionalAuthMiddleware gin.HandlerFunc
|
||||||
|
DeviceMiddleware gin.HandlerFunc
|
||||||
|
ServerMiddleware gin.HandlerFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
|||||||
+275
-240
@@ -3,15 +3,21 @@
|
|||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import "encoding/json"
|
|
||||||
|
|
||||||
type ActivateOrderRequest struct {
|
type ActivateOrderRequest struct {
|
||||||
OrderNo string `json:"order_no" validate:"required"`
|
OrderNo string `json:"order_no" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RefundOrderRequest struct {
|
type AdminInvitedUser struct {
|
||||||
Id int64 `json:"id" validate:"required"`
|
Id int64 `json:"id"`
|
||||||
Reason string `json:"reason,omitempty" validate:"omitempty,max=500"`
|
Avatar string `json:"avatar"`
|
||||||
|
Identifier string `json:"identifier"`
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
OrderCount int64 `json:"order_count"`
|
||||||
|
HasPurchased bool `json:"has_purchased"`
|
||||||
|
InviterCommission int64 `json:"inviter_commission"`
|
||||||
|
InviterGiftDays int64 `json:"inviter_gift_days"`
|
||||||
|
InviteeGiftDays int64 `json:"invitee_gift_days"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ads struct {
|
type Ads struct {
|
||||||
@@ -126,6 +132,10 @@ type ApplicationVersion struct {
|
|||||||
IsDefault bool `json:"is_default"`
|
IsDefault bool `json:"is_default"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApproveWithdrawalRequest struct {
|
||||||
|
WithdrawalId int64 `json:"withdrawal_id" validate:"required,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
type AttachAppleTransactionByIdRequest struct {
|
type AttachAppleTransactionByIdRequest struct {
|
||||||
OrderNo string `json:"order_no" validate:"required"`
|
OrderNo string `json:"order_no" validate:"required"`
|
||||||
TransactionId string `json:"transaction_id" validate:"required"`
|
TransactionId string `json:"transaction_id" validate:"required"`
|
||||||
@@ -251,6 +261,10 @@ type BindTelegramResponse struct {
|
|||||||
ExpiredAt int64 `json:"expired_at"`
|
ExpiredAt int64 `json:"expired_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CancelWithdrawalRequest struct {
|
||||||
|
WithdrawalId int64 `json:"withdrawal_id" validate:"required,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
type CheckUserRequest struct {
|
type CheckUserRequest struct {
|
||||||
Email string `form:"email" validate:"required"`
|
Email string `form:"email" validate:"required"`
|
||||||
}
|
}
|
||||||
@@ -316,45 +330,6 @@ type ContactRequest struct {
|
|||||||
Notes string `json:"notes" validate:"max=2000"`
|
Notes string `json:"notes" validate:"max=2000"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PromoPrice struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
SubscribeId int64 `json:"subscribe_id"`
|
|
||||||
PromoRuleId int64 `json:"promo_rule_id"`
|
|
||||||
Quantity int64 `json:"quantity"`
|
|
||||||
PromoPrice int64 `json:"promo_price"`
|
|
||||||
CreatedAt int64 `json:"created_at"`
|
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PromoPriceItem struct {
|
|
||||||
SubscribeId int64 `json:"subscribe_id" validate:"required,gt=0"`
|
|
||||||
Quantity int64 `json:"quantity" validate:"required,gt=0,lte=1000"`
|
|
||||||
PromoPrice int64 `json:"promo_price" validate:"required,gt=0"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PromoRule struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Params map[string]interface{} `json:"params"`
|
|
||||||
Priority int64 `json:"priority"`
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
StartTime *int64 `json:"start_time"`
|
|
||||||
EndTime *int64 `json:"end_time"`
|
|
||||||
CreatedAt int64 `json:"created_at"`
|
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PromoUsage struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
PromoRuleId int64 `json:"promo_rule_id"`
|
|
||||||
SubscribeId int64 `json:"subscribe_id"`
|
|
||||||
OrderNo string `json:"order_no"`
|
|
||||||
PromoPrice int64 `json:"promo_price"`
|
|
||||||
CreatedAt int64 `json:"created_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Coupon struct {
|
type Coupon struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -414,16 +389,6 @@ type CreateCouponRequest struct {
|
|||||||
Enable *bool `json:"enable,omitempty"`
|
Enable *bool `json:"enable,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreatePromoRuleRequest struct {
|
|
||||||
Name string `json:"name" validate:"required,max=100"`
|
|
||||||
Type string `json:"type" validate:"required,oneof=new_user inactive_user campaign"`
|
|
||||||
Params map[string]interface{} `json:"params"`
|
|
||||||
Priority int64 `json:"priority" validate:"gte=0"`
|
|
||||||
Enabled *bool `json:"enabled"`
|
|
||||||
StartTime *int64 `json:"start_time"`
|
|
||||||
EndTime *int64 `json:"end_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateDocumentRequest struct {
|
type CreateDocumentRequest struct {
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
Content string `json:"content" validate:"required"`
|
Content string `json:"content" validate:"required"`
|
||||||
@@ -485,6 +450,16 @@ type CreatePaymentMethodRequest struct {
|
|||||||
Enable *bool `json:"enable" validate:"required"`
|
Enable *bool `json:"enable" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreatePromoRuleRequest struct {
|
||||||
|
Name string `json:"name" validate:"required,max=100"`
|
||||||
|
Type string `json:"type" validate:"required,oneof=new_user inactive_user campaign"`
|
||||||
|
Params map[string]interface{} `json:"params"`
|
||||||
|
Priority int64 `json:"priority" validate:"gte=0"`
|
||||||
|
Enabled *bool `json:"enabled"`
|
||||||
|
StartTime *int64 `json:"start_time"`
|
||||||
|
EndTime *int64 `json:"end_time"`
|
||||||
|
}
|
||||||
|
|
||||||
type CreateQuotaTaskRequest struct {
|
type CreateQuotaTaskRequest struct {
|
||||||
Subscribers []int64 `json:"subscribers"`
|
Subscribers []int64 `json:"subscribers"`
|
||||||
IsActive *bool `json:"is_active"`
|
IsActive *bool `json:"is_active"`
|
||||||
@@ -668,6 +643,14 @@ type DeletePaymentMethodRequest struct {
|
|||||||
Id int64 `json:"id" validate:"required"`
|
Id int64 `json:"id" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeletePromoPriceRequest struct {
|
||||||
|
Id int64 `uri:"id" validate:"required,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeletePromoRuleRequest struct {
|
||||||
|
Id int64 `uri:"id" validate:"required,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteRedemptionCodeRequest struct {
|
type DeleteRedemptionCodeRequest struct {
|
||||||
Id int64 `json:"id" validate:"required"`
|
Id int64 `json:"id" validate:"required"`
|
||||||
}
|
}
|
||||||
@@ -823,14 +806,6 @@ type FamilySummary struct {
|
|||||||
UpdatedAt int64 `json:"updated_at"`
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileUploadRequest struct {
|
|
||||||
BizType string `form:"biz_type" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FileUploadResponse struct {
|
|
||||||
Url string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FileUploadCompleteRequest struct {
|
type FileUploadCompleteRequest struct {
|
||||||
FileId string `json:"file_id" validate:"required"`
|
FileId string `json:"file_id" validate:"required"`
|
||||||
}
|
}
|
||||||
@@ -856,6 +831,14 @@ type FileUploadInitResponse struct {
|
|||||||
ExpiredAt int64 `json:"expired_at"`
|
ExpiredAt int64 `json:"expired_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FileUploadRequest struct {
|
||||||
|
BizType string `form:"biz_type" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileUploadResponse struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
type FilterBalanceLogRequest struct {
|
type FilterBalanceLogRequest struct {
|
||||||
FilterLogParams
|
FilterLogParams
|
||||||
UserId int64 `form:"user_id,optional"`
|
UserId int64 `form:"user_id,optional"`
|
||||||
@@ -876,17 +859,6 @@ type FilterCommissionLogResponse struct {
|
|||||||
List []CommissionLog `json:"list"`
|
List []CommissionLog `json:"list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilterOrderRefundLogRequest struct {
|
|
||||||
FilterLogParams
|
|
||||||
OrderId int64 `form:"order_id,optional"`
|
|
||||||
UserId int64 `form:"user_id,optional"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FilterOrderRefundLogResponse struct {
|
|
||||||
Total int64 `json:"total"`
|
|
||||||
List []OrderRefundLog `json:"list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FilterEmailLogResponse struct {
|
type FilterEmailLogResponse struct {
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
List []MessageLog `json:"list"`
|
List []MessageLog `json:"list"`
|
||||||
@@ -936,6 +908,17 @@ type FilterNodeListResponse struct {
|
|||||||
List []Node `json:"list"`
|
List []Node `json:"list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FilterOrderRefundLogRequest struct {
|
||||||
|
FilterLogParams
|
||||||
|
OrderId int64 `form:"order_id,optional"`
|
||||||
|
UserId int64 `form:"user_id,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FilterOrderRefundLogResponse struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []OrderRefundLog `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
type FilterRegisterLogRequest struct {
|
type FilterRegisterLogRequest struct {
|
||||||
FilterLogParams
|
FilterLogParams
|
||||||
UserId int64 `form:"user_id,optional"`
|
UserId int64 `form:"user_id,optional"`
|
||||||
@@ -1027,6 +1010,32 @@ type GenerateCaptchaResponse struct {
|
|||||||
BlockImage string `json:"block_image,omitempty"`
|
BlockImage string `json:"block_image,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetAdminUserInviteListRequest struct {
|
||||||
|
Page int `form:"page"`
|
||||||
|
Size int `form:"size"`
|
||||||
|
UserId int64 `form:"user_id" validate:"required"`
|
||||||
|
Search string `form:"search,omitempty"`
|
||||||
|
Enable *bool `form:"enable,omitempty"`
|
||||||
|
UserIdSearch int64 `form:"user_id_search,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetAdminUserInviteListResponse struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []AdminInvitedUser `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetAdminUserInviteStatsRequest struct {
|
||||||
|
UserId int64 `form:"user_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetAdminUserInviteStatsResponse struct {
|
||||||
|
InviteCount int64 `json:"invite_count"`
|
||||||
|
TotalCommission int64 `json:"total_commission"`
|
||||||
|
CurrentCommission int64 `json:"current_commission"`
|
||||||
|
ReferralPercentage uint8 `json:"referral_percentage"`
|
||||||
|
OnlyFirstPurchase bool `json:"only_first_purchase"`
|
||||||
|
}
|
||||||
|
|
||||||
type GetAdsDetailRequest struct {
|
type GetAdsDetailRequest struct {
|
||||||
Id int64 `form:"id"`
|
Id int64 `form:"id"`
|
||||||
}
|
}
|
||||||
@@ -1145,48 +1154,6 @@ type GetCouponListResponse struct {
|
|||||||
List []Coupon `json:"list"`
|
List []Coupon `json:"list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetPromoPriceListRequest struct {
|
|
||||||
PromoRuleId int64 `form:"promo_rule_id" validate:"required,gt=0"`
|
|
||||||
Page int64 `form:"page" validate:"required,gt=0"`
|
|
||||||
Size int64 `form:"size" validate:"required,gt=0,lte=200"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetPromoPriceListResponse struct {
|
|
||||||
Total int64 `json:"total"`
|
|
||||||
List []PromoPrice `json:"list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetPromoRuleDetailRequest struct {
|
|
||||||
Id int64 `uri:"id" validate:"required,gt=0"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetPromoRuleListRequest struct {
|
|
||||||
Page int64 `form:"page" validate:"required,gt=0"`
|
|
||||||
Size int64 `form:"size" validate:"required,gt=0,lte=200"`
|
|
||||||
Type string `form:"type" validate:"omitempty,oneof=new_user inactive_user campaign"`
|
|
||||||
Enabled *bool `form:"enabled"`
|
|
||||||
Search string `form:"search,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetPromoRuleListResponse struct {
|
|
||||||
Total int64 `json:"total"`
|
|
||||||
List []PromoRule `json:"list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetPromoUsageListRequest struct {
|
|
||||||
Page int64 `form:"page" validate:"required,gt=0"`
|
|
||||||
Size int64 `form:"size" validate:"required,gt=0,lte=200"`
|
|
||||||
RuleId int64 `form:"rule_id,omitempty"`
|
|
||||||
UserId int64 `form:"user_id,omitempty"`
|
|
||||||
SubscribeId int64 `form:"subscribe_id,omitempty"`
|
|
||||||
OrderNo string `form:"order_no,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetPromoUsageListResponse struct {
|
|
||||||
Total int64 `json:"total"`
|
|
||||||
List []PromoUsage `json:"list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetDetailRequest struct {
|
type GetDetailRequest struct {
|
||||||
Id int64 `form:"id" validate:"required"`
|
Id int64 `form:"id" validate:"required"`
|
||||||
}
|
}
|
||||||
@@ -1327,16 +1294,55 @@ type GetGroupHistoryResponse struct {
|
|||||||
List []GroupHistory `json:"list"`
|
List []GroupHistory `json:"list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetInviteSalesRequest struct {
|
type GetInviteManageListRequest struct {
|
||||||
|
Page int `form:"page"`
|
||||||
|
Size int `form:"size"`
|
||||||
|
Search string `form:"search"`
|
||||||
|
InviterId int64 `form:"inviter_id"`
|
||||||
|
InviteeId int64 `form:"invitee_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetInviteManageListResponse struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []InviteManageRecord `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetInviteRecordsRequest struct {
|
||||||
Page int `form:"page"`
|
Page int `form:"page"`
|
||||||
Size int `form:"size"`
|
Size int `form:"size"`
|
||||||
StartTime int64 `form:"start_time"`
|
StartTime int64 `form:"start_time"`
|
||||||
EndTime int64 `form:"end_time"`
|
EndTime int64 `form:"end_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetInviteSalesResponse struct {
|
type GetInviteRecordsResponse struct {
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
List []InvitedUserSale `json:"list"`
|
List []InviteRecord `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetLogMessageRawRequest struct {
|
||||||
|
Id int64 `form:"id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetLogMessageRawResponse struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
AppVersion string `json:"app_version"`
|
||||||
|
OsName string `json:"os_name"`
|
||||||
|
OsVersion string `json:"os_version"`
|
||||||
|
DeviceId string `json:"device_id"`
|
||||||
|
UserId *int64 `json:"user_id"`
|
||||||
|
SessionId string `json:"session_id"`
|
||||||
|
Level uint8 `json:"level"`
|
||||||
|
ErrorCode string `json:"error_code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Stack string `json:"stack"`
|
||||||
|
Context interface{} `json:"context"`
|
||||||
|
ClientIP string `json:"client_ip"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
Locale string `json:"locale"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
OccurredAt int64 `json:"occurred_at"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetLoginLogRequest struct {
|
type GetLoginLogRequest struct {
|
||||||
@@ -1417,6 +1423,48 @@ type GetPreSendEmailCountResponse struct {
|
|||||||
Count int64 `json:"count"`
|
Count int64 `json:"count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetPromoPriceListRequest struct {
|
||||||
|
PromoRuleId int64 `form:"promo_rule_id" validate:"required,gt=0"`
|
||||||
|
Page int64 `form:"page" validate:"required,gt=0"`
|
||||||
|
Size int64 `form:"size" validate:"required,gt=0,lte=200"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPromoPriceListResponse struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []PromoPrice `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPromoRuleDetailRequest struct {
|
||||||
|
Id int64 `uri:"id" validate:"required,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPromoRuleListRequest struct {
|
||||||
|
Page int64 `form:"page" validate:"required,gt=0"`
|
||||||
|
Size int64 `form:"size" validate:"required,gt=0,lte=200"`
|
||||||
|
Type string `form:"type" validate:"omitempty,oneof=new_user inactive_user campaign"`
|
||||||
|
Enabled *bool `form:"enabled"`
|
||||||
|
Search string `form:"search,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPromoRuleListResponse struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []PromoRule `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPromoUsageListRequest struct {
|
||||||
|
Page int64 `form:"page" validate:"required,gt=0"`
|
||||||
|
Size int64 `form:"size" validate:"required,gt=0,lte=200"`
|
||||||
|
RuleId int64 `form:"rule_id,omitempty"`
|
||||||
|
UserId int64 `form:"user_id,omitempty"`
|
||||||
|
SubscribeId int64 `form:"subscribe_id,omitempty"`
|
||||||
|
OrderNo string `form:"order_no,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPromoUsageListResponse struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []PromoUsage `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
type GetRedemptionCodeListRequest struct {
|
type GetRedemptionCodeListRequest struct {
|
||||||
Page int64 `form:"page" validate:"required"`
|
Page int64 `form:"page" validate:"required"`
|
||||||
Size int64 `form:"size" validate:"required"`
|
Size int64 `form:"size" validate:"required"`
|
||||||
@@ -1708,6 +1756,19 @@ type GetUserTrafficStatsResponse struct {
|
|||||||
TotalTraffic int64 `json:"total_traffic"`
|
TotalTraffic int64 `json:"total_traffic"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetWithdrawalListRequest struct {
|
||||||
|
Page int `form:"page"`
|
||||||
|
Size int `form:"size"`
|
||||||
|
UserId *int64 `form:"user_id,omitempty"`
|
||||||
|
Status *uint8 `form:"status,omitempty"`
|
||||||
|
Method *uint8 `form:"method,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetWithdrawalListResponse struct {
|
||||||
|
List []WithdrawalLog `json:"list"`
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
}
|
||||||
|
|
||||||
type GiftLog struct {
|
type GiftLog struct {
|
||||||
Type uint16 `json:"type"`
|
Type uint16 `json:"type"`
|
||||||
UserId int64 `json:"user_id"`
|
UserId int64 `json:"user_id"`
|
||||||
@@ -1768,11 +1829,27 @@ type InviteConfig struct {
|
|||||||
GiftDays int64 `json:"gift_days"`
|
GiftDays int64 `json:"gift_days"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InvitedUserSale struct {
|
type InviteManageRecord struct {
|
||||||
Amount float64 `json:"amount"`
|
InviterId int64 `json:"inviter_id"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
InviterIdentifier string `json:"inviter_identifier"`
|
||||||
UserHash string `json:"user_hash"`
|
InviteeId int64 `json:"invitee_id"`
|
||||||
ProductName string `json:"product_name"`
|
InviteeIdentifier string `json:"invitee_identifier"`
|
||||||
|
InviteeAvatar string `json:"invitee_avatar"`
|
||||||
|
InviteeEnable bool `json:"invitee_enable"`
|
||||||
|
InvitedAt int64 `json:"invited_at"`
|
||||||
|
OrderCount int64 `json:"order_count"`
|
||||||
|
HasPurchased bool `json:"has_purchased"`
|
||||||
|
InviterCommission int64 `json:"inviter_commission"`
|
||||||
|
InviterGiftDays int64 `json:"inviter_gift_days"`
|
||||||
|
InviteeGiftDays int64 `json:"invitee_gift_days"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type InviteRecord struct {
|
||||||
|
Role string `json:"role"`
|
||||||
|
PeerHash string `json:"peer_hash"`
|
||||||
|
GiftDays int64 `json:"gift_days"`
|
||||||
|
OrderNo string `json:"order_no"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KickOfflineRequest struct {
|
type KickOfflineRequest struct {
|
||||||
@@ -2157,6 +2234,45 @@ type PrivacyPolicyConfig struct {
|
|||||||
PrivacyPolicy string `json:"privacy_policy"`
|
PrivacyPolicy string `json:"privacy_policy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PromoPrice struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
SubscribeId int64 `json:"subscribe_id"`
|
||||||
|
PromoRuleId int64 `json:"promo_rule_id"`
|
||||||
|
Quantity int64 `json:"quantity"`
|
||||||
|
PromoPrice int64 `json:"promo_price"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PromoPriceItem struct {
|
||||||
|
SubscribeId int64 `json:"subscribe_id" validate:"required,gt=0"`
|
||||||
|
Quantity int64 `json:"quantity" validate:"required,gt=0,lte=1000"`
|
||||||
|
PromoPrice int64 `json:"promo_price" validate:"required,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PromoRule struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Params map[string]interface{} `json:"params"`
|
||||||
|
Priority int64 `json:"priority"`
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
StartTime *int64 `json:"start_time"`
|
||||||
|
EndTime *int64 `json:"end_time"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PromoUsage struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
|
PromoRuleId int64 `json:"promo_rule_id"`
|
||||||
|
SubscribeId int64 `json:"subscribe_id"`
|
||||||
|
OrderNo string `json:"order_no"`
|
||||||
|
PromoPrice int64 `json:"promo_price"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
type Protocol struct {
|
type Protocol struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
@@ -2405,10 +2521,6 @@ type QueryUserSubscribeNodeListResponse struct {
|
|||||||
List []UserSubscribeInfo `json:"list"`
|
List []UserSubscribeInfo `json:"list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CancelWithdrawalRequest struct {
|
|
||||||
WithdrawalId int64 `json:"withdrawal_id" validate:"required,gt=0"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type QueryWithdrawalLogListRequest struct {
|
type QueryWithdrawalLogListRequest struct {
|
||||||
Page int `form:"page"`
|
Page int `form:"page"`
|
||||||
Size int `form:"size"`
|
Size int `form:"size"`
|
||||||
@@ -2419,28 +2531,6 @@ type QueryWithdrawalLogListResponse struct {
|
|||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetWithdrawalListRequest struct {
|
|
||||||
Page int `form:"page"`
|
|
||||||
Size int `form:"size"`
|
|
||||||
UserId *int64 `form:"user_id,omitempty"`
|
|
||||||
Status *uint8 `form:"status,omitempty"`
|
|
||||||
Method *uint8 `form:"method,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetWithdrawalListResponse struct {
|
|
||||||
List []WithdrawalLog `json:"list"`
|
|
||||||
Total int64 `json:"total"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ApproveWithdrawalRequest struct {
|
|
||||||
WithdrawalId int64 `json:"withdrawal_id" validate:"required,gt=0"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RejectWithdrawalRequest struct {
|
|
||||||
WithdrawalId int64 `json:"withdrawal_id" validate:"required,gt=0"`
|
|
||||||
Reason string `json:"reason" validate:"required,max=500"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type QuotaTask struct {
|
type QuotaTask struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Subscribers []int64 `json:"subscribers"`
|
Subscribers []int64 `json:"subscribers"`
|
||||||
@@ -2527,6 +2617,11 @@ type RedemptionRecord struct {
|
|||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RefundOrderRequest struct {
|
||||||
|
Id int64 `json:"id" validate:"required"`
|
||||||
|
Reason string `json:"reason,omitempty" validate:"omitempty,max=500"`
|
||||||
|
}
|
||||||
|
|
||||||
type RegisterConfig struct {
|
type RegisterConfig struct {
|
||||||
StopRegister bool `json:"stop_register"`
|
StopRegister bool `json:"stop_register"`
|
||||||
EnableTrial bool `json:"enable_trial"`
|
EnableTrial bool `json:"enable_trial"`
|
||||||
@@ -2550,6 +2645,11 @@ type RegisterLog struct {
|
|||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RejectWithdrawalRequest struct {
|
||||||
|
WithdrawalId int64 `json:"withdrawal_id" validate:"required,gt=0"`
|
||||||
|
Reason string `json:"reason" validate:"required,max=500"`
|
||||||
|
}
|
||||||
|
|
||||||
type RemoveFamilyMemberRequest struct {
|
type RemoveFamilyMemberRequest struct {
|
||||||
FamilyId int64 `json:"family_id" validate:"required,gt=0"`
|
FamilyId int64 `json:"family_id" validate:"required,gt=0"`
|
||||||
UserId int64 `json:"user_id" validate:"required,gt=0"`
|
UserId int64 `json:"user_id" validate:"required,gt=0"`
|
||||||
@@ -2808,6 +2908,11 @@ type SetNodeMultiplierRequest struct {
|
|||||||
Periods []TimePeriod `json:"periods"`
|
Periods []TimePeriod `json:"periods"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SetPromoPriceRequest struct {
|
||||||
|
PromoRuleId int64 `json:"promo_rule_id" validate:"required,gt=0"`
|
||||||
|
Items []PromoPriceItem `json:"items" validate:"required,min=1,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
type Shadowsocks struct {
|
type Shadowsocks struct {
|
||||||
Method string `json:"method" validate:"required"`
|
Method string `json:"method" validate:"required"`
|
||||||
Port int `json:"port" validate:"required"`
|
Port int `json:"port" validate:"required"`
|
||||||
@@ -2865,13 +2970,6 @@ type StripePayment struct {
|
|||||||
PublishableKey string `json:"publishable_key"`
|
PublishableKey string `json:"publishable_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubscribePromo struct {
|
|
||||||
RuleName string `json:"rule_name"`
|
|
||||||
RuleType string `json:"rule_type"`
|
|
||||||
PromoPrice int64 `json:"promo_price"`
|
|
||||||
ExpiresAt int64 `json:"expires_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Subscribe struct {
|
type Subscribe struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -2974,6 +3072,13 @@ type SubscribeLog struct {
|
|||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SubscribePromo struct {
|
||||||
|
RuleName string `json:"rule_name"`
|
||||||
|
RuleType string `json:"rule_type"`
|
||||||
|
PromoPrice int64 `json:"promo_price"`
|
||||||
|
ExpiresAt int64 `json:"expires_at"`
|
||||||
|
}
|
||||||
|
|
||||||
type SubscribeSortRequest struct {
|
type SubscribeSortRequest struct {
|
||||||
Sort []SortItem `json:"sort"`
|
Sort []SortItem `json:"sort"`
|
||||||
}
|
}
|
||||||
@@ -3221,30 +3326,6 @@ type UpdateCouponRequest struct {
|
|||||||
Enable *bool `json:"enable,omitempty"`
|
Enable *bool `json:"enable,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetPromoPriceRequest struct {
|
|
||||||
PromoRuleId int64 `json:"promo_rule_id" validate:"required,gt=0"`
|
|
||||||
Items []PromoPriceItem `json:"items" validate:"required,min=1,dive"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeletePromoPriceRequest struct {
|
|
||||||
Id int64 `uri:"id" validate:"required,gt=0"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeletePromoRuleRequest struct {
|
|
||||||
Id int64 `uri:"id" validate:"required,gt=0"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdatePromoRuleRequest struct {
|
|
||||||
Id int64 `uri:"id" validate:"required,gt=0"`
|
|
||||||
Name string `json:"name" validate:"required,max=100"`
|
|
||||||
Type string `json:"type" validate:"required,oneof=new_user inactive_user campaign"`
|
|
||||||
Params map[string]interface{} `json:"params"`
|
|
||||||
Priority int64 `json:"priority" validate:"gte=0"`
|
|
||||||
Enabled *bool `json:"enabled"`
|
|
||||||
StartTime *int64 `json:"start_time"`
|
|
||||||
EndTime *int64 `json:"end_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateDocumentRequest struct {
|
type UpdateDocumentRequest struct {
|
||||||
Id int64 `json:"id" validate:"required"`
|
Id int64 `json:"id" validate:"required"`
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
@@ -3311,6 +3392,17 @@ type UpdatePaymentMethodRequest struct {
|
|||||||
Enable *bool `json:"enable" validate:"required"`
|
Enable *bool `json:"enable" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdatePromoRuleRequest struct {
|
||||||
|
Id int64 `uri:"id" validate:"required,gt=0"`
|
||||||
|
Name string `json:"name" validate:"required,max=100"`
|
||||||
|
Type string `json:"type" validate:"required,oneof=new_user inactive_user campaign"`
|
||||||
|
Params map[string]interface{} `json:"params"`
|
||||||
|
Priority int64 `json:"priority" validate:"gte=0"`
|
||||||
|
Enabled *bool `json:"enabled"`
|
||||||
|
StartTime *int64 `json:"start_time"`
|
||||||
|
EndTime *int64 `json:"end_time"`
|
||||||
|
}
|
||||||
|
|
||||||
type UpdateRedemptionCodeRequest struct {
|
type UpdateRedemptionCodeRequest struct {
|
||||||
Id int64 `json:"id" validate:"required"`
|
Id int64 `json:"id" validate:"required"`
|
||||||
TotalCount int64 `json:"total_count,omitempty"`
|
TotalCount int64 `json:"total_count,omitempty"`
|
||||||
@@ -3442,7 +3534,7 @@ type UpdateUserSubscribeRequest struct {
|
|||||||
ExpiredAt int64 `json:"expired_at"`
|
ExpiredAt int64 `json:"expired_at"`
|
||||||
Upload int64 `json:"upload"`
|
Upload int64 `json:"upload"`
|
||||||
Download int64 `json:"download"`
|
Download int64 `json:"download"`
|
||||||
SpeedLimit *int64 `json:"speed_limit,omitempty"`
|
SpeedLimit *int64 `json:"speed_limit,omitempty" validate:"omitempty,gte=0"`
|
||||||
TrafficLimit *string `json:"traffic_limit,omitempty"`
|
TrafficLimit *string `json:"traffic_limit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3469,7 +3561,7 @@ type User struct {
|
|||||||
EnableLoginNotify bool `json:"enable_login_notify"`
|
EnableLoginNotify bool `json:"enable_login_notify"`
|
||||||
EnableSubscribeNotify bool `json:"enable_subscribe_notify"`
|
EnableSubscribeNotify bool `json:"enable_subscribe_notify"`
|
||||||
EnableTradeNotify bool `json:"enable_trade_notify"`
|
EnableTradeNotify bool `json:"enable_trade_notify"`
|
||||||
UseStatus bool `json:"use_status"`
|
UseStatus bool `json:"use_status"` // Whether to show the "bind email to get free trial" prompt
|
||||||
AuthMethods []UserAuthMethod `json:"auth_methods"`
|
AuthMethods []UserAuthMethod `json:"auth_methods"`
|
||||||
UserDevices []UserDevice `json:"user_devices"`
|
UserDevices []UserDevice `json:"user_devices"`
|
||||||
Rules []string `json:"rules"`
|
Rules []string `json:"rules"`
|
||||||
@@ -3786,60 +3878,3 @@ type WithdrawalLog struct {
|
|||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetAdminUserInviteStatsRequest struct {
|
|
||||||
UserId int64 `form:"user_id" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetAdminUserInviteStatsResponse struct {
|
|
||||||
InviteCount int64 `json:"invite_count"`
|
|
||||||
TotalCommission int64 `json:"total_commission"`
|
|
||||||
CurrentCommission int64 `json:"current_commission"`
|
|
||||||
ReferralPercentage uint8 `json:"referral_percentage"`
|
|
||||||
OnlyFirstPurchase bool `json:"only_first_purchase"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetAdminUserInviteListRequest struct {
|
|
||||||
UserId int64 `form:"user_id" validate:"required"`
|
|
||||||
Page int `form:"page"`
|
|
||||||
Size int `form:"size"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AdminInvitedUser struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Avatar string `json:"avatar"`
|
|
||||||
Identifier string `json:"identifier"`
|
|
||||||
Enable bool `json:"enable"`
|
|
||||||
CreatedAt int64 `json:"created_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetAdminUserInviteListResponse struct {
|
|
||||||
Total int64 `json:"total"`
|
|
||||||
List []AdminInvitedUser `json:"list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetLogMessageRawRequest struct {
|
|
||||||
Id int64 `form:"id" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetLogMessageRawResponse struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Platform string `json:"platform"`
|
|
||||||
AppVersion string `json:"app_version"`
|
|
||||||
OsName string `json:"os_name"`
|
|
||||||
OsVersion string `json:"os_version"`
|
|
||||||
DeviceId string `json:"device_id"`
|
|
||||||
UserId *int64 `json:"user_id"`
|
|
||||||
SessionId string `json:"session_id"`
|
|
||||||
Level uint8 `json:"level"`
|
|
||||||
ErrorCode string `json:"error_code"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
Stack string `json:"stack"`
|
|
||||||
Context json.RawMessage `json:"context"`
|
|
||||||
ClientIP string `json:"client_ip"`
|
|
||||||
UserAgent string `json:"user_agent"`
|
|
||||||
Locale string `json:"locale"`
|
|
||||||
Digest string `json:"digest"`
|
|
||||||
OccurredAt int64 `json:"occurred_at"`
|
|
||||||
CreatedAt int64 `json:"created_at"`
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,15 +3,26 @@ package hash
|
|||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"hash/fnv"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/spaolacci/murmur3"
|
"github.com/spaolacci/murmur3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const invitePeerHashSalt = "ppanel_invite_" + "sales_v1"
|
||||||
|
|
||||||
// Hash returns the hash value of data.
|
// Hash returns the hash value of data.
|
||||||
func Hash(data []byte) uint64 {
|
func Hash(data []byte) uint64 {
|
||||||
return murmur3.Sum64(data)
|
return murmur3.Sum64(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InvitePeerHash(userId int64) string {
|
||||||
|
h := fnv.New64a()
|
||||||
|
_, _ = h.Write([]byte(invitePeerHashSalt))
|
||||||
|
_, _ = h.Write([]byte(strconv.FormatInt(userId, 10)))
|
||||||
|
return fmt.Sprintf("%010d", h.Sum64()%10000000000)
|
||||||
|
}
|
||||||
|
|
||||||
// Md5 returns the md5 bytes of data.
|
// Md5 returns the md5 bytes of data.
|
||||||
func Md5(data []byte) []byte {
|
func Md5(data []byte) []byte {
|
||||||
digest := md5.New()
|
digest := md5.New()
|
||||||
|
|||||||
+1
-37
@@ -8,40 +8,4 @@ info (
|
|||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
import (
|
import "apis/ppanel.api"
|
||||||
"apis/common.api"
|
|
||||||
"apis/node/node.api"
|
|
||||||
"apis/auth/auth.api"
|
|
||||||
"apis/admin/system.api"
|
|
||||||
"apis/admin/user.api"
|
|
||||||
"apis/admin/auth.api"
|
|
||||||
"apis/admin/server.api"
|
|
||||||
"apis/admin/subscribe.api"
|
|
||||||
"apis/admin/payment.api"
|
|
||||||
"apis/admin/coupon.api"
|
|
||||||
"apis/admin/redemption.api"
|
|
||||||
"apis/admin/order.api"
|
|
||||||
"apis/admin/ticket.api"
|
|
||||||
"apis/admin/announcement.api"
|
|
||||||
"apis/admin/document.api"
|
|
||||||
"apis/admin/tool.api"
|
|
||||||
"apis/admin/console.api"
|
|
||||||
"apis/admin/log.api"
|
|
||||||
"apis/admin/ads.api"
|
|
||||||
"apis/admin/marketing.api"
|
|
||||||
"apis/admin/application.api"
|
|
||||||
"apis/admin/group.api"
|
|
||||||
"apis/public/user.api"
|
|
||||||
"apis/public/subscribe.api"
|
|
||||||
"apis/public/redemption.api"
|
|
||||||
"apis/public/recovery.api"
|
|
||||||
"apis/public/order.api"
|
|
||||||
"apis/public/announcement.api"
|
|
||||||
"apis/public/ticket.api"
|
|
||||||
"apis/public/payment.api"
|
|
||||||
"apis/public/document.api"
|
|
||||||
"apis/public/file.api"
|
|
||||||
"apis/public/portal.api"
|
|
||||||
"apis/public/iap.api"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|||||||
@@ -1183,15 +1183,15 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/v1/public/user/invite_sales": {
|
"/v1/public/user/invite_records": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Get Invite Sales",
|
"summary": "Get Invite Records",
|
||||||
"operationId": "GetInviteSales",
|
"operationId": "GetInviteRecords",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "A successful response.",
|
"description": "A successful response.",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/GetInviteSalesResponse"
|
"$ref": "#/definitions/GetInviteRecordsResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3166,7 +3166,7 @@
|
|||||||
"connection_records"
|
"connection_records"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"GetInviteSalesRequest": {
|
"GetInviteRecordsRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"page": {
|
"page": {
|
||||||
@@ -3186,7 +3186,7 @@
|
|||||||
"format": "int64"
|
"format": "int64"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"title": "GetInviteSalesRequest",
|
"title": "GetInviteRecordsRequest",
|
||||||
"required": [
|
"required": [
|
||||||
"page",
|
"page",
|
||||||
"size",
|
"size",
|
||||||
@@ -3194,7 +3194,7 @@
|
|||||||
"end_time"
|
"end_time"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"GetInviteSalesResponse": {
|
"GetInviteRecordsResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"total": {
|
"total": {
|
||||||
@@ -3204,11 +3204,11 @@
|
|||||||
"list": {
|
"list": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/InvitedUserSale"
|
"$ref": "#/definitions/InviteRecord"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"title": "GetInviteSalesResponse",
|
"title": "GetInviteRecordsResponse",
|
||||||
"required": [
|
"required": [
|
||||||
"total",
|
"total",
|
||||||
"list"
|
"list"
|
||||||
@@ -3558,30 +3558,34 @@
|
|||||||
"gift_days"
|
"gift_days"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"InvitedUserSale": {
|
"InviteRecord": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"amount": {
|
"role": {
|
||||||
"type": "number",
|
"type": "string"
|
||||||
"format": "double"
|
|
||||||
},
|
},
|
||||||
"updated_at": {
|
"peer_hash": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gift_days": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
},
|
},
|
||||||
"user_hash": {
|
"order_no": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"product_name": {
|
"created_at": {
|
||||||
"type": "string"
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"title": "InvitedUserSale",
|
"title": "InviteRecord",
|
||||||
"required": [
|
"required": [
|
||||||
"amount",
|
"role",
|
||||||
"updated_at",
|
"peer_hash",
|
||||||
"user_hash",
|
"gift_days",
|
||||||
"product_name"
|
"order_no",
|
||||||
|
"created_at"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"MessageLog": {
|
"MessageLog": {
|
||||||
|
|||||||
Reference in New Issue
Block a user