|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- package taobao
-
- import (
- "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"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/syyongx/php2go"
- "strings"
- "xorm.io/xorm"
- )
-
- //TaoBaoArgs is args
- type TaoBaoArgs struct {
- Keyword string
- PageIndex string
- PageSize string
- Sort string
- StartPrice string
- EndPrice string
- IsTmall string
- IsCoupon string
- StartCommissionRate string
- EndCommissionRate string
- }
-
- 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)
- if err != nil {
- return goods
- }
- list, err := sdk.TaoBaoFeaturedList(postData)
- if list != nil {
- for _, v := range *list {
- var tmp = map[string]string{
- "gid": zhios_third_party_utils.AnyToString(v.ItemID),
- "title": v.Title,
- "img": v.PictURL,
- "sales": zhios_third_party_utils.IntToStr(v.Volume),
- "price": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.ZkFinalPrice) - float64(v.CouponAmount)),
- "cost_price": v.ZkFinalPrice,
- "coupon": zhios_third_party_utils.IntToStr(v.CouponAmount),
- "commission_rate": zhios_third_party_utils.AnyToString(zhios_third_party_utils.StrToFloat64(v.CommissionRate) / 100),
- "commission": zhios_third_party_utils.Float64ToStr((zhios_third_party_utils.StrToFloat64(v.ZkFinalPrice) - float64(v.CouponAmount)) * (zhios_third_party_utils.StrToFloat64(v.CommissionRate) / 100 / 100)),
- "pvd": md.PVD_TB,
- "share_content": "",
- }
- goods = append(goods, tmp)
- }
- }
- return goods
-
- }
- 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)
- if err != nil {
- return goods
- }
- list, err := sdk.TaoBaoSearchList(postData)
- if list != nil {
- for _, v := range *list {
- imgList := make([]string, 0)
- if len(v.SmallImages.String) == 0 {
- imgList = append(imgList, v.PictURL)
- } else {
- for _, v1 := range v.SmallImages.String {
- imgList = append(imgList, v1)
-
- }
- }
- var tmp = map[string]string{
- "img_list": zhios_third_party_utils.SerializeStr(imgList),
- "gid": zhios_third_party_utils.AnyToString(v.ItemID),
- "title": v.Title,
- "img": v.PictURL,
- "sales": zhios_third_party_utils.IntToStr(v.Volume),
- "price": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.ZkFinalPrice) - zhios_third_party_utils.StrToFloat64(v.CouponAmount)),
- "cost_price": v.ZkFinalPrice,
- "coupon": v.CouponAmount,
- "commission_rate": zhios_third_party_utils.AnyToString(zhios_third_party_utils.StrToFloat64(v.CommissionRate) / 100),
- "commission": zhios_third_party_utils.Float64ToStr((zhios_third_party_utils.StrToFloat64(v.ZkFinalPrice) - zhios_third_party_utils.StrToFloat64(v.CouponAmount)) * (zhios_third_party_utils.StrToFloat64(v.CommissionRate) / 100 / 100)),
- "pvd": md.PVD_TB,
- "share_content": "",
- }
- goods = append(goods, tmp)
- }
- }
- return goods
-
- }
-
- // TaoBaoSearchList is return taobao search list
- func (t *TB) TaoBaoFeaturedList(args map[string]string) (*[]md.TBFeatureStruct, error) {
- list, err := t.FeaturedList(
- args,
- )
- if err != nil {
- return nil, err
- }
- return list, nil
- }
- func (t *TB) TaoBaoSearchList(args map[string]string) (*[]Material, error) {
- list, err := t.SearchList(
- args,
- )
- if err != nil {
- return nil, err
- }
- return list, nil
- }
-
- // 商品详情
- func (t *TB) ItemDetailById(id, bizSceneId string) (*Material, error) {
- if php2go.IsNumeric(id) {
- return t.ItemDetailByLink("https://item.taobao.com/item.htm?id="+id, "2")
- }
- return t.ItemDetailByLink("https://uland.taobao.com/item/edetail?id="+id, "")
- }
-
- func (t *TB) ItemDetailByLink(l, bizSceneId string) (*Material, error) {
- args := map[string]string{
- "q": l,
- "adzone_id": AdZoneId(t.SelfPromoIdWeb), // 默认使用安卓, 转链时候才要针对不同的渠道
- "session": t.SID,
- "page_size": "1",
- "page_no": "1",
- }
- if bizSceneId == "2" {
- args["biz_scene_id"] = "2"
- }
- method := TBK_DG_MTL_OPT
- //判断是否跟随官方 需要换接口
- if t.AuthType == 1 {
- method = TBK_SC_MTL_OPT
- Sid := t.UserSID
- args["session"] = Sid
- _, args["site_id"], args["adzone_id"] = SplitPid(t.SelfPromoIdWeb)
- }
- resp, err := send(args, method, t.Web_AK, t.Web_SK)
- if err != nil {
- return nil, err
- }
- fmt.Println("淘宝", args)
- fmt.Println("淘宝", string(resp))
- // todo 可能还需返回的说明, 里面包含详细介绍的图片
- // "https://mdetail.tmall.com/templates/pages/desc?id=" + id
- // "https://h5.m.taobao.com/app/detail/desc.html?type=1&f=&sellerType=B&_isH5Des=true#!id=" + id
- // 如果是跟随官方 结构不一样
-
- if t.AuthType == 1 {
- var tmp scMaterialOptionalStruct
- if err = json.Unmarshal(resp, &tmp); err != nil {
- return nil, err
- }
- if len(tmp.TbkScMaterialOptionalResponse.ResultList.MapData) == 0 {
- return nil, errors.New("没有数据")
- }
- data := tmp.TbkScMaterialOptionalResponse.ResultList.MapData[0]
- itemID, ok := data.ItemID.(float64)
- if ok {
- data.ItemID = int64(itemID)
- }
- return &data, nil
- } else {
- var tmp wrapperStruct
- if err = json.Unmarshal(resp, &tmp); err != nil {
- return nil, err
-
- }
- if len(tmp.TbkDgMaterialOptionalResponse.ResultList.MapData) == 0 {
- return nil, err
- }
- data := tmp.TbkDgMaterialOptionalResponse.ResultList.MapData[0]
- itemID, ok := data.ItemID.(float64)
- if ok {
- data.ItemID = int64(itemID)
- }
- return &data, nil
- }
- }
-
- func (t *TB) ItemDetailByIdKey(l, bizSceneId string) (*Material, error) {
- l += "&"
- l = strings.ReplaceAll(l, "?", "&")
- ex := php2go.Explode("&id=", l)
- id := ""
- if len(ex) > 1 {
- ex1 := php2go.Explode("&", ex[1])
- if len(ex1) > 0 {
- id = ex1[0]
- }
- }
- if id == "" || id == "622130940777" {
- return nil, errors.New("找不到商品")
- }
- args := map[string]string{
- "num_iids": id,
- "session": t.SID,
- "platform": "2",
- }
- if bizSceneId == "2" {
- //args["biz_scene_id"] = "2"
- }
- method := "taobao.tbk.item.info.get"
- //判断是否跟随官方 需要换接口
- if t.AuthType == 1 {
- Sid := t.UserSID
- args["session"] = Sid
- }
- resp, err := send(args, method, t.Web_AK, t.Web_SK)
- if err != nil {
- return nil, err
- }
- var tmp tbDetailStruct
- if err = json.Unmarshal(resp, &tmp); err != nil {
- return nil, err
- }
- if len(tmp.TbkItemInfoGetResponse.Results.NBbkItem) == 0 {
- return nil, err
- }
- data := tmp.TbkItemInfoGetResponse.Results.NBbkItem[0]
- data.ItemID = data.InputNumIid
- itemID, ok := data.ItemID.(float64)
- if ok {
- data.ItemID = int64(itemID)
- }
- return &data, nil
- }
|