Files
jx-callback/business/partner/delivery/fn/store.go
苏尹岚 01c87b3415 aa
2020-12-23 09:31:11 +08:00

85 lines
2.8 KiB
Go

package fn
import (
"strings"
"git.rosy.net.cn/baseapi/platformapi/fnpsapi"
"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/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) {
err = api.FnAPI.CreateStore(&fnpsapi.CreateStoreParam{
ChainStoreCode: utils.Int2Str(storeDetail.ID),
ChainStoreName: globals.StoreName + "-" + storeDetail.Name,
ContactPhone: storeDetail.Tel1,
Address: storeDetail.Address,
PositionSource: 3,
Longitude: utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lng)),
Latitude: utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lat)),
})
if err == nil {
vendorStoreID = utils.Int2Str(storeDetail.ID)
}
return vendorStoreID, status, err
}
func shopStatus2JX(status int) (jxStatus int) {
if status == 1 {
return 0
} else {
return 1
}
}
func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) {
shopInfo, err := api.FnAPI.GetStore(vendorStoreID)
if err == nil {
storeDetail = &dao.StoreDetail2{
Store: model.Store{
Name: shopInfo.ChainStoreName,
Tel1: shopInfo.ContactPhone,
Address: shopInfo.Address,
Lng: jxutils.StandardCoordinate2Int(utils.Str2Float64(shopInfo.Longitude)),
Lat: jxutils.StandardCoordinate2Int(utils.Str2Float64(shopInfo.Latitude)),
},
VendorID: model.VendorIDFengNiao,
VendorStoreID: shopInfo.ChainStoreCode,
CourierStatus: shopStatus2JX(shopInfo.Status),
}
}
return storeDetail, err
}
func (c *DeliveryHandler) IsErrStoreExist(err error) bool {
return fnpsapi.IsErrShopExist(err)
}
func (c *DeliveryHandler) IsErrStoreNotExist(err error) bool {
return fnpsapi.IsErrShopNotExist(err)
}
func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error) {
params := &fnpsapi.CreateStoreParam{
ChainStoreCode: utils.Int2Str(storeDetail.ID),
// ChainStoreName: globals.StoreName + "-" + storeDetail.Name,
ContactPhone: storeDetail.Tel1,
Address: storeDetail.Address,
PositionSource: 3,
Longitude: utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lng)),
Latitude: utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lat)),
}
if !strings.Contains(storeDetail.Name, globals.StoreName+"-") {
params.ChainStoreName = globals.StoreName + "-" + storeDetail.Name
} else {
params.ChainStoreName = storeDetail.Name
}
err = api.FnAPI.UpdateStore(params)
return err
}