fix: align business pages and detail drawers with prototype
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
var (
|
||||
ErrChannelNotFound = errors.NotFound("SW_CHANNEL_NOT_FOUND", "渠道不存在")
|
||||
ErrChannelScope = errors.Forbidden("SW_CHANNEL_SCOPE", "无权查看该渠道")
|
||||
ErrChannelCreateScope = errors.Forbidden("SW_CHANNEL_CREATE_SCOPE", "仅三级商务可添加渠道")
|
||||
ErrChannelInput = errors.BadRequest("SW_CHANNEL_INPUT", "渠道查询参数不正确")
|
||||
ErrChannelAccount = errors.BadRequest("SW_CHANNEL_ACCOUNT", "渠道账号需为中文/英文/数字,长度 4-30 位")
|
||||
ErrChannelPassword = errors.BadRequest("SW_CHANNEL_PASSWORD", "渠道密码长度需为 6-15 位")
|
||||
@@ -35,6 +36,7 @@ type Channel struct {
|
||||
ChannelKey
|
||||
Account, Nickname, ParentName, RealName string
|
||||
Phone string
|
||||
BusinessPath []string
|
||||
SettlementDays *int
|
||||
Level, RegisterType, Status, LockStatus *int
|
||||
ParentID, TopPromoteID, BusierID uint64
|
||||
@@ -47,6 +49,9 @@ type Channel struct {
|
||||
}
|
||||
|
||||
func (c *Channel) BusinessDisplayName() string {
|
||||
if len(c.BusinessPath) > 0 {
|
||||
return strings.Join(c.BusinessPath, "→")
|
||||
}
|
||||
account, user := strings.TrimSpace(c.BindingAccount), strings.TrimSpace(c.BindingUserName)
|
||||
if account == "" {
|
||||
return user
|
||||
@@ -56,6 +61,26 @@ func (c *Channel) BusinessDisplayName() string {
|
||||
}
|
||||
return account + "(" + user + ")"
|
||||
}
|
||||
|
||||
func (c *Channel) ParentDisplayName() string {
|
||||
if c.Level != nil && *c.Level == 1 {
|
||||
if len(c.BusinessPath) > 0 {
|
||||
return c.BusinessPath[len(c.BusinessPath)-1]
|
||||
}
|
||||
return c.BusinessDisplayName()
|
||||
}
|
||||
return c.ParentName
|
||||
}
|
||||
|
||||
func ChannelLockStatusLabel(status *int) string {
|
||||
if status == nil || *status == 0 {
|
||||
return "正常"
|
||||
}
|
||||
if *status == -2 {
|
||||
return "解除合作"
|
||||
}
|
||||
return "锁定"
|
||||
}
|
||||
func (c *Channel) IncludesStat(other *Channel, includeSub bool) bool {
|
||||
if c.SourceDB != other.SourceDB {
|
||||
return false
|
||||
@@ -73,6 +98,7 @@ func (c *Channel) IncludesStat(other *Channel, includeSub bool) bool {
|
||||
}
|
||||
|
||||
type ChannelFilter struct {
|
||||
IncludeSub, IDCardDedup bool
|
||||
Effective *bool
|
||||
Sources []string
|
||||
BusierUserID *uint
|
||||
@@ -179,6 +205,9 @@ func normalizeIDCard(raw string) string {
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// ChannelIdentity is shared by list metrics and storage-side metric ordering.
|
||||
func ChannelIdentity(raw string) string { return normalizeIDCard(raw) }
|
||||
func (uc *ChannelUsecase) List(ctx context.Context, filter ChannelFilter, options ...ListOption) (*ChannelPage, error) {
|
||||
scope, err := uc.scope(ctx)
|
||||
if err != nil {
|
||||
@@ -189,14 +218,15 @@ func (uc *ChannelUsecase) List(ctx context.Context, filter ChannelFilter, option
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
page, err := uc.repo.List(ctx, scope, filter, options...)
|
||||
if err != nil || len(page.Rows) == 0 {
|
||||
return page, err
|
||||
}
|
||||
pref, err := uc.preferences.Current(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filter.IncludeSub, filter.IDCardDedup = pref.IncludeSubPromote, pref.IDCardDedup
|
||||
page, err := uc.repo.List(ctx, scope, filter, options...)
|
||||
if err != nil || len(page.Rows) == 0 {
|
||||
return page, err
|
||||
}
|
||||
statChannels := page.Rows
|
||||
if pref.IncludeSubPromote {
|
||||
statChannels, err = uc.repo.StatChannels(ctx, page.Rows)
|
||||
@@ -290,6 +320,13 @@ func (uc *ChannelUsecase) Create(ctx context.Context, input *ChannelCreate) (*Ch
|
||||
if input == nil {
|
||||
return nil, ErrChannelInput
|
||||
}
|
||||
actor, accountOwner, err := uc.accounts.actor(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if actor.AuthorityID != 888 && accountOwner.Level != 3 {
|
||||
return nil, ErrChannelCreateScope
|
||||
}
|
||||
account := strings.TrimSpace(input.Account)
|
||||
if !channelAccountPattern.MatchString(account) {
|
||||
return nil, ErrChannelAccount
|
||||
|
||||
Reference in New Issue
Block a user