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

[feat] 自动清理支付宝退款 #116

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 example/alipay/example-alipay-records.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 ,,
49 changes: 48 additions & 1 deletion pkg/provider/alipay/alipay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_
}
6 changes: 0 additions & 6 deletions pkg/provider/alipay/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down