fix: 按营业厅余量接口补上流量语音和短信
This commit is contained in:
@@ -236,7 +236,7 @@ func (c *Client) Query(ctx context.Context, phone string) (Snapshot, error) {
|
||||
return BuildSnapshot(phone, balance, nil), err
|
||||
}
|
||||
if err != nil {
|
||||
return BuildSnapshot(phone, balance, nil), nil
|
||||
return BuildSnapshot(phone, balance, nil), errors.New("套餐余量没有拿到")
|
||||
}
|
||||
return BuildSnapshot(phone, balance, plan), nil
|
||||
}
|
||||
@@ -661,12 +661,15 @@ func (c *Client) syncMall(ctx context.Context) string {
|
||||
return ""
|
||||
}
|
||||
c.setDomainCookie("loginflag", "true")
|
||||
if prov := pad3(asString(wrap.UserInfo["provincecode"])); prov != "" {
|
||||
prov := pad3(asString(wrap.UserInfo["provincecode"]))
|
||||
cityCode := asString(wrap.UserInfo["citycode"])
|
||||
if prov != "" {
|
||||
c.setDomainCookie("userprocode", prov)
|
||||
c.setDomainCookie("selectedProvince", prov)
|
||||
c.setDomainCookie("city", prov+"|")
|
||||
}
|
||||
if city := asString(wrap.UserInfo["citycode"]); city != "" {
|
||||
c.setDomainCookie("citycode", city)
|
||||
c.setDomainCookie("city", city)
|
||||
if cityCode != "" {
|
||||
c.setDomainCookie("citycode", cityCode)
|
||||
}
|
||||
if enc := asString(wrap.UserInfo["encryptPhoneNumber"]); enc != "" {
|
||||
c.setDomainCookie("u_account", url.QueryEscape(enc))
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestBuildSnapshot(t *testing.T) {
|
||||
if snap.PackageName != "测试套餐" || snap.DataRemain != "1.5 GB" {
|
||||
t.Fatalf("plan %#v", snap)
|
||||
}
|
||||
if snap.VoiceTotal != "100" || snap.VoiceRemain != "98" {
|
||||
if snap.VoiceTotal != "100" || snap.VoiceRemain != "98" || snap.SmsRemain != "97" {
|
||||
t.Fatalf("voice %s %s", snap.VoiceTotal, snap.VoiceRemain)
|
||||
}
|
||||
if len(snap.Resources) != 3 || snap.Resources[0].Unit != "GB" || snap.Resources[0].Total != "2" {
|
||||
|
||||
@@ -88,6 +88,11 @@
|
||||
<div class="stat"><span>上月结转</span><b id="carryOver">-</b></div>
|
||||
<div class="stat"><span>本月存入</span><b id="monthIn">-</b></div>
|
||||
</div>
|
||||
<div class="stats">
|
||||
<div class="stat"><span>剩余流量</span><b id="dataRemain">-</b></div>
|
||||
<div class="stat"><span>剩余语音</span><b id="voiceRemain">-</b></div>
|
||||
<div class="stat"><span>剩余短信</span><b id="smsRemain">-</b></div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div id="pkg" class="hint"></div>
|
||||
<div class="res head"><span>项目</span><span>已用</span><span>剩余</span><span>总量</span></div>
|
||||
@@ -155,6 +160,9 @@ function render(view) {
|
||||
$("monthFee").textContent = view.monthFee || "-";
|
||||
$("carryOver").textContent = view.carryOver || "-";
|
||||
$("monthIn").textContent = view.monthIn || "-";
|
||||
$("dataRemain").textContent = view.dataRemain || "-";
|
||||
$("voiceRemain").textContent = view.voiceRemain ? view.voiceRemain + " 分钟" : "-";
|
||||
$("smsRemain").textContent = view.smsRemain ? view.smsRemain + " 条" : "-";
|
||||
const who = [view.phoneMasked, view.packageName].filter(Boolean).join(" · ");
|
||||
$("pkg").textContent = who;
|
||||
$("pollMinutes").value = view.pollMinutes || 30;
|
||||
|
||||
Reference in New Issue
Block a user