- 适应快递API接口变更
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner/delivery/dada"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
@@ -997,7 +998,7 @@ func AddStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID
|
|||||||
if vendorID == model.VendorIDDada {
|
if vendorID == model.VendorIDDada {
|
||||||
storeList, err2 := dao.GetMissingDadaStores(db, storeID, false)
|
storeList, err2 := dao.GetMissingDadaStores(db, storeID, false)
|
||||||
if err = err2; err == nil && len(storeList) > 0 {
|
if err = err2; err == nil && len(storeList) > 0 {
|
||||||
storeList[0].DadaStoreID = storeCourierMap.VendorStoreID
|
storeList[0].VendorStoreID = storeCourierMap.VendorStoreID
|
||||||
err = updateOrCreateDadaStore(storeList[0])
|
err = updateOrCreateDadaStore(storeList[0])
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Debugf("AddStoreCourierMap GetMissingDadaStores error:%v, len(storeList):%d", err, len(storeList))
|
globals.SugarLogger.Debugf("AddStoreCourierMap GetMissingDadaStores error:%v, len(storeList):%d", err, len(storeList))
|
||||||
@@ -1069,7 +1070,7 @@ func RefreshMissingDadaStores(ctx *jxcontext.Context, storeID int, isAsync, isCo
|
|||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
storeDetail := batchItemList[0].(*dao.StoreDetail2)
|
storeDetail := batchItemList[0].(*dao.StoreDetail2)
|
||||||
var resultList []interface{}
|
var resultList []interface{}
|
||||||
if storeDetail.DadaStoreID == "" {
|
if storeDetail.VendorStoreID == "" {
|
||||||
if storeDetail.DistrictName == "" || storeDetail.CityName == "" {
|
if storeDetail.DistrictName == "" || storeDetail.CityName == "" {
|
||||||
return nil, fmt.Errorf("门店:%s的城市码或区码有错误", storeDetail.Name)
|
return nil, fmt.Errorf("门店:%s的城市码或区码有错误", storeDetail.Name)
|
||||||
}
|
}
|
||||||
@@ -1102,36 +1103,16 @@ func updateOrCreateDadaStore(storeDetail *dao.StoreDetail2) (err error) {
|
|||||||
if storeDetail.CityName == "" {
|
if storeDetail.CityName == "" {
|
||||||
return fmt.Errorf("门店的城市码有问题,请检查")
|
return fmt.Errorf("门店的城市码有问题,请检查")
|
||||||
}
|
}
|
||||||
if dadaDistrictMap[storeDetail.DistrictName] != "" {
|
|
||||||
if dadaDistrictMap[storeDetail.DistrictName] == "1" { // 区镇信息
|
storeDetail.CourierStoreName = composeDadaStoreName(storeDetail)
|
||||||
storeDetail.CityName = storeDetail.DistrictName
|
|
||||||
storeDetail.DistrictName, _ = api.AutonaviAPI.GetCoordinateTownInfo(jxutils.IntCoordinate2Standard(storeDetail.Lng), jxutils.IntCoordinate2Standard(storeDetail.Lat))
|
|
||||||
}
|
|
||||||
if dadaDistrictMap[storeDetail.DistrictName] != "" {
|
|
||||||
storeDetail.DistrictName = dadaDistrictMap[storeDetail.DistrictName]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if globals.EnableStoreWrite {
|
if globals.EnableStoreWrite {
|
||||||
_, err = api.DadaAPI.ShopDetail(storeDetail.DadaStoreID)
|
_, err = api.DadaAPI.ShopDetail(storeDetail.VendorStoreID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if codeErr, ok := err.(*utils.ErrorWithCode); ok && codeErr.IntCode() == dadaapi.ResponseCodeShopNotExist {
|
if codeErr, ok := err.(*utils.ErrorWithCode); ok && codeErr.IntCode() == dadaapi.ResponseCodeShopNotExist {
|
||||||
_, err = api.DadaAPI.ShopAdd(storeDetail.DadaStoreID, composeDadaStoreName(storeDetail), dadaapi.BusinessTypeConvStore, storeDetail.CityName,
|
_, err = api.DadaAPI.ShopAdd(dada.StoreDetail2ShopInfo(storeDetail))
|
||||||
storeDetail.DistrictName, storeDetail.Address, jxutils.IntCoordinate2Standard(storeDetail.Lng), jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
|
||||||
storeDetail.Tel1, storeDetail.Tel1, nil)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
params := map[string]interface{}{
|
err = api.DadaAPI.ShopUpdate(dada.StoreDetail2ShopInfo(storeDetail))
|
||||||
"station_name": composeDadaStoreName(storeDetail),
|
|
||||||
"business": dadaapi.BusinessTypeConvStore,
|
|
||||||
"city_name": storeDetail.CityName,
|
|
||||||
"area_name": storeDetail.DistrictName,
|
|
||||||
"station_address": storeDetail.Address,
|
|
||||||
"lng": jxutils.IntCoordinate2Standard(storeDetail.Lng),
|
|
||||||
"lat": jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
|
||||||
"contact_name": storeDetail.Tel1,
|
|
||||||
"phone": storeDetail.Tel1,
|
|
||||||
}
|
|
||||||
err = api.DadaAPI.ShopUpdate(storeDetail.DadaStoreID, params)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1142,7 +1123,7 @@ func updateOrCreateDadaStore(storeDetail *dao.StoreDetail2) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) {
|
func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) {
|
||||||
return storeDetail.Name + "-" + storeDetail.DadaStoreID
|
return storeDetail.Name + "-" + storeDetail.VendorStoreID
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExportShopsHealthInfo(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func ExportShopsHealthInfo(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 带购物平台信息的
|
||||||
type StoreDetail struct {
|
type StoreDetail struct {
|
||||||
model.Store
|
model.Store
|
||||||
|
|
||||||
@@ -29,10 +30,13 @@ type StoreDetail struct {
|
|||||||
CityName string `json:"cityName"`
|
CityName string `json:"cityName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 带快递门店信息的
|
||||||
type StoreDetail2 struct {
|
type StoreDetail2 struct {
|
||||||
model.Store
|
model.Store
|
||||||
VendorStoreID string `orm:"column(vendor_store_id)"` // 这个在GetMissingDadaStores返回中指的是到家的vendorStoreID
|
|
||||||
DadaStoreID string `orm:"column(dada_store_id)"`
|
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||||
|
CourierStoreName string
|
||||||
|
VendorStoreID string `orm:"column(vendor_store_id)"`
|
||||||
DistrictName string
|
DistrictName string
|
||||||
CityName string
|
CityName string
|
||||||
}
|
}
|
||||||
@@ -86,7 +90,7 @@ func GetStoreDetailByVendorStoreID(db *DaoDB, vendorStoreID string, vendorID int
|
|||||||
return getStoreDetail(db, 0, vendorID, vendorStoreID)
|
return getStoreDetail(db, 0, vendorID, vendorStoreID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPossibleStoresByPlaceName(db *DaoDB, cityName, provinceName string) (storeList []*StoreDetail2, err error) {
|
func GetPossibleStoresByPlaceName(db *DaoDB, cityName, provinceName string) (storeList []*StoreDetail, err error) {
|
||||||
sqlList := []string{
|
sqlList := []string{
|
||||||
`
|
`
|
||||||
SELECT t1.*, t5.vendor_store_id
|
SELECT t1.*, t5.vendor_store_id
|
||||||
@@ -148,9 +152,8 @@ func GetPossibleStoresByPlaceName(db *DaoDB, cityName, provinceName string) (sto
|
|||||||
func GetMissingDadaStores(db *DaoDB, storeID int, isMustHaveJdStore bool) (storeList []*StoreDetail2, err error) {
|
func GetMissingDadaStores(db *DaoDB, storeID int, isMustHaveJdStore bool) (storeList []*StoreDetail2, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.*,
|
SELECT t1.*,
|
||||||
t2.vendor_store_id vendor_store_id,
|
|
||||||
city.name city_name, district.name district_name,
|
city.name city_name, district.name district_name,
|
||||||
t3.vendor_store_id dada_store_id
|
t3.vendor_store_id, t3.vendor_id
|
||||||
FROM store t1
|
FROM store t1
|
||||||
LEFT JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
|
LEFT JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
|
||||||
LEFT JOIN place city ON city.code = t1.city_code
|
LEFT JOIN place city ON city.code = t1.city_code
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ const (
|
|||||||
StoreIsSyncYes = 1
|
StoreIsSyncYes = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
StoreAuditStatusCreated = 1
|
||||||
|
StoreAuditStatusOnline = 0
|
||||||
|
StoreAuditStatusRejected = -1
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MainSubStoreName = "本店"
|
MainSubStoreName = "本店"
|
||||||
MainSubStoreAddress = "本店"
|
MainSubStoreAddress = "本店"
|
||||||
@@ -368,6 +374,7 @@ type StoreCourierMap struct {
|
|||||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
|
AuditStatus int `json:"auditStatus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*StoreCourierMap) TableUnique() [][]string {
|
func (*StoreCourierMap) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
@@ -29,6 +30,17 @@ var (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
CurDeliveryHandler *DeliveryHandler
|
CurDeliveryHandler *DeliveryHandler
|
||||||
|
|
||||||
|
dadaDistrictMap = map[string]string{
|
||||||
|
"苏州工业园区": "工业园区",
|
||||||
|
"郫都区": "郫县",
|
||||||
|
"管城回族区": "管城区",
|
||||||
|
"昆山市": "1",
|
||||||
|
"常熟市": "1",
|
||||||
|
"太仓市": "1",
|
||||||
|
"虞山街道": "虞山镇",
|
||||||
|
"常福街道": "虞山镇",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeliveryHandler struct {
|
type DeliveryHandler struct {
|
||||||
@@ -103,6 +115,51 @@ func (c *DeliveryHandler) callbackMsg2Waybill(msg *dadaapi.CallbackMsg) (retVal
|
|||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StoreDetail2ShopInfo(storeDetail *dao.StoreDetail2) (shopInfo *dadaapi.ShopInfo) {
|
||||||
|
lng := jxutils.IntCoordinate2Standard(storeDetail.Lng)
|
||||||
|
lat := jxutils.IntCoordinate2Standard(storeDetail.Lat)
|
||||||
|
cityName := storeDetail.CityName
|
||||||
|
districtName := storeDetail.DistrictName
|
||||||
|
if dadaDistrictMap[districtName] != "" {
|
||||||
|
if dadaDistrictMap[districtName] == "1" { // 区镇信息
|
||||||
|
cityName = districtName
|
||||||
|
districtName, _ = api.AutonaviAPI.GetCoordinateTownInfo(lng, lat)
|
||||||
|
}
|
||||||
|
if dadaDistrictMap[storeDetail.DistrictName] != "" {
|
||||||
|
storeDetail.DistrictName = dadaDistrictMap[storeDetail.DistrictName]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shopInfo = &dadaapi.ShopInfo{
|
||||||
|
OriginShopID: utils.Int2Str(storeDetail.ID),
|
||||||
|
StationName: storeDetail.Name,
|
||||||
|
CityName: cityName,
|
||||||
|
AreaName: districtName,
|
||||||
|
StationAddress: storeDetail.Address,
|
||||||
|
Lng: lng,
|
||||||
|
Lat: lat,
|
||||||
|
ContactName: storeDetail.PayeeName,
|
||||||
|
Phone: storeDetail.Tel1,
|
||||||
|
}
|
||||||
|
return shopInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) {
|
||||||
|
if globals.EnableStoreWrite {
|
||||||
|
_, err = api.DadaAPI.ShopAdd(StoreDetail2ShopInfo(storeDetail))
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
status = model.StoreAuditStatusOnline
|
||||||
|
}
|
||||||
|
return "", status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error) {
|
||||||
|
if globals.EnableStoreWrite {
|
||||||
|
err = api.DadaAPI.ShopUpdate(StoreDetail2ShopInfo(storeDetail))
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *partner.WaybillFeeInfo, err error) {
|
func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *partner.WaybillFeeInfo, err error) {
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
deliveryFeeInfo = &partner.WaybillFeeInfo{}
|
deliveryFeeInfo = &partner.WaybillFeeInfo{}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
@@ -30,6 +31,12 @@ var (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
curDeliveryHandler *DeliveryHandler
|
curDeliveryHandler *DeliveryHandler
|
||||||
|
auditStatusMap = map[int]int{
|
||||||
|
mtpsapi.ShopStatusCreateSuccess: model.StoreAuditStatusCreated,
|
||||||
|
mtpsapi.ShopStatusAuditRejected: model.StoreAuditStatusRejected,
|
||||||
|
mtpsapi.ShopStatusAuditPassed: model.StoreAuditStatusCreated,
|
||||||
|
mtpsapi.ShopStatusOnline: model.StoreAuditStatusOnline,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeliveryHandler struct {
|
type DeliveryHandler struct {
|
||||||
@@ -114,6 +121,36 @@ func (c *DeliveryHandler) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (re
|
|||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) {
|
||||||
|
businessHours := []*mtpsapi.BusinessHour{
|
||||||
|
&mtpsapi.BusinessHour{
|
||||||
|
BeginTime: "06:00",
|
||||||
|
EndTime: "22:00",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
shopInfo := &mtpsapi.ShopInfo{
|
||||||
|
ShopID: utils.Int2Str(storeDetail.ID),
|
||||||
|
ShopName: storeDetail.Name,
|
||||||
|
Category: mtpsapi.ShopCategoryFruit,
|
||||||
|
SecondCategory: mtpsapi.ShopCategoryFruitFruit,
|
||||||
|
ContactName: storeDetail.PayeeName,
|
||||||
|
ContactPhone: storeDetail.Tel1,
|
||||||
|
ShopAddress: storeDetail.Address,
|
||||||
|
ShopLng: storeDetail.Lng,
|
||||||
|
ShopLat: storeDetail.Lat,
|
||||||
|
CoordinateType: mtpsapi.CoordinateTypeMars,
|
||||||
|
BusinessHours: string(utils.MustMarshal(businessHours)),
|
||||||
|
}
|
||||||
|
shopStatus := mtpsapi.ShopStatusCreateSuccess
|
||||||
|
if globals.EnableStoreWrite {
|
||||||
|
shopStatus, err = api.MtpsAPI.ShopCreate(shopInfo)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
status = auditStatusMap[shopStatus]
|
||||||
|
}
|
||||||
|
return "", status, err
|
||||||
|
}
|
||||||
|
|
||||||
func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *partner.WaybillFeeInfo, err error) {
|
func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *partner.WaybillFeeInfo, err error) {
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
deliveryFeeInfo = &partner.WaybillFeeInfo{}
|
deliveryFeeInfo = &partner.WaybillFeeInfo{}
|
||||||
|
|||||||
Reference in New Issue
Block a user