From 92622fc9b1bd851f9a3692763ff8d26d50885a1d Mon Sep 17 00:00:00 2001 From: wikiboss Date: Sat, 12 Sep 2026 17:15:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(goods):=20=E5=95=86=E5=93=81=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0=E5=A4=8D=E8=B4=AD?= =?UTF-8?q?=E7=AB=8B=E5=87=8F=E6=8F=90=E7=A4=BA=E4=B8=8E=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/shopro/controller/Goods.php | 29 +++++++++++++++++++ .../shopro/tests/repurchase_discount_test.php | 26 +++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/addons/shopro/controller/Goods.php b/addons/shopro/controller/Goods.php index d86e40f..10d7255 100644 --- a/addons/shopro/controller/Goods.php +++ b/addons/shopro/controller/Goods.php @@ -46,6 +46,35 @@ class Goods extends Base $detail['cartNum'] = count($cartList); } + // 复购立减提示信息 + $detail['repurchase_info'] = [ + 'is_enable' => false, + 'is_user_repurchase' => false, + 'tip' => '' + ]; + try { + $isEnable = \addons\shopro\library\commission\RepurchaseService::isGoodsRepurchaseEnable($id); + if ($isEnable) { + $config = \addons\shopro\library\commission\RepurchaseService::getConfig(); + if (!empty($config['enable']) && !empty($config['self_enable'])) { + $detail['repurchase_info']['is_enable'] = true; + $discountDesc = ($config['self_type'] ?? 'fixed') === 'rate' + ? ($config['self_rate'] . '%') + : ('¥' . $config['self_amount']); + $detail['repurchase_info']['discount_desc'] = $discountDesc; + + $userId = $this->auth->id ?? 0; + if ($userId && \addons\shopro\library\commission\RepurchaseService::isUserRepurchasedGoods($userId, $id)) { + $detail['repurchase_info']['is_user_repurchase'] = true; + $detail['repurchase_info']['tip'] = '您曾购买过本商品,再次下单立减' . $discountDesc; + } else { + $detail['repurchase_info']['tip'] = '老客复购享立减' . $discountDesc; + } + } + } + } catch (\Throwable $e) { + } + $this->success('商品详情', $detail); } diff --git a/addons/shopro/tests/repurchase_discount_test.php b/addons/shopro/tests/repurchase_discount_test.php index 0e7d1f2..aec6179 100644 --- a/addons/shopro/tests/repurchase_discount_test.php +++ b/addons/shopro/tests/repurchase_discount_test.php @@ -27,6 +27,7 @@ class RepurchaseDiscountTest $this->testRepurchaseRateDiscount(); $this->testDiscountCapProtection(); $this->testMixedOrderDiscounts(); + $this->testGoodsDetailRepurchaseTip(); echo "\n----------------------------------------\n"; echo "测试结果: {$this->passed} 通过, {$this->failed} 失败\n"; @@ -265,6 +266,31 @@ class RepurchaseDiscountTest $this->assert($newGoodsList[0]['repurchase_discount_money'] === 10.00, "商品 201 立减应为 10.00 (实际: {$newGoodsList[0]['repurchase_discount_money']})"); $this->assert($newGoodsList[1]['repurchase_discount_money'] === 0.00, "商品 202 立减应为 0.00 (实际: {$newGoodsList[1]['repurchase_discount_money']})"); } + + /** + * 测试场景 7: 商详复购立减提示文案与状态 + */ + public function testGoodsDetailRepurchaseTip() + { + echo "\n场景 7: 商详页复购立减提示逻辑\n"; + + $config = [ + 'enable' => true, + 'self_enable' => true, + 'self_type' => 'fixed', + 'self_amount' => 15.00, + 'self_rate' => 0 + ]; + + // 模拟已购买老客 + $discountDesc = ($config['self_type'] ?? 'fixed') === 'rate' ? ($config['self_rate'] . '%') : ('¥' . $config['self_amount']); + $tipRepurchase = '您曾购买过本商品,再次下单立减' . $discountDesc; + $tipNew = '老客复购享立减' . $discountDesc; + + $this->assert($tipRepurchase === '您曾购买过本商品,再次下单立减¥15', "老客专享提示文案匹配 (实际: {$tipRepurchase})"); + $this->assert($tipNew === '老客复购享立减¥15', "新客引导提示文案匹配 (实际: {$tipNew})"); + } } (new RepurchaseDiscountTest())->run(); +