fix: 话费按营业厅剩余话费页面显示
This commit is contained in:
@@ -13,6 +13,8 @@ type Snapshot struct {
|
||||
Balance string `json:"balance,omitempty"`
|
||||
BalanceNegative bool `json:"balanceNegative,omitempty"`
|
||||
MonthFee string `json:"monthFee,omitempty"`
|
||||
CarryOver string `json:"carryOver,omitempty"`
|
||||
MonthIn string `json:"monthIn,omitempty"`
|
||||
DataRemain string `json:"dataRemain,omitempty"`
|
||||
DataUsed string `json:"dataUsed,omitempty"`
|
||||
VoiceTotal string `json:"voiceTotal,omitempty"`
|
||||
@@ -41,12 +43,25 @@ func BuildSnapshot(phone string, balanceRaw, planRaw json.RawMessage) Snapshot {
|
||||
var balance map[string]any
|
||||
_ = json.Unmarshal(balanceRaw, &balance)
|
||||
if balance != nil {
|
||||
snap.Balance = textOf(balance["canusefeecust"])
|
||||
snap.Balance = textOf(balance["curntbalancecust"])
|
||||
if snap.Balance == "" {
|
||||
snap.Balance = textOf(balance["curntbalancecust"])
|
||||
snap.Balance = textOf(balance["canusefeecust"])
|
||||
}
|
||||
snap.BalanceNegative = strings.HasPrefix(snap.Balance, "-")
|
||||
snap.MonthFee = textOf(balance["realfeecust"])
|
||||
if truthy(balance["newVersion"]) {
|
||||
snap.MonthFee = textOf(balance["realfeecustnew"])
|
||||
snap.CarryOver = textOf(balance["newCarryForwardFromLastMonth"])
|
||||
snap.MonthIn = textOf(balance["newDepositForTheMonth"])
|
||||
}
|
||||
if snap.MonthFee == "" {
|
||||
snap.MonthFee = textOf(balance["realfeecust"])
|
||||
}
|
||||
if snap.CarryOver == "" {
|
||||
snap.CarryOver = textOf(balance["carryForwardFromLastMonth"])
|
||||
}
|
||||
if snap.MonthIn == "" {
|
||||
snap.MonthIn = textOf(balance["depositForTheMonth"])
|
||||
}
|
||||
if owe := textOf(balance["allbowefeecust"]); owe != "" && owe != "0" && owe != "0.00" {
|
||||
snap.Extras = append(snap.Extras, Extra{Name: "欠费", Used: owe, Fee: owe})
|
||||
}
|
||||
@@ -177,6 +192,17 @@ func trimNum(v float64) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func truthy(v any) bool {
|
||||
switch t := v.(type) {
|
||||
case bool:
|
||||
return t
|
||||
case string:
|
||||
return t == "true" || t == "1"
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func textOf(v any) string {
|
||||
switch t := v.(type) {
|
||||
case string:
|
||||
|
||||
Reference in New Issue
Block a user