123 lines
3.9 KiB
Go
123 lines
3.9 KiB
Go
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("美团外卖不支持此操作")
|
|
}
|