- 重构配送门店管理
This commit is contained in:
@@ -82,6 +82,7 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
"actTypeName": model.ActTypeName,
|
||||
"actStatusName": model.ActStatusName,
|
||||
"actCreateTypeName": model.ActCreateTypeName,
|
||||
"storeAuditStatusName": model.StoreAuditStatusName,
|
||||
},
|
||||
}
|
||||
Init()
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"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/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/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
@@ -71,17 +70,6 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
dadaDistrictMap = map[string]string{
|
||||
"苏州工业园区": "工业园区",
|
||||
"郫都区": "郫县",
|
||||
"管城回族区": "管城区",
|
||||
"昆山市": "1",
|
||||
"常熟市": "1",
|
||||
"太仓市": "1",
|
||||
"虞山街道": "虞山镇",
|
||||
"常福街道": "虞山镇",
|
||||
}
|
||||
|
||||
storeKeyPropertyMap = map[string]int{
|
||||
"name": 1,
|
||||
"cityCode": 1,
|
||||
@@ -624,6 +612,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
||||
dao.Commit(db)
|
||||
globals.SugarLogger.Debugf("UpdateStore track:%s, before call SyncStore", ctx.GetTrackInfo())
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, -1, store.ID, false, userName)
|
||||
if err2 := updateCourierStores(ctx, storeID); err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dao.Commit(db)
|
||||
@@ -703,7 +694,7 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i
|
||||
dao.WrapAddIDCULDEntity(store, userName)
|
||||
store.ID = existingID
|
||||
if err = dao.CreateEntity(nil, store); err == nil {
|
||||
RefreshMissingDadaStores(ctx, store.ID, false, false)
|
||||
UpdateOrCreateCourierStores(ctx, store.ID, false, false, false)
|
||||
return store.ID, err
|
||||
}
|
||||
return 0, err
|
||||
@@ -986,43 +977,45 @@ func GetStoreCourierMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, ven
|
||||
}
|
||||
|
||||
func AddStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeCourierMap *model.StoreCourierMap) (outStoreCourierMap *model.StoreCourierMap, err error) {
|
||||
return addStoreCourierMap(ctx, db, storeID, vendorID, storeCourierMap, true)
|
||||
}
|
||||
|
||||
func addStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeCourierMap *model.StoreCourierMap, isNeedUpdateRemote bool) (outStoreCourierMap *model.StoreCourierMap, err error) {
|
||||
userName := ctx.GetUserName()
|
||||
if handler := partner.GetDeliveryPlatformFromVendorID(vendorID); handler != nil {
|
||||
dao.WrapAddIDCULDEntity(storeCourierMap, userName)
|
||||
storeCourierMap.StoreID = storeID
|
||||
storeCourierMap.VendorID = vendorID
|
||||
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
}
|
||||
if vendorID == model.VendorIDDada {
|
||||
storeList, err2 := dao.GetMissingDadaStores(db, storeID, false)
|
||||
if err = err2; err == nil && len(storeList) > 0 {
|
||||
storeList[0].VendorStoreID = storeCourierMap.VendorStoreID
|
||||
err = updateOrCreateDadaStore(storeList[0])
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("AddStoreCourierMap GetMissingDadaStores error:%v, len(storeList):%d", err, len(storeList))
|
||||
if isNeedUpdateRemote {
|
||||
storeDetail, err2 := dao.GetStoreDetail2(db, storeID, "", vendorID)
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if storeDetail.VendorStoreID != "" && storeDetail.VendorStoreID != storeCourierMap.VendorStoreID {
|
||||
return nil, fmt.Errorf("门店已经绑定了%s, ID:%s, 如需重新绑定, 请先解绑", model.VendorChineseNames[vendorID], storeDetail.VendorStoreID)
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(storeCourierMap, userName)
|
||||
storeCourierMap.StoreID = storeID
|
||||
storeCourierMap.VendorID = vendorID
|
||||
storeDetail.VendorStoreID = storeCourierMap.VendorStoreID
|
||||
if err = updateCourierStore(ctx, storeDetail); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if err = dao.CreateEntity(db, storeCourierMap); err == nil {
|
||||
dao.Commit(db)
|
||||
outStoreCourierMap = storeCourierMap
|
||||
if err == nil {
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, storeCourierMap.VendorID, storeID, false, userName)
|
||||
}
|
||||
} else {
|
||||
dao.Rollback(db)
|
||||
if err = dao.CreateEntity(db, storeCourierMap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
outStoreCourierMap = storeCourierMap
|
||||
dao.Commit(db)
|
||||
} else {
|
||||
err = ErrCanNotFindVendor
|
||||
}
|
||||
@@ -1034,14 +1027,12 @@ func DeleteStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendo
|
||||
db = dao.GetDB()
|
||||
}
|
||||
storeCourierMap := &model.StoreCourierMap{}
|
||||
if num, err = dao.DeleteEntityLogically(db, storeCourierMap, map[string]interface{}{
|
||||
num, err = dao.DeleteEntityLogically(db, storeCourierMap, map[string]interface{}{
|
||||
model.FieldStatus: model.StoreStatusDisabled,
|
||||
}, userName, map[string]interface{}{
|
||||
model.FieldStoreID: storeID,
|
||||
model.FieldVendorID: vendorID,
|
||||
}); err == nil && num > 0 {
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
||||
}
|
||||
})
|
||||
return num, err
|
||||
}
|
||||
|
||||
@@ -1050,6 +1041,7 @@ func UpdateStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendo
|
||||
db = dao.GetDB()
|
||||
}
|
||||
dummyStoreCourierMap := &model.StoreCourierMap{}
|
||||
delete(payload, "auditStatus") // 不允许直接修改auditStatus的值
|
||||
valid := dao.NormalMakeMapByStructObject(payload, dummyStoreCourierMap, userName)
|
||||
if len(valid) > 0 {
|
||||
num, err = dao.UpdateEntityLogically(db, dummyStoreCourierMap, valid, userName, map[string]interface{}{
|
||||
@@ -1060,31 +1052,113 @@ func UpdateStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendo
|
||||
return num, err
|
||||
}
|
||||
|
||||
func RefreshMissingDadaStores(ctx *jxcontext.Context, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetMissingDadaStores(db, storeID, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
func updateCourierStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error) {
|
||||
if handlerInfo := partner.GetDeliveryPlatformFromVendorID(storeDetail.VendorID); handlerInfo != nil && handlerInfo.Use4CreateWaybill {
|
||||
if updateHandler, ok := handlerInfo.Handler.(partner.IDeliveryUpdateStoreHandler); ok {
|
||||
storeDetail.CourierStoreName = composeDadaStoreName(storeDetail)
|
||||
err = updateHandler.UpdateStore(ctx, storeDetail)
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("RefreshMissingDadaStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeDetail := batchItemList[0].(*dao.StoreDetail2)
|
||||
var resultList []interface{}
|
||||
if storeDetail.VendorStoreID == "" {
|
||||
if storeDetail.DistrictName == "" || storeDetail.CityName == "" {
|
||||
return nil, fmt.Errorf("门店:%s的城市码或区码有错误", storeDetail.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func updateCourierStores(ctx *jxcontext.Context, storeID int) (err error) {
|
||||
db := dao.GetDB()
|
||||
errList := errlist.New()
|
||||
for k, v := range partner.DeliveryPlatformHandlers {
|
||||
if v.Use4CreateWaybill {
|
||||
if _, ok := v.Handler.(partner.IDeliveryUpdateStoreHandler); ok {
|
||||
storeDetail, err2 := dao.GetStoreDetail2(db, storeID, "", k)
|
||||
if err = err2; err2 == nil {
|
||||
err = updateCourierStore(ctx, storeDetail)
|
||||
}
|
||||
db := dao.GetDB()
|
||||
if _, err = AddStoreCourierMap(ctx, db, storeDetail.ID, model.VendorIDDada, &model.StoreCourierMap{
|
||||
VendorStoreID: utils.Int2Str(storeDetail.ID),
|
||||
Status: model.StoreStatusOpened,
|
||||
}); err == nil {
|
||||
resultList = append(resultList, 1)
|
||||
errList.AddErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func updateOrCreateCourierStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (isCreated bool, err error) {
|
||||
if handlerInfo := partner.GetDeliveryPlatformFromVendorID(storeDetail.VendorID); handlerInfo != nil && handlerInfo.Use4CreateWaybill {
|
||||
if storeDetail.DistrictName == "" {
|
||||
return false, fmt.Errorf("门店的区码有问题,请检查")
|
||||
}
|
||||
if storeDetail.CityName == "" {
|
||||
return false, fmt.Errorf("门店的城市码有问题,请检查")
|
||||
}
|
||||
storeDetail.CourierStoreName = composeDadaStoreName(storeDetail)
|
||||
if _, err = handlerInfo.Handler.GetStore(ctx, 0, storeDetail.VendorStoreID); err != nil {
|
||||
if !handlerInfo.Handler.IsErrStoreNotExist(err) {
|
||||
storeDetail.VendorStoreID, storeDetail.AuditStatus, err = handlerInfo.Handler.CreateStore(ctx, storeDetail)
|
||||
isCreated = true
|
||||
}
|
||||
} else {
|
||||
if updateHandler, _ := handlerInfo.Handler.(partner.IDeliveryUpdateStoreHandler); updateHandler != nil {
|
||||
err = updateHandler.UpdateStore(ctx, storeDetail)
|
||||
} else {
|
||||
// err = fmt.Errorf("快递平台%s不支持更新门店信息,请手动处理", model.VendorChineseNames[storeDetail.VendorID])
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
err = fmt.Errorf("门店ID:%d,门店名:%s,错误描述:%s", storeDetail.Store.ID, storeDetail.Name, err.Error())
|
||||
globals.SugarLogger.Debugf("updateOrCreateDadaStore storeID:%d failed with error:%v", storeDetail.ID, err)
|
||||
}
|
||||
}
|
||||
return isCreated, err
|
||||
}
|
||||
|
||||
func UpdateOrCreateCourierStores(ctx *jxcontext.Context, storeID int, isForceUpdate, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var storeIDs []int
|
||||
if storeID != 0 {
|
||||
storeIDs = []int{storeID}
|
||||
} else {
|
||||
storesInfo, err2 := GetStores(ctx, "", map[string]interface{}{}, 0, -1, utils.DefaultTimeValue, utils.DefaultTimeValue, 0, 0)
|
||||
if err = err2; err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, v := range storesInfo.Stores {
|
||||
storeIDs = append(storeIDs, v.ID)
|
||||
}
|
||||
}
|
||||
|
||||
task := tasksch.NewParallelTask("UpdateOrCreateCourierStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
var resultList []interface{}
|
||||
storeID := batchItemList[0].(int)
|
||||
errList := errlist.New()
|
||||
db := dao.GetDB()
|
||||
for k, v := range partner.DeliveryPlatformHandlers {
|
||||
if v.Use4CreateWaybill {
|
||||
if _, ok := v.Handler.(partner.IDeliveryUpdateStoreHandler); ok {
|
||||
storeDetail, err2 := dao.GetStoreDetail2(db, storeID, "", k)
|
||||
if err = err2; err2 == nil {
|
||||
isStoreExist := storeDetail.VendorStoreID == ""
|
||||
storeDetail.VendorStoreID = utils.Int2Str(storeDetail.ID)
|
||||
if isForceUpdate || !isStoreExist {
|
||||
var isCreated bool
|
||||
if isCreated, err = updateOrCreateCourierStore(ctx, storeDetail); err == nil && isCreated {
|
||||
storeCourier := &model.StoreCourierMap{
|
||||
VendorStoreID: storeDetail.VendorStoreID,
|
||||
Status: model.StoreStatusOpened,
|
||||
AuditStatus: storeDetail.AuditStatus,
|
||||
}
|
||||
if storeDetail.AuditStatus != model.StoreAuditStatusOnline {
|
||||
storeCourier.Status = model.StoreStatusDisabled
|
||||
}
|
||||
if _, err = addStoreCourierMap(ctx, db, storeDetail.ID, storeDetail.VendorID, storeCourier, false); err == nil {
|
||||
resultList = append(resultList, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
errList.AddErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultList, err
|
||||
}, storeList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
}, storeIDs)
|
||||
tasksch.HandleTask(task, nil, len(storeIDs) > 1).Run()
|
||||
if !isAsync {
|
||||
resultList, err2 := task.GetResult(0)
|
||||
if err = err2; err == nil {
|
||||
@@ -1096,32 +1170,6 @@ func RefreshMissingDadaStores(ctx *jxcontext.Context, storeID int, isAsync, isCo
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func updateOrCreateDadaStore(storeDetail *dao.StoreDetail2) (err error) {
|
||||
if storeDetail.DistrictName == "" {
|
||||
return fmt.Errorf("门店的区码有问题,请检查")
|
||||
}
|
||||
if storeDetail.CityName == "" {
|
||||
return fmt.Errorf("门店的城市码有问题,请检查")
|
||||
}
|
||||
|
||||
storeDetail.CourierStoreName = composeDadaStoreName(storeDetail)
|
||||
if globals.EnableStoreWrite {
|
||||
_, err = api.DadaAPI.ShopDetail(storeDetail.VendorStoreID)
|
||||
if err != nil {
|
||||
if codeErr, ok := err.(*utils.ErrorWithCode); ok && codeErr.IntCode() == dadaapi.ResponseCodeShopNotExist {
|
||||
_, err = api.DadaAPI.ShopAdd(dada.StoreDetail2ShopInfo(storeDetail))
|
||||
}
|
||||
} else {
|
||||
err = api.DadaAPI.ShopUpdate(dada.StoreDetail2ShopInfo(storeDetail))
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
err = fmt.Errorf("门店ID:%d,门店名:%s,错误描述:%s", storeDetail.Store.ID, storeDetail.Name, err.Error())
|
||||
globals.SugarLogger.Debugf("updateOrCreateDadaStore storeID:%d failed with error:%v", storeDetail.ID, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) {
|
||||
return storeDetail.Name + "-" + storeDetail.VendorStoreID
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cms
|
||||
|
||||
import (
|
||||
"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/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
@@ -100,3 +101,19 @@ func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int,
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StoreManager) OnCourierStoreStatusChanged(ctx *jxcontext.Context, vendorStoreID string, vendorID int, auditStatus int) (err error) {
|
||||
if vendorStoreID != "" {
|
||||
db := dao.GetDB()
|
||||
_, err2 := dao.GetStoreDetail2(db, 0, vendorStoreID, vendorID)
|
||||
if err = err2; err == nil {
|
||||
_, err = dao.UpdateEntityLogically(db, &model.StoreCourierMap{}, map[string]interface{}{
|
||||
"AuditStatus": auditStatus,
|
||||
}, ctx.GetUserName(), map[string]interface{}{
|
||||
model.FieldVendorStoreID: vendorStoreID,
|
||||
model.FieldVendorID: vendorID,
|
||||
})
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -36,12 +36,14 @@ type StoreDetail struct {
|
||||
type StoreDetail2 struct {
|
||||
model.Store
|
||||
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id)" json:"vendorStoreID"` // 这个其实是京西快递门店ID的概念
|
||||
CourierStatus int `json:"courierStatus"`
|
||||
AuditStatus int `json:"auditStatus"`
|
||||
|
||||
CourierStoreName string `json:"courierStoreName"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id)" json:"vendorStoreID"`
|
||||
DistrictName string `json:"districtName"`
|
||||
CityName string `json:"cityName"`
|
||||
AuditStatus int `json:"auditStatus"`
|
||||
}
|
||||
|
||||
func (s *StoreDetail) GetPricePerentage(price int) (pricePercentage int) {
|
||||
@@ -152,36 +154,31 @@ func GetPossibleStoresByPlaceName(db *DaoDB, cityName, provinceName string) (sto
|
||||
}
|
||||
|
||||
// 这个返回的地点信息是城市
|
||||
func GetMissingDadaStores(db *DaoDB, storeID int, isMustHaveJdStore bool) (storeList []*StoreDetail2, err error) {
|
||||
func GetStoreDetail2(db *DaoDB, storeID int, vendorStoreID string, vendorID int) (storeDetail *StoreDetail2, err error) {
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
city.name city_name, district.name district_name,
|
||||
t3.vendor_store_id, t3.vendor_id
|
||||
t3.vendor_store_id, t3.vendor_id, t3.status courier_status, t3.audit_status
|
||||
FROM store t1
|
||||
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 district ON district.code = t1.district_code
|
||||
LEFT JOIN store_courier_map t3 ON t3.store_id = t1.id AND t3.vendor_id = ? AND t3.deleted_at = ?
|
||||
WHERE t1.deleted_at = ?
|
||||
`
|
||||
WHERE t1.deleted_at = ?`
|
||||
sqlParams := []interface{}{
|
||||
model.VendorIDJD,
|
||||
utils.DefaultTimeValue,
|
||||
model.VendorIDDada,
|
||||
vendorID,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if isMustHaveJdStore {
|
||||
sql += " AND t2.id IS NOT NULL"
|
||||
}
|
||||
if storeID != 0 {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
if err = GetRows(db, &storeList, sql, sqlParams...); err == nil {
|
||||
return storeList, nil
|
||||
if vendorStoreID != "" {
|
||||
sql += " AND t3.vendor_store_id = ?"
|
||||
sqlParams = append(sqlParams, vendorStoreID)
|
||||
}
|
||||
return nil, err
|
||||
err = GetRow(db, &storeDetail, sql, sqlParams...)
|
||||
return storeDetail, err
|
||||
}
|
||||
|
||||
func GetStoreCourierList(db *DaoDB, storeID, status int) (courierStoreList []*model.StoreCourierMap, err error) {
|
||||
|
||||
@@ -227,6 +227,11 @@ var (
|
||||
"NHQS": "农信银清算中心",
|
||||
"CBBQS": "城市商业银行资金清算中心",
|
||||
}
|
||||
StoreAuditStatusName = map[int]string{
|
||||
StoreAuditStatusCreated: "待审核",
|
||||
StoreAuditStatusOnline: "上线",
|
||||
StoreAuditStatusRejected: "拒绝",
|
||||
}
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
|
||||
@@ -130,7 +130,7 @@ func StoreDetail2ShopInfo(storeDetail *dao.StoreDetail2) (shopInfo *dadaapi.Shop
|
||||
}
|
||||
}
|
||||
shopInfo = &dadaapi.ShopInfo{
|
||||
OriginShopID: utils.Int2Str(storeDetail.ID),
|
||||
OriginShopID: storeDetail.VendorStoreID,
|
||||
StationName: storeDetail.CourierStoreName,
|
||||
CityName: cityName,
|
||||
AreaName: districtName,
|
||||
@@ -160,6 +160,31 @@ func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) {
|
||||
shopInfo, err := api.DadaAPI.ShopDetail(vendorStoreID)
|
||||
if err == nil {
|
||||
storeDetail = &dao.StoreDetail2{
|
||||
Store: model.Store{
|
||||
Address: shopInfo.StationAddress,
|
||||
Lng: jxutils.StandardCoordinate2Int(shopInfo.Lng),
|
||||
Lat: jxutils.StandardCoordinate2Int(shopInfo.Lat),
|
||||
PayeeName: shopInfo.ContactName,
|
||||
Tel1: shopInfo.Phone,
|
||||
},
|
||||
VendorID: model.VendorIDDada,
|
||||
VendorStoreID: shopInfo.OriginShopID,
|
||||
CourierStoreName: shopInfo.StationName,
|
||||
CityName: shopInfo.CityName,
|
||||
DistrictName: shopInfo.AreaName,
|
||||
}
|
||||
}
|
||||
return storeDetail, err
|
||||
}
|
||||
|
||||
func (c *DeliveryHandler) IsErrStoreNotExist(err error) bool {
|
||||
return dadaapi.IsErrShopNotExist(err)
|
||||
}
|
||||
|
||||
func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *partner.WaybillFeeInfo, err error) {
|
||||
db := dao.GetDB()
|
||||
deliveryFeeInfo = &partner.WaybillFeeInfo{}
|
||||
|
||||
86
business/partner/delivery/mtps/store.go
Normal file
86
business/partner/delivery/mtps/store.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package mtps
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||
"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/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
var (
|
||||
auditStatusMap = map[int]int{
|
||||
mtpsapi.ShopStatusCreateSuccess: model.StoreAuditStatusCreated,
|
||||
mtpsapi.ShopStatusAuditRejected: model.StoreAuditStatusRejected,
|
||||
mtpsapi.ShopStatusAuditPassed: model.StoreAuditStatusCreated,
|
||||
mtpsapi.ShopStatusOnline: model.StoreAuditStatusOnline,
|
||||
}
|
||||
)
|
||||
|
||||
func OnStoreStatus(msg *mtpsapi.CallbackShopStatusMsg) (retVal *mtpsapi.CallbackResponse) {
|
||||
return curDeliveryHandler.OnStoreStatus(msg)
|
||||
}
|
||||
|
||||
func (c *DeliveryHandler) OnStoreStatus(msg *mtpsapi.CallbackShopStatusMsg) (retVal *mtpsapi.CallbackResponse) {
|
||||
auditStatus := auditStatusMap[msg.Status]
|
||||
err := partner.CurStoreManager.OnCourierStoreStatusChanged(jxcontext.AdminCtx, msg.ShopID, model.VendorIDMTPS, auditStatus)
|
||||
retVal = mtpsapi.Err2CallbackResponse(err, "mtps OnStoreStatus")
|
||||
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: storeDetail.VendorStoreID,
|
||||
ShopName: storeDetail.CourierStoreName,
|
||||
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) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) {
|
||||
shopInfo, err := api.MtpsAPI.ShopQuery(vendorStoreID)
|
||||
if err == nil {
|
||||
storeDetail = &dao.StoreDetail2{
|
||||
Store: model.Store{
|
||||
CityCode: shopInfo.City,
|
||||
PayeeName: shopInfo.ContactName,
|
||||
Tel1: shopInfo.ContactPhone,
|
||||
Address: shopInfo.ShopAddress,
|
||||
Lng: shopInfo.ShopLng,
|
||||
Lat: shopInfo.ShopLat,
|
||||
},
|
||||
VendorID: model.VendorIDMTPS,
|
||||
VendorStoreID: shopInfo.ShopID,
|
||||
CourierStoreName: shopInfo.ShopName,
|
||||
}
|
||||
}
|
||||
return storeDetail, err
|
||||
}
|
||||
|
||||
func (c *DeliveryHandler) IsErrStoreNotExist(err error) bool {
|
||||
return mtpsapi.IsErrShopNotExist(err)
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||
"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"
|
||||
@@ -31,12 +30,6 @@ var (
|
||||
|
||||
var (
|
||||
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 {
|
||||
@@ -121,36 +114,6 @@ func (c *DeliveryHandler) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (re
|
||||
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.CourierStoreName,
|
||||
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) {
|
||||
db := dao.GetDB()
|
||||
deliveryFeeInfo = &partner.WaybillFeeInfo{}
|
||||
|
||||
@@ -145,6 +145,7 @@ type IOrderManager interface {
|
||||
|
||||
type IStoreManager interface {
|
||||
OnStoreStatusChanged(vendorStoreID string, vendorID int, storeStatus int) (err error)
|
||||
OnCourierStoreStatusChanged(ctx *jxcontext.Context, vendorStoreID string, vendorID int, auditStatus int) (err error)
|
||||
}
|
||||
|
||||
// purchase handler中
|
||||
|
||||
@@ -3,7 +3,9 @@ package partner
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -28,12 +30,19 @@ type CreateWaybillPolicy func(refDeliveryFee, refAddFee, deliveryFee int64) (err
|
||||
type IDeliveryPlatformHandler interface {
|
||||
GetVendorID() int
|
||||
|
||||
CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error)
|
||||
GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error)
|
||||
IsErrStoreNotExist(err error) bool
|
||||
|
||||
CreateWaybill(order *model.GoodsOrder, policy CreateWaybillPolicy) (bill *model.Waybill, err error)
|
||||
CancelWaybill(bill *model.Waybill, cancelReasonID int, cancelReason string) (err error)
|
||||
|
||||
GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *WaybillFeeInfo, err error)
|
||||
}
|
||||
|
||||
type IDeliveryUpdateStoreHandler interface {
|
||||
UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error)
|
||||
}
|
||||
|
||||
type DeliveryPlatformHandlerInfo struct {
|
||||
Handler IDeliveryPlatformHandler
|
||||
Use4CreateWaybill bool
|
||||
|
||||
@@ -335,18 +335,19 @@ func (c *StoreController) DeleteStoreCourierMap() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 根据绑定的京东定,自动创建达达店
|
||||
// @Description 根据绑定的京东定,自动创建达达店
|
||||
// @Title 自动创建或更新快递门店
|
||||
// @Description 自动创建或更新快递门店
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID formData int false "门店ID"
|
||||
// @Param isForceUpdate formData bool false "是否强制更新"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /RefreshMissingDadaStores [put]
|
||||
func (c *StoreController) RefreshMissingDadaStores() {
|
||||
c.callRefreshMissingDadaStores(func(params *tStoreRefreshMissingDadaStoresParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.RefreshMissingDadaStores(params.Ctx, params.StoreID, params.IsAsync, params.IsContinueWhenError)
|
||||
// @router /UpdateOrCreateCourierStores [put]
|
||||
func (c *StoreController) UpdateOrCreateCourierStores() {
|
||||
c.callUpdateOrCreateCourierStores(func(params *tStoreUpdateOrCreateCourierStoresParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.UpdateOrCreateCourierStores(params.Ctx, params.StoreID, params.IsForceUpdate, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,3 +49,16 @@ func (c *MtpsController) Except() {
|
||||
c.Abort("404")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *MtpsController) StoreStatus() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
obj, callbackResponse := api.MtpsAPI.GetShopStatusCallbackMsg(c.Ctx.Request)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = mtps.OnStoreStatus(obj)
|
||||
}
|
||||
c.Data["json"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
} else {
|
||||
c.Abort("404")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1330,15 +1330,6 @@ 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: "RefreshMissingDadaStores",
|
||||
Router: `/RefreshMissingDadaStores`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
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: "TmpGetJxBadComments",
|
||||
@@ -1366,6 +1357,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: "UpdateOrCreateCourierStores",
|
||||
Router: `/UpdateOrCreateCourierStores`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
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: "UpdateStore",
|
||||
|
||||
Reference in New Issue
Block a user