|
|
@@ -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) |
|
|
|
} |
|
|
|
|
|
|
|