Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
663ecee4
Commit
663ecee4
authored
Mar 14, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
家族代理限制
parent
c4357bf8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
244 additions
and
9 deletions
+244
-9
dealer.go
domain/model/diamond_m/dealer.go
+211
-0
groupPower.go
domain/model/groupPower_m/groupPower.go
+14
-0
diamond.go
domain/service/diamond_s/diamond.go
+19
-9
No files found.
domain/model/diamond_m/dealer.go
0 → 100644
View file @
663ecee4
package
diamond_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-group/common"
"hilo-group/myerr"
)
type
DiamondDealer
struct
{
mysql
.
Entity
UserId
uint64
Diamond
uint32
Wechat
string
Whatsapp
string
Contact
string
Status
int
HasInvite
int
IsFamilyAgent
int8
}
func
(
dealer
*
DiamondDealer
)
Save
(
db
*
gorm
.
DB
)
error
{
if
dealer
.
ID
>
0
{
db
=
db
.
Omit
(
"diamond"
,
"status"
)
}
else
{
dealer
.
Status
=
common
.
SWITCH_ON
}
return
db
.
Save
(
dealer
)
.
Error
}
func
(
dealer
*
DiamondDealer
)
Get
(
db
*
gorm
.
DB
)
error
{
return
db
.
Where
(
dealer
)
.
First
(
dealer
)
.
Error
}
func
IsDiamondDealer
(
db
*
gorm
.
DB
,
userId
uint64
)
(
bool
,
error
)
{
dd
:=
DiamondDealer
{
UserId
:
userId
,
Status
:
common
.
SWITCH_ON
}
if
err
:=
dd
.
Get
(
db
);
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
false
,
nil
}
else
{
return
false
,
err
}
}
return
true
,
nil
}
// 是否是家族代理
func
IsFamilyDiamondDealer
(
db
*
gorm
.
DB
,
userId
uint64
)
(
bool
,
error
)
{
dd
:=
DiamondDealer
{
UserId
:
userId
,
Status
:
common
.
SWITCH_ON
,
IsFamilyAgent
:
1
}
if
err
:=
dd
.
Get
(
db
);
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
false
,
nil
}
else
{
return
false
,
err
}
}
return
true
,
nil
}
func
GetDiamondDealer
(
db
*
gorm
.
DB
,
userId
uint64
)
(
*
DiamondDealer
,
error
)
{
dd
:=
&
DiamondDealer
{
UserId
:
userId
,
Status
:
common
.
SWITCH_ON
}
if
err
:=
dd
.
Get
(
db
);
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
nil
,
nil
}
else
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
return
dd
,
nil
}
func
(
dealer
*
DiamondDealer
)
GetAll
(
db
*
gorm
.
DB
,
status
*
uint8
)
([]
DiamondDealer
,
error
)
{
rows
:=
make
([]
DiamondDealer
,
0
)
if
status
==
nil
{
if
err
:=
db
.
Where
(
dealer
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
}
else
if
err
:=
db
.
Where
(
dealer
)
.
Where
(
"status = ?"
,
*
status
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
rows
,
nil
}
func
(
dealer
*
DiamondDealer
)
Remove
(
db
*
gorm
.
DB
)
(
int64
,
error
)
{
result
:=
db
.
Where
(
dealer
)
.
Delete
(
&
DiamondDealer
{})
return
result
.
RowsAffected
,
result
.
Error
}
func
(
dealer
*
DiamondDealer
)
SafeReduceDiamond
(
db
*
gorm
.
DB
,
diamond
uint32
)
(
int64
,
error
)
{
result
:=
db
.
Model
(
&
DiamondDealer
{})
.
Where
(
dealer
)
.
Where
(
"diamond >= ?"
,
diamond
)
.
UpdateColumn
(
"diamond"
,
gorm
.
Expr
(
"diamond - ?"
,
diamond
))
return
result
.
RowsAffected
,
result
.
Error
}
func
(
dealer
*
DiamondDealer
)
AddDiamond
(
db
*
gorm
.
DB
,
diamond
uint32
)
(
int64
,
error
)
{
result
:=
db
.
Model
(
&
DiamondDealer
{})
.
Where
(
dealer
)
.
Where
(
"status = ?"
,
common
.
SWITCH_ON
)
.
UpdateColumn
(
"diamond"
,
gorm
.
Expr
(
"diamond + ?"
,
diamond
))
return
result
.
RowsAffected
,
result
.
Error
}
func
(
dealer
*
DiamondDealer
)
SetStatus
(
db
*
gorm
.
DB
,
status
uint8
)
error
{
return
db
.
Model
(
&
DiamondDealer
{})
.
Where
(
dealer
)
.
Update
(
"status"
,
status
)
.
Error
}
type
DealerTransferDetail
struct
{
mysql
.
Entity
DealerId
uint64
ReceiverId
uint64
Diamond
uint32
Dollar
uint
}
func
(
dtd
*
DealerTransferDetail
)
Create
(
db
*
gorm
.
DB
)
error
{
return
db
.
Create
(
dtd
)
.
Error
}
func
(
dfd
*
DealerTransferDetail
)
Find
(
db
*
gorm
.
DB
,
offset
,
limit
int
)
([]
DealerTransferDetail
,
error
)
{
rows
:=
make
([]
DealerTransferDetail
,
0
)
if
err
:=
db
.
Where
(
dfd
)
.
Order
(
"created_time DESC"
)
.
Offset
(
offset
)
.
Limit
(
limit
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
rows
,
nil
}
func
(
dfd
*
DealerTransferDetail
)
CountByDealer
(
db
*
gorm
.
DB
,
dealerIds
[]
uint64
)
(
map
[
uint64
]
uint
,
error
)
{
type
summary
struct
{
DealerId
uint64
C
uint
}
rows
:=
make
([]
summary
,
0
)
if
err
:=
db
.
Model
(
&
DealerTransferDetail
{})
.
Where
(
"dealer_id IN ?"
,
dealerIds
)
.
Select
(
"dealer_id, COUNT(0) AS c"
)
.
Group
(
"dealer_id"
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
result
:=
make
(
map
[
uint64
]
uint
,
0
)
for
_
,
i
:=
range
rows
{
result
[
i
.
DealerId
]
=
i
.
C
}
return
result
,
nil
}
func
(
dfd
*
DealerTransferDetail
)
Sum
(
db
*
gorm
.
DB
)
(
uint
,
uint32
,
uint
,
error
)
{
type
summary
struct
{
C
uint
Diamond
uint32
Dollar
uint
}
s
:=
summary
{}
if
err
:=
db
.
Model
(
&
DealerTransferDetail
{})
.
Where
(
dfd
)
.
Select
(
"COUNT(0) AS c, SUM(diamond) AS diamond, SUM(dollar) AS dollar"
)
.
First
(
&
s
)
.
Error
;
err
!=
nil
{
return
0
,
0
,
0
,
err
}
return
s
.
C
,
s
.
Diamond
,
s
.
Dollar
,
nil
}
type
DealerChargeDetail
struct
{
mysql
.
Entity
DealerId
uint64
MgrId
uint64
Diamond
uint32
Dollar
uint
PaymentMethod
string
Type
uint8
Money
float32
`json:"money"`
// 支付的货币数值
Currency
string
`json:"currency"`
// 支付货币
GoodsId
string
`json:"goodsId"`
// 充值钻石套餐id/商品id
}
func
(
dcd
*
DealerChargeDetail
)
Create
(
db
*
gorm
.
DB
)
error
{
return
db
.
Create
(
dcd
)
.
Error
}
type
DealerCountry
struct
{
DealerId
uint64
Country
string
}
func
(
dc
*
DealerCountry
)
Find
(
db
*
gorm
.
DB
)
([]
DealerCountry
,
error
)
{
rows
:=
make
([]
DealerCountry
,
0
)
if
err
:=
db
.
Where
(
dc
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
rows
,
nil
}
func
(
dc
*
DealerCountry
)
Delete
(
db
*
gorm
.
DB
)
error
{
return
db
.
Where
(
dc
)
.
Delete
(
&
DealerCountry
{})
.
Error
}
func
(
dc
*
DealerCountry
)
BatchInsert
(
db
*
gorm
.
DB
,
dealerId
uint64
,
countries
[]
string
)
error
{
rows
:=
make
([]
DealerCountry
,
0
)
for
_
,
i
:=
range
countries
{
rows
=
append
(
rows
,
DealerCountry
{
DealerId
:
dealerId
,
Country
:
i
,
})
}
return
db
.
Create
(
&
rows
)
.
Error
}
// 活动排行榜黑名单 获取所有已经上架代理币商的群组id
func
GetAllValidActivityBlackImGroupIds
(
model
*
domain
.
Model
)
[]
mysql
.
Str
{
//return []mysql.Str{"HTGS#a88745892", "@TGS#3UW6RFSIX"}
var
imGroupIds
[]
mysql
.
Str
subQuery
:=
model
.
Db
.
WithContext
(
model
)
.
Model
(
DiamondDealer
{})
.
Where
(
"status = 1"
)
.
Select
(
"user_id"
)
if
err
:=
model
.
Db
.
WithContext
(
model
)
.
Table
(
"group_info"
)
.
Select
(
"im_group_id"
)
.
Where
(
"owner in (?)"
,
subQuery
)
.
Scan
(
&
imGroupIds
)
.
Error
;
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"GetAllValidActivityBlackImGroupIds fail:%v"
,
err
)
}
imGroupIds
=
append
(
imGroupIds
,
"HTGS#a88745892"
,
"@TGS#3UW6RFSIX"
)
return
imGroupIds
}
domain/model/groupPower_m/groupPower.go
View file @
663ecee4
...
...
@@ -356,6 +356,20 @@ func IsGroupPowerHasMgrDealer(model *domain.Model, groupId mysql.ID) (bool, erro
return
false
,
nil
}
// 某个家族是否有家族代理
func
IsGroupPowerHasFamilyAgent
(
model
*
domain
.
Model
,
groupId
mysql
.
ID
)
(
bool
,
error
)
{
var
num
int64
if
err
:=
model
.
Db
.
Raw
(
"select count(1) from diamond_dealer where status=1 and is_family_agent=1 and user_id in "
+
"(select user_id from group_power_user where group_power_id = ?)"
,
groupId
)
.
Scan
(
&
num
)
.
Error
;
err
!=
nil
{
return
false
,
myerr
.
WrapErr
(
err
)
}
if
num
>
0
{
return
true
,
nil
}
return
false
,
nil
}
func
GetGroupPowerMap
(
db
*
gorm
.
DB
,
userIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
uint64
,
error
)
{
rows
:=
make
([]
GroupPowerUser
,
0
)
if
len
(
userIds
)
>
0
{
...
...
domain/service/diamond_s/diamond.go
View file @
663ecee4
...
...
@@ -3,7 +3,9 @@ package diamond_s
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"hilo-group/common"
"hilo-group/domain/model/diamond_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/res_m"
"hilo-group/myerr"
...
...
@@ -27,26 +29,34 @@ func (this *DiamondService) CheckDealerTransferFamilyLimit(dealerId, userId uint
if
err
!=
nil
{
return
err
}
// 代理是否是家族代理
isFamilyAgent
,
err
:=
diamond_m
.
IsFamilyDiamondDealer
(
mysql
.
Db
,
dealerId
)
if
err
!=
nil
{
return
err
}
userFamily
,
err
:=
groupPower_m
.
GetGroupPowerUserOrNil
(
model
,
userId
)
if
err
!=
nil
{
return
err
}
// 用户的家族是否有家族
长,而且家族长是
代理
var
hasDealerMgr
bool
// 用户的家族是否有家族代理
var
userHasFamilyAgent
bool
if
userFamily
!=
nil
{
hasDealerMgr
,
err
=
groupPower_m
.
IsGroupPowerHasMgrDealer
(
model
,
userFamily
.
GroupPowerId
)
userHasFamilyAgent
,
err
=
groupPower_m
.
IsGroupPowerHasFamilyAgent
(
model
,
userFamily
.
GroupPowerId
)
if
err
!=
nil
{
return
err
}
}
if
dealerFamily
!=
nil
&&
dealerFamily
.
GroupPowerId
>
0
{
// 家族代理
// 家族代理:只能向本家族成员转移钻石,如果向非家族成员转移钻石,则提示“非家族成员”
if
userFamily
==
nil
||
userFamily
.
GroupPowerId
!=
dealerFamily
.
GroupPowerId
{
if
dealerFamily
!=
nil
&&
dealerFamily
.
GroupPowerId
>
0
{
// 代理加入了家族
if
isFamilyAgent
&&
(
userFamily
==
nil
||
userFamily
.
GroupPowerId
!=
dealerFamily
.
GroupPowerId
)
{
// 是家族代理:只能向本家族成员转移钻石,如果向非家族成员转移钻石,则提示“非家族成员”
return
myerr
.
WrapErr
(
res_m
.
GetErrByLanguage
(
model
.
Db
,
common
.
MSG_ID_NOT_FAMILY_MEMBER
,
lang
,
bizerr
.
GroupPowerDealerNotMember
))
}
}
else
{
// 普通代理,没有加入家族的
// 普通代理:不能向已经加入家族的成员(并且家族长是代理)转移钻石,如果转移则提示“此用户已有家族代理,不能出售钻石”
if
hasDealerMgr
{
if
!
isFamilyAgent
&&
userHasFamilyAgent
{
// 不是家族代理:如果用户加入了家族,且家族中有家族代理,那么也不能,“此用户已有家族代理,不能出售钻石”
return
myerr
.
WrapErr
(
res_m
.
GetErrByLanguage
(
model
.
Db
,
common
.
MSG_ID_DEALER_CAN_NOT_SOLE
,
lang
,
bizerr
.
GroupPowerDealerCanNotSole
))
}
}
else
{
// 代理没有加入家族的
// 普通代理:不能向已经加入家族的成员(并且家族有家族代理)转移钻石,如果转移则提示“此用户已有家族代理,不能出售钻石”
if
userHasFamilyAgent
{
return
myerr
.
WrapErr
(
res_m
.
GetErrByLanguage
(
model
.
Db
,
common
.
MSG_ID_DEALER_CAN_NOT_SOLE
,
lang
,
bizerr
.
GroupPowerDealerCanNotSole
))
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment