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
8b06f02b
Commit
8b06f02b
authored
Apr 25, 2026
by
龚双喜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加商品批量收藏和佣金、推广人排行
parent
0da9431f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
365 additions
and
2 deletions
+365
-2
Ranking.php
addons/shopro/controller/commission/Ranking.php
+300
-0
GoodsLog.php
addons/shopro/controller/user/GoodsLog.php
+63
-0
queue.php
application/extra/queue.php
+1
-1
redis.php
application/extra/redis.php
+1
-1
No files found.
addons/shopro/controller/commission/Ranking.php
0 → 100644
View file @
8b06f02b
<?php
namespace
addons\shopro\controller\commission
;
use
app\admin\model\shopro\commission\Agent
as
AgentModel
;
use
app\admin\model\shopro\commission\Reward
as
RewardModel
;
use
app\admin\model\shopro\user\User
as
UserModel
;
use
think\Db
;
class
Ranking
extends
Commission
{
protected
$noNeedLogin
=
[];
protected
$noNeedRight
=
[
'*'
];
/**
* 佣金排行榜
* 按已结算佣金金额排序
*/
public
function
commission
()
{
$limit
=
$this
->
request
->
param
(
'limit'
,
20
);
$timeType
=
$this
->
request
->
param
(
'time_type'
,
'all'
);
// all|month|week|day
$query
=
RewardModel
::
field
([
'agent_id'
,
'sum(commission) as total_commission'
,
'count(distinct order_id) as order_count'
])
->
where
(
'status'
,
RewardModel
::
COMMISSION_REWARD_STATUS_ACCOUNTED
)
->
group
(
'agent_id'
);
// 时间筛选
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
(
'total_commission'
,
'desc'
)
->
limit
(
$limit
)
->
select
();
if
(
empty
(
$rankings
))
{
$this
->
success
(
'获取成功'
,
[]);
}
$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
=
[];
foreach
(
$rankings
as
$index
=>
$item
)
{
$user
=
$userMap
[
$item
->
agent_id
]
??
null
;
$result
[]
=
[
'rank'
=>
$index
+
1
,
'user_id'
=>
$item
->
agent_id
,
'nickname'
=>
$user
?
$user
->
nickname
:
'匿名用户'
,
//string_hide($user->nickname, 5) : '匿名用户',
'avatar'
=>
$user
?
$user
->
avatar
:
''
,
'total_commission'
=>
round
(
$item
->
total_commission
,
2
),
'order_count'
=>
$item
->
order_count
];
}
// 获取当前用户排名
$currentUser
=
auth_user
();
$currentRank
=
null
;
if
(
$currentUser
)
{
$currentRank
=
$this
->
getCurrentUserCommissionRank
(
$currentUser
->
id
,
$timeType
,
$result
);
}
$this
->
success
(
'获取成功'
,
[
'list'
=>
$result
,
'current_user_rank'
=>
$currentRank
]);
}
/**
* 推广人排行榜
* 按推广人数排序
*/
public
function
promoter
()
{
$limit
=
$this
->
request
->
param
(
'limit'
,
20
);
$timeType
=
$this
->
request
->
param
(
'time_type'
,
'all'
);
// all|month|week|day
$query
=
UserModel
::
field
([
'parent_user_id'
,
'count(*) as invite_count'
])
->
where
(
'parent_user_id'
,
'>'
,
0
)
->
where
(
'status'
,
'normal'
)
->
group
(
'parent_user_id'
);
// 时间筛选
switch
(
$timeType
)
{
case
'month'
:
$query
->
whereTime
(
'jointime'
,
'month'
);
break
;
case
'week'
:
$query
->
whereTime
(
'jointime'
,
'week'
);
break
;
case
'day'
:
$query
->
whereTime
(
'jointime'
,
'today'
);
break
;
}
$rankings
=
$query
->
order
(
'invite_count'
,
'desc'
)
->
limit
(
$limit
)
->
select
();
if
(
empty
(
$rankings
))
{
$this
->
success
(
'获取成功'
,
[]);
}
$parentIds
=
array_column
(
$rankings
,
'parent_user_id'
);
// 获取推广人信息
$users
=
UserModel
::
whereIn
(
'id'
,
$parentIds
)
->
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
)
{
$user
=
$userMap
[
$item
->
parent_user_id
]
??
null
;
$result
[]
=
[
'rank'
=>
$index
+
1
,
'user_id'
=>
$item
->
parent_user_id
,
'nickname'
=>
$user
?
$user
->
nickname
:
'匿名用户'
,
'avatar'
=>
$user
?
$user
->
avatar
:
''
,
'invite_count'
=>
$item
->
invite_count
];
}
// 获取当前用户排名
$currentUser
=
auth_user
();
$currentRank
=
null
;
if
(
$currentUser
)
{
$currentRank
=
$this
->
getCurrentUserPromoterRank
(
$currentUser
->
id
,
$timeType
,
$result
);
}
$this
->
success
(
'获取成功'
,
[
'list'
=>
$result
,
'current_user_rank'
=>
$currentRank
]);
}
/**
* 获取当前用户佣金排名
*/
private
function
getCurrentUserCommissionRank
(
$userId
,
$timeType
,
$existingList
)
{
// 先检查是否在已有列表中
foreach
(
$existingList
as
$item
)
{
if
(
$item
[
'user_id'
]
==
$userId
)
{
return
$item
;
}
}
// 查询当前用户的佣金
$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
(
$totalCommission
<=
0
)
{
return
null
;
}
// 计算排名
$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
;
}
$rank
=
$rankWhereQuery
->
group
(
'agent_id'
)
->
having
(
'sum(commission) > '
.
$totalCommission
)
->
count
()
+
1
;
$user
=
UserModel
::
get
(
$userId
);
return
[
'rank'
=>
$rank
,
'user_id'
=>
$userId
,
'nickname'
=>
$user
?
$user
->
nickname
:
'我'
,
'avatar'
=>
$user
?
$user
->
avatar
:
''
,
'total_commission'
=>
round
(
$totalCommission
,
2
),
'order_count'
=>
$orderCount
,
'is_out_list'
=>
true
];
}
/**
* 获取当前用户推广排名
*/
private
function
getCurrentUserPromoterRank
(
$userId
,
$timeType
,
$existingList
)
{
// 先检查是否在已有列表中
foreach
(
$existingList
as
$item
)
{
if
(
$item
[
'user_id'
]
==
$userId
)
{
return
$item
;
}
}
// 查询当前用户的推广人数
$query
=
UserModel
::
where
(
'parent_user_id'
,
$userId
)
->
where
(
'status'
,
'normal'
);
switch
(
$timeType
)
{
case
'month'
:
$query
->
whereTime
(
'jointime'
,
'month'
);
break
;
case
'week'
:
$query
->
whereTime
(
'jointime'
,
'week'
);
break
;
case
'day'
:
$query
->
whereTime
(
'jointime'
,
'today'
);
break
;
}
$inviteCount
=
$query
->
count
();
if
(
$inviteCount
<=
0
)
{
return
null
;
}
// 计算排名
$rankWhereQuery
=
UserModel
::
where
(
'parent_user_id'
,
'>'
,
0
)
->
where
(
'status'
,
'normal'
);
switch
(
$timeType
)
{
case
'month'
:
$rankWhereQuery
->
whereTime
(
'jointime'
,
'month'
);
break
;
case
'week'
:
$rankWhereQuery
->
whereTime
(
'jointime'
,
'week'
);
break
;
case
'day'
:
$rankWhereQuery
->
whereTime
(
'jointime'
,
'today'
);
break
;
}
$rank
=
$rankWhereQuery
->
group
(
'parent_user_id'
)
->
having
(
'count(*) > '
.
$inviteCount
)
->
count
()
+
1
;
$user
=
UserModel
::
get
(
$userId
);
return
[
'rank'
=>
$rank
,
'user_id'
=>
$userId
,
'nickname'
=>
$user
?
$user
->
nickname
:
'我'
,
'avatar'
=>
$user
?
$user
->
avatar
:
''
,
'invite_count'
=>
$inviteCount
,
'is_out_list'
=>
true
];
}
}
addons/shopro/controller/user/GoodsLog.php
View file @
8b06f02b
...
@@ -36,6 +36,69 @@ class GoodsLog extends Common
...
@@ -36,6 +36,69 @@ class GoodsLog extends Common
/**
/**
* 批量收藏商品
*
* @return void
*/
public
function
batchFavorite
()
{
if
(
!
$this
->
request
->
isPost
())
{
$this
->
error
(
'请求方式错误'
);
}
$user
=
auth_user
();
$goodsIds
=
$this
->
request
->
param
(
'goods_ids/a'
);
if
(
empty
(
$goodsIds
)
||
!
is_array
(
$goodsIds
))
{
$this
->
error
(
'请选择要收藏的商品'
);
}
// 过滤已存在的收藏
$existingFavorites
=
UserGoodsLogModel
::
favorite
()
->
whereIn
(
'goods_id'
,
$goodsIds
)
->
where
(
'user_id'
,
$user
->
id
)
->
column
(
'goods_id'
);
$newGoodsIds
=
array_diff
(
$goodsIds
,
$existingFavorites
);
if
(
empty
(
$newGoodsIds
))
{
$this
->
success
(
'所选商品已收藏'
,
[
'total'
=>
count
(
$goodsIds
),
'success'
=>
0
,
'exists'
=>
count
(
$existingFavorites
),
'failed'
=>
0
]);
}
// 验证商品是否存在且上架
$validGoods
=
Goods
::
show
()
->
whereIn
(
'id'
,
$newGoodsIds
)
->
column
(
'id'
);
$invalidGoodsIds
=
array_diff
(
$newGoodsIds
,
$validGoods
);
$successCount
=
0
;
$now
=
time
();
foreach
(
$validGoods
as
$goodsId
)
{
$log
=
new
UserGoodsLogModel
();
$log
->
goods_id
=
$goodsId
;
$log
->
user_id
=
$user
->
id
;
$log
->
type
=
'favorite'
;
$log
->
createtime
=
$now
;
$log
->
updatetime
=
$now
;
$log
->
save
();
$successCount
++
;
}
$this
->
success
(
'收藏成功'
,
[
'total'
=>
count
(
$goodsIds
),
'success'
=>
$successCount
,
'exists'
=>
count
(
$existingFavorites
),
'failed'
=>
count
(
$invalidGoodsIds
),
'failed_goods_ids'
=>
array_values
(
$invalidGoodsIds
)
]);
}
/**
* 收藏/取消收藏
* 收藏/取消收藏
*
*
* @param Request $request
* @param Request $request
...
...
application/extra/queue.php
View file @
8b06f02b
...
@@ -5,7 +5,7 @@ return [
...
@@ -5,7 +5,7 @@ return [
'default'
=>
'default'
,
// 默认的队列名称
'default'
=>
'default'
,
// 默认的队列名称
'host'
=>
'127.0.0.1'
,
// redis 主机ip
'host'
=>
'127.0.0.1'
,
// redis 主机ip
'port'
=>
6379
,
// redis 端口
'port'
=>
6379
,
// redis 端口
'password'
=>
'
123456
'
,
// redis 密码
'password'
=>
''
,
// redis 密码
'select'
=>
0
,
// 使用哪一个 db,默认为 db0
'select'
=>
0
,
// 使用哪一个 db,默认为 db0
'timeout'
=>
0
,
// redis连接的超时时间
'timeout'
=>
0
,
// redis连接的超时时间
'persistent'
=>
false
,
'persistent'
=>
false
,
...
...
application/extra/redis.php
View file @
8b06f02b
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
return
[
return
[
'host'
=>
'127.0.0.1'
,
'host'
=>
'127.0.0.1'
,
'password'
=>
'
123456
'
,
'password'
=>
''
,
'port'
=>
'6379'
,
'port'
=>
'6379'
,
'select'
=>
'1'
,
'select'
=>
'1'
,
'timeout'
=>
'0'
,
'timeout'
=>
'0'
,
...
...
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