This commit is contained in:
gazebo
2018-11-22 10:24:36 +08:00
parent dd6a4723d8
commit 3835a47c71
7 changed files with 271 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ const (
FieldJdSyncStatus = "JdSyncStatus"
FieldElmSyncStatus = "ElmSyncStatus"
FieldEbaiSyncStatus = "EbaiSyncStatus"
FieldMtwmSyncStatus = "MtwmSyncStatus"
FieldVendorID = "VendorID"
FieldStoreID = "StoreID"
@@ -28,6 +29,7 @@ const (
FieldJdID = "JdID"
FieldElmID = "ElmID"
FieldEbaiID = "EbaiID"
FieldMtwmID = "MtwmID"
FieldSkuID = "SkuID"
FieldLevel = "Level"

View File

@@ -0,0 +1,99 @@
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"
)
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 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
}

View File

@@ -0,0 +1,18 @@
package mtwm
import (
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
}

View File

@@ -0,0 +1,122 @@
package mtwm
import (
"errors"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
const (
VendorStorePrefix = "美好菜市"
)
type tEbaiStoreInfo struct {
model.Store
VendorStoreID string `orm:"column(vendor_store_id)"`
RealLastOperator string
EbaiStoreStatus int
SyncStatus int
ProvinceID int `orm:"column(province_id)"`
CityID int `orm:"column(city_id)"`
DistrictID int `orm:"column(district_id)"`
}
func (p *PurchaseHandler) GetFieldIDName() string {
return model.FieldMtwmID
}
func (p *PurchaseHandler) GetFieldSyncStatusName() string {
return model.FieldMtwmSyncStatus
}
func (p *PurchaseHandler) CreateStore(db *dao.DaoDB, storeID int, userName string) (vendorStoreID string, err error) {
return vendorStoreID, err
}
func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error) {
result, err := api.MtwmAPI.PoiGet(vendorStoreID)
if err == nil {
// globals.SugarLogger.Debug(utils.Format4Output(result, false))
retVal := &model.Store{
Address: utils.Interface2String(result["address"]),
Tel1: utils.Interface2String(result["phone"]),
}
_, retVal.Name = jxutils.SplitStoreName(utils.Interface2String(result["name"]), partner.StoreNameSeparator, VendorStorePrefix)
retVal.DeliveryType = 0 // todo
openTimes := openTimeMtwm2JX(result["shipping_time"].(string))
if len(openTimes) > 0 {
retVal.OpenTime1 = openTimes[0][0]
retVal.CloseTime1 = openTimes[0][1]
if len(openTimes) > 1 {
retVal.OpenTime2 = openTimes[1][0]
retVal.CloseTime2 = openTimes[1][1]
}
}
retVal.Status = bizStatusMtwm2JX(int(utils.MustInterface2Int64(result["open_level"])), int(utils.MustInterface2Int64(result["is_online"])))
tel2 := utils.Interface2String(result["standby_tel"])
if tel2 != "" && tel2 != retVal.Tel1 {
retVal.Tel2 = tel2
}
retVal.Lng = int(utils.MustInterface2Float64(result["longitude"]))
retVal.Lat = int(utils.MustInterface2Float64(result["latitude"]))
lng := jxutils.IntCoordinate2Standard(retVal.Lng)
lat := jxutils.IntCoordinate2Standard(retVal.Lat)
db := dao.GetDB()
retVal.DistrictCode = api.AutonaviAPI.GetCoordinateDistrictCode(lng, lat)
if district, err := dao.GetPlaceByCode(db, retVal.DistrictCode); err == nil {
retVal.CityCode = district.ParentCode
}
poiCode := utils.Interface2String(result["app_poi_code"])
retVal.ID = int(utils.Str2Int64WithDefault(poiCode, 0))
retVal.DeliveryRangeType = model.DeliveryRangeTypePolygon
if deliveryRangeInfo, err := api.MtwmAPI.ShippingList(poiCode); err != nil {
return nil, err
} else {
if len(deliveryRangeInfo) > 0 {
retVal.DeliveryRange = rangeMtwm2JX(deliveryRangeInfo[0]["area"].(string))
}
}
return retVal, nil
}
return nil, err
}
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
type StoreAndVendorInfo struct {
model.Store
model.StoreMap
}
var store StoreAndVendorInfo
sql := `
SELECT *
FROM store t1
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND (t2.deleted_at = ? OR t2.sync_status <> 0)
LEFT JOIN place city ON t1.city_code = city.code
LEFT JOIN place district ON t1.district_code = district.code
WHERE t1.id = ?
ORDER BY t2.updated_at
`
if db == nil {
db = dao.GetDB()
}
if err = dao.GetRow(db, &store, sql, model.VendorIDJD, utils.DefaultTimeValue, storeID); err == nil {
globals.SugarLogger.Debug(utils.Format4Output(store, false))
}
}
func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
return "", errors.New("美团外卖不支持此操作")
}

View File

@@ -0,0 +1,24 @@
package mtwm
import (
"testing"
"git.rosy.net.cn/baseapi/utils"
// _ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
)
func TestReadStore(t *testing.T) {
store, err := new(PurchaseHandler).ReadStore("4351018")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(store, false))
}
func TestUpdateStore(t *testing.T) {
store, err := new(PurchaseHandler).UpdateStore("4351018")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(store, false))
}

View File

@@ -12,6 +12,9 @@ routinePoolSize = 1000
dadaAppKey = "dada147f7a190ce7b3c"
dadaAppSecret = "2c717ad914767d6e2beb3f743db9e477"
mtwmAppID = "589"
mtwmSecret = "a81eb3df418d83d6a1a4b7c572156d2f"
autonaviKey = "4427170f870af2110becb8852d36ab08"
enableStore = true

View File

@@ -7,6 +7,7 @@ import (
"git.rosy.net.cn/baseapi/platformapi/elmapi"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/cache"
@@ -23,6 +24,7 @@ var (
EbaiAPI *ebaiapi.API
MtpsAPI *mtpsapi.API
DadaAPI *dadaapi.API
MtwmAPI *mtwmapi.API
WeixinAPI *weixinapi.API
AutonaviAPI *autonavi.API
QiniuAPI *qbox.Mac
@@ -40,6 +42,7 @@ func Init() {
if !beego.AppConfig.DefaultBool("disableMtps", false) {
MtpsAPI = mtpsapi.New(beego.AppConfig.String("mtpsAppKey"), beego.AppConfig.String("mtpsSecret"))
}
MtwmAPI = mtwmapi.New(beego.AppConfig.String("mtwmAppID"), beego.AppConfig.String("mtwmSecret"))
if !beego.AppConfig.DefaultBool("disableDada", false) {
DadaAPI = dadaapi.New(beego.AppConfig.String("dadaAppKey"), beego.AppConfig.String("dadaAppSecret"), beego.AppConfig.String("dadaSourceID"), beego.AppConfig.String("dadaCallbackURL"), beego.AppConfig.DefaultBool("dadaIsProd", false))
}