Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(provider, analyser): support jd new bill format, Set plusaccount to methodaccount for refund records in jd bills #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/analyser/jd/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,8 @@ func (a JD) GetAccountsAndTags(o *ir.Order, cfg *config.Config, target, provider
strings.HasPrefix(o.Item, "解冻-")) {
ignore = true
}
if o.TypeOriginal == "不计收支" && (strings.HasPrefix(o.Item, "退款-")) {
return ignore, resPlus, resMinus, extraAccounts, tags
}
return ignore, resMinus, resPlus, extraAccounts, tags
}
21 changes: 14 additions & 7 deletions pkg/provider/jd/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"log"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -129,17 +130,17 @@ func (c *JD) translateLine(row []string) error {
if err != nil {
return err
}
bill.Category = row[1]
bill.PeerType = row[2]
bill.ItemName = row[3]
bill.Category = row[7]
bill.PeerType = row[1]
bill.ItemName = row[2]

bill.Type = c.translateType(row[4])
bill.Money, err = c.translateValue(row[5])
bill.Type = c.translateType(row[6])
bill.Money, err = c.translateValue(row[3])
if err != nil {
return err
}
bill.Method = row[6]
bill.Status = row[7]
bill.Method = row[4]
bill.Status = row[5]
bill.DealNo = row[8]
bill.MerchantId = row[9]
bill.Notes = row[10]
Expand Down Expand Up @@ -187,6 +188,12 @@ func (c *JD) convertToIRType(s Type) ir.Type {
}

func (c *JD) translateValue(s string) (int64, error) {

re := regexp.MustCompile(`\(已退款[0-9]+(\.[0-9]+)?\)|\(已全额退款\)$`)

// 检查金额是否以 '(已全额退款)' 或者 '(已退款xx.xx)' 结尾
// 如果是,去掉后缀
s = re.ReplaceAllString(s, "")
s = strings.ReplaceAll(s, ".", "")
return strconv.ParseInt(s, 10, 64)
}
Expand Down
Loading