From b8a46e0ca5738cd86d010300a8ced8acb406c340 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 4 Dec 2024 21:18:32 +0800 Subject: [PATCH] update --- app/hdl/hdl_wallet.go | 52 ++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/app/hdl/hdl_wallet.go b/app/hdl/hdl_wallet.go index 962dd88..c9ab236 100644 --- a/app/hdl/hdl_wallet.go +++ b/app/hdl/hdl_wallet.go @@ -506,23 +506,49 @@ func BindAlipayAccount(c *gin.Context) { e.OutErr(c, e.ERR, err.Error()) return } - now := time.Now() - m := model.AlipayUserInfo{ - Uid: user.Id, - UserId: info.Response.UserId, - OpenId: info.Response.OpenId, - AppId: client.AppId, - UserName: info.Response.NickName, - Ext: "", - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - } infoDb := implement.NewAlipayUserInfoDb(db.Db) - _, err = infoDb.AlipayUserInfoInsert(&m) + userInfo, err := infoDb.GetAlipayUserInfo(user.Id) if err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) + e.OutErr(c, e.ERR, err.Error()) return } + now := time.Now() + if userInfo == nil { + m := model.AlipayUserInfo{ + Uid: user.Id, + UserId: info.Response.UserId, + OpenId: info.Response.OpenId, + AppId: client.AppId, + UserName: info.Response.NickName, + Ext: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + } + _, err = infoDb.AlipayUserInfoInsert(&m) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + } else { + cols := []string{"open_id", "app_id", "user_id", "user_name"} + m := model.AlipayUserInfo{ + Id: userInfo.Id, + Uid: userInfo.Uid, + UserId: info.Response.UserId, + OpenId: info.Response.OpenId, + AppId: client.AppId, + UserName: info.Response.NickName, + Ext: "", + CreateAt: userInfo.CreateAt, + UpdateAt: now.Format("2006-01-02 15:04:05"), + } + _, err := infoDb.UpdateAlipayUserInfo(&m, cols...) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + } + e.OutSuc(c, "success", nil) }