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
ef230759
Commit
ef230759
authored
Apr 27, 2026
by
龚双喜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新佣金排行和工艺技术排行接口
parent
7f49f083
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
117 deletions
+102
-117
Ranking.php
addons/shopro/controller/commission/Ranking.php
+94
-111
Company.php
addons/shopro/controller/company/Company.php
+8
-6
No files found.
addons/shopro/controller/commission/Ranking.php
View file @
ef230759
...
...
@@ -14,90 +14,71 @@ class Ranking extends Commission
/**
* 佣金排行榜
* 按
用户表佣金字段
排序
* 按
已结算佣金金额
排序
*/
public
function
commission
()
{
$limit
=
$this
->
request
->
param
(
'limit'
,
20
);
$timeType
=
$this
->
request
->
param
(
'time_type'
,
'all'
);
// all|month|week|day
// 从User表直接读取commission字段
$query
=
UserModel
::
field
([
'id as user_id'
,
'nickname'
,
'avatar'
,
'commission as total_commission'
$query
=
RewardModel
::
field
([
'agent_id'
,
'sum(commission) as total_commission'
,
'count(distinct order_id) as order_count'
])
->
where
(
'commission'
,
'>'
,
0
)
->
where
(
'status'
,
'normal'
);
// 时间筛选(根据佣金记录计算时间范围内的佣金)
if
(
$timeType
!==
'all'
)
{
// 查询在时间范围内有佣金记录的用户
$rewardQuery
=
RewardModel
::
field
(
'agent_id'
)
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
switch
(
$timeType
)
{
case
'month'
:
$rewardQuery
->
whereTime
(
'commission_time'
,
'month'
);
break
;
case
'week'
:
$rewardQuery
->
whereTime
(
'commission_time'
,
'week'
);
break
;
case
'day'
:
$rewardQuery
->
whereTime
(
'commission_time'
,
'today'
);
break
;
}
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
)
->
group
(
'agent_id'
);
$agentIds
=
$rewardQuery
->
group
(
'agent_id'
)
->
column
(
'agent_id'
);
$query
->
whereIn
(
'id'
,
$agentIds
);
// 时间筛选
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
;
}
$rankings
=
$query
->
order
(
'commission'
,
'desc'
)
$rankings
=
$query
->
order
(
'
total_
commission'
,
'desc'
)
->
limit
(
$limit
)
->
select
();
if
(
empty
(
$rankings
))
{
$this
->
success
(
'获取成功'
,
[
'list'
=>
[],
'current_user_rank'
=>
null
]);
$this
->
success
(
'获取成功'
,
[]);
}
$agentIds
=
array_column
(
$rankings
,
'agent_id'
);
// 获取用户信息(排除已删除用户)
$users
=
UserModel
::
whereIn
(
'id'
,
$agentIds
)
->
where
(
'status'
,
'normal'
)
->
field
(
'id, nickname, avatar'
)
->
select
();
$userMap
=
[];
if
(
is_array
(
$users
))
{
$userMap
=
array_column
(
$users
,
null
,
'id'
);
}
else
{
$userMap
=
$users
->
column
(
null
,
'id'
);
}
$result
=
[];
foreach
(
$rankings
as
$index
=>
$item
)
{
// 查询订单数量
$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'
);
$user
=
$userMap
[
$item
->
agent_id
]
??
null
;
// 跳过已删除的用户
if
(
!
$user
)
{
continue
;
}
$result
[]
=
[
'rank'
=>
$index
+
1
,
'user_id'
=>
$item
[
'user_id'
]
,
'nickname'
=>
$
item
[
'nickname'
]
?
:
'匿名用户'
,
'avatar'
=>
$
item
[
'avatar'
]
?
:
''
,
'total_commission'
=>
round
(
$item
[
'total_commission'
]
,
2
),
'order_count'
=>
$
orderC
ount
'rank'
=>
count
(
$result
)
+
1
,
'user_id'
=>
$item
->
agent_id
,
'nickname'
=>
$
user
?
$user
->
nickname
:
'匿名用户'
,
'avatar'
=>
$
user
?
$user
->
avatar
:
''
,
'total_commission'
=>
round
(
$item
->
total_commission
,
2
),
'order_count'
=>
$
item
->
order_c
ount
];
}
...
...
@@ -203,63 +184,65 @@ class Ranking extends Commission
}
}
// 查询当前用户信息
$user
=
UserModel
::
get
(
$userId
);
if
(
!
$user
||
$user
->
commission
<=
0
)
{
return
null
;
// 查询当前用户的佣金
$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
;
}
$totalCommission
=
$user
->
commission
;
// 时间筛选时,检查用户是否有对应时间范围内的佣金记录
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
;
}
$totalCommission
=
$query
->
sum
(
'commission'
);
$orderCount
=
$query
->
count
(
'distinct order_id'
);
if
(
!
$query
->
find
())
{
return
null
;
}
if
(
$totalCommission
<=
0
)
{
return
null
;
}
// 查询订单数量
$orderQuery
=
RewardModel
::
where
(
'agent_id'
,
$userId
)
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
if
(
$timeType
!==
'all'
)
{
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
;
}
// 计算排名(排除已删除用户)
$rankWhereQuery
=
RewardModel
::
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
);
switch
(
$timeType
)
{
case
'month'
:
$rankWhereQuery
->
whereTime
(
'commission_time'
,
'month'
);
break
;
case
'week'
:
$rankWhereQuery
->
whereTime
(
'commission_time'
,
'week'
);
break
;
case
'day'
:
$rankWhereQuery
->
whereTime
(
'commission_time'
,
'today'
);
break
;
}
$orderCount
=
$orderQuery
->
count
(
'distinct order_id'
);
// 只统计正常状态用户的佣金
$rank
=
$rankWhereQuery
->
group
(
'agent_id'
)
->
having
(
'sum(commission) > '
.
$totalCommission
)
->
select
();
// 计算排名:统计佣金大于当前用户的人数
$rank
=
UserModel
::
where
(
'commission'
,
'>'
,
$totalCommission
)
->
where
(
'status'
,
'normal'
)
->
count
()
+
1
;
// 过滤掉已删除的用户
$validRank
=
0
;
if
(
$rank
)
{
$rankIds
=
array_column
(
$rank
,
'agent_id'
);
$validUsers
=
UserModel
::
whereIn
(
'id'
,
$rankIds
)
->
where
(
'status'
,
'normal'
)
->
column
(
'id'
);
$validRank
=
count
(
$validUsers
);
}
$user
=
UserModel
::
where
(
'id'
,
$userId
)
->
where
(
'status'
,
'normal'
)
->
find
();
if
(
!
$user
)
{
return
null
;
}
return
[
'rank'
=>
$
rank
,
'rank'
=>
$
validRank
+
1
,
'user_id'
=>
$userId
,
'nickname'
=>
$user
->
nickname
?:
'我'
,
'avatar'
=>
$user
->
avatar
?:
''
,
...
...
addons/shopro/controller/company/Company.php
View file @
ef230759
...
...
@@ -34,8 +34,8 @@ class Company extends Common
*/
public
function
store_list
()
{
$page
=
$this
->
request
->
get
(
'page'
)
??
1
;
//页码
$limit
=
$this
->
request
->
get
(
'limit'
)
??
10
;
//每页显示条数
$page
=
$this
->
request
->
get
(
'page'
)
??
1
;
//页码
$limit
=
$this
->
request
->
get
(
'limit'
)
??
10
;
//每页显示条数
$storeList
=
Store
::
where
(
'status'
,
'normal'
)
->
field
(
'id,store_name,store_logo,detail_address,phone,longitude,latitude,store_intro'
)
->
order
(
'weigh'
,
'desc'
)
...
...
@@ -50,13 +50,15 @@ class Company extends Common
*/
public
function
technology_list
()
{
$page
=
$this
->
request
->
get
(
'page'
)
??
1
;
//页码
$limit
=
$this
->
request
->
get
(
'limit'
)
??
3
;
//每页显示条数
$limit
=
$this
->
request
->
get
(
'limit'
)
??
3
;
//每页显示条数
if
(
$limit
<
1
)
{
$limit
=
1
;
}
$technologyList
=
CompanyTechnology
::
where
(
'status'
,
'normal'
)
->
field
(
'id,tech_name,tech_image,tech_desc'
)
->
order
(
'weigh'
,
'desc'
)
->
paginate
([
"page"
=>
$page
,
"list_rows"
=>
$limit
]);
->
limit
(
$limit
)
->
select
();
return
$this
->
success
(
'成功'
,
$technologyList
);
}
...
...
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