分佣订单优化

This commit is contained in:
Dev
2026-10-14 14:59:10 +08:00
parent aad64abf8a
commit 419c578b2c
@@ -270,16 +270,21 @@ class PromotionService
*/ */
public static function getOverview(int $userId): array public static function getOverview(int $userId): array
{ {
$base = self::where('promoter_id', $userId)->where('order_status', 'in', self::VISIBLE_ORDER_STATUS); //TP5.0 克隆查询对象会共用参数绑定导致 HY093,每次都新建查询
$settledAmount = (clone $base)->where('commission_status', self::COMMISSION_STATUS_SETTLED)->sum('commission_amount'); $base = [
$pendingCount = (clone $base)->where('commission_status', self::COMMISSION_STATUS_PENDING)->count(); 'promoter_id' => $userId,
'order_status' => ['in', self::VISIBLE_ORDER_STATUS],
];
$settledAmount = self::where($base)->where('commission_status', self::COMMISSION_STATUS_SETTLED)->sum('commission_amount');
$pendingCount = self::where($base)->where('commission_status', self::COMMISSION_STATUS_PENDING)->count();
$orderCount = self::where($base)->count();
return [ return [
'enabled' => self::isEnabled(), 'enabled' => self::isEnabled(),
'soft_ratio_percent' => floatval(bcmul(self::getRatio(OrderService::ORDER_TYPE_SOFTWARE), '100', 2)), 'soft_ratio_percent' => floatval(bcmul(self::getRatio(OrderService::ORDER_TYPE_SOFTWARE), '100', 2)),
'demand_ratio_percent' => floatval(bcmul(self::getRatio(OrderService::ORDER_TYPE_FIRST_PAYMENT), '100', 2)), 'demand_ratio_percent' => floatval(bcmul(self::getRatio(OrderService::ORDER_TYPE_FIRST_PAYMENT), '100', 2)),
'invite_count' => User::where('promoter_id', $userId)->count(), 'invite_count' => User::where('promoter_id', $userId)->count(),
'order_count' => (clone $base)->count(), 'order_count' => $orderCount,
'settled_amount' => bcadd((string)$settledAmount, '0', 2), 'settled_amount' => bcadd((string)$settledAmount, '0', 2),
'pending_count' => $pendingCount, 'pending_count' => $pendingCount,
]; ];