- 京东门店相关的操作改用新API(非map)

This commit is contained in:
gazebo
2019-09-19 15:56:38 +08:00
parent af41dbb6b8
commit 4917b8fca6
3 changed files with 97 additions and 86 deletions

View File

@@ -2,7 +2,6 @@ package jd
import (
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
@@ -19,10 +18,8 @@ var (
func init() {
globals.SugarLogger.Debug("init jd")
if getAPI("") != nil {
CurPurchaseHandler = new(PurchaseHandler)
partner.RegisterPurchasePlatform(CurPurchaseHandler)
}
CurPurchaseHandler = new(PurchaseHandler)
partner.RegisterPurchasePlatform(CurPurchaseHandler)
}
func getAPI(appOrgCode string) (apiObj *jdapi.API) {
@@ -33,8 +30,8 @@ func (c *PurchaseHandler) GetVendorID() int {
return model.VendorIDJD
}
func JdOperationTime2JxOperationTime(value1 interface{}) int16 {
value := int16(utils.Interface2Int64WithDefault(value1, 0))
func JdOperationTime2JxOperationTime(value1 int) int16 {
value := int16(value1)
return (value/2)*100 + (value%2)*30
}
@@ -42,12 +39,10 @@ func JxOperationTime2JdOperationTime(value int16) int16 {
return (value/100)*2 + (value%100)/30
}
func JdStoreStatus2JxStatus(yn, closeStatus interface{}) int {
yn2 := utils.Interface2Int64WithDefault(yn, 0)
closeStatus2 := utils.Interface2Int64WithDefault(closeStatus, 0)
if yn2 == 1 {
func JdStoreStatus2JxStatus(yn, closeStatus int) int {
if yn == 1 {
return model.StoreStatusDisabled
} else if closeStatus2 == 1 {
} else if closeStatus == 1 {
return model.StoreStatusClosed
}
return model.StoreStatusOpened

View File

@@ -15,22 +15,24 @@ const (
func (c *PurchaseHandler) onOrderComment2(msg *jdapi.CallbackOrderMsg) (err error) {
intOrderID := utils.Str2Int64(msg.BillID)
result, err := getAPI("").GetCommentByOrderId(intOrderID)
result, err := getAPI("").GetCommentByOrderId2(intOrderID)
if err == nil {
globals.SugarLogger.Debugf("onOrderComment comment:%s", utils.Format4Output(result, true))
orderCommend := &model.OrderComment{
VendorOrderID: utils.Int64ToStr(utils.MustInterface2Int64(result["orderId"])),
VendorID: model.VendorIDJD,
UserCommentID: "",
VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["storeId"])),
TagList: string(utils.MustMarshal(result["venderTags"])),
Score: int8(utils.MustInterface2Int64(result["score4"])),
Content: utils.Interface2String(result["score4Content"]),
CommentCreatedAt: utils.Timestamp2Time(utils.MustInterface2Int64(result["createTime"].(map[string]interface{})["time"]) / 1000),
ModifyDuration: JDDJ_BAD_COMMENTS_MAX_MODIFY_TIME,
OriginalMsg: string(utils.MustMarshal(result)),
VendorOrderID: utils.Int64ToStr(result.OrderID),
VendorID: model.VendorIDJD,
UserCommentID: "",
VendorStoreID: utils.Int64ToStr(result.StoreID),
TagList: string(utils.MustMarshal(result.VenderTags)),
Score: int8(result.Score4),
Content: result.Score4Content,
ModifyDuration: JDDJ_BAD_COMMENTS_MAX_MODIFY_TIME,
OriginalMsg: string(utils.MustMarshal(result)),
}
if result["orgCommentContent"] != nil {
if result.CreateTime != nil {
orderCommend.CommentCreatedAt = result.CreateTime.GoTime()
}
if result.OrgCommentContent != "" {
orderCommend.IsReplied = 1
}
err = partner.CurOrderManager.OnOrderComments([]*model.OrderComment{orderCommend})

View File

@@ -33,38 +33,38 @@ type tJdStoreInfo struct {
}
func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorStoreID string) (*dao.StoreDetail, error) {
result, err := getAPI("").GetStoreInfoByStationNo(vendorStoreID)
result, err := getAPI("").GetStoreInfoByStationNo2(vendorStoreID)
if err == nil {
retVal := &dao.StoreDetail{
Store: model.Store{
Address: utils.Interface2String(result["stationAddress"]),
OpenTime1: JdOperationTime2JxOperationTime(result["serviceTimeStart1"]),
CloseTime1: JdOperationTime2JxOperationTime(result["serviceTimeEnd1"]),
OpenTime2: JdOperationTime2JxOperationTime(result["serviceTimeStart2"]),
CloseTime2: JdOperationTime2JxOperationTime(result["serviceTimeEnd2"]),
Status: JdStoreStatus2JxStatus(result["yn"], result["closeStatus"]),
Tel1: utils.Interface2String(result["phone"]),
Address: result.StationAddress,
OpenTime1: JdOperationTime2JxOperationTime(result.ServiceTimeStart1),
CloseTime1: JdOperationTime2JxOperationTime(result.ServiceTimeEnd1),
OpenTime2: JdOperationTime2JxOperationTime(result.ServiceTimeStart2),
CloseTime2: JdOperationTime2JxOperationTime(result.ServiceTimeEnd2),
Status: JdStoreStatus2JxStatus(int(result.Yn), result.CloseStatus),
Tel1: result.Phone,
},
}
retVal.OriginalName = utils.Interface2String(result["stationName"])
retVal.OriginalName = result.StationName
_, retVal.Name = jxutils.SplitStoreName(retVal.OriginalName, partner.StoreNameSeparator, VendorStorePrefix)
retVal.DeliveryType = JdDeliveryType2Jx(int(utils.MustInterface2Int64(result["carrierNo"])))
retVal.DeliveryType = JdDeliveryType2Jx(result.CarrierNo)
tel2 := utils.Interface2String(result["mobile"])
tel2 := result.Mobile
if tel2 != "" && tel2 != retVal.Tel1 {
retVal.Tel2 = tel2
}
lng := utils.MustInterface2Float64(result["lng"])
lat := utils.MustInterface2Float64(result["lat"])
lng := result.Lng
lat := result.Lat
retVal.Lng = jxutils.StandardCoordinate2Int(lng)
retVal.Lat = jxutils.StandardCoordinate2Int(lat)
db := dao.GetDB()
cityCode := int(utils.MustInterface2Int64(result["city"]))
cityCode := result.City
if cityCode != 0 {
if city, err2 := dao.GetPlaceByJdCode(db, cityCode); err2 == nil {
retVal.CityCode = city.Code
districtName := utils.Interface2String(result["countyName"]) // 京东的市区号码与通用数据完全无法关联,只有通过名字来关联
districtName := result.CountyName // 京东的市区号码与通用数据完全无法关联,只有通过名字来关联
if retVal.CityCode != 0 && districtName != "" {
if district, err2 := dao.GetPlaceByName(db, districtName, 3, city.Code); err2 == nil {
retVal.DistrictCode = district.Code
@@ -81,14 +81,14 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorStoreID string
}
}
retVal.ID = int(utils.Str2Int64WithDefault(utils.Interface2String(result["outSystemId"]), 0))
result, err2 := getAPI("").GetDeliveryRangeByStationNo(vendorStoreID)
retVal.ID = int(utils.Str2Int64WithDefault(result.OutSystemID, 0))
deliveryRange, err2 := getAPI("").GetDeliveryRangeByStationNo2(vendorStoreID)
if err = err2; err == nil {
retVal.DeliveryRangeType = int8(utils.MustInterface2Int64(result["deliveryRangeType"]))
retVal.DeliveryRangeType = int8(deliveryRange.DeliveryRangeType)
if retVal.DeliveryRangeType == model.DeliveryRangeTypePolygon {
retVal.DeliveryRange = strings.Trim(utils.Interface2String(result["deliveryRange"]), ";")
retVal.DeliveryRange = strings.Trim(deliveryRange.DeliveryRange, ";")
} else {
retVal.DeliveryRange = utils.Int64ToStr(utils.MustInterface2Int64(result["deliveryRangeRadius"]))
retVal.DeliveryRange = utils.Int2Str(deliveryRange.DeliveryRangeRadius)
}
return retVal, nil
}
@@ -111,43 +111,45 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
`
if err = dao.GetRows(db, &stores, sql, model.VendorIDJD, utils.DefaultTimeValue, storeID); err == nil {
for _, store := range stores {
outSystemID := ""
storeParams := &jdapi.OpStoreParams{
StationNo: store.VendorStoreID,
Operator: userName,
Phone: store.Tel1,
Mobile: store.Tel2,
}
if store.SyncStatus&model.SyncFlagDeletedMask == 0 {
outSystemID = utils.Int2Str(int(store.ID))
storeParams.OutSystemID = utils.Int2Str(int(store.ID))
} else {
storeParams.OutSystemID = store.VendorStoreID
}
params := map[string]interface{}{
"outSystemId": outSystemID, // todo 直接修改这个字段可能会有问题
"phone": store.Tel1,
"mobile": store.Tel2,
}
fillOpTimeParams(params, store.GetOpTimeList())
if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreName) != 0 {
params["stationName"] = jxutils.ComposeStoreName(store.Name, model.VendorIDJD)
storeParams.StationName = jxutils.ComposeStoreName(store.Name, model.VendorIDJD)
}
if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreAddress) != 0 {
params["stationAddress"] = store.Address
params["deliveryRangeType"] = store.DeliveryRangeType
params["coordinateType"] = 3 // 一直用高德
params["lng"] = jxutils.IntCoordinate2Standard(store.Lng)
params["lat"] = jxutils.IntCoordinate2Standard(store.Lat)
storeParams.StationAddress = store.Address
storeParams.DeliveryRangeType = store.DeliveryRangeType
storeParams.CoordinateType = jdapi.CoordinateTypeAutonavi // 一直用高德
storeParams.Lng = jxutils.IntCoordinate2Standard(store.Lng)
storeParams.Lat = jxutils.IntCoordinate2Standard(store.Lat)
if store.JdCityCode != 0 {
params["city"] = store.JdCityCode
storeParams.City = store.JdCityCode
}
if store.JdDistrictCode != 0 {
params["county"] = store.JdDistrictCode
storeParams.County = store.JdDistrictCode
}
if store.DeliveryRangeType == model.DeliveryRangeTypePolygon {
params["coordinatePoints"] = store.DeliveryRange
storeParams.CoordinatePoints = store.DeliveryRange
} else {
params["deliveryRangeRadius"] = utils.Str2Int64WithDefault(store.DeliveryRange, 0)
storeParams.DeliveryRangeRadius = int(utils.Str2Int64WithDefault(store.DeliveryRange, 0))
}
}
if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreStatus) != 0 {
_, params["closeStatus"] = JxStoreStatus2JdStatus(jxutils.MergeStoreStatus(store.Status, store.JdStoreStatus))
if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagDeletedMask|model.SyncFlagStoreStatus) != 0 {
_, storeParams.CloseStatus = JxStoreStatus2JdStatus(jxutils.MergeStoreStatus(store.Status, store.JdStoreStatus))
}
globals.SugarLogger.Debug(utils.Format4Output(params, false))
fillOpTimeParams(storeParams, store.GetOpTimeList())
globals.SugarLogger.Debug(utils.Format4Output(storeParams, false))
if globals.EnableJdStoreWrite {
if err = getAPI("").UpdateStoreInfo4Open(store.VendorStoreID, store.RealLastOperator, params); err != nil {
if err = getAPI("").UpdateStoreInfo4Open2(storeParams); err != nil {
return err
}
}
@@ -197,14 +199,16 @@ func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask
task1 := tasksch.NewParallelTask(taskName, nil, ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
store := batchItemList[0].(*tJdStoreInfo)
storeParams := map[string]interface{}{
"outSystemId": utils.Int2Str(int(store.ID)),
storeParams := &jdapi.OpStoreParams{
StationNo: store.VendorStoreID,
Operator: ctx.GetUserName(),
OutSystemID: utils.Int2Str(int(store.ID)),
}
if step != stepCount-1 {
storeParams["outSystemId"] = store.VendorStoreID
storeParams.OutSystemID = store.VendorStoreID
}
if globals.EnableJdStoreWrite {
err = getAPI("").UpdateStoreInfo4Open(store.VendorStoreID, ctx.GetUserName(), storeParams)
err = getAPI("").UpdateStoreInfo4Open2(storeParams)
}
return nil, err
}, stores)
@@ -259,9 +263,9 @@ func JdDeliveryType2Jx(deliveryType int) int8 {
}
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeStatus int, err error) {
result, err := getAPI("").GetStoreInfoByStationNo(vendorStoreID)
result, err := getAPI("").GetStoreInfoByStationNo2(vendorStoreID)
if err == nil {
storeStatus = JdStoreStatus2JxStatus(result["yn"], result["closeStatus"])
storeStatus = JdStoreStatus2JxStatus(int(result.Yn), result.CloseStatus)
}
return storeStatus, err
}
@@ -292,17 +296,16 @@ func (p *PurchaseHandler) EnableAutoAcceptOrder(ctx *jxcontext.Context, storeID
func (c *PurchaseHandler) UpdateStoreStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, status int) (err error) {
_, closeStatus := JxStoreStatus2JdStatus(status)
if globals.EnableJdStoreWrite {
err = getAPI("").UpdateStoreInfo4Open(vendorStoreID, ctx.GetUserName(), map[string]interface{}{
"closeStatus": closeStatus,
err = getAPI("").UpdateStoreInfo4Open2(&jdapi.OpStoreParams{
StationNo: vendorStoreID,
Operator: ctx.GetUserName(),
CloseStatus: closeStatus,
})
}
return err
}
func fillOpTimeParams(params map[string]interface{}, opTimeList []int16) map[string]interface{} {
if params == nil {
params = make(map[string]interface{})
}
func fillOpTimeParams(params *jdapi.OpStoreParams, opTimeList []int16) {
index := 1
opTimeListLen := len(opTimeList)
if opTimeListLen > 4 {
@@ -311,20 +314,28 @@ func fillOpTimeParams(params map[string]interface{}, opTimeList []int16) map[str
opTimeListLen = opTimeListLen / 2 * 2
for k := 0; k < len(opTimeList); k += 2 {
if opTimeList[k] != 0 {
params[fmt.Sprintf("serviceTimeStart%d", index)] = JxOperationTime2JdOperationTime(int16(opTimeList[k]))
params[fmt.Sprintf("serviceTimeEnd%d", index)] = JxOperationTime2JdOperationTime(int16(opTimeList[k+1]))
if index == 1 {
params.ServiceTimeStart1 = int(JxOperationTime2JdOperationTime(int16(opTimeList[k])))
params.ServiceTimeEnd1 = int(JxOperationTime2JdOperationTime(int16(opTimeList[k+1])))
} else {
params.ServiceTimeStart2 = int(JxOperationTime2JdOperationTime(int16(opTimeList[k])))
params.ServiceTimeEnd2 = int(JxOperationTime2JdOperationTime(int16(opTimeList[k+1])))
}
} else {
break
}
index++
}
return params
}
func (c *PurchaseHandler) UpdateStoreOpTime(ctx *jxcontext.Context, storeID int, vendorStoreID string, opTimeList []int16) (err error) {
params := fillOpTimeParams(nil, opTimeList)
params := &jdapi.OpStoreParams{
StationNo: vendorStoreID,
Operator: ctx.GetUserName(),
}
fillOpTimeParams(params, opTimeList)
if globals.EnableJdStoreWrite {
err = getAPI("").UpdateStoreInfo4Open(vendorStoreID, ctx.GetUserName(), params)
err = getAPI("").UpdateStoreInfo4Open2(params)
}
return err
}
@@ -441,9 +452,12 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S
func (c *PurchaseHandler) UpdateStoreCustomID(ctx *jxcontext.Context, vendorStoreID string, storeID int64) (err error) {
if globals.EnableJdStoreWrite {
err = getAPI("").UpdateStoreInfo4Open(vendorStoreID, ctx.GetUserName(), map[string]interface{}{
jdapi.KeyOutSystemId: utils.Int64ToStr(storeID),
})
err = getAPI("").UpdateStoreInfo4Open2(
&jdapi.OpStoreParams{
StationNo: vendorStoreID,
Operator: ctx.GetUserName(),
OutSystemID: utils.Int2Str(int(storeID)),
})
}
return err
}