From 8600f85a8fd41e6ec86a67cfa50f55978c05af72 Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Mon, 26 Apr 2021 11:44:59 +0800 Subject: [PATCH] pdd --- business/jxstore/cms/job.go | 54 ++++++++++++++++++------ business/jxstore/partner/jds/union.go | 6 ++- business/jxstore/partner/mt/union.go | 4 ++ business/jxstore/partner/partner.go | 1 + business/jxstore/partner/pdd/pdd.go | 26 ++++++++++++ business/jxstore/partner/pdd/union.go | 18 ++++++++ business/jxstore/partner/taobao/union.go | 4 ++ business/model/dao/dao_user.go | 18 ++++++++ conf/app.conf | 5 ++- globals/api/api.go | 3 ++ 10 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 business/jxstore/partner/pdd/union.go diff --git a/business/jxstore/cms/job.go b/business/jxstore/cms/job.go index a1d56d821..9b65259d2 100644 --- a/business/jxstore/cms/job.go +++ b/business/jxstore/cms/job.go @@ -3,6 +3,7 @@ package cms import ( "encoding/json" "fmt" + "git.rosy.net.cn/baseapi/platformapi/tbunionapi" "math" "strings" "sync" @@ -1967,25 +1968,54 @@ func GetUnionActList(ctx *jxcontext.Context, vendorID, actType int) (actList []* func ShareUnionLink(ctx *jxcontext.Context, jobID, shareType, linkType int) (link string, err error) { var ( - job = &model.Job{} - db = dao.GetDB() - sid string //推广位ID,美团为userID,淘宝饿了么本地化暂时是固定的京西推广位ID,pdd为表中推广位ID + job = &model.Job{} + db = dao.GetDB() + sid string //推广位ID,美团为userID,淘宝饿了么本地化暂时是固定的京西推广位ID,pdd为表中推广位ID + userID = ctx.GetUserID() + userBinds []*model.UserUnionBind ) job.ID = jobID if err = dao.GetEntity(db, job); err != nil { return "", err } + vendorID := job.VendorID + handler := partner.GetHandler(vendorID) //1、建推广位(本地和平台) - + if userBinds, err = dao.GetUserUnionBind(db, userID, vendorID); err != nil { + return "", err + } + //本地已有推广位 + if len(userBinds) > 0 { + sid = userBinds[0].UnionID + } else { + userBind := &model.UserUnionBind{ + UserID: userID, + VendorID: vendorID, + } + dao.WrapAddIDCULDEntity(userBind, ctx.GetUserName()) + if handler != nil { + if sid, err = handler.CreateUnionPosition(ctx, userID); err == nil { + if sid == "" { + sid = userID + if vendorID == model.VendorIDTB { + sid = utils.Int2Str(tbunionapi.JxAdzoneID) + } + } + } + } + userBind.UnionID = sid + dao.CreateEntity(db, userBind) + } //2、分享链接 - if handler := partner.GetHandler(job.VendorID); handler != nil { - link, err = handler.ShareUnionLink(ctx, linkType, job.UnionActID, sid, ctx.GetUserID()) - if job.VendorID == model.VendorIDMTWM || job.VendorID == model.VendorIDTB { - if linkType == partner.LinkTypeWeiXinMini { - if resBinary, _, err := jxutils.DownloadFileByURL(link + "?imageView2/1/w/150/h/150/q/75"); err == nil { - if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+link[strings.LastIndex(link, "/")+1:len(link)]); err == nil { - if err == nil { - link = jxutils.MixWatermarkImg(downloadURL, job.UnionImg, job.UnionQrcodePosition) + if handler != nil { + if link, err = handler.ShareUnionLink(ctx, linkType, job.UnionActID, sid, userID); err == nil { + if vendorID == model.VendorIDMTWM || vendorID == model.VendorIDTB { + if linkType == partner.LinkTypeWeiXinMini { + if resBinary, _, err := jxutils.DownloadFileByURL(link + "?imageView2/1/w/150/h/150/q/75"); err == nil { + if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+link[strings.LastIndex(link, "/")+1:len(link)]); err == nil { + if err == nil { + link = jxutils.MixWatermarkImg(downloadURL, job.UnionImg, job.UnionQrcodePosition) + } } } } diff --git a/business/jxstore/partner/jds/union.go b/business/jxstore/partner/jds/union.go index c53ad35f0..f2d13bb04 100644 --- a/business/jxstore/partner/jds/union.go +++ b/business/jxstore/partner/jds/union.go @@ -17,7 +17,7 @@ func init() { partner.HandlerMap[model.VendorIDJDShop] = unionHandler } -func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, userID string) (link string, err error) { +func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string) (link string, err error) { return "jds", err } @@ -25,3 +25,7 @@ func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionAct func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) { return } + +func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) { + return sID, err +} diff --git a/business/jxstore/partner/mt/union.go b/business/jxstore/partner/mt/union.go index 8f3c1e424..70d9ce25e 100644 --- a/business/jxstore/partner/mt/union.go +++ b/business/jxstore/partner/mt/union.go @@ -44,3 +44,7 @@ func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (act } return actList, err } + +func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) { + return sID, err +} diff --git a/business/jxstore/partner/partner.go b/business/jxstore/partner/partner.go index c8f15a3d6..fe375050a 100644 --- a/business/jxstore/partner/partner.go +++ b/business/jxstore/partner/partner.go @@ -47,6 +47,7 @@ func init() { type UnionInterface interface { ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string) (link string, err error) GetUnionActList(ctx *jxcontext.Context, actType int) (result []*ActivityList, err error) + CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) //GetUnionCouponList(ctx *jxcontext.Context) } diff --git a/business/jxstore/partner/pdd/pdd.go b/business/jxstore/partner/pdd/pdd.go index 695f07a9c..845afa21c 100644 --- a/business/jxstore/partner/pdd/pdd.go +++ b/business/jxstore/partner/pdd/pdd.go @@ -1 +1,27 @@ package pdd + +import ( + "git.rosy.net.cn/baseapi/platformapi/pddapi" + "git.rosy.net.cn/jx-callback/business/jxstore/partner" + "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals/api" +) + +type UnionHandler struct { +} + +var ( + unionHandler *UnionHandler +) + +func init() { + partner.HandlerMap[model.VendorIDPDD] = unionHandler +} + +func getAPI() (apiobj *pddapi.API) { + if configs, err := dao.QueryConfigs(dao.GetDB(), "pddunionCookie", model.ConfigTypeCookie, ""); err == nil { + api.PddAPI.SetCookieWithStr(configs[0].Value) + } + return api.PddAPI +} diff --git a/business/jxstore/partner/pdd/union.go b/business/jxstore/partner/pdd/union.go new file mode 100644 index 000000000..eb25b0879 --- /dev/null +++ b/business/jxstore/partner/pdd/union.go @@ -0,0 +1,18 @@ +package pdd + +import ( + "git.rosy.net.cn/jx-callback/business/jxstore/partner" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" +) + +func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string) (link string, err error) { + return link, err +} + +func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) { + return actList, err +} + +func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) { + return sID, err +} diff --git a/business/jxstore/partner/taobao/union.go b/business/jxstore/partner/taobao/union.go index c96b5154e..309a1c7c8 100644 --- a/business/jxstore/partner/taobao/union.go +++ b/business/jxstore/partner/taobao/union.go @@ -42,3 +42,7 @@ func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (act } return actList, err } + +func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) { + return sID, err +} diff --git a/business/model/dao/dao_user.go b/business/model/dao/dao_user.go index b6baa7129..2b3865d95 100644 --- a/business/model/dao/dao_user.go +++ b/business/model/dao/dao_user.go @@ -394,3 +394,21 @@ func GetUserAllWaitRealCashPrice(db *DaoDB, userID string) (price int, err error err = GetRow(db, &result, sql, sqlParams) return result.Price, err } +func GetUserUnionBind(db *DaoDB, userID string, vendorID int) (userBinds []*model.UserUnionBind, err error) { + sql := ` + SELECT * FROM user_union_bind WHERE deleted_at = ? + ` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + } + if userID != "" { + sql += " AND user_id = ?" + sqlParams = append(sqlParams, userID) + } + if vendorID != -1 { + sql += " AND vendor_id = ?" + sqlParams = append(sqlParams, vendorID) + } + err = GetRows(db, &userBinds, sql, sqlParams) + return userBinds, err +} diff --git a/conf/app.conf b/conf/app.conf index f39383160..c4e84df79 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -266,4 +266,7 @@ mtUnionAppKey = "b6481f92b47918cd6e42e7ea4fae6084" mtUnionAppSecret = "84d390777ddf691ff092e744ba26bfdd" tbUnionAppKey = "32724809" -tbUnionAppSecret = "2c2bce02eab860d486f68aa59a0127d9" \ No newline at end of file +tbUnionAppSecret = "2c2bce02eab860d486f68aa59a0127d9" + +pddAppKey = "f9d95aaf5856485eabf39588f69a86de" +pddAppSecret = "fa40c1fe356eebc1376ace1d2380ed44e553c602" \ No newline at end of file diff --git a/globals/api/api.go b/globals/api/api.go index e3fd20d2e..c537d3c5b 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -1,6 +1,7 @@ package api import ( + "git.rosy.net.cn/baseapi/platformapi/pddapi" "git.rosy.net.cn/baseapi/platformapi/tbunionapi" "io/ioutil" @@ -45,6 +46,7 @@ import ( var ( MtUnionAPI *mtunionapi.API TbUnionAPI *tbunionapi.API + PddAPI *pddapi.API JdEclpAPI *jdeclpapi.API JdShopAPI *jdshopapi.API @@ -90,6 +92,7 @@ func init() { func Init() { MtUnionAPI = mtunionapi.New(beego.AppConfig.DefaultString("mtUnionAppKey", ""), beego.AppConfig.DefaultString("mtUnionAppSecret", "")) TbUnionAPI = tbunionapi.New(beego.AppConfig.DefaultString("tbUnionAppKey", ""), beego.AppConfig.DefaultString("tbUnionAppSecret", "")) + PddAPI = pddapi.New(beego.AppConfig.DefaultString("pddAppKey", ""), beego.AppConfig.DefaultString("pddAppSecret", "")) if !beego.AppConfig.DefaultBool("disableJdEclp", false) { JdEclpAPI = jdeclpapi.New(beego.AppConfig.String("jdEclpAccessToken"), beego.AppConfig.String("jdEclpAppKey"), beego.AppConfig.String("jdEclpAppSecret"))