Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
刘小敏
loveisland
Commits
ab4c7407
Commit
ab4c7407
authored
Apr 27, 2026
by
gongs
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://git.ruanyiit.com/liuxiaomin/loveisland
into dev
parents
cbc15409
1efedae0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
76 deletions
+112
-76
Ranking.php
addons/shopro/controller/commission/Ranking.php
+112
-76
No files found.
addons/shopro/controller/commission/Ranking.php
View file @
ab4c7407
...
@@ -14,66 +14,90 @@ class Ranking extends Commission
...
@@ -14,66 +14,90 @@ class Ranking extends Commission
/**
/**
* 佣金排行榜
* 佣金排行榜
* 按
已结算佣金金额
排序
* 按
用户表佣金字段
排序
*/
*/
public
function
commission
()
public
function
commission
()
{
{
$limit
=
$this
->
request
->
param
(
'limit'
,
20
);
$limit
=
$this
->
request
->
param
(
'limit'
,
20
);
$timeType
=
$this
->
request
->
param
(
'time_type'
,
'all'
);
// all|month|week|day
$timeType
=
$this
->
request
->
param
(
'time_type'
,
'all'
);
// all|month|week|day
$query
=
RewardModel
::
field
([
// 从User表直接读取commission字段
'agent_id'
,
$query
=
UserModel
::
field
([
'sum(commission) as total_commission'
,
'id as user_id'
,
'count(distinct order_id) as order_count'
'nickname'
,
'avatar'
,
'commission as total_commission'
])
])
->
where
(
'
status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
)
->
where
(
'
commission'
,
'>'
,
0
)
->
group
(
'agent_id
'
);
->
where
(
'status'
,
'normal
'
);
// 时间筛选
// 时间筛选(根据佣金记录计算时间范围内的佣金)
switch
(
$timeType
)
{
if
(
$timeType
!==
'all'
)
{
case
'month'
:
// 查询在时间范围内有佣金记录的用户
$query
->
whereTime
(
'commission_time'
,
'month'
);
$rewardQuery
=
RewardModel
::
field
(
'agent_id'
)
break
;
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
case
'week'
:
$query
->
whereTime
(
'commission_time'
,
'week'
);
switch
(
$timeType
)
{
break
;
case
'month'
:
case
'day'
:
$rewardQuery
->
whereTime
(
'commission_time'
,
'month'
);
$query
->
whereTime
(
'commission_time'
,
'today'
);
break
;
break
;
case
'week'
:
$rewardQuery
->
whereTime
(
'commission_time'
,
'week'
);
break
;
case
'day'
:
$rewardQuery
->
whereTime
(
'commission_time'
,
'today'
);
break
;
}
$agentIds
=
$rewardQuery
->
group
(
'agent_id'
)
->
column
(
'agent_id'
);
$query
->
whereIn
(
'id'
,
$agentIds
);
}
}
$rankings
=
$query
->
order
(
'
total_
commission'
,
'desc'
)
$rankings
=
$query
->
order
(
'commission'
,
'desc'
)
->
limit
(
$limit
)
->
limit
(
$limit
)
->
select
();
->
select
();
if
(
empty
(
$rankings
))
{
if
(
empty
(
$rankings
))
{
$this
->
success
(
'获取成功'
,
[]);
$this
->
success
(
'获取成功'
,
[
}
'list'
=>
[],
'current_user_rank'
=>
null
$agentIds
=
array_column
(
$rankings
,
'agent_id'
);
]);
// 获取用户信息
$users
=
UserModel
::
whereIn
(
'id'
,
$agentIds
)
->
field
(
'id, nickname, avatar'
)
->
select
();
$userMap
=
[];
if
(
is_array
(
$users
))
{
$userMap
=
array_column
(
$users
,
null
,
'id'
);
}
else
{
$userMap
=
$users
->
column
(
null
,
'id'
);
}
}
$result
=
[];
$result
=
[];
foreach
(
$rankings
as
$index
=>
$item
)
{
foreach
(
$rankings
as
$index
=>
$item
)
{
$user
=
$userMap
[
$item
->
agent_id
]
??
null
;
// 查询订单数量
$orderCount
=
0
;
if
(
$timeType
!==
'all'
)
{
$orderQuery
=
RewardModel
::
where
(
'agent_id'
,
$item
[
'user_id'
])
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
switch
(
$timeType
)
{
case
'month'
:
$orderQuery
->
whereTime
(
'commission_time'
,
'month'
);
break
;
case
'week'
:
$orderQuery
->
whereTime
(
'commission_time'
,
'week'
);
break
;
case
'day'
:
$orderQuery
->
whereTime
(
'commission_time'
,
'today'
);
break
;
}
$orderCount
=
$orderQuery
->
count
(
'distinct order_id'
);
}
else
{
$orderCount
=
RewardModel
::
where
(
'agent_id'
,
$item
[
'user_id'
])
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
)
->
count
(
'distinct order_id'
);
}
$result
[]
=
[
$result
[]
=
[
'rank'
=>
$index
+
1
,
'rank'
=>
$index
+
1
,
'user_id'
=>
$item
->
agent_id
,
'user_id'
=>
$item
[
'user_id'
]
,
'nickname'
=>
$
user
?
$user
->
nickname
:
'匿名用户'
,
//string_hide($user->nickname, 5)
: '匿名用户',
'nickname'
=>
$
item
[
'nickname'
]
?
:
'匿名用户'
,
'avatar'
=>
$
user
?
$user
->
avatar
:
''
,
'avatar'
=>
$
item
[
'avatar'
]
?
:
''
,
'total_commission'
=>
round
(
$item
->
total_commission
,
2
),
'total_commission'
=>
round
(
$item
[
'total_commission'
]
,
2
),
'order_count'
=>
$
item
->
order_c
ount
'order_count'
=>
$
orderC
ount
];
];
}
}
...
@@ -179,54 +203,66 @@ class Ranking extends Commission
...
@@ -179,54 +203,66 @@ class Ranking extends Commission
}
}
}
}
// 查询当前用户的佣金
// 查询当前用户信息
$query
=
RewardModel
::
where
(
'agent_id'
,
$userId
)
$user
=
UserModel
::
get
(
$userId
);
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
if
(
!
$user
||
$user
->
commission
<=
0
)
{
return
null
;
switch
(
$timeType
)
{
case
'month'
:
$query
->
whereTime
(
'commission_time'
,
'month'
);
break
;
case
'week'
:
$query
->
whereTime
(
'commission_time'
,
'week'
);
break
;
case
'day'
:
$query
->
whereTime
(
'commission_time'
,
'today'
);
break
;
}
}
$totalCommission
=
$query
->
sum
(
'commission'
);
$totalCommission
=
$user
->
commission
;
$orderCount
=
$query
->
count
(
'distinct order_id'
);
// 时间筛选时,检查用户是否有对应时间范围内的佣金记录
if
(
$timeType
!==
'all'
)
{
$query
=
RewardModel
::
where
(
'agent_id'
,
$userId
)
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
switch
(
$timeType
)
{
case
'month'
:
$query
->
whereTime
(
'commission_time'
,
'month'
);
break
;
case
'week'
:
$query
->
whereTime
(
'commission_time'
,
'week'
);
break
;
case
'day'
:
$query
->
whereTime
(
'commission_time'
,
'today'
);
break
;
}
if
(
$totalCommission
<=
0
)
{
if
(
!
$query
->
find
())
{
return
null
;
return
null
;
}
}
}
// 计算排名
// 查询订单数量
$rankWhereQuery
=
RewardModel
::
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
$orderQuery
=
RewardModel
::
where
(
'agent_id'
,
$userId
)
switch
(
$timeType
)
{
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
case
'month'
:
$rankWhereQuery
->
whereTime
(
'commission_time'
,
'month'
);
if
(
$timeType
!==
'all'
)
{
break
;
switch
(
$timeType
)
{
case
'week'
:
case
'month'
:
$rankWhereQuery
->
whereTime
(
'commission_time'
,
'week'
);
$orderQuery
->
whereTime
(
'commission_time'
,
'month'
);
break
;
break
;
case
'day'
:
case
'week'
:
$rankWhereQuery
->
whereTime
(
'commission_time'
,
'today'
);
$orderQuery
->
whereTime
(
'commission_time'
,
'week'
);
break
;
break
;
case
'day'
:
$orderQuery
->
whereTime
(
'commission_time'
,
'today'
);
break
;
}
}
}
$rank
=
$rankWhereQuery
->
group
(
'agent_id'
)
$orderCount
=
$orderQuery
->
count
(
'distinct order_id'
);
->
having
(
'sum(commission) > '
.
$totalCommission
)
->
count
()
+
1
;
$user
=
UserModel
::
get
(
$userId
);
// 计算排名:统计佣金大于当前用户的人数
$rank
=
UserModel
::
where
(
'commission'
,
'>'
,
$totalCommission
)
->
where
(
'status'
,
'normal'
)
->
count
()
+
1
;
return
[
return
[
'rank'
=>
$rank
,
'rank'
=>
$rank
,
'user_id'
=>
$userId
,
'user_id'
=>
$userId
,
'nickname'
=>
$user
?
$user
->
nickname
:
'我'
,
'nickname'
=>
$user
->
nickname
?
:
'我'
,
'avatar'
=>
$user
?
$user
->
avatar
:
''
,
'avatar'
=>
$user
->
avatar
?
:
''
,
'total_commission'
=>
round
(
$totalCommission
,
2
),
'total_commission'
=>
round
(
$totalCommission
,
2
),
'order_count'
=>
$orderCount
,
'order_count'
=>
$orderCount
,
'is_out_list'
=>
true
'is_out_list'
=>
true
...
...
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