diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index f5326f72b..219983f22 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -2745,3 +2745,91 @@ func RefreshJdLevel(ctx *jxcontext.Context) (err error) { } return err } + +type tJdStoreInfo struct { + model.Store + VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空 + + FreightDeductionPack string `orm:"size(32)" json:"freightDeductionPack"` // + + JdCityCode int + JdDistrictCode int + JdStoreStatus int + VendorStoreID string `orm:"column(vendor_store_id)"` + RealLastOperator string + SyncStatus int + VendorStoreName string +} + +func UpdateJdStoreNameAll(ctx *jxcontext.Context) (err error) { + db := dao.GetDB() + userName := ctx.GetUserName() + var stores []*tJdStoreInfo + sql := ` + SELECT + t1.*, city.jd_code jd_city_code, district.jd_code jd_district_code, + t2.status jd_store_status, t2.vendor_store_id, IF(t1.updated_at > t2.updated_at, t1.last_operator, + t2.last_operator) real_last_operator, + t2.sync_status, t2.freight_deduction_pack, t2.vendor_org_code, t2.vendor_store_name + FROM store t1 + JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? + 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 err = dao.GetRows(db, &stores, sql, model.VendorIDJD, 102108); err == nil { + for _, store := range stores { + a := jd.GetAPI(store.VendorOrgCode) + storeParams := &jdapi.OpStoreParams{ + StationNo: store.VendorStoreID, + Operator: userName, + Phone: store.Tel1, + Mobile: store.Tel2, + } + if store.SyncStatus&model.SyncFlagDeletedMask == 0 { + storeParams.OutSystemID = utils.Int2Str(int(store.ID)) + } else { + storeParams.OutSystemID = store.VendorStoreID + } + if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreName) != 0 { + if store.VendorStoreName != "" { + storeParams.StationName = store.VendorStoreName + } else { + storeParams.StationName = jxutils.ComposeStoreName(store.Name, model.VendorIDJD) + } + storeParams.StationName = utils.LimitUTF8StringLen(storeParams.StationName, jdapi.MaxStoreNameLen) + } + if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreAddress) != 0 { + storeParams.StationAddress = store.Address + storeParams.CoordinateType = jdapi.CoordinateTypeAutonavi // 一直用高德 + storeParams.Lng = jxutils.IntCoordinate2Standard(store.Lng) + storeParams.Lat = jxutils.IntCoordinate2Standard(store.Lat) + if store.JdCityCode != 0 { + storeParams.City = store.JdCityCode + } + if store.JdDistrictCode != 0 { + storeParams.County = store.JdDistrictCode + } + } + // if specialDistrictMap[storeParams.County] != 0 { + // storeParams.City = storeParams.County + // storeParams.County = specialDistrictMap[storeParams.County] + // } + storeParams.StoreNotice = store.PromoteInfo + modifyCloseStatus := false + if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagDeletedMask|model.SyncFlagStoreStatus) != 0 { + modifyCloseStatus = true + _, storeParams.CloseStatus = jd.JxStoreStatus2JdStatus(jxutils.MergeStoreStatus(store.Status, store.JdStoreStatus)) + } + // fillOpTimeParams(storeParams, store.GetOpTimeList()) + // globals.SugarLogger.Debug(utils.Format4Output(storeParams, false)) + errList := errlist.New() + if globals.EnableJdStoreWrite { + errList.AddErr(a.UpdateStoreInfo4Open2(storeParams, modifyCloseStatus)) + } + err = errList.GetErrListAsOne() + } + } + return err +} diff --git a/controllers/cms_store.go b/controllers/cms_store.go index 180344e6b..e30712941 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -634,3 +634,16 @@ func (c *StoreController) RefreshJdLevel() { return retVal, "", err }) } + +// @Title 同步指定京东门店 +// @Description 同步京东门店 +// @Param token header string true "认证token" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /SyncJdStore [post] +func (c *StoreController) SyncJdStore() { + c.callSyncJdStore(func(params *tStoreSyncJdStoreParams) (retVal interface{}, errCode string, err error) { + err = cms.UpdateJdStoreNameAll(params.Ctx) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index d1add6505..b040b6c6e 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1647,6 +1647,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], + beego.ControllerComments{ + Method: "SyncJdStore", + Router: `/SyncJdStore`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], beego.ControllerComments{ Method: "SyncStoresCourierInfo",