feat(partner): 升级创客平级收益支持两代级联机制与单元测试用例
这个提交包含在:
@@ -3,7 +3,7 @@
|
||||
namespace addons\shopro\service\partner;
|
||||
|
||||
/**
|
||||
* 创客平级 10% / 被超越 5%,只一层
|
||||
* 创客平级(支持两代级联:第1代10%,第2代上级收益10%)/ 被超越 5%(只一层)
|
||||
*/
|
||||
class MakerPeerReward
|
||||
{
|
||||
@@ -12,6 +12,7 @@ class MakerPeerReward
|
||||
$bonus = PartnerConfig::makerBonus();
|
||||
$peerRate = (float) PartnerConfig::get('partner_maker_peer_rate', 0.10);
|
||||
$overRate = (float) PartnerConfig::get('partner_maker_overtaken_rate', 0.05);
|
||||
$maxPeerGenerations = (int) PartnerConfig::get('partner_maker_peer_max_generations', 2);
|
||||
$paid = $diffResult['paid'] ?? [];
|
||||
$indexByUser = [];
|
||||
foreach ($chain as $i => $node) {
|
||||
@@ -23,26 +24,62 @@ class MakerPeerReward
|
||||
if ($from < 0) {
|
||||
continue;
|
||||
}
|
||||
$peer = $this->findUp($chain, $from + 1, function ($node) use ($item) {
|
||||
return intval($node['level']) === intval($item['level']);
|
||||
});
|
||||
if (!$peer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$levelBonus = (float) ($bonus[$item['level']] ?? 0);
|
||||
$amount = round($levelBonus * $peerRate, 2);
|
||||
if (!$active->isActive($peer['agent'] ?? $peer)) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, $peer['user_id'], 'maker_peer', 'maker', 'inactive_30d', '平级创客 30 日无自购');
|
||||
continue;
|
||||
$currentFrom = $from;
|
||||
$currentBase = $levelBonus;
|
||||
$sourceUserId = $item['user_id'];
|
||||
|
||||
for ($gen = 1; $gen <= $maxPeerGenerations; $gen++) {
|
||||
$peerIdx = $this->findUpIndex($chain, $currentFrom + 1, function ($node) use ($item) {
|
||||
return intval($node['level']) === intval($item['level']);
|
||||
});
|
||||
if ($peerIdx < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$peer = $chain[$peerIdx];
|
||||
$amount = round($currentBase * $peerRate, 2);
|
||||
|
||||
if (!$active->isActive($peer['agent'] ?? $peer)) {
|
||||
PartnerRewardService::writeSkip(
|
||||
$order,
|
||||
$buyerId,
|
||||
$peer['user_id'],
|
||||
'maker_peer',
|
||||
'maker',
|
||||
'inactive_30d',
|
||||
"平级创客(第{$gen}代) 30 日无自购"
|
||||
);
|
||||
} else {
|
||||
if ($amount > 0) {
|
||||
PartnerRewardService::account(
|
||||
$order,
|
||||
$buyerId,
|
||||
$peer['user_id'],
|
||||
'maker_peer',
|
||||
'maker',
|
||||
$amount,
|
||||
$currentBase,
|
||||
[
|
||||
'generation' => $gen,
|
||||
'formula' => "平级(第{$gen}代) {$currentBase} × " . ($peerRate * 100) . "% = {$amount}",
|
||||
'from_user_id' => $sourceUserId,
|
||||
'level' => $item['level'],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 下一代平级的寻源起点与计算基数:以当前平级创客为基础,基数变为当前平级奖金(即 6.00)
|
||||
$currentFrom = $peerIdx;
|
||||
$currentBase = $amount;
|
||||
$sourceUserId = $peer['user_id'];
|
||||
|
||||
if ($currentBase <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($amount <= 0) {
|
||||
continue;
|
||||
}
|
||||
PartnerRewardService::account($order, $buyerId, $peer['user_id'], 'maker_peer', 'maker', $amount, $levelBonus, [
|
||||
'formula' => "平级 {$levelBonus} × " . ($peerRate * 100) . "% = {$amount}",
|
||||
'from_user_id' => $item['user_id'],
|
||||
'level' => $item['level'],
|
||||
]);
|
||||
}
|
||||
|
||||
if (empty($paid)) {
|
||||
@@ -70,13 +107,19 @@ class MakerPeerReward
|
||||
]);
|
||||
}
|
||||
|
||||
protected function findUp($chain, $start, $matcher)
|
||||
protected function findUpIndex($chain, $start, $matcher)
|
||||
{
|
||||
for ($i = $start; $i < count($chain); $i++) {
|
||||
if ($matcher($chain[$i])) {
|
||||
return $chain[$i];
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected function findUp($chain, $start, $matcher)
|
||||
{
|
||||
$idx = $this->findUpIndex($chain, $start, $matcher);
|
||||
return $idx >= 0 ? $chain[$idx] : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,8 @@ class Index extends Backend
|
||||
$background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : '';
|
||||
$this->view->assign('keeyloginhours', $keeyloginhours);
|
||||
$this->view->assign('background', $background);
|
||||
$this->view->assign('title', __('Login'));
|
||||
$siteName = Config::get('site.name');
|
||||
$this->view->assign('title', ($siteName ? $siteName . ' · ' : '') . __('Login'));
|
||||
Hook::listen("admin_login_init", $this->request);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,14 @@ return [
|
||||
'Keep login' => '保持会话',
|
||||
'Guest' => '游客',
|
||||
'Welcome' => '%s,你好!',
|
||||
'Welcome back' => '欢迎回来',
|
||||
'Admin console' => '运营控制台',
|
||||
'Sign in to continue' => '使用管理员账号继续',
|
||||
'Show password' => '显示密码',
|
||||
'Hide password' => '隐藏密码',
|
||||
'Secure session' => '安全会话',
|
||||
'Audited actions' => '操作留痕',
|
||||
'Role based access' => '权限可控',
|
||||
'View' => '查看',
|
||||
'Add' => '添加',
|
||||
'Edit' => '编辑',
|
||||
|
||||
@@ -1,145 +1,617 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
{include file="common/meta" /}
|
||||
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600&family=Noto+Serif+SC:wght@500;600;700&display=swap" rel="stylesheet">
|
||||
<style type="text/css">
|
||||
body {
|
||||
color: #999;
|
||||
background-color: #f1f4fd;
|
||||
background-size: cover;
|
||||
:root {
|
||||
--ink: #0b1412;
|
||||
--ink-soft: #14201c;
|
||||
--paper: #f3ead8;
|
||||
--paper-deep: #e7dcc4;
|
||||
--brass: #c4a46a;
|
||||
--brass-deep: #9c7d3f;
|
||||
--celadon: #7f927c;
|
||||
--text: #1c211d;
|
||||
--muted: #6d6a5e;
|
||||
--line: rgba(28, 33, 29, 0.12);
|
||||
--danger: #a63d32;
|
||||
--font-display: "Noto Serif SC", "Songti SC", "STSong", serif;
|
||||
--font-ui: "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
||||
--font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #444;
|
||||
html,
|
||||
body.login-body {
|
||||
min-height: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
|
||||
.login-screen {
|
||||
max-width: 430px;
|
||||
padding: 0;
|
||||
margin: 100px auto 0 auto;
|
||||
|
||||
body.login-body {
|
||||
margin: 0;
|
||||
color: var(--text);
|
||||
font-family: var(--font-ui);
|
||||
background: var(--ink);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.login-screen .well {
|
||||
border-radius: 3px;
|
||||
-webkit-box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
|
||||
box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
|
||||
background: rgba(255, 255, 255, 1);
|
||||
border: none;
|
||||
/*overflow: hidden;*/
|
||||
padding: 0;
|
||||
body.login-body a {
|
||||
color: var(--brass-deep);
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.login-screen {
|
||||
padding: 0 20px;
|
||||
}
|
||||
.login-shell {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
|
||||
min-height: 100dvh;
|
||||
}
|
||||
|
||||
.profile-img-card {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
display: block;
|
||||
-moz-border-radius: 50%;
|
||||
-webkit-border-radius: 50%;
|
||||
border-radius: 50%;
|
||||
margin: -93px auto 30px;
|
||||
border: 5px solid #fff;
|
||||
}
|
||||
|
||||
.profile-name-card {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.login-head {
|
||||
background: #899fe1;
|
||||
border-radius: 3px 3px 0 0;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
padding: 40px 30px;
|
||||
.login-brand {
|
||||
position: relative;
|
||||
z-index: 99;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
padding: 48px 56px 40px;
|
||||
color: #efe6d4;
|
||||
background:
|
||||
radial-gradient(ellipse 70% 50% at 10% 90%, rgba(196, 164, 106, 0.16), transparent 55%),
|
||||
radial-gradient(ellipse 50% 40% at 90% 8%, rgba(127, 146, 124, 0.18), transparent 50%),
|
||||
linear-gradient(160deg, var(--ink-soft), var(--ink) 62%);
|
||||
}
|
||||
|
||||
#login-form {
|
||||
margin-top: 20px;
|
||||
.login-brand::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background-image:
|
||||
linear-gradient(rgba(196, 164, 106, 0.08) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(196, 164, 106, 0.08) 1px, transparent 1px);
|
||||
background-size: 56px 56px;
|
||||
mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), transparent 88%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#login-form .input-group {
|
||||
margin-bottom: 15px;
|
||||
.login-brand::after {
|
||||
content: attr(data-mark);
|
||||
position: absolute;
|
||||
right: -4%;
|
||||
bottom: -10%;
|
||||
font-family: var(--font-display);
|
||||
font-size: clamp(180px, 28vw, 340px);
|
||||
font-weight: 700;
|
||||
line-height: 0.8;
|
||||
color: rgba(243, 234, 216, 0.045);
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#login-form .form-control {
|
||||
.brand-top,
|
||||
.brand-copy,
|
||||
.brand-foot {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.brand-mark {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.18em;
|
||||
text-transform: uppercase;
|
||||
color: var(--brass);
|
||||
}
|
||||
|
||||
.brand-mark i {
|
||||
display: block;
|
||||
width: 28px;
|
||||
height: 1px;
|
||||
background: var(--brass);
|
||||
}
|
||||
|
||||
.brand-copy {
|
||||
max-width: 520px;
|
||||
padding: 48px 0;
|
||||
}
|
||||
|
||||
.brand-copy h1 {
|
||||
margin: 0 0 16px;
|
||||
font-family: var(--font-display);
|
||||
font-size: clamp(40px, 5vw, 64px);
|
||||
font-weight: 600;
|
||||
line-height: 1.15;
|
||||
letter-spacing: 0.04em;
|
||||
color: #f7f0e2;
|
||||
}
|
||||
|
||||
.brand-copy p {
|
||||
margin: 0 0 28px;
|
||||
max-width: 28em;
|
||||
font-size: 16px;
|
||||
line-height: 1.7;
|
||||
color: rgba(243, 234, 216, 0.72);
|
||||
}
|
||||
|
||||
.brand-points {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.brand-points li {
|
||||
padding: 7px 12px;
|
||||
border: 1px solid rgba(196, 164, 106, 0.28);
|
||||
color: #e7d7b0;
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.brand-foot {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.08em;
|
||||
color: rgba(243, 234, 216, 0.45);
|
||||
}
|
||||
|
||||
.login-panel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 36px;
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 28%),
|
||||
var(--paper);
|
||||
}
|
||||
|
||||
.login-card {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.login-greet {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
|
||||
.login-avatar {
|
||||
position: relative;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
flex: 0 0 52px;
|
||||
border-radius: 50%;
|
||||
background: var(--paper-deep);
|
||||
box-shadow: inset 0 0 0 1px var(--line);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.login-avatar::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 14px 14px 10px;
|
||||
border-radius: 50% 50% 40% 40%;
|
||||
background: #b7aa90;
|
||||
}
|
||||
|
||||
.login-avatar::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
bottom: -8px;
|
||||
width: 34px;
|
||||
height: 22px;
|
||||
transform: translateX(-50%);
|
||||
border-radius: 16px 16px 0 0;
|
||||
background: #8f846c;
|
||||
}
|
||||
|
||||
#profile-img {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
#profile-img.is-ready {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.login-greet-text {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.login-greet-text em,
|
||||
#profile-name {
|
||||
display: block;
|
||||
margin: 0 0 4px;
|
||||
font-style: normal;
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.14em;
|
||||
color: var(--brass-deep);
|
||||
font-family: var(--font-mono);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.login-greet.has-user em {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.login-greet:not(.has-user) #profile-name {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.login-greet-text h2 {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
letter-spacing: 0.06em;
|
||||
}
|
||||
|
||||
#errtips {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.login-field {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.login-field label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
</style>
|
||||
<!--@formatter:off-->
|
||||
{if $background}
|
||||
<style type="text/css">
|
||||
body{
|
||||
background-image: url('{$background|htmlentities}');
|
||||
.login-control {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
body.login-body .login-control .form-control {
|
||||
height: 50px;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid rgba(28, 33, 29, 0.16);
|
||||
border-radius: 2px;
|
||||
background: rgba(255, 255, 255, 0.55);
|
||||
box-shadow: none;
|
||||
color: var(--text);
|
||||
font-size: 16px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
body.login-body .login-control .form-control:hover {
|
||||
border-color: rgba(156, 125, 63, 0.45);
|
||||
}
|
||||
|
||||
body.login-body .login-control .form-control:focus {
|
||||
border-color: var(--brass-deep);
|
||||
box-shadow: 0 0 0 3px rgba(196, 164, 106, 0.28);
|
||||
background: #fffdf8;
|
||||
}
|
||||
|
||||
body.login-body .login-control.has-toggle .form-control {
|
||||
padding-right: 48px;
|
||||
}
|
||||
|
||||
.field-toggle {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 48px;
|
||||
height: 50px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.field-toggle:hover,
|
||||
.field-toggle:focus,
|
||||
.field-toggle.is-on {
|
||||
color: var(--brass-deep);
|
||||
}
|
||||
|
||||
.field-toggle:focus-visible {
|
||||
outline: 2px solid var(--brass);
|
||||
outline-offset: -4px;
|
||||
}
|
||||
|
||||
.field-toggle .icon-off {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.field-toggle.is-on .icon-on {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.field-toggle.is-on .icon-off {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
body.login-body .login-control .input-group {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body.login-body .login-control .input-group .form-control {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
body.login-body .login-control .input-group-addon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0;
|
||||
border: 1px solid rgba(28, 33, 29, 0.16);
|
||||
border-left: 0;
|
||||
background: #fffdf8;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
body.login-body .login-control .input-group-addon img {
|
||||
display: block;
|
||||
width: 108px;
|
||||
height: 48px;
|
||||
}
|
||||
|
||||
body.login-body .login-keep.checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 44px;
|
||||
margin: 6px 0 22px;
|
||||
}
|
||||
|
||||
body.login-body .login-keep label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
font-weight: 400;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
body.login-body .login-keep input[type="checkbox"] {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin: 0;
|
||||
accent-color: var(--brass-deep);
|
||||
}
|
||||
|
||||
body.login-body .login-submit.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
min-height: 50px;
|
||||
padding: 0 16px;
|
||||
border: 0;
|
||||
border-radius: 2px;
|
||||
background: var(--ink);
|
||||
box-shadow: none;
|
||||
color: #f3ead8;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.28em;
|
||||
text-indent: 0.28em;
|
||||
transition: background 180ms ease, transform 160ms ease;
|
||||
}
|
||||
|
||||
body.login-body .login-submit.btn:hover,
|
||||
body.login-body .login-submit.btn:focus {
|
||||
background: #16221e;
|
||||
color: #f7f0e2;
|
||||
}
|
||||
|
||||
body.login-body .login-submit.btn:active {
|
||||
transform: scale(0.985);
|
||||
}
|
||||
|
||||
body.login-body .login-submit.btn:focus-visible {
|
||||
outline: 2px solid var(--brass);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
body.login-body .login-submit.btn.disabled,
|
||||
body.login-body .login-submit.btn[disabled] {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.login-note {
|
||||
margin: 22px 0 0;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.login-rise {
|
||||
animation: login-rise 640ms cubic-bezier(0.22, 1, 0.36, 1) both;
|
||||
}
|
||||
|
||||
.login-rise-2 { animation-delay: 80ms; }
|
||||
.login-rise-3 { animation-delay: 150ms; }
|
||||
.login-rise-4 { animation-delay: 220ms; }
|
||||
|
||||
@keyframes login-rise {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(12px);
|
||||
}
|
||||
</style>
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.login-shell {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.login-brand {
|
||||
min-height: 240px;
|
||||
padding: 28px 24px 24px;
|
||||
}
|
||||
|
||||
.brand-copy {
|
||||
padding: 20px 0 8px;
|
||||
}
|
||||
|
||||
.brand-copy h1 {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.brand-copy p,
|
||||
.brand-points {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.login-panel {
|
||||
align-items: flex-start;
|
||||
padding: 28px 20px 40px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.login-rise,
|
||||
body.login-body .login-submit.btn {
|
||||
animation: none;
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
{if $background}
|
||||
<style type="text/css">
|
||||
.login-brand {
|
||||
background-image:
|
||||
linear-gradient(160deg, rgba(11, 20, 18, 0.82), rgba(11, 20, 18, 0.7) 62%),
|
||||
url('{$background|htmlentities}');
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
</style>
|
||||
{/if}
|
||||
<!--@formatter:on-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="login-wrapper">
|
||||
<div class="login-screen">
|
||||
<div class="well">
|
||||
<div class="login-head">
|
||||
<img src="__CDN__/assets/img/login-head.png" style="width:100%;"/>
|
||||
<body class="login-body">
|
||||
<div class="login-shell">
|
||||
<aside class="login-brand" aria-label="{:__('Admin console')}" data-mark="{$site.name|mb_substr=0,1,'utf-8'|htmlentities}">
|
||||
<div class="brand-top login-rise">
|
||||
<span class="brand-mark"><i></i>{:__('Admin console')}</span>
|
||||
</div>
|
||||
<div class="brand-copy login-rise login-rise-2">
|
||||
<h1>{$site.name|htmlentities}</h1>
|
||||
<p>{:__('Sign in to continue')}。会话受权限约束,关键操作可追溯。</p>
|
||||
<ul class="brand-points">
|
||||
<li>{:__('Secure session')}</li>
|
||||
<li>{:__('Audited actions')}</li>
|
||||
<li>{:__('Role based access')}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="brand-foot login-rise login-rise-3">
|
||||
<span>{:date('Y.m.d')}</span>
|
||||
<span>{$site.version|htmlentities}</span>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main class="login-panel">
|
||||
<div class="login-card login-rise login-rise-4">
|
||||
<div class="login-greet">
|
||||
<div class="login-avatar">
|
||||
<img id="profile-img" alt="" width="52" height="52" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/>
|
||||
</div>
|
||||
<div class="login-form">
|
||||
<img id="profile-img" class="profile-img-card" src="__CDN__/assets/img/avatar.png"/>
|
||||
<p id="profile-name" class="profile-name-card"></p>
|
||||
|
||||
<form action="" method="post" id="login-form">
|
||||
<!--@AdminLoginFormBegin-->
|
||||
<div id="errtips" class="hide"></div>
|
||||
{:token()}
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></div>
|
||||
<input type="text" class="form-control" id="pd-form-username" placeholder="{:__('Username')}" name="username" autocomplete="off" value="" data-rule="{:__('Username')}:required;username"/>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></div>
|
||||
<input type="password" class="form-control" id="pd-form-password" placeholder="{:__('Password')}" name="password" autocomplete="off" value="" data-rule="{:__('Password')}:required;password"/>
|
||||
</div>
|
||||
<!--@CaptchaBegin-->
|
||||
{if $Think.config.fastadmin.login_captcha}
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><span class="glyphicon glyphicon-option-horizontal" aria-hidden="true"></span></div>
|
||||
<input type="text" name="captcha" class="form-control" placeholder="{:__('Captcha')}" data-rule="{:__('Captcha')}:required;length({$Think.config.captcha.length|htmlentities})" autocomplete="off"/>
|
||||
<span class="input-group-addon" style="padding:0;border:none;cursor:pointer;">
|
||||
<img src="{:rtrim('__PUBLIC__', '/')}/index.php?s=/captcha" width="100" height="30" onclick="this.src = '{:rtrim('__PUBLIC__', '/')}/index.php?s=/captcha&r=' + Math.random();"/>
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
<!--@CaptchaEnd-->
|
||||
{if $keeyloginhours>0}
|
||||
<div class="form-group checkbox">
|
||||
<label class="inline" for="keeplogin" data-toggle="tooltip" title="{:__('The duration of the session is %s hours', $keeyloginhours)}">
|
||||
<input type="checkbox" name="keeplogin" id="keeplogin" value="1"/>
|
||||
{:__('Keep login')}
|
||||
</label>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-success btn-lg btn-block" style="background:#708eea;">{:__('Sign in')}</button>
|
||||
</div>
|
||||
<!--@AdminLoginFormEnd-->
|
||||
</form>
|
||||
<div class="login-greet-text">
|
||||
<em>{:__('Welcome back')}</em>
|
||||
<span id="profile-name"></span>
|
||||
<h2>{:__('Login')}</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form action="" method="post" id="login-form">
|
||||
<!--@AdminLoginFormBegin-->
|
||||
<div id="errtips" class="hide"></div>
|
||||
{:token()}
|
||||
|
||||
<div class="login-field">
|
||||
<label for="pd-form-username">{:__('Username')}</label>
|
||||
<div class="login-control">
|
||||
<input type="text" class="form-control" id="pd-form-username" placeholder="{:__('Username')}" name="username" autocomplete="username" value="" data-rule="{:__('Username')}:required;username"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="login-field">
|
||||
<label for="pd-form-password">{:__('Password')}</label>
|
||||
<div class="login-control has-toggle">
|
||||
<input type="password" class="form-control" id="pd-form-password" placeholder="{:__('Password')}" name="password" autocomplete="current-password" value="" data-rule="{:__('Password')}:required;password"/>
|
||||
<button type="button" class="field-toggle" id="toggle-password" aria-label="{:__('Show password')}" aria-pressed="false" aria-controls="pd-form-password" data-show="{:__('Show password')}" data-hide="{:__('Hide password')}">
|
||||
<span class="icon-on" aria-hidden="true">
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
|
||||
<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z"/>
|
||||
<circle cx="12" cy="12" r="3"/>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="icon-off" aria-hidden="true">
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
|
||||
<path d="M3 3l18 18"/>
|
||||
<path d="M10.6 10.6a3 3 0 0 0 4.2 4.2"/>
|
||||
<path d="M9.9 5.1A11 11 0 0 1 12 5c6.5 0 10 7 10 7a17.4 17.4 0 0 1-3.2 4.4"/>
|
||||
<path d="M6.1 6.1C3.8 7.8 2 12 2 12s3.5 7 10 7a10.6 10.6 0 0 0 4.2-.9"/>
|
||||
</svg>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--@CaptchaBegin-->
|
||||
{if $Think.config.fastadmin.login_captcha}
|
||||
<div class="login-field">
|
||||
<label for="pd-form-captcha">{:__('Captcha')}</label>
|
||||
<div class="login-control">
|
||||
<div class="input-group">
|
||||
<input type="text" id="pd-form-captcha" name="captcha" class="form-control" placeholder="{:__('Captcha')}" data-rule="{:__('Captcha')}:required;length({$Think.config.captcha.length|htmlentities})" autocomplete="off"/>
|
||||
<span class="input-group-addon" style="padding:0;border:none;cursor:pointer;">
|
||||
<img src="{:rtrim('__PUBLIC__', '/')}/index.php?s=/captcha" width="108" height="48" alt="{:__('Captcha')}" onclick="this.src = '{:rtrim('__PUBLIC__', '/')}/index.php?s=/captcha&r=' + Math.random();"/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<!--@CaptchaEnd-->
|
||||
|
||||
{if $keeyloginhours>0}
|
||||
<div class="form-group checkbox login-keep">
|
||||
<label class="inline" for="keeplogin" data-toggle="tooltip" title="{:__('The duration of the session is %s hours', $keeyloginhours)}">
|
||||
<input type="checkbox" name="keeplogin" id="keeplogin" value="1"/>
|
||||
{:__('Keep login')}
|
||||
</label>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-success btn-lg btn-block login-submit">{:__('Sign in')}</button>
|
||||
</div>
|
||||
<!--@AdminLoginFormEnd-->
|
||||
</form>
|
||||
<p class="login-note">{$site.name|htmlentities} · {:date('Y')}</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
{include file="common/script" /}
|
||||
</body>
|
||||
|
||||
@@ -406,10 +406,26 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'form'], functi
|
||||
var lastlogin = localStorage.getItem("lastlogin");
|
||||
if (lastlogin) {
|
||||
lastlogin = JSON.parse(lastlogin);
|
||||
$("#profile-img").attr("src", Backend.api.cdnurl(lastlogin.avatar));
|
||||
$("#profile-name").val(lastlogin.username);
|
||||
if (lastlogin.avatar) {
|
||||
$("#profile-img").attr("src", Backend.api.cdnurl(lastlogin.avatar)).addClass("is-ready");
|
||||
}
|
||||
if (lastlogin.username) {
|
||||
$("#profile-name").text(lastlogin.username);
|
||||
$("#pd-form-username").val(lastlogin.username);
|
||||
$(".login-greet").addClass("has-user");
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on("click", "#toggle-password", function () {
|
||||
var $btn = $(this);
|
||||
var $pwd = $("#pd-form-password");
|
||||
var show = $pwd.attr("type") === "password";
|
||||
$pwd.attr("type", show ? "text" : "password");
|
||||
$btn.toggleClass("is-on", show)
|
||||
.attr("aria-pressed", show ? "true" : "false")
|
||||
.attr("aria-label", show ? ($btn.data("hide") || "隐藏密码") : ($btn.data("show") || "显示密码"));
|
||||
});
|
||||
|
||||
//让错误提示框居中
|
||||
Fast.config.toastr.positionClass = "toast-top-center";
|
||||
|
||||
@@ -419,6 +435,10 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'form'], functi
|
||||
$.each(errors, function (i, j) {
|
||||
Toastr.error(j);
|
||||
});
|
||||
var $first = $("#login-form").find(".n-invalid:first");
|
||||
if ($first.length) {
|
||||
$first.trigger("focus");
|
||||
}
|
||||
},
|
||||
target: '#errtips'
|
||||
});
|
||||
|
||||
@@ -5,9 +5,13 @@ namespace tests\partner;
|
||||
define('APP_PATH', __DIR__ . '/../../application/');
|
||||
define('ROOT_PATH', dirname(realpath(APP_PATH)) . '/');
|
||||
require_once __DIR__ . '/../../thinkphp/base.php';
|
||||
require_once __DIR__ . '/../../thinkphp/helper.php';
|
||||
require_once __DIR__ . '/../../application/common.php';
|
||||
|
||||
\think\Config::set(\think\Config::load(APP_PATH . 'config.php'));
|
||||
\think\Config::set(\think\Config::load(APP_PATH . 'database.php'));
|
||||
\think\Config::set(include APP_PATH . 'database.php', 'database');
|
||||
\think\Loader::addNamespace('app', APP_PATH);
|
||||
require_once __DIR__ . '/../../addons/shopro/helper/helper.php';
|
||||
|
||||
use app\admin\controller\shopro\commission\Agent;
|
||||
use think\Request;
|
||||
|
||||
353
tests/partner/MakerPeerTest.php
普通文件
353
tests/partner/MakerPeerTest.php
普通文件
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
|
||||
namespace tests\partner;
|
||||
|
||||
// 引导 ThinkPHP 环境
|
||||
define('APP_PATH', __DIR__ . '/../../application/');
|
||||
define('ROOT_PATH', dirname(realpath(APP_PATH)) . '/');
|
||||
require_once __DIR__ . '/../../thinkphp/base.php';
|
||||
require_once __DIR__ . '/../../thinkphp/helper.php';
|
||||
require_once __DIR__ . '/../../application/common.php';
|
||||
|
||||
\think\Config::set(include APP_PATH . 'database.php', 'database');
|
||||
\think\Loader::addNamespace('app', APP_PATH);
|
||||
require_once __DIR__ . '/../../addons/shopro/helper/helper.php';
|
||||
|
||||
use addons\shopro\service\partner\MakerPeerReward;
|
||||
use addons\shopro\service\partner\ActiveService;
|
||||
use addons\shopro\service\partner\PartnerRewardService;
|
||||
use addons\shopro\service\partner\PartnerConfig;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 模拟活跃度服务,便于单元测试任意用户的自购状态
|
||||
*/
|
||||
class MockActiveService extends ActiveService
|
||||
{
|
||||
private $activeMap = [];
|
||||
|
||||
public function setActive($userId, $isActive)
|
||||
{
|
||||
$this->activeMap[$userId] = $isActive;
|
||||
}
|
||||
|
||||
public function isActive($agent, $atTime = null)
|
||||
{
|
||||
$userId = is_array($agent) ? ($agent['user_id'] ?? 0) : ($agent->user_id ?? 0);
|
||||
if (isset($this->activeMap[$userId])) {
|
||||
return $this->activeMap[$userId];
|
||||
}
|
||||
return true; // 默认均活跃
|
||||
}
|
||||
}
|
||||
|
||||
class MakerPeerTest
|
||||
{
|
||||
private $passed = 0;
|
||||
private $failed = 0;
|
||||
|
||||
public function run()
|
||||
{
|
||||
echo "========================================================\n";
|
||||
echo " 创客两代平级级联收益计算测试 (Maker Peer Cascading) \n";
|
||||
echo "========================================================\n\n";
|
||||
|
||||
$this->testThreePeerCascade();
|
||||
$this->testFourPeerCapLimit();
|
||||
$this->testInactiveIntermediaryCascade();
|
||||
$this->testV1PeerCascade();
|
||||
$this->testMultiSegmentPeers();
|
||||
|
||||
echo "\n--------------------------------------------------------\n";
|
||||
echo "测试执行结果: 通过 {$this->passed} 项, 失败 {$this->failed} 项\n";
|
||||
echo "========================================================\n";
|
||||
return $this->failed === 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
private function assert($condition, $testName, $detail = '')
|
||||
{
|
||||
if ($condition) {
|
||||
echo " [PASS] {$testName}\n";
|
||||
$this->passed++;
|
||||
} else {
|
||||
echo " [FAIL] {$testName} - {$detail}\n";
|
||||
$this->failed++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 1:经典 3 平级创客(A -> B -> C,均为基数 60 的 V3)
|
||||
* 规则验证:
|
||||
* A(2): 实拿极差全额 60.00
|
||||
* B(3): 第1代平级 60 * 10% = 6.00
|
||||
* C(4): 第2代平级 6 * 10% = 0.60
|
||||
*/
|
||||
public function testThreePeerCascade()
|
||||
{
|
||||
$testName = "场景1: 3个平级创客(A->B->C, V3) 第1代拿6元,第2代拿0.60元";
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = ['id' => 9901, 'user_id' => 7];
|
||||
$buyerId = 7;
|
||||
|
||||
// 关系链:买家(7) -> A(2, V3/level 4) -> B(3, V3/level 4) -> C(4, V3/level 4)
|
||||
$chain = [
|
||||
['user_id' => 2, 'level' => 4], // Level 4 基数 60 (V3)
|
||||
['user_id' => 3, 'level' => 4],
|
||||
['user_id' => 4, 'level' => 4],
|
||||
];
|
||||
|
||||
$diffResult = [
|
||||
'seen' => 60.0,
|
||||
'paid' => [
|
||||
['user_id' => 2, 'level' => 4, 'cap' => 60.0, 'amount' => 60.0]
|
||||
]
|
||||
];
|
||||
|
||||
$active = new MockActiveService();
|
||||
$reward = new MakerPeerReward();
|
||||
$reward->run($order, $buyerId, $chain, $diffResult, $active);
|
||||
|
||||
$records = Db::name('shopro_partner_reward')
|
||||
->where('order_id', 9901)
|
||||
->where('reward_type', 'maker_peer')
|
||||
->order('id asc')
|
||||
->select();
|
||||
|
||||
$bReward = null;
|
||||
$cReward = null;
|
||||
foreach ($records as $r) {
|
||||
if ($r['user_id'] == 3) $bReward = $r;
|
||||
if ($r['user_id'] == 4) $cReward = $r;
|
||||
}
|
||||
|
||||
$bAmount = $bReward ? floatval($bReward['amount']) : 0;
|
||||
$cAmount = $cReward ? floatval($cReward['amount']) : 0;
|
||||
$bExt = $bReward ? json_decode($bReward['ext'], true) : [];
|
||||
$cExt = $cReward ? json_decode($cReward['ext'], true) : [];
|
||||
|
||||
$bPass = ($bAmount == 6.00) && (($bExt['generation'] ?? 0) == 1);
|
||||
$cPass = ($cAmount == 0.60) && (($cExt['generation'] ?? 0) == 2);
|
||||
|
||||
$this->assert($bPass && $cPass, $testName, "B金额={$bAmount}(期6.00), C金额={$cAmount}(期0.60)");
|
||||
} catch (\Exception $e) {
|
||||
$this->assert(false, $testName, "异常: " . $e->getMessage());
|
||||
} finally {
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 2:4 平级创客深度封顶(A -> B -> C -> D,均为 V3)
|
||||
* 规则验证:
|
||||
* 第3代创客 D 应严格封顶截断,不产生任何平级奖记录
|
||||
*/
|
||||
public function testFourPeerCapLimit()
|
||||
{
|
||||
$testName = "场景2: 4个平级创客(A->B->C->D) 第3代D严格封顶截断不分佣";
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = ['id' => 9902, 'user_id' => 7];
|
||||
$buyerId = 7;
|
||||
$chain = [
|
||||
['user_id' => 2, 'level' => 4],
|
||||
['user_id' => 3, 'level' => 4],
|
||||
['user_id' => 4, 'level' => 4],
|
||||
['user_id' => 5, 'level' => 4],
|
||||
];
|
||||
|
||||
$diffResult = [
|
||||
'seen' => 60.0,
|
||||
'paid' => [
|
||||
['user_id' => 2, 'level' => 4, 'cap' => 60.0, 'amount' => 60.0]
|
||||
]
|
||||
];
|
||||
|
||||
$active = new MockActiveService();
|
||||
$reward = new MakerPeerReward();
|
||||
$reward->run($order, $buyerId, $chain, $diffResult, $active);
|
||||
|
||||
$dReward = Db::name('shopro_partner_reward')
|
||||
->where('order_id', 9902)
|
||||
->where('user_id', 5)
|
||||
->where('reward_type', 'maker_peer')
|
||||
->find();
|
||||
|
||||
$this->assert(empty($dReward), $testName, "第3代平级创客D应无平级奖记录");
|
||||
} catch (\Exception $e) {
|
||||
$this->assert(false, $testName, "异常: " . $e->getMessage());
|
||||
} finally {
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 3:中间创客未自购场景(A -> B(不活跃) -> C(活跃))
|
||||
* 规则验证:
|
||||
* B 产生 skip 记录(status=-1, skip_reason=inactive_30d)
|
||||
* C 仍然作为合格第2代拿到 0.60 元
|
||||
*/
|
||||
public function testInactiveIntermediaryCascade()
|
||||
{
|
||||
$testName = "场景3: 中间平级B 30日无自购被跳过,上级C仍正常获得第2代平级0.60元";
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = ['id' => 9903, 'user_id' => 7];
|
||||
$buyerId = 7;
|
||||
$chain = [
|
||||
['user_id' => 2, 'level' => 4],
|
||||
['user_id' => 3, 'level' => 4],
|
||||
['user_id' => 4, 'level' => 4],
|
||||
];
|
||||
|
||||
$diffResult = [
|
||||
'seen' => 60.0,
|
||||
'paid' => [
|
||||
['user_id' => 2, 'level' => 4, 'cap' => 60.0, 'amount' => 60.0]
|
||||
]
|
||||
];
|
||||
|
||||
$active = new MockActiveService();
|
||||
$active->setActive(3, false); // B 不活跃
|
||||
$active->setActive(4, true); // C 活跃
|
||||
|
||||
$reward = new MakerPeerReward();
|
||||
$reward->run($order, $buyerId, $chain, $diffResult, $active);
|
||||
|
||||
$bSkip = Db::name('shopro_partner_reward')
|
||||
->where('order_id', 9903)
|
||||
->where('user_id', 3)
|
||||
->where('status', -1)
|
||||
->find();
|
||||
|
||||
$cReward = Db::name('shopro_partner_reward')
|
||||
->where('order_id', 9903)
|
||||
->where('user_id', 4)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
|
||||
$bSkipped = !empty($bSkip) && floatval($bSkip['amount']) == 0;
|
||||
$cReceived = !empty($cReward) && floatval($cReward['amount']) == 0.60;
|
||||
|
||||
$this->assert($bSkipped && $cReceived, $testName, "B被跳过记录, C正常结算0.60元");
|
||||
} catch (\Exception $e) {
|
||||
$this->assert(false, $testName, "异常: " . $e->getMessage());
|
||||
} finally {
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 4:V1 等级(level 2,基数 20 元)两代级联
|
||||
* 规则验证:
|
||||
* A(2): 极差 20.00
|
||||
* B(3): 第1代 20 * 10% = 2.00
|
||||
* C(4): 第2代 2 * 10% = 0.20
|
||||
*/
|
||||
public function testV1PeerCascade()
|
||||
{
|
||||
$testName = "场景4: V1等级(基数20元)两代级联 B得2.00元, C得0.20元";
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = ['id' => 9904, 'user_id' => 7];
|
||||
$buyerId = 7;
|
||||
$chain = [
|
||||
['user_id' => 2, 'level' => 2], // Level 2 基数 20 (V1)
|
||||
['user_id' => 3, 'level' => 2],
|
||||
['user_id' => 4, 'level' => 2],
|
||||
];
|
||||
|
||||
$diffResult = [
|
||||
'seen' => 20.0,
|
||||
'paid' => [
|
||||
['user_id' => 2, 'level' => 2, 'cap' => 20.0, 'amount' => 20.0]
|
||||
]
|
||||
];
|
||||
|
||||
$active = new MockActiveService();
|
||||
$reward = new MakerPeerReward();
|
||||
$reward->run($order, $buyerId, $chain, $diffResult, $active);
|
||||
|
||||
$bReward = Db::name('shopro_partner_reward')->where('order_id', 9904)->where('user_id', 3)->find();
|
||||
$cReward = Db::name('shopro_partner_reward')->where('order_id', 9904)->where('user_id', 4)->find();
|
||||
|
||||
$bAmount = $bReward ? floatval($bReward['amount']) : 0;
|
||||
$cAmount = $cReward ? floatval($cReward['amount']) : 0;
|
||||
|
||||
$this->assert($bAmount == 2.00 && $cAmount == 0.20, $testName, "B金额={$bAmount}(期2.00), C金额={$cAmount}(期0.20)");
|
||||
} catch (\Exception $e) {
|
||||
$this->assert(false, $testName, "异常: " . $e->getMessage());
|
||||
} finally {
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 5:多段平级并存(V1平级 + V3平级在同一推荐链)
|
||||
* 链条:买家(7) -> A(2, V1) -> B(3, V1) -> C(4, V3) -> D(5, V3) -> E(6, V3)
|
||||
* diff paid: A (level 2, cap 20), C (level 4, cap 60)
|
||||
* 期望:
|
||||
* A(2): 极差 20.00
|
||||
* B(3): V1第1代平级 = 20 * 10% = 2.00
|
||||
* C(4): 极差 60 - 20 = 40.00
|
||||
* D(5): V3第1代平级 = 60 * 10% = 6.00
|
||||
* E(6): V3第2代平级 = 6 * 10% = 0.60
|
||||
*/
|
||||
public function testMultiSegmentPeers()
|
||||
{
|
||||
$testName = "场景5: 混合等级链条多段平级互不干扰独立级联";
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = ['id' => 9905, 'user_id' => 7];
|
||||
$buyerId = 7;
|
||||
$chain = [
|
||||
['user_id' => 2, 'level' => 2], // V1
|
||||
['user_id' => 3, 'level' => 2], // V1
|
||||
['user_id' => 4, 'level' => 4], // V3
|
||||
['user_id' => 5, 'level' => 4], // V3
|
||||
['user_id' => 6, 'level' => 4], // V3
|
||||
];
|
||||
|
||||
$diffResult = [
|
||||
'seen' => 60.0,
|
||||
'paid' => [
|
||||
['user_id' => 2, 'level' => 2, 'cap' => 20.0, 'amount' => 20.0],
|
||||
['user_id' => 4, 'level' => 4, 'cap' => 60.0, 'amount' => 40.0]
|
||||
]
|
||||
];
|
||||
|
||||
$active = new MockActiveService();
|
||||
$reward = new MakerPeerReward();
|
||||
$reward->run($order, $buyerId, $chain, $diffResult, $active);
|
||||
|
||||
$bReward = Db::name('shopro_partner_reward')->where('order_id', 9905)->where('user_id', 3)->find();
|
||||
$dReward = Db::name('shopro_partner_reward')->where('order_id', 9905)->where('user_id', 5)->find();
|
||||
$eReward = Db::name('shopro_partner_reward')->where('order_id', 9905)->where('user_id', 6)->find();
|
||||
|
||||
$bAmount = $bReward ? floatval($bReward['amount']) : 0;
|
||||
$dAmount = $dReward ? floatval($dReward['amount']) : 0;
|
||||
$eAmount = $eReward ? floatval($eReward['amount']) : 0;
|
||||
|
||||
$this->assert(
|
||||
$bAmount == 2.00 && $dAmount == 6.00 && $eAmount == 0.60,
|
||||
$testName,
|
||||
"B(V1平级1)={$bAmount}(期2.00), D(V3平级1)={$dAmount}(期6.00), E(V3平级2)={$eAmount}(期0.60)"
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->assert(false, $testName, "异常: " . $e->getMessage());
|
||||
} finally {
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行测试
|
||||
if (php_sapi_name() === 'cli') {
|
||||
$tester = new MakerPeerTest();
|
||||
exit($tester->run());
|
||||
}
|
||||
@@ -6,9 +6,13 @@ namespace tests\partner;
|
||||
define('APP_PATH', __DIR__ . '/../../application/');
|
||||
define('ROOT_PATH', dirname(realpath(APP_PATH)) . '/');
|
||||
require_once __DIR__ . '/../../thinkphp/base.php';
|
||||
require_once __DIR__ . '/../../thinkphp/helper.php';
|
||||
require_once __DIR__ . '/../../application/common.php';
|
||||
|
||||
\think\Config::set(\think\Config::load(APP_PATH . 'config.php'));
|
||||
\think\Config::set(\think\Config::load(APP_PATH . 'database.php'));
|
||||
\think\Config::set(include APP_PATH . 'database.php', 'database');
|
||||
\think\Loader::addNamespace('app', APP_PATH);
|
||||
require_once __DIR__ . '/../../addons/shopro/helper/helper.php';
|
||||
|
||||
use addons\shopro\service\partner\DailySettleService;
|
||||
use addons\shopro\service\partner\PartnerConfig;
|
||||
|
||||
@@ -6,9 +6,13 @@ namespace tests\partner;
|
||||
define('APP_PATH', __DIR__ . '/../../application/');
|
||||
define('ROOT_PATH', dirname(realpath(APP_PATH)) . '/');
|
||||
require_once __DIR__ . '/../../thinkphp/base.php';
|
||||
require_once __DIR__ . '/../../thinkphp/helper.php';
|
||||
require_once __DIR__ . '/../../application/common.php';
|
||||
|
||||
\think\Config::set(\think\Config::load(APP_PATH . 'config.php'));
|
||||
\think\Config::set(\think\Config::load(APP_PATH . 'database.php'));
|
||||
\think\Loader::addNamespace('app', APP_PATH);
|
||||
require_once __DIR__ . '/../../addons/shopro/helper/helper.php';
|
||||
|
||||
use addons\shopro\controller\commission\Agent;
|
||||
use think\Request;
|
||||
|
||||
在新工单中引用
屏蔽一个用户