fix: 按营业厅余量接口补上流量语音和短信
This commit is contained in:
@@ -19,6 +19,7 @@ type Snapshot struct {
|
||||
DataUsed string `json:"dataUsed,omitempty"`
|
||||
VoiceTotal string `json:"voiceTotal,omitempty"`
|
||||
VoiceRemain string `json:"voiceRemain,omitempty"`
|
||||
SmsRemain string `json:"smsRemain,omitempty"`
|
||||
Resources []Resource `json:"resources"`
|
||||
Extras []Extra `json:"extras"`
|
||||
}
|
||||
@@ -78,7 +79,8 @@ func BuildSnapshot(phone string, balanceRaw, planRaw json.RawMessage) Snapshot {
|
||||
snap.DataRemain = remain + unitSuffix(textOf(plan["canuseFlowAllUnit"]))
|
||||
}
|
||||
snap.Resources = resourcesFromPlan(plan)
|
||||
snap.VoiceTotal, snap.VoiceRemain = voiceHeadline(snap.Resources)
|
||||
snap.VoiceTotal, snap.VoiceRemain = voiceHeadline(snap.Resources, "分钟")
|
||||
snap.SmsRemain = smsRemain(snap.Resources)
|
||||
}
|
||||
return snap
|
||||
}
|
||||
@@ -136,11 +138,11 @@ func unitFor(elemType string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func voiceHeadline(list []Resource) (total, remain string) {
|
||||
func voiceHeadline(list []Resource, unit string) (total, remain string) {
|
||||
var sumTotal, sumRemain float64
|
||||
var seen bool
|
||||
for _, item := range list {
|
||||
if item.Unit != "分钟" {
|
||||
if item.Unit != unit {
|
||||
continue
|
||||
}
|
||||
t, err1 := strconv.ParseFloat(item.Total, 64)
|
||||
@@ -158,6 +160,11 @@ func voiceHeadline(list []Resource) (total, remain string) {
|
||||
return trimNum(sumTotal), trimNum(sumRemain)
|
||||
}
|
||||
|
||||
func smsRemain(list []Resource) string {
|
||||
_, remain := voiceHeadline(list, "条")
|
||||
return remain
|
||||
}
|
||||
|
||||
func mbToGB(raw string) string {
|
||||
v, err := strconv.ParseFloat(strings.TrimSpace(raw), 64)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user