package fn import ( "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/business/partner" "git.rosy.net.cn/jx-callback/globals/api" ) var ( auditStatusMap = map[int]int{ // 创建 fnpsapi.ShopCreateStatusAuditRejected: model.StoreAuditStatusCreated, fnpsapi.ShopCreateStatusAuditPassed: model.StoreAuditStatusRejected, fnpsapi.ShopCreateStatusAuditCreated: model.StoreAuditStatusCreated, fnpsapi.ShopCreateStatusAuditOnline: model.StoreAuditStatusOnline, fnpsapi.ShopCreateStatusAuditUpdateRejected: model.StoreAuditStatusOnline, // 修改 fnpsapi.ShopUpdateStatusAuditRejected: model.StoreAuditStatusCreated, } ) func getAuditStatus(vendorAuditStatus int) int { if auditStatus, ok := auditStatusMap[vendorAuditStatus]; ok { return auditStatus } return model.StoreAuditStatusCreated } func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) { // 获取品牌名称 brandInfo, err := dao.GetBrands(dao.GetDB(), "", storeDetail.BrandID, "", false, "") if err != nil { return "", 0, err } createStore := &fnpsapi.CreateStoreBaseInfo{ ContactPhone: storeDetail.Tel1, Address: storeDetail.Address, Longitude: utils.Int2Float64(storeDetail.Lng) / 1000000, Latitude: utils.Int2Float64(storeDetail.Lat) / 1000000, PositionSource: 3, OutShopCode: utils.Int2Str(storeDetail.ID), CategoryID: "51", OwnerName: storeDetail.IDName, OwnerIDNum: storeDetail.IDCode, HandheldLicencePicHash: "暂不需要(手持身份证、营业执照图片)", OwnerIDPicFrontHash: "暂不需要(省份证正)", OwnerIDPicBackHash: "暂不需要(身份证反)", CreditCode: storeDetail.LicenceCode, BusinessLicencePicHash: storeDetail.Licence, } if len(brandInfo) >= 0 { createStore.HeadShopName = brandInfo[0].Name + "-" + storeDetail.Name } else { createStore.HeadShopName = storeDetail.Name } fnShopId, err := api.FnAPI.CreateStore(createStore) if err != nil { return "", 0, err } return fnShopId, 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.Name, Tel1: shopInfo.ContactPhone, Address: shopInfo.Address, Lng: jxutils.StandardCoordinate2Int(shopInfo.Longitude), Lat: jxutils.StandardCoordinate2Int(shopInfo.Latitude), }, VendorID: model.VendorIDFengNiao, VendorStoreID: string(shopInfo.ChainStoreID), 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) { // 获取品牌名称 brandInfo, err := dao.GetBrands(dao.GetDB(), "", storeDetail.BrandID, "", false, "") if err != nil { return err } // 获取蜂鸟门店id fnStore, err := api.FnAPI.GetStore(storeDetail.VendorStoreID) if err != nil { return err } updateStore := &fnpsapi.UpdateStoreParam{ ChainStoreID: fnStore.ChainStoreID, HeadShopName: brandInfo[0].Name + "-" + storeDetail.Name, ContactPhone: storeDetail.Tel1, Address: storeDetail.Address, Longitude: utils.Int2Float64(storeDetail.Lng) / 1000000, Latitude: utils.Int2Float64(storeDetail.Lat) / 1000000, PositionSource: 3, OutShopCode: utils.Int2Str(storeDetail.ID), CategoryID: "51", OwnerName: storeDetail.IDName, OwnerIDNum: storeDetail.IDCode, HandheldLicencePicHash: "暂不需要(手持身份证、营业执照图片)", OwnerIDPicFrontHash: "暂不需要(省份证正)", OwnerIDPicBackHash: "暂不需要(身份证反)", CreditCode: storeDetail.LicenceCode, BusinessLicencePicHash: storeDetail.Licence, } if len(brandInfo) >= 0 { updateStore.HeadShopName = brandInfo[0].Name + "-" + storeDetail.Name } else { updateStore.HeadShopName = storeDetail.Name } return api.FnAPI.UpdateStore(updateStore) } // 蜂鸟门店状态改变 func OnStoreStatus(msg map[string]interface{}) (retVal *fnpsapi.CallbackResponse) { return curDeliveryHandler.OnStoreStatus(msg) } // 修改本地门店审核状态 func (c *DeliveryHandler) OnStoreStatus(msg map[string]interface{}) (retVal *fnpsapi.CallbackResponse) { var status int = 0 if storeStatus, ok := msg["status"]; ok && storeStatus != 0 { status = int(utils.ForceInterface2Int64(storeStatus)) } else { status = int(utils.ForceInterface2Int64(msg["modify_status"])) } err := partner.CurStoreManager.OnCourierStoreStatusChanged( jxcontext.AdminCtx, utils.Interface2String(msg["out_shop_code"]), model.VendorIDFengNiao, getAuditStatus(status), utils.Interface2String(msg["remark"]), ) retVal = fnpsapi.Err2CallbackResponse(err, "mtps OnStoreStatus") return retVal } type ChainstoreParam struct { MerchantId string `json:"merchant_id"` // 商户id ChainStoreId string `json:"chain_store_id"` // 蜂鸟门店id OutShopCode string `json:"out_shop_code"` // 外部门店编码 Status string `json:"status"` // 门店认证状态 ModifyStatus string `json:"modify_status"` // 门店修改状态 Remark string `json:"remark "` // 门店认证、修改等驳回时返回原因 }