From 3a873c13a37fcdd820eab45142079a8d1f8809b5 Mon Sep 17 00:00:00 2001
From: lwl0608 <lwl0608@foxmail.com>
Date: Mon, 9 Dec 2024 16:44:08 +0800
Subject: [PATCH] add

---
 api/errs/error.go                           |  2 +-
 app/mix/service/cron/sync_alipay_balance.go |  2 +-
 app/mix/service/logic/vas.go                | 15 +++++++++++++--
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/api/errs/error.go b/api/errs/error.go
index a4f351c5..92c381ed 100644
--- a/api/errs/error.go
+++ b/api/errs/error.go
@@ -60,7 +60,7 @@ var (
 	ErrVasInvalidParam                 = errors.New("invalid param")
 	ErrVasNoEnoughWithdrawDias         = errors.New("no enough withdraw dias")
 	ErrVasAlipayUniTransferFail        = errors.New("alipay uni transfer fail")
-	ErrVasOverTodayWithdrawCnt         = errors.New("over today withdraw cnt")
+	ErrVasOverTodayWithdrawCnt         = errors.New("今日提现次数到达上限")
 	ErrVasRefundLimit                  = errors.New("账号已受限,解限请联系客服")
 	ErrVasHvyogoSingleDistributionFail = errors.New("hvyogo single distribution fail")
 )
diff --git a/app/mix/service/cron/sync_alipay_balance.go b/app/mix/service/cron/sync_alipay_balance.go
index fe813c32..ebff1c69 100644
--- a/app/mix/service/cron/sync_alipay_balance.go
+++ b/app/mix/service/cron/sync_alipay_balance.go
@@ -11,7 +11,7 @@ import (
 
 func (c *Cron) SyncAlipayBalance() {
 	logger.Info("SyncAlipayBalance Start")
-	for range time.Tick(time.Second * 5) {
+	for range time.Tick(time.Second * 30) {
 		ctx := context.Background()
 		allClients := alipaycli.GetAllAlipayClients()
 		for _, client := range allClients {
diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go
index 50f46151..fa7d9509 100644
--- a/app/mix/service/logic/vas.go
+++ b/app/mix/service/logic/vas.go
@@ -2015,8 +2015,15 @@ func (v *Vas) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq) (t
 		return
 	}
 
-	// 2000元以下直接操作
-	alipayCli := alipaycli.GetAlipayClientByAppId(alipaycli.AppIdXinYiDaoLe)
+	// 获取能提现的支付宝
+	alipayAcnt, err := v.store.GetAvailableWithdrawAlipayAccount(ctx, money)
+	if err != nil {
+		logger.Error("GetAvailableWithdrawAlipayAccount fail, err: %v", err)
+		err = fmt.Errorf("提现维护中,请稍后再试")
+		return
+	}
+	alipayCli := alipaycli.GetAlipayClientByAppId(alipayAcnt.AppId)
+	logger.Info("Get AlipayAcnt ok, aliAcnt: %v, req: %v", util.ToJson(alipayCli), util.ToJson(req))
 
 	// 更改状态
 	err = v.store.UpdateWithdrawOrderStatus(ctx, tx, orderId, dbstruct.VasWithdrawOrderStatusInit, dbstruct.VasWithdrawOrderStatusAuto)
@@ -2085,6 +2092,10 @@ func (v *Vas) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq) (t
 		logger.Error("UniTransfer fail, param: %v, resp: %v, err: %v", util.ToJson(transferParam), util.ToJson(transferResp), err)
 		return
 	}
+	_err := v.store.UpdateAlipayAccountWithdrawUt(ctx, alipayCli.AppId)
+	if _err != nil {
+		logger.Error("UpdateAlipayAccountWithdrawUt, err: %v", err)
+	}
 	//}
 	return
 }