96 lines
2.9 KiB
Go
96 lines
2.9 KiB
Go
|
package api
|
|||
|
|
|||
|
import (
|
|||
|
"database/sql/driver"
|
|||
|
"encoding/json"
|
|||
|
"fmt"
|
|||
|
ctxLogger "github.com/luizsuper/ctxLoggers"
|
|||
|
"go.uber.org/zap"
|
|||
|
"time"
|
|||
|
)
|
|||
|
|
|||
|
type (
|
|||
|
ShopDetailReq struct {
|
|||
|
ShopId string `json:"shopId"`
|
|||
|
SceneType int `json:"sceneType"`
|
|||
|
}
|
|||
|
ShopDResp struct {
|
|||
|
Head struct {
|
|||
|
Msg string `json:"msg"`
|
|||
|
Code int `json:"code"`
|
|||
|
} `json:"head"`
|
|||
|
Data struct {
|
|||
|
ShopId string `json:"shopId"`
|
|||
|
ShopName string `json:"shopName"`
|
|||
|
ShopScore float64 `json:"shopScore"`
|
|||
|
ShopAddr string `json:"shopAddr"`
|
|||
|
ShopTagName interface{} `json:"shopTagName"`
|
|||
|
ShopContractTelNumOne string `json:"shopContractTelNumOne"`
|
|||
|
ShopContractTelNumTwo string `json:"shopContractTelNumTwo"`
|
|||
|
ConsumptionUserSuccCount int `json:"consumptionUserSuccCount"`
|
|||
|
ShopLongitude string `json:"shopLongitude"`
|
|||
|
ShopLatitude string `json:"shopLatitude"`
|
|||
|
ShopCoverUrl string `json:"shopCoverUrl"`
|
|||
|
ShopLogoUrl string `json:"shopLogoUrl"`
|
|||
|
BannerList []interface{} `json:"bannerList"`
|
|||
|
RecommendScriptList []interface{} `json:"recommendScriptList"`
|
|||
|
NewScriptList []interface{} `json:"newScriptList"`
|
|||
|
} `json:"data"`
|
|||
|
}
|
|||
|
)
|
|||
|
|
|||
|
const ShopDetailUrl = `https://api.h5.helloaba.cn/shop/shopDetail_V2`
|
|||
|
|
|||
|
type ShopDetailInfo struct {
|
|||
|
ID int `json:"id" gorm:"column:id"`
|
|||
|
Resp ShopDResp `json:"resp" gorm:"column:resp"`
|
|||
|
}
|
|||
|
|
|||
|
func (m *ShopDetailInfo) TableName() string {
|
|||
|
return "shop_detail_info"
|
|||
|
}
|
|||
|
|
|||
|
func (p ShopDResp) Value() (driver.Value, error) {
|
|||
|
return json.Marshal(p)
|
|||
|
}
|
|||
|
|
|||
|
func (p *ShopDResp) Scan(input interface{}) error {
|
|||
|
return json.Unmarshal(input.([]byte), &p)
|
|||
|
}
|
|||
|
|
|||
|
func ShopDMarshal(req, body []byte) (resp interface{}, err error) {
|
|||
|
r := new(ShopDResp)
|
|||
|
err = json.Unmarshal(body, r)
|
|||
|
if err != nil {
|
|||
|
ctxLogger.Error(nil, "json UnmarshalError", zap.String("resp body", string(body)))
|
|||
|
}
|
|||
|
if r.Head.Code != 200 || r.Head.Msg != "成功" {
|
|||
|
ctxLogger.Error(nil, "net wrok error", zap.String("resq body", string(req)), zap.String("resp body", string(body)))
|
|||
|
}
|
|||
|
return r, err
|
|||
|
}
|
|||
|
|
|||
|
// ShopDKvStr todo:抽象
|
|||
|
// ShopDKvStr 按照顺序对查询的key排序
|
|||
|
func ShopDKvStr(body ShopDetailReq) string {
|
|||
|
var s = ""
|
|||
|
s += fmt.Sprintf("%v=%v&", "sceneType", body.SceneType)
|
|||
|
s += fmt.Sprintf("%v=%v", "shopId", body.ShopId)
|
|||
|
return s
|
|||
|
}
|
|||
|
|
|||
|
func shopDetail(body ShopDetailReq) {
|
|||
|
dto, err := Attach(ShopDetailUrl, GetCheckSum(ShopDKvStr(body)), body, M, ShopDMarshal)
|
|||
|
if err != nil {
|
|||
|
ctxLogger.Error(nil, "net error record")
|
|||
|
}
|
|||
|
if s, ok := dto.(*ShopDResp); !ok {
|
|||
|
ctxLogger.Error(nil, "assertion error")
|
|||
|
} else {
|
|||
|
info := ShopDetailInfo{Resp: *s}
|
|||
|
DB.Create(&info)
|
|||
|
ctxLogger.Info(nil, "detailOk", zap.String("ShopId", s.Data.ShopId))
|
|||
|
time.Sleep(time.Duration(1) * time.Second)
|
|||
|
}
|
|||
|
}
|