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
3ff6ee1d
Commit
3ff6ee1d
authored
Jul 07, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(share): 阻止自己点击自己链接并优化日志
parent
e41ccba9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
16 deletions
+23
-16
Share.php
addons/shopro/controller/Share.php
+11
-4
Share.php
application/admin/model/shopro/Share.php
+12
-12
No files found.
addons/shopro/controller/Share.php
View file @
3ff6ee1d
...
...
@@ -19,18 +19,25 @@ class Share extends Common
}
$params
=
$this
->
request
->
only
([
'shareId'
,
'spm'
,
'page'
,
'query'
,
'from'
,
'platform'
]);
custom_log
(
'[share.add] 解析请求参数: '
.
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
0
,
'share'
);
//
custom_log('[share.add] 解析请求参数: ' . json_encode($params, JSON_UNESCAPED_UNICODE), 0, 'share');
$user
=
auth_user
();
$userId
=
$user
->
id
??
0
;
custom_log
(
'[share.add] 用户认证通过, user_id='
.
$userId
,
$userId
,
'share'
);
// custom_log('[share.add] 用户认证通过, user_id=' . $userId, $userId, 'share');
$shareId
=
$params
[
'shareId'
];
if
(
$shareId
==
$userId
)
{
custom_log
(
'[share.add] 自己点自己链接,拒绝写入, shareId='
.
$shareId
.
' == user_id='
.
$userId
,
$userId
,
'share'
,
'warning'
);
return
false
;
}
$shareInfo
=
ShareModel
::
log
(
$user
,
$params
);
if
(
$shareInfo
)
{
$logData
=
method_exists
(
$shareInfo
,
'toArray'
)
?
$shareInfo
->
toArray
()
:
json_decode
(
json_encode
(
$shareInfo
),
true
);
custom_log
(
'[share.add] 分享记录写入成功, 记录详情: '
.
json_encode
(
$logData
,
JSON_UNESCAPED_UNICODE
),
$userId
,
'share'
);
custom_log
(
'[share.add] 分享记录写入成功,
解析请求参数:'
.
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
)
.
'
记录详情: '
.
json_encode
(
$logData
,
JSON_UNESCAPED_UNICODE
),
$userId
,
'share'
);
}
else
{
custom_log
(
'[share.add] 分享记录写入失败(返回false/空,可能原因: spm为空/shareId无效/自己点自己/5分钟内重复/sharing不存在)
'
,
$userId
,
'share'
,
'warning'
);
custom_log
(
'[share.add] 分享记录写入失败(返回false/空,可能原因: spm为空/shareId无效/自己点自己/5分钟内重复/sharing不存在)
解析请求参数:'
.
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
)
,
$userId
,
'share'
,
'warning'
);
}
$this
->
success
(
""
);
...
...
application/admin/model/shopro/Share.php
View file @
3ff6ee1d
...
...
@@ -42,29 +42,29 @@ class Share extends Common
public
static
function
log
(
Object
$user
,
$params
)
{
$userId
=
$user
->
id
??
0
;
custom_log
(
'[share.log] 进入方法, user_id='
.
$userId
.
', params='
.
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$userId
,
'share'
);
custom_log
(
'[share.log] 进入
写日志
方法, user_id='
.
$userId
.
', params='
.
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$userId
,
'share'
);
// 错误的分享参数
if
(
empty
(
$params
[
'spm'
]))
{
custom_log
(
'[share.log] spm为空,拒绝写入'
,
$userId
,
'share'
,
'warning'
);
//
custom_log('[share.log] spm为空,拒绝写入', $userId, 'share', 'warning');
return
false
;
}
custom_log
(
'[share.log] spm校验通过: '
.
$params
[
'spm'
],
$userId
,
'share'
);
//
custom_log('[share.log] spm校验通过: ' . $params['spm'], $userId, 'share');
$shareId
=
$params
[
'shareId'
];
// 分享用户为空
if
(
$shareId
<=
0
)
{
custom_log
(
'[share.log] shareId无效(<=0): '
.
$shareId
,
$userId
,
'share'
,
'warning'
);
//
custom_log('[share.log] shareId无效(<=0): ' . $shareId, $userId, 'share', 'warning');
return
false
;
}
custom_log
(
'[share.log] shareId校验通过: '
.
$shareId
,
$userId
,
'share'
);
//
custom_log('[share.log] shareId校验通过: ' . $shareId, $userId, 'share');
// 不能分享给本人
if
(
$shareId
==
$user
->
id
)
{
custom_log
(
'[share.log] 自己点自己链接,拒绝写入, shareId='
.
$shareId
.
' == user_id='
.
$user
->
id
,
$userId
,
'share'
,
'warning'
);
//
custom_log('[share.log] 自己点自己链接,拒绝写入, shareId=' . $shareId . ' == user_id=' . $user->id, $userId, 'share', 'warning');
return
false
;
}
custom_log
(
'[share.log] 非本人分享校验通过'
,
$userId
,
'share'
);
//
custom_log('[share.log] 非本人分享校验通过', $userId, 'share');
// 新用户不能分享给老用户 按需打开
// if($user->id < $shareId) {
...
...
@@ -74,10 +74,10 @@ class Share extends Common
$shareUser
=
UserModel
::
where
(
'id'
,
$shareId
)
->
find
();
// 分享人不存在
if
(
!
$shareUser
)
{
custom_log
(
'[share.log] 分享人不存在, shareId='
.
$shareId
,
$userId
,
'share'
,
'warning'
);
//
custom_log('[share.log] 分享人不存在, shareId=' . $shareId, $userId, 'share', 'warning');
return
false
;
}
custom_log
(
'[share.log] 分享人存在, shareId='
.
$shareId
,
$userId
,
'share'
);
//
custom_log('[share.log] 分享人存在, shareId=' . $shareId, $userId, 'share');
// 5分钟内相同的分享信息不保存,防止冗余数据
$lastShareLog
=
self
::
where
([
...
...
@@ -88,7 +88,7 @@ class Share extends Common
custom_log
(
'[share.log] 5分钟内重复分享记录,返回已有记录, last_id='
.
$lastShareLog
->
id
.
', spm='
.
$params
[
'spm'
],
$userId
,
'share'
,
'warning'
);
return
$lastShareLog
;
}
custom_log
(
'[share.log] 重复检查通过'
,
$userId
,
'share'
);
//
custom_log('[share.log] 重复检查通过', $userId, 'share');
$memoText
=
'通过'
.
(
self
::
FROM
)[
$params
[
'from'
]]
.
'访问了'
;
if
(
$params
[
'page'
]
==
'/pages/index/index'
)
{
...
...
@@ -135,10 +135,10 @@ class Share extends Common
'ext'
=>
$ext
]);
custom_log
(
'[share.log] 写入shopro_share成功, record_id='
.
(
$shareInfo
->
id
??
''
)
.
', memo='
.
$memoText
,
$userId
,
'share'
);
//
custom_log('[share.log] 写入shopro_share成功, record_id=' . ($shareInfo->id ?? '') . ', memo=' . $memoText, $userId, 'share');
$data
=
[
'shareInfo'
=>
$shareInfo
];
custom_log
(
'[share.log] 触发 user_share_after Hook'
,
$userId
,
'share'
);
//
custom_log('[share.log] 触发 user_share_after Hook', $userId, 'share');
\think\Hook
::
listen
(
'user_share_after'
,
$data
);
custom_log
(
'[share.log] 方法执行完毕,返回分享记录, record_id='
.
(
$shareInfo
->
id
??
''
),
$userId
,
'share'
);
...
...
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