143 lines
4.2 KiB
Go
143 lines
4.2 KiB
Go
package mtwm
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-callback/business/partner"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
)
|
|
|
|
var (
|
|
curPurchaseHandler *PurchaseHandler
|
|
)
|
|
|
|
type PurchaseHandler struct {
|
|
partner.BasePurchasePlatform
|
|
}
|
|
|
|
func init() {
|
|
curPurchaseHandler = new(PurchaseHandler)
|
|
// partner.RegisterPurchasePlatform(curPurchaseHandler)
|
|
}
|
|
|
|
func (c *PurchaseHandler) GetVendorID() int {
|
|
return model.VendorIDMTWM
|
|
}
|
|
|
|
func (p *PurchaseHandler) GetVendorCategories() (vendorCats []*model.SkuVendorCategory, err error) {
|
|
cats, err := api.MtwmAPI.RetailGetSpTagIds()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
vendorCatMapList := make([]map[string]*model.SkuVendorCategory, 3)
|
|
manID := 10000
|
|
for i := 0; i < 3; i++ {
|
|
vendorCatMapList[i] = make(map[string]*model.SkuVendorCategory)
|
|
for _, v := range cats {
|
|
if utils.MustInterface2Int64(v["level"]) == 3 {
|
|
namePathList := strings.Split(strings.Trim(utils.Interface2String(v["namePath"]), ","), ",")
|
|
if len(namePathList) != 3 {
|
|
panic(fmt.Sprintf("%s没有三级结构", v["namePath"]))
|
|
}
|
|
name := namePathList[i]
|
|
if _, ok := vendorCatMapList[i][name]; !ok {
|
|
cat := &model.SkuVendorCategory{
|
|
VendorID: model.VendorIDMTWM,
|
|
Name: utils.Interface2String(v["name"]),
|
|
Level: int(utils.MustInterface2Int64(v["level"])),
|
|
}
|
|
cat.LastOperator = "builder"
|
|
vendorCats = append(vendorCats, cat)
|
|
vendorCatMapList[i][name] = cat
|
|
if i == 2 {
|
|
cat.IsLeaf = int8(1)
|
|
cat.VendorCategoryID = utils.Int64ToStr(utils.MustInterface2Int64(v["id"]))
|
|
} else {
|
|
cat.VendorCategoryID = utils.Int2Str(manID) // 非叶子结点编码没有实际使用
|
|
manID++
|
|
}
|
|
if i > 0 {
|
|
cat.ParentID = vendorCatMapList[i-1][namePathList[i-1]].VendorCategoryID
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return vendorCats, nil
|
|
}
|
|
|
|
func rangeMtwm2JX(areaStr string) string {
|
|
var area []interface{}
|
|
if err := utils.UnmarshalUseNumber([]byte(areaStr), &area); err == nil {
|
|
if len(area) > 0 {
|
|
coordList := make([]string, len(area))
|
|
for k, v := range area {
|
|
vv := v.(map[string]interface{})
|
|
coordList[k] = fmt.Sprintf("%.6f,%.6f", jxutils.IntCoordinate2Standard(int(utils.MustInterface2Int64(vv["x"]))), jxutils.IntCoordinate2Standard(int(utils.MustInterface2Int64(vv["y"]))))
|
|
}
|
|
return strings.Join(coordList, ";")
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func rangeJX2Mtwm(coords string) string {
|
|
pairs := strings.Split(strings.Trim(coords, ";"), ";")
|
|
if len(pairs) > 0 {
|
|
coordList := make([]map[string]interface{}, len(pairs))
|
|
for k, v := range pairs {
|
|
pair := strings.Split(v, ",")
|
|
coordList[k] = map[string]interface{}{
|
|
"x": jxutils.StandardCoordinate2Int(utils.Str2Float64(pair[0])),
|
|
"y": jxutils.StandardCoordinate2Int(utils.Str2Float64(pair[1])),
|
|
}
|
|
}
|
|
return string(utils.MustMarshal(coordList))
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func openTimeMtwm2JX(vendorOpenTime string) [][2]int16 {
|
|
timePairs := strings.Split(vendorOpenTime, ",")
|
|
jxOpenTimers := make([][2]int16, len(timePairs))
|
|
for k, v := range timePairs {
|
|
times := strings.Split(v, "-")
|
|
jxOpenTimers[k][0] = jxutils.StrTime2JxOperationTime(times[0], 700)
|
|
jxOpenTimers[k][1] = jxutils.StrTime2JxOperationTime(times[1], 2000)
|
|
}
|
|
return jxOpenTimers
|
|
}
|
|
|
|
func openTimeJX2Mtwm(times [][2]int16) string {
|
|
strPairs := make([]string, len(times))
|
|
for k, v := range times {
|
|
strPairs[k] = jxutils.JxOperationTime2StrTime(v[0]) + "-" + jxutils.JxOperationTime2StrTime(v[1])
|
|
}
|
|
return strings.Join(strPairs, ",")
|
|
}
|
|
|
|
func bizStatusMtwm2JX(openLevel, online int) int {
|
|
if online == mtwmapi.PoiOffline {
|
|
return model.StoreStatusDisabled
|
|
} else {
|
|
if openLevel == mtwmapi.PoiOpenLevelHaveRest {
|
|
return model.StoreStatusClosed
|
|
}
|
|
}
|
|
return model.StoreStatusOpened
|
|
}
|
|
|
|
func bizStatusJX2Mtwm(status int) (openLevel, online int) {
|
|
if status == model.StoreStatusDisabled {
|
|
return mtwmapi.PoiOpenLevelHaveRest, mtwmapi.PoiOffline
|
|
} else if status == model.StoreStatusClosed {
|
|
return mtwmapi.PoiOpenLevelHaveRest, mtwmapi.PoiOnline
|
|
}
|
|
return mtwmapi.PoiOpenLevelNormal, mtwmapi.PoiOnline
|
|
}
|