From 467bae29f3ee515b72e8a767df3cfab4f18cc4bc Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 26 Jan 2024 09:37:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chain_transfer/chain_transfer.go | 11 +++++++- chain_transfer/svc/svc_turnchain.go | 12 ++++----- chain_transfer/turn_chain.go | 6 +++++ db/db_taobao_user_relation.go | 39 +++++++++++++++++++++++++++++ db/model/taobao_user_relation.go | 11 ++++++++ taobao/base.go | 16 ++++++++---- taobao/taobao.go | 4 +-- 7 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 db/db_taobao_user_relation.go create mode 100644 db/model/taobao_user_relation.go diff --git a/chain_transfer/chain_transfer.go b/chain_transfer/chain_transfer.go index 6126d4d..49d50d0 100644 --- a/chain_transfer/chain_transfer.go +++ b/chain_transfer/chain_transfer.go @@ -26,7 +26,16 @@ func ChainTransfer(eg *xorm.Engine, args map[string]string) map[string]string { res["word"] = "" userProfile, _ := db.UserProfileFindByID(eg, args["uid"]) + UnionId := "" if userProfile != nil { + if args["provider"] == md.PVD_TB || args["provider"] == md.PVD_TM { + //新的渠道id 存储 + relation := db.GetTaobaoUserRelationByUid(eg, userProfile.Uid) + if relation != nil { + userProfile.AccTaobaoShareId = relation.RelationId + UnionId = zhios_third_party_utils.IntToStr(relation.UnionId) + } + } args["acc_taobao_share_id"] = zhios_third_party_utils.Int64ToStr(userProfile.AccTaobaoShareId) if userProfile.AccJdCloudId == "" { userProfile.AccJdCloudId = userProfile.AccJdShareId @@ -36,7 +45,7 @@ func ChainTransfer(eg *xorm.Engine, args map[string]string) map[string]string { } switch args["provider"] { case md.PVD_TB, md.PVD_TM: - taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]), UnionId) if err != nil { return res } diff --git a/chain_transfer/svc/svc_turnchain.go b/chain_transfer/svc/svc_turnchain.go index c70ddfd..f005a7f 100644 --- a/chain_transfer/svc/svc_turnchain.go +++ b/chain_transfer/svc/svc_turnchain.go @@ -77,7 +77,7 @@ func TBOrTmTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*m var couponUrl = "" if urls != nil { - taobaoSdk, err := taobao.NewTaobaoSDK(eg, dbName, args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + taobaoSdk, err := taobao.NewTaobaoSDK(eg, dbName, args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]), args["union_id"]) if err != nil { fmt.Println("=======商品10", err) @@ -231,7 +231,7 @@ func ConvertUrl(eg *xorm.Engine, args map[string]string) (*md.ConvertedUrls, err var urls *md.ConvertedUrls switch args["provider"] { case md.PVD_TB, md.PVD_TM: - taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]), args["union_id"]) if err != nil { return nil, err } @@ -440,7 +440,7 @@ func TikTokUrl(eg *xorm.Engine, dbName string, gid, activityId string) string { func CheckTaobaoWordGetId(eg *xorm.Engine, dbName string, s string, args map[string]string) string { ak := db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_AK) sk := db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_SK) - taobaoSdk, _ := taobao.NewTaobaoSDK(eg, dbName, args["platfrom"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + taobaoSdk, _ := taobao.NewTaobaoSDK(eg, dbName, args["platfrom"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]), args["union_id"]) if taobaoSdk == nil { return "" } @@ -553,7 +553,7 @@ func CommGetGoods(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]strin return tcPrase, reqCount } func ReplaceTbAll(eg *xorm.Engine, url string, args map[string]string) (taoBaoWord, shortURL string) { - taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]), args["union_id"]) if err != nil { return } @@ -779,7 +779,7 @@ func CheckTaobao(eg *xorm.Engine, dbName, s string, args map[string]string) *md. bizSceneId = "" } - taobaoSdk, _ := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + taobaoSdk, _ := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]), args["union_id"]) itemInfo, err := taobaoSdk.ItemDetailByLink(s, bizSceneId) if itemInfo == nil || err != nil { return nil @@ -1029,7 +1029,7 @@ func TikTokByGoodsID(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]st func TBByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (productDetail *md.ProductDetailResponse, pvd, couponShareURL, couponAmount string) { //获取到传进来的id先请求淘宝 //根据prodId获取对应产品信息 - taobaoSdk, err := taobao.NewTaobaoSDK(eg, tmp["master_id"], tmp["platform"], zhios_third_party_utils.StrToInt(tmp["acc_taobao_share_id"])) + taobaoSdk, err := taobao.NewTaobaoSDK(eg, tmp["master_id"], tmp["platform"], zhios_third_party_utils.StrToInt(tmp["acc_taobao_share_id"]), tmp["union_id"]) if err != nil { //e.OutErr(c, e.ERR_SYSUNION_CONFIG, err) diff --git a/chain_transfer/turn_chain.go b/chain_transfer/turn_chain.go index bde92de..5fc1809 100644 --- a/chain_transfer/turn_chain.go +++ b/chain_transfer/turn_chain.go @@ -25,6 +25,12 @@ func TurnChain(eg *xorm.Engine, officialEg *xorm.Engine, args map[string]string) user, _ := db.UserFindByID(eg, args["uid"]) userProfile, _ := db.UserProfileFindByID(eg, user.Uid) if userProfile != nil { + //新的渠道id 存储 + relation := db.GetTaobaoUserRelationByUid(eg, userProfile.Uid) + if relation != nil { + userProfile.AccTaobaoShareId = relation.RelationId + args["union_id"] = zhios_third_party_utils.IntToStr(relation.UnionId) + } args["acc_taobao_share_id"] = zhios_third_party_utils.Int64ToStr(userProfile.AccTaobaoShareId) if userProfile.AccJdCloudId == "" { userProfile.AccJdCloudId = userProfile.AccJdShareId diff --git a/db/db_taobao_user_relation.go b/db/db_taobao_user_relation.go new file mode 100644 index 0000000..e2303a9 --- /dev/null +++ b/db/db_taobao_user_relation.go @@ -0,0 +1,39 @@ +package db + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/model" + "xorm.io/xorm" +) + +func GetTaobaoUserRelation(eg *xorm.Engine, unionId, uid int) *model.TaobaoUserRelation { + var data model.TaobaoUserRelation + get, _ := eg.Where("union_id=? and uid=?", unionId, uid).Get(&data) + if get == false { + return nil + } + return &data +} +func GetTaobaoUserRelationByUid(eg *xorm.Engine, uid int) *model.TaobaoUserRelation { + var data model.TaobaoUserRelation + get, _ := eg.Where(" uid=?", uid).Get(&data) + if get == false { + return nil + } + return &data +} +func TaobaoUserRelationExistByRelationID(Db *xorm.Engine, RelationID string) (bool, error) { + has, err := Db.Where("relation_id = ? ", RelationID).Exist(&model.TaobaoUserRelation{}) + + if err != nil { + return false, err + } + return has, nil +} +func TaobaoUserRelationExistBySpecialId(Db *xorm.Engine, RelationID string) (bool, error) { + has, err := Db.Where("special_id = ? ", RelationID).Exist(&model.TaobaoUserRelation{}) + + if err != nil { + return false, err + } + return has, nil +} diff --git a/db/model/taobao_user_relation.go b/db/model/taobao_user_relation.go new file mode 100644 index 0000000..5c98ead --- /dev/null +++ b/db/model/taobao_user_relation.go @@ -0,0 +1,11 @@ +package model + +type TaobaoUserRelation struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Uid int `json:"uid" xorm:"default 0 unique(uid) INT(11)"` + UnionId int `json:"union_id" xorm:"default 0 unique(uid) INT(11)"` + RelationId int64 `json:"relation_id" xorm:"default 0 BIGINT(12)"` + SpecialId int64 `json:"special_id" xorm:"default 0 BIGINT(12)"` + Nickname string `json:"nickname" xorm:"not null default '' comment('淘宝昵称') VARCHAR(50)"` + Time int64 `json:"time" xorm:"not null default 0 comment('淘宝授权备案时间') BIGINT(11)"` +} diff --git a/taobao/base.go b/taobao/base.go index 5d3847b..31dfee5 100644 --- a/taobao/base.go +++ b/taobao/base.go @@ -2,6 +2,7 @@ package taobao import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/model" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" "errors" @@ -9,12 +10,17 @@ import ( "xorm.io/xorm" ) -func NewTaobaoSDK(eg *xorm.Engine, dbName, Platform string, AccTaobaoShareId int) (*TB, error) { +func NewTaobaoSDK(eg *xorm.Engine, dbName, Platform string, AccTaobaoShareId int, UnionId string) (*TB, error) { // 从联盟设置中获取淘宝配置 - - taobaoCfg, err := db.SysUnionByTaobaoByUseByAuth(eg, dbName) - if err != nil { - return nil, err + var taobaoCfg *model.SysUnionSet + var err error + if UnionId != "" { + taobaoCfg = db.SysUnionById(eg, UnionId) + } else { + taobaoCfg, err = db.SysUnionByTaobaoByUseByAuth(eg, dbName) + if err != nil { + return nil, err + } } var cfg *TB diff --git a/taobao/taobao.go b/taobao/taobao.go index c6c383f..fda71a0 100644 --- a/taobao/taobao.go +++ b/taobao/taobao.go @@ -27,7 +27,7 @@ type TaoBaoArgs struct { func TaoBaoFeaturedList(eg *xorm.Engine, dbName, Platform string, AccTaobaoShareId int, postData map[string]string) []map[string]string { var goods = make([]map[string]string, 0) - sdk, err := NewTaobaoSDK(eg, dbName, Platform, AccTaobaoShareId) + sdk, err := NewTaobaoSDK(eg, dbName, Platform, AccTaobaoShareId, "") if err != nil { return goods } @@ -55,7 +55,7 @@ func TaoBaoFeaturedList(eg *xorm.Engine, dbName, Platform string, AccTaobaoShare } func TaoBaoSearchList(eg *xorm.Engine, dbName, Platform string, AccTaobaoShareId int, postData map[string]string) []map[string]string { var goods = make([]map[string]string, 0) - sdk, err := NewTaobaoSDK(eg, dbName, Platform, AccTaobaoShareId) + sdk, err := NewTaobaoSDK(eg, dbName, Platform, AccTaobaoShareId, "") if err != nil { return goods }