Browse Source

拼多多联盟

master
huangjiajun 7 months ago
parent
commit
31f90a5e27
3 changed files with 411 additions and 57 deletions
  1. +92
    -57
      chain_transfer/svc/svc_turnchain.go
  2. +189
    -0
      zhimeng/own_pdd_convert_url.go
  3. +130
    -0
      zhimeng/own_pdd_goods.go

+ 92
- 57
chain_transfer/svc/svc_turnchain.go View File

@@ -149,8 +149,19 @@ func JDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.Co
//pdd转链 //pdd转链
func PDDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.ConvertedUrls, error) { func PDDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.ConvertedUrls, error) {
pid := args["acc_pdd_self_id"] pid := args["acc_pdd_self_id"]
union, _ := db.SysUnionByPVDByUse(eg, dbName, "pdd")
var urls *md.ConvertedUrls var urls *md.ConvertedUrls
var err error var err error
miniApp := "0"
isShares := "2"
if union != nil && union.AuthType == 2 {
pid = "own_" + dbName + "_" + args["uid"]
urls, err = zhimeng.OwnPDDConvertUrl(union, args["gid"], pid, "", miniApp, "", isShares)
if err != nil {
return nil, err
}
return urls, nil
}
thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key")
if thirdZmAppKeyData == nil || err != nil { if thirdZmAppKeyData == nil || err != nil {
return urls, err return urls, err
@@ -159,8 +170,7 @@ func PDDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.C
if thirdZmAppSecretData == nil || err != nil { if thirdZmAppSecretData == nil || err != nil {
return urls, err return urls, err
} }
miniApp := "0"
isShares := "2"

masterPid := pid masterPid := pid
pddPidData, _ := pdd.NewZhiMengPDDSDK(). pddPidData, _ := pdd.NewZhiMengPDDSDK().
SelectFunction("get_pid_list"). SelectFunction("get_pid_list").
@@ -196,6 +206,7 @@ func PDDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.C
if err != nil { if err != nil {
return nil, err return nil, err
} }

return urls, nil return urls, nil
} }


@@ -389,48 +400,60 @@ func ConvertUrl(eg *xorm.Engine, officialEg *xorm.Engine, args map[string]string
"", "vendoapi", openId, "1") "", "vendoapi", openId, "1")
case md.PVD_PDD: case md.PVD_PDD:
pid := args["acc_pdd_self_id"] pid := args["acc_pdd_self_id"]
thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key")
if thirdZmAppKeyData == nil || err != nil {
return urls, err
}
thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret")
if thirdZmAppSecretData == nil || err != nil {
return urls, err
union, _ := db.SysUnionByPVDByUse(eg, args["master_id"], "pdd")
authType := "0"
if union != nil && union.AuthType == 2 {
pid = "own_" + args["uid"] + "_" + args["uid"]
authType = "2"
} }
miniApp := "0" miniApp := "0"
isShares := "2" isShares := "2"
masterPid := pid
pddPidData, _ := pdd.NewZhiMengPDDSDK().
SelectFunction("get_pid_list").
WithArgs(map[string]interface{}{
"appkey": db.SysCfgGetWithDb(eg, args["master_id"], md.KEY_CFG_ZM_AK),
"secret_key": db.SysCfgGetWithDb(eg, args["master_id"], md.KEY_CFG_ZM_SK),
"pid": masterPid},
).Result()
if pddPidData != nil {
b, _ := json.Marshal(pddPidData.ToInterface())
pddPid := gjson.GetBytes(b, "pdd_pid").String()
if pddPid == "" {
if authType == "2" {
urls, err = zhimeng.OwnPDDConvertUrl(union, args["gid"], pid, "", miniApp, "", isShares)
} else {
thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key")
if thirdZmAppKeyData == nil || err != nil {
return urls, err
}
thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret")
if thirdZmAppSecretData == nil || err != nil {
return urls, err
}

masterPid := pid

pddPidData, _ := pdd.NewZhiMengPDDSDK().
SelectFunction("get_pid_list").
WithArgs(map[string]interface{}{
"appkey": db.SysCfgGetWithDb(eg, args["master_id"], md.KEY_CFG_ZM_AK),
"secret_key": db.SysCfgGetWithDb(eg, args["master_id"], md.KEY_CFG_ZM_SK),
"pid": masterPid},
).Result()
if pddPidData != nil {
b, _ := json.Marshal(pddPidData.ToInterface())
pddPid := gjson.GetBytes(b, "pdd_pid").String()
if pddPid == "" {
profile, _ := db.UserProfileFindByID(eg, 0)
if profile != nil {
masterPid = profile.AccPddSelfId
}
}
} else {
profile, _ := db.UserProfileFindByID(eg, 0) profile, _ := db.UserProfileFindByID(eg, 0)
if profile != nil { if profile != nil {
masterPid = profile.AccPddSelfId masterPid = profile.AccPddSelfId
} }
} }
} else {
profile, _ := db.UserProfileFindByID(eg, 0)
if profile != nil {
masterPid = profile.AccPddSelfId
}
urls, err = zhimeng.PDDConvertUrl(
thirdZmAppKeyData.Val,
thirdZmAppSecretData.Val,
args["gid"],
masterPid,
pid,
"",
miniApp,
"0", isShares)
} }
urls, err = zhimeng.PDDConvertUrl(
thirdZmAppKeyData.Val,
thirdZmAppSecretData.Val,
args["gid"],
masterPid,
pid,
"",
miniApp,
"0", isShares)
} }
return urls, err return urls, err
} }
@@ -1345,6 +1368,7 @@ func JDByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string
} }
return nil, "", "", "" return nil, "", "", ""
} }

func PDDByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (*md.ProductDetailResponse, string) { func PDDByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (*md.ProductDetailResponse, string) {
postData := make(map[string]interface{}) postData := make(map[string]interface{})
isList := false isList := false
@@ -1356,30 +1380,41 @@ func PDDByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]strin
} }
postData["appkey"] = db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK) postData["appkey"] = db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK)
postData["secret_key"] = db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK) postData["secret_key"] = db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK)
//换为用搜索接口查商品
var pddPid string
var coustom string
master, err := db.UserProfileFindByID(eg, 0)
pddPid = master.AccPddSelfId
coustom = master.AccPddSelfId
postData["pid"] = pddPid
postData["custom_parameters"] = coustom
pddData, err := pdd.NewZhiMengPDDSDK().
SelectFunction("getgoods").
WithArgs(postData).
Result()
if err != nil || pddData == nil {
return nil, ""
}
if isList {
err = pddData.PddToStruct(mdData)
union, _ := db.SysUnionByPVDByUse(eg, tmp["master_id"], "pdd")
if union != nil && union.AuthType == 2 {
newpid := "own_" + tmp["master_id"] + "_" + tmp["uid"]
slist1 := zhimeng.OwnPddSearchGoods(newpid, union, postData)
err := zhimeng.OwnPddToStruct(slist1, mdData)
if err != nil {
return nil, ""
}
} else { } else {
err = pddData.ToStruct(mdData)
}
if err != nil {
//e.OutErr(c, e.ERR_INVALID_ARGS, err)
return nil, ""
//换为用搜索接口查商品
var pddPid string
var coustom string
master, err := db.UserProfileFindByID(eg, 0)
pddPid = master.AccPddSelfId
coustom = master.AccPddSelfId
postData["pid"] = pddPid
postData["custom_parameters"] = coustom
pddData, err := pdd.NewZhiMengPDDSDK().
SelectFunction("getgoods").
WithArgs(postData).
Result()
if err != nil || pddData == nil {
return nil, ""
}
if isList {
err = pddData.PddToStruct(mdData)
} else {
err = pddData.ToStruct(mdData)
}
if err != nil {
//e.OutErr(c, e.ERR_INVALID_ARGS, err)
return nil, ""
}
} }

if mdData != nil && (mdData.GID == goodsId || goodsId == "") { if mdData != nil && (mdData.GID == goodsId || goodsId == "") {
r := &md.ProductDetailResponse{} r := &md.ProductDetailResponse{}
r.GoodID = mdData.GoodsSign r.GoodID = mdData.GoodsSign


+ 189
- 0
zhimeng/own_pdd_convert_url.go View File

@@ -0,0 +1,189 @@
package zhimeng

import (
"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"
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/pdd_union"
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
"errors"
"github.com/tidwall/gjson"
)

func pddcomm() map[string]string {
keyArr := map[string]string{
"app_key": "43eed45f20d94fbf828744a77a45e3e2",
"app_secret": "4ee672167e1ee51aa3a9ea864d33629a230a114c",
}
return keyArr
}
func OwnAuthUrl(auth *model.SysUnionSet, pid string) string {
keyArr := pddcomm()
param := map[string]interface{}{
"access_token": gjson.Get(auth.KeyData, "accessToken").String(),
"pid": gjson.Get(auth.KeyData, "pid").String(),
"custom_parameters": "{\"uid\":\"" + pid + "\"}",
}

return pdd_union.CheckAuthUrl(keyArr, param)
}
func OwnPDDConvertUrl(auth *model.SysUnionSet, itemId, pid, couponPrice, isWxMini, isBindUrl, isShare string) (*md.ConvertedUrls, error) {
keyArr := pddcomm()
buyType := "self"
if isShare == "1" {
buyType = "share"
}
if isShare == "2" {
buyType = "cloud"
}
if isShare == "3" {
buyType = "free"
}
param := map[string]interface{}{
"access_token": gjson.Get(auth.KeyData, "accessToken").String(),
"p_id": gjson.Get(auth.KeyData, "pid").String(),
"goods_sign_list": zhios_third_party_utils.SerializeStr([]string{itemId}),
"generate_short_url": "true",
"generate_schema_url": "true",
"multi_group": "true",
"custom_parameters": "{\"uid\":\"" + pid + "\",\"buy_type\":\"" + buyType + "\"}",
}
if isWxMini == "1" {
param["generate_we_app"] = "true"
}
if isBindUrl == "1" {
param["generate_authority_url"] = "true"
}
url := pdd_union.ExtendUrl(keyArr, param)
if url["url"] == "" {
return nil, errors.New("转链失败")
}
return &md.ConvertedUrls{
ItemId: itemId,
URL: url["url"],
ShortenURL: url["no_open_app_url"],
NoOpenAppURL: url["open_app_url"],
AppURL: url["schema_url"],
HasCoupon: false,
CommissionRate: couponPrice,
WeChatMiniURL: url["page_path"],
}, nil
}

// 生成多多进宝频道推广
func OwnPDDActivityConvertUrl(auth *model.SysUnionSet, resourceType, pid, urls string, isShare int) (*md.ConvertedUrls, error) {
keyArr := pddcomm()
buyType := "self"
if isShare == 1 {
buyType = "share"
}
param := map[string]interface{}{
"access_token": gjson.Get(auth.KeyData, "accessToken").String(),
"pid": gjson.Get(auth.KeyData, "pid").String(),
"resource_type": resourceType,
"url": urls,
"generate_short_url": "true",
"generate_schema_url": "true",
"generate_mobile": "true",
"custom_parameters": "{\"uid\":\"" + pid + "\",\"buy_type\":\"" + buyType + "\"}",
}
url := pdd_union.MainThemeUrl(keyArr, param)
if url["url"] == "" {
return nil, errors.New("转链失败")
}
return &md.ConvertedUrls{
URL: url["url"],
ShortenURL: url["no_open_app_url"],
NoOpenAppURL: url["open_app_url"],
AppURL: url["schema_url"],
WeChatMiniURL: url["page_path"],
}, nil

}
func OwnPDDWnConvertUrl(auth *model.SysUnionSet, pid, urls string, isShare int) (*md.ConvertedUrls, error) {
keyArr := pddcomm()
buyType := "self"
if isShare == 1 {
buyType = "share"
}
param := map[string]interface{}{
"access_token": gjson.Get(auth.KeyData, "accessToken").String(),
"pid": gjson.Get(auth.KeyData, "pid").String(),
"source_url": urls,
"generate_short_url": "true",
"generate_schema_url": "true",
"generate_mobile": "true",
"custom_parameters": "{\"uid\":\"" + pid + "\",\"buy_type\":\"" + buyType + "\"}",
}
url := pdd_union.WnMainThemeUrl(keyArr, param)
if url["url"] == "" {
return nil, errors.New("转链失败")
}
return &md.ConvertedUrls{
URL: url["url"],
ShortenURL: url["no_open_app_url"],
NoOpenAppURL: url["open_app_url"],
AppURL: url["schema_url"],
WeChatMiniURL: url["page_path"],
}, nil
}

// 生成商城-频道推广链接
func OwnPDDActivityStoreConvertUrl(auth *model.SysUnionSet, resourceType, pid, urls string, isShare int) (*md.ConvertedUrls, error) {
keyArr := pddcomm()
buyType := "self"
if isShare == 1 {
buyType = "share"
}
param := map[string]interface{}{
"access_token": gjson.Get(auth.KeyData, "accessToken").String(),
"p_id_list": zhios_third_party_utils.SerializeStr([]string{gjson.Get(auth.KeyData, "pid").String()}),
"channel_type": resourceType,
"generate_short_url": "true",
"generate_schema_url": "true",
"generate_weapp_webview": "false",
"generate_we_app": "true",
"custom_parameters": "{\"uid\":\"" + pid + "\",\"buy_type\":\"" + buyType + "\"}",
}
url := pdd_union.PromUrl(keyArr, param)
if url["url"] == "" {
return nil, errors.New("转链失败")
}
return &md.ConvertedUrls{
URL: url["url"],
ShortenURL: url["no_open_app_url"],
NoOpenAppURL: url["open_app_url"],
AppURL: url["schema_url"],
WeChatMiniURL: url["page_path"],
}, nil
}

// 生成营销工具推广链接
func OwnPDDActivitySaleConvertUrl(auth *model.SysUnionSet, resourceType, pid string, isShare int) (*md.ConvertedUrls, error) {

keyArr := pddcomm()
buyType := "self"
if isShare == 1 {
buyType = "share"
}
param := map[string]interface{}{
"access_token": gjson.Get(auth.KeyData, "accessToken").String(),
"p_id_list": zhios_third_party_utils.SerializeStr([]string{gjson.Get(auth.KeyData, "pid").String()}),
"channel_type": resourceType,
"generate_short_url": "true",
"generate_schema_url": "true",
"generate_weapp_webview": "false",
"generate_we_app": "true",
"custom_parameters": "{\"uid\":\"" + pid + "\",\"buy_type\":\"" + buyType + "\"}",
}
url := pdd_union.RpUrl(keyArr, param)
if url["url"] == "" {
return nil, errors.New("转链失败")
}
return &md.ConvertedUrls{
URL: url["url"],
ShortenURL: url["no_open_app_url"],
NoOpenAppURL: url["open_app_url"],
AppURL: url["schema_url"],
WeChatMiniURL: url["page_path"],
}, nil
}

+ 130
- 0
zhimeng/own_pdd_goods.go View File

@@ -0,0 +1,130 @@
package zhimeng

import (
"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"
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/pdd_union"
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
"encoding/json"
"github.com/tidwall/gjson"
)

func OwnPddToStruct(data string, r *md.MoreDetailResponse) error {
if err := json.Unmarshal([]byte(data), r); err != nil {
return err
}
return nil
}
func OwnPddSearchGoods(pid string, auth *model.SysUnionSet, postData map[string]interface{}) string {
newPostData := make(map[string]interface{})
for k, v := range postData {
if v != "" && v != "<nil>" && v != nil {
newPostData[k] = v
}
}
postData = newPostData
param := make(map[string]interface{})
param["access_token"] = gjson.Get(auth.KeyData, "accessToken").String()
param["page"] = postData["p"]
param["page_size"] = postData["size"]
param["sort_type"] = "0"
param["pid"] = gjson.Get(auth.KeyData, "pid").String()
if postData["keyword"] != "" && postData["keyword"] != nil {
param["keyword"] = postData["keyword"]
}
if postData["gid"] != "" && postData["gid"] != nil {
param["keyword"] = postData["gid"]
param["page_size"] = "10"
}

if postData["cat_id"] != "" && postData["cat_id"] != nil {
param["cat_id"] = postData["cat_id"]
}
if postData["activity_tags"] != "" && postData["activity_tags"] != nil {
param["activity_tags"] = zhios_third_party_utils.SerializeStr([]interface{}{postData["activity_tags"]})
}
if postData["cid"] != "" && postData["cid"] != nil {
param["cat_id"] = postData["cid"]
}
rangeList := make([]map[string]string, 0)
if zhios_third_party_utils.AnyToFloat64(postData["start_price"]) > 0 || zhios_third_party_utils.AnyToFloat64(postData["end_price"]) > 0 {
if zhios_third_party_utils.AnyToFloat64(postData["start_price"]) == 0 {
postData["start_price"] = "0"
}
if zhios_third_party_utils.AnyToFloat64(postData["end_price"]) == 0 {
postData["end_price"] = "50000"
}
tmp := map[string]string{
"range_id": "1",
"range_from": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.AnyToFloat64(postData["start_price"]) * 100),
"range_to": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.AnyToFloat64(postData["end_price"]) * 100),
}
rangeList = append(rangeList, tmp)
}
if zhios_third_party_utils.AnyToFloat64(postData["start_commission_rate"]) > 0 || zhios_third_party_utils.AnyToFloat64(postData["end_commission_rate"]) > 0 {
if zhios_third_party_utils.AnyToFloat64(postData["start_commission_rate"]) == 0 {
postData["start_commission_rate"] = "0"
}
if zhios_third_party_utils.AnyToFloat64(postData["end_commission_rate"]) == 0 {
postData["end_commission_rate"] = "100"
}
tmp := map[string]string{
"range_id": "2",
"range_from": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.AnyToFloat64(postData["start_commission_rate"]) * 10),
"range_to": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.AnyToFloat64(postData["end_commission_rate"]) * 10),
}
rangeList = append(rangeList, tmp)
}
if zhios_third_party_utils.AnyToFloat64(postData["start_sales"]) > 0 || zhios_third_party_utils.AnyToFloat64(postData["end_commission_rate"]) > 0 {
if zhios_third_party_utils.AnyToFloat64(postData["start_sales"]) == 0 {
postData["start_sales"] = ""
}
if zhios_third_party_utils.AnyToFloat64(postData["end_sales"]) == 0 {
postData["end_sales"] = ""
}
tmp := map[string]string{
"range_id": "5",
"range_from": zhios_third_party_utils.AnyToString(postData["start_sales"]),
"range_to": zhios_third_party_utils.AnyToString(postData["end_sales"]),
}
rangeList = append(rangeList, tmp)
}
if len(rangeList) > 0 {
param["range_list"] = zhios_third_party_utils.SerializeStr(rangeList)
}
sort_arr := map[string]int{
"default": 0, //默认排序
"commission asc": 1, //佣金比率升序
"commission desc": 2, //佣金比率降序
"commission1 desc": 14, //佣金降序
"goods_price asc": 3, //价格升序
"goods_price desc": 4, //价格降序
"goods_sales asc": 5, //销量升序
"goods_sales desc": 6, //销量降序
"coupon asc": 7, //优惠券升序
"coupon desc": 8, //优惠券降序
"coupon after asc": 9, //券后价升序
"coupon after desc": 10, //券后价降序
"update asc": 11, //多多进宝 更新时间 升序
"update desc": 12, //多多进宝 更新时间 降序
}
if sort_arr[zhios_third_party_utils.AnyToString(postData["sort"])] != 0 {
param["sort_type"] = sort_arr[zhios_third_party_utils.AnyToString(postData["sort"])]
}
if postData["sort_num"] != "" && postData["sort_num"] != nil {
param["sort_type"] = postData["sort_num"]
}
//是否有优惠券
param["with_coupon"] = "false"
if postData["conpon"] != "" && postData["conpon"] != nil {
param["with_coupon"] = "true"
}
param["custom_parameters"] = "{\"uid\":\"" + pid + "\"}"

res1 := pdd_union.GetSearchGoods(pddcomm(), param)
if len(res1) == 0 {
return ""
}
return zhios_third_party_utils.SerializeStr(res1)

}

Loading…
Cancel
Save