You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.6 KiB
107 lines
2.6 KiB
package taobao
|
|
|
|
import (
|
|
"fmt"
|
|
"go.dtapp.net/dorm"
|
|
"go.dtapp.net/golog"
|
|
"go.dtapp.net/gorequest"
|
|
"go.dtapp.net/gostring"
|
|
"gorm.io/gorm"
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
type ConfigClient struct {
|
|
AppKey string // 应用Key
|
|
AppSecret string // 密钥
|
|
AdzoneId int64 // mm_xxx_xxx_xxx的第三位
|
|
MongoDb *dorm.MongoClient // 日志数据库
|
|
PgsqlDb *gorm.DB // 日志数据库
|
|
DatabaseName string // 库名
|
|
}
|
|
|
|
type Client struct {
|
|
client *gorequest.App // 请求客户端
|
|
log *golog.ApiClient // 日志服务
|
|
config *ConfigClient // 配置
|
|
}
|
|
|
|
func NewClient(config *ConfigClient) (*Client, error) {
|
|
|
|
var err error
|
|
c := &Client{config: config}
|
|
|
|
c.client = gorequest.NewHttp()
|
|
c.client.Uri = apiUrl
|
|
|
|
if c.config.PgsqlDb != nil {
|
|
c.log, err = golog.NewApiClient(
|
|
golog.WithGormClient(c.config.PgsqlDb),
|
|
golog.WithTableName(logTable),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
if c.config.MongoDb != nil {
|
|
c.log, err = golog.NewApiClient(
|
|
golog.WithMongoClient(c.config.MongoDb),
|
|
golog.WithDatabaseName(c.config.DatabaseName),
|
|
golog.WithCollectionName(logTable),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return c, nil
|
|
}
|
|
|
|
type ErrResp struct {
|
|
ErrorResponse struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
SubCode string `json:"sub_code"`
|
|
SubMsg string `json:"sub_msg"`
|
|
RequestId string `json:"request_id"`
|
|
} `json:"error_response"`
|
|
}
|
|
|
|
func (c *Client) ZkFinalPriceParseInt64(ZkFinalPrice string) int64 {
|
|
parseInt, err := strconv.ParseInt(ZkFinalPrice, 10, 64)
|
|
if err != nil {
|
|
re := regexp.MustCompile("[0-9]+")
|
|
SalesTipMap := re.FindAllString(ZkFinalPrice, -1)
|
|
if len(SalesTipMap) == 2 {
|
|
return gostring.ToInt64(fmt.Sprintf("%s%s", SalesTipMap[0], SalesTipMap[1])) * 10
|
|
} else {
|
|
return gostring.ToInt64(SalesTipMap[0]) * 100
|
|
}
|
|
} else {
|
|
return parseInt * 100
|
|
}
|
|
}
|
|
|
|
func (c *Client) CommissionRateParseInt64(CommissionRate string) int64 {
|
|
parseInt, err := strconv.ParseInt(CommissionRate, 10, 64)
|
|
if err != nil {
|
|
re := regexp.MustCompile("[0-9]+")
|
|
SalesTipMap := re.FindAllString(CommissionRate, -1)
|
|
if len(SalesTipMap) == 2 {
|
|
return gostring.ToInt64(fmt.Sprintf("%s%s", SalesTipMap[0], SalesTipMap[1]))
|
|
} else {
|
|
return gostring.ToInt64(SalesTipMap[0])
|
|
}
|
|
} else {
|
|
return parseInt
|
|
}
|
|
}
|
|
|
|
func (c *Client) CouponAmountToInt64(CouponAmount int64) int64 {
|
|
return CouponAmount * 100
|
|
}
|
|
|
|
func (c *Client) CommissionIntegralToInt64(GoodsPrice, CouponProportion int64) int64 {
|
|
return (GoodsPrice * CouponProportion) / 100
|
|
}
|