feat(goods): 商品详情接口增加复购立减提示与完善单元测试
这个提交包含在:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户