where(function ($query) { $query->where('price', '>', 0) ->whereOr('use_money', '>', 0); }) ->where('status', '=', 1) ->where('pay_time', '>=', $startTime) ->where('pay_time', '<=', $endTime) ->field('sum(use_money) as balance_consumed, sum(price) as wechat_consumed') ->find(); // 处理查询结果 $result = [ 'money_consumed' => round(floatval($consumptionData['balance_consumed'] ?? 0), 2), // 余额消费 'wechat_consumed' => round(floatval($consumptionData['wechat_consumed'] ?? 0), 2), // 微信支付消费 'total_consumed' => round(floatval(($consumptionData['balance_consumed'] ?? 0) + ($consumptionData['wechat_consumed'] ?? 0)), 2) // 总消费 ]; return $result; } }