package pinduoduo import ( "fmt" "go.dtapp.net/dorm" "go.dtapp.net/golog" "go.dtapp.net/gorequest" "go.dtapp.net/gostring" "gorm.io/gorm" "regexp" "strconv" "strings" ) type ConfigClient struct { ClientId string // POP分配给应用的client_id ClientSecret string // POP分配给应用的client_secret MediaId string // 媒体ID Pid string // 推广位 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 } func (c *Client) ConfigPid(pid string) *Client { n := c n.config.Pid = pid return n } type ErrResp struct { ErrorResponse struct { ErrorMsg string `json:"error_msg"` SubMsg string `json:"sub_msg"` SubCode interface{} `json:"sub_code"` ErrorCode int `json:"error_code"` RequestId string `json:"request_id"` } `json:"error_response"` } type CustomParametersResult struct { Sid string `json:"sid"` Uid string `json:"uid"` } func (c *Client) SalesTipParseInt64(salesTip string) int64 { parseInt, err := strconv.ParseInt(salesTip, 10, 64) if err != nil { salesTipStr := salesTip if strings.Contains(salesTip, "万+") { salesTipStr = strings.Replace(salesTip, "万+", "0000", -1) } else if strings.Contains(salesTip, "万") { salesTipStr = strings.Replace(salesTip, "万", "000", -1) } re := regexp.MustCompile("[0-9]+") SalesTipMap := re.FindAllString(salesTipStr, -1) if len(SalesTipMap) == 2 { return gostring.ToInt64(fmt.Sprintf("%s%s", SalesTipMap[0], SalesTipMap[1])) } else if len(SalesTipMap) == 1 { return gostring.ToInt64(SalesTipMap[0]) } else { return 0 } } else { return parseInt } } func (c *Client) CommissionIntegralToInt64(GoodsPrice, CouponProportion int64) int64 { return (GoodsPrice * CouponProportion) / 1000 }