diff --git a/example/alipay/example-alipay-records.csv b/example/alipay/example-alipay-records.csv index 93f0059..3e590d4 100644 --- a/example/alipay/example-alipay-records.csv +++ b/example/alipay/example-alipay-records.csv @@ -28,3 +28,6 @@ 2023-02-04 18:21:04 ,退款 ,xxxxxxx ,/ ,退款-亲情卡 ,不计收支 ,16.03 ,交通银行信用卡(7449) ,退款成功 ,2xxxxxxxxxxxxxxxx8 ,20xxxxxxxxxxxxxxxx5 , , 2023-02-02 15:24:35 ,投资理财 ,蚂蚁财富-蚂蚁(杭州)基金销售有限公司 ,/ ,蚂蚁财富-交银定期支付双息平衡混合-卖出至余额宝,不计收支 ,99.34 ,余额宝 ,交易成功 ,2xxxxxxxxxxxxxxxxxxxxxxxxxx8 , , , 2023-01-18 10:17:29 ,转账红包 ,xxxx ,xxx***@163.com ,转账 ,收入 ,222228.50 ,余额 ,交易成功 ,2xxxxxxxxxxxxxxxxxxxxxxxxx9 , , , +2023-01-10 13:10:16,日用百货,xxxx,/,xxxx,不计收支,82.00,,交易关闭,xxxx ,xxxx ,, +2023-01-09 18:22:28,退款,一卡通,fin***@jieyisoft.com,退款-一卡通充值,不计收支,50.00,余额宝,退款成功,2023xxxxx88_2023xx57 ,D12*****14 ,, +2023-01-09 18:21:50,交通出行,一卡通,fin***@jieyisoft.com,一卡通充值,支出,50.00,余额宝,交易关闭,2023xxxxx88 ,D12*****14 ,, diff --git a/pkg/provider/alipay/alipay.go b/pkg/provider/alipay/alipay.go index 48f80bb..34ef617 100644 --- a/pkg/provider/alipay/alipay.go +++ b/pkg/provider/alipay/alipay.go @@ -90,5 +90,52 @@ func (a *Alipay) Translate(filename string) (*ir.IR, error) { } log.Printf("Finished to parse the file %s", filename) - return a.convertToIR(), nil + ir := a.convertToIR() + return a.postProcess(ir), nil +} + +func (a *Alipay) postProcess(ir_ *ir.IR) *ir.IR { + var orders []ir.Order + for i := 0; i < len(ir_.Orders); i++ { + var order = ir_.Orders[i] + // found alipay refund tx + if order.Metadata["status"] == "閫娆炬垚鍔" && order.Category == "閫娆" { + for j := 0; j < len(ir_.Orders); j++ { + // find the order corresponding to the refund + // (different tx) && (prefix match) && (money equal) + if i != j && + strings.HasPrefix( + ir_.Orders[i].Metadata["orderId"], + ir_.Orders[j].Metadata["orderId"]) && + ir_.Orders[i].Money == ir_.Orders[j].Money { + log.Printf("[orderId %s] Refund for [orderId %s].", + ir_.Orders[i].Metadata["orderId"], + ir_.Orders[j].Metadata["orderId"]) + ir_.Orders[i].Metadata["useless"] = "true" + ir_.Orders[j].Metadata["useless"] = "true" + } + } + } + // found alipay closed tx + if order.Metadata["status"] == "浜ゆ槗鍏抽棴" && order.Metadata["type"] == "涓嶈鏀舵敮" { + ir_.Orders[i].Metadata["useless"] = "true" + log.Printf("[orderId %s] canceled.", + ir_.Orders[i].Metadata["orderId"]) + } + } + + for _, v := range ir_.Orders { + if v.Metadata["useless"] != "true" { + if v.Metadata["status"] == "浜ゆ槗鍏抽棴" { + log.Printf("[orderId %s] canceled tx left unprocessed.", v.Metadata["orderId"]) + } + if v.Metadata["status"] == "閫娆炬垚鍔" { + log.Printf("[orderId %s] refund tx left unprocessed.", v.Metadata["orderId"]) + } + orders = append(orders, v) + } + } + ir_.Orders = orders + // 瓒呮椂 + return ir_ } diff --git a/pkg/provider/alipay/parse.go b/pkg/provider/alipay/parse.go index bad0cd3..afe09e0 100644 --- a/pkg/provider/alipay/parse.go +++ b/pkg/provider/alipay/parse.go @@ -39,12 +39,6 @@ func (a *Alipay) translateToOrders(array []string) error { return err } bill.Status = array[8] - if bill.Status == "浜ゆ槗鍏抽棴" { - log.Printf("[orderId %s ] There is a mole, The tx is canceled.", bill.DealNo) - } - if bill.Status == "閫娆炬垚鍔" { - log.Printf("[orderId %s ] There has a refund transaction.", bill.DealNo) - } bill.PayTime, err = time.Parse(localTimeFmt, array[0]+" +0800 CST") if err != nil { log.Println("parse create time error:", array[0], err)