fix: add missing $casts for numeric columns (PostgreSQL compatibility)#842
Open
onesyue wants to merge 1 commit intocedar2025:masterfrom
Open
fix: add missing $casts for numeric columns (PostgreSQL compatibility)#842onesyue wants to merge 1 commit intocedar2025:masterfrom
onesyue wants to merge 1 commit intocedar2025:masterfrom
Conversation
PostgreSQL's PDO driver returns bigint/decimal/double columns as PHP
strings, unlike MySQL which auto-converts to native types. When these
string values reach the frontend via JSON, JavaScript's + operator
performs string concatenation instead of numeric addition.
Confirmed bug: Payment.handling_fee_fixed stored as "0" (string) in
PG → JS evaluates ("0" || 0) as "0" (truthy) → 3328 + "0" = "33280"
(concat) → order total displayed as ¥41,600,332.80 instead of ¥449.28.
This patch adds integer/float $casts to all numeric columns across 10
models. The change is backward-compatible — MySQL already returns
correct types, so the casts are effectively no-ops on MySQL while
fixing all PG deployments.
Models patched: Payment, Order, User, Coupon, Plan, Server,
CommissionLog, Stat, StatUser, StatServer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using PostgreSQL as the database backend, PHP's PDO driver returns
bigint,decimal, anddouble precisioncolumns as strings (unlike MySQL which auto-converts to native PHP types). These string values pass through Laravel's JSON serialization unchanged, causing JavaScript's+operator to perform string concatenation instead of numeric addition in the frontend.Confirmed Bug: Payment Page Total = ¥41,600,332.80
The
handling_fee_fixedcolumn (double precision) is returned as string"0"from PG. In the frontend checkout page:Expected: ¥449.28 — Displayed: ¥41,600,332.80
Other Affected Areas
The same class of bug affects any frontend code that uses
+with values from:User.u + User.d(traffic calculation)Order.total_amount + Order.handling_amount(order totals)Coupon.value(discount calculation)Stat*.u + Stat*.d(traffic statistics)Solution
Add
$castsdeclarations for all numeric columns across 10 models. This ensures Laravel converts PG string values to proper PHPint/floattypes before JSON serialization.Backward compatible: MySQL already returns correct native types, so these casts are effectively no-ops on MySQL deployments.
Changes
handling_fee_percent(float),handling_fee_fixed(integer)total_amount,discount_amount,balance_amount,refund_amount,surplus_amount,commission_balance,actual_commission_balancebalance,commission_balance,discount,u,d,transfer_enable,t,speed_limit,device_limit,online_countvalue,type,limit_use,limit_use_with_usertransfer_enable,speed_limit,capacity_limit,device_limitrate(float),server_portorder_amount,get_amountorder_count,order_total,commission_count,commission_total,paid_count,paid_total,register_count,invite_countu,d,server_rate(float)u,dTest Plan