This commit is contained in:
richboo111
2022-11-09 15:42:53 +08:00
parent 9bf424bcac
commit d1a059cd58
4 changed files with 273 additions and 184 deletions

View File

@@ -32,7 +32,7 @@ func CreateWarehouse(appOrgCode string, storeID int64) (warehouseID string, err
if err != nil {
return "", fmt.Errorf("获取门店本地信息失败:%v", err)
}
param := &warehouse_create_request.WarehouseCreateParam{
resp, err := getAPI(appOrgCode, 0, "").CreateWarehouse(&warehouse_create_request.WarehouseCreateParam{
OutWarehouseId: utils.Int64ToStr(storeID), //本地storeID绑定
Name: "京西菜市_" + storeDetail.Name + "_" + utils.Int64ToStr(storeID) + "_区域仓",
Intro: "",
@@ -45,31 +45,26 @@ func CreateWarehouse(appOrgCode string, storeID int64) (warehouseID string, err
},
AddressDetail: storeDetail.Address,
},
}
resp, err := getAPI(appOrgCode, 0, "").CreateWarehouse(param)
})
if err != nil {
return "", fmt.Errorf("创建单个区域仓失败:%v", err)
}
return resp.WarehouseId, nil
}
// /warehouse/createBatch 批量创建区域仓
// /warehouse/createBatch 批量创建区域仓 暂时不使用
func (P *PurchaseHandler) BatchCreateWarehouse(param warehouse_createBatch_request.WarehouseCreateBatchParam, appOrgCode string) error {
infos := []warehouse_createBatch_request.OutWarehouseListItem{}
for _, v := range param.OutWarehouseList {
info := warehouse_createBatch_request.OutWarehouseListItem{
OutWarehouseId: v.OutWarehouseId,
Name: v.Name,
Intro: v.Intro,
AddressDetail: v.AddressDetail,
WarehouseLocation: v.WarehouseLocation,
}
infos = append(infos, info)
}
req := &warehouse_createBatch_request.WarehouseCreateBatchParam{
OutWarehouseList: infos,
OutWarehouseList: []warehouse_createBatch_request.OutWarehouseListItem{
{
OutWarehouseId: param.OutWarehouseList[0].OutWarehouseId,
Name: param.OutWarehouseList[0].Name,
Intro: param.OutWarehouseList[0].Intro,
AddressDetail: param.OutWarehouseList[0].AddressDetail,
WarehouseLocation: param.OutWarehouseList[0].WarehouseLocation,
},
},
}
resp, err := getAPI(appOrgCode, 0, "").BatchCreateWarehouse(req)
if err != nil {
return err
@@ -82,11 +77,10 @@ func (P *PurchaseHandler) BatchCreateWarehouse(param warehouse_createBatch_reque
// /warehouse/bindStore 仓库绑定门店
func BindStoreWarehouse(VendorOrgCode, outWarehouseID string, storeIDs int64) error {
param := &warehouse_bindStore_request.WarehouseBindStoreParam{
if _, err := getAPI(VendorOrgCode, 0, "").StoreBindWarehouse(&warehouse_bindStore_request.WarehouseBindStoreParam{
StoreIds: []int64{storeIDs},
OutWarehouseId: outWarehouseID,
}
if _, err := getAPI(VendorOrgCode, 0, "").StoreBindWarehouse(param); err != nil {
}); err != nil {
return err
}
return nil
@@ -94,11 +88,11 @@ func BindStoreWarehouse(VendorOrgCode, outWarehouseID string, storeIDs int64) er
// /warehouse/getWarehouseByStore 门店id获取绑定仓库详情包括电子围栏
func GetWarehouseByStore(appOrgCode string, storeID int64) (map[int64][]warehouse_getWarehouseByStore_response.WarehouseInfoMapItem, error) {
info, err := getAPI(appOrgCode, 0, "").GetWarehouseByStore(storeID)
if err != nil {
if resp, err := getAPI(appOrgCode, 0, "").GetWarehouseByStore(storeID); err != nil {
return nil, err
} else {
return resp, nil
}
return info, nil
}
type LocalStore struct {
@@ -118,7 +112,6 @@ func CreateFenceByStore(appOrgCode string, storeID int64) (fenceID string, err e
param = &warehouse_createFence_request.WarehouseCreateFenceParam{}
sqlParam = []interface{}{}
)
sqlStr := `SELECT t.lng,t.lat,t.delivery_range_type,t.delivery_range FROM store t`
if storeID != 0 {
sqlStr += " WHERE t.id = ? "
@@ -243,11 +236,10 @@ func UpdateFenceByStore(appOrgCode, outFenceID string, storeID int) error {
//门店直接绑定围栏
func BindFenceByStore(appOrgCode string, storeID int64, addOutFenceIDs []string) error {
param := &warehouse_bindFencesByStore_request.WarehouseBindFencesByStoreParam{
if _, err := getAPI(appOrgCode, 0, "").BindFenceByStore(&warehouse_bindFencesByStore_request.WarehouseBindFencesByStoreParam{
StoreId: storeID,
AddOutFenceIds: addOutFenceIDs,
}
if _, err := getAPI(appOrgCode, 0, "").BindFenceByStore(param); err != nil {
}); err != nil {
return err
}
return nil
@@ -255,22 +247,26 @@ func BindFenceByStore(appOrgCode string, storeID int64, addOutFenceIDs []string)
//获取电子围栏信息
func GetFence(appOrgCode, outFenceID string) (warehouse_getFences_response.FencesItem, error) {
data := warehouse_getFences_response.FencesItem{}
resp, err := getAPI(appOrgCode, 0, "").GetFence(outFenceID)
if err != nil {
return data, err
emptyResp := warehouse_getFences_response.FencesItem{}
if resp, err := getAPI(appOrgCode, 0, "").GetFence(outFenceID); err != nil {
return emptyResp, err
} else {
return resp.Fences[0], nil
}
return resp.Fences[0], nil
}
//特殊处理
func SpecialTreat(vendorOrgCode string, vendorStoreID, storeID, deliveryFeeDeductionFee, minPrice int64) error {
func SpecialTreat(vendorOrgCode string, vendorStoreID, storeID, deliveryFeeDeductionFee, minPrice int64, userName string) error {
var (
errList = errlist.New()
FreightTemplate = &model.FreightTemplate{}
db *dao.DaoDB
errList = errlist.New()
FreightTemplate = &model.FreightTemplate{
VendorStoreID: utils.Int64ToStr(vendorStoreID),
StoreID: int(storeID),
}
)
//首先获取绑定信息
//1.运费模板
bindFreightIDs, err := GetStoreFreight(vendorOrgCode, vendorStoreID)
if err != nil {
globals.SugarLogger.Debug("获取门店(%d) 绑定运费模板出错:", vendorStoreID, err)
@@ -294,13 +290,12 @@ func SpecialTreat(vendorOrgCode string, vendorStoreID, storeID, deliveryFeeDeduc
errList.AddErr(fmt.Errorf("更新运费模板失败:%v", err))
}
}
//设置门店打包费 默认为0
//2.设置门店打包费 默认为0
if err := SetStorePackageFee(vendorOrgCode, vendorStoreID, deliveryFeeDeductionFee); err != nil {
errList.AddErr(fmt.Errorf("设置门店打包费失败:%v", err))
}
//设置门店起送价 默认为0
bindSaleLimitID, err := GetStoreSaleLimit(vendorOrgCode, vendorStoreID)
if err != nil {
//3.设置门店起送价 默认为0
if bindSaleLimitID, err := GetStoreSaleLimit(vendorOrgCode, vendorStoreID); err != nil {
errList.AddErr(fmt.Errorf("获取门店限售模板失败:%v", err))
} else {
if bindSaleLimitID == 0 || utils.IsNil(bindSaleLimitID) { //创建
@@ -317,14 +312,18 @@ func SpecialTreat(vendorOrgCode string, vendorStoreID, storeID, deliveryFeeDeduc
}
}
}
err1 := dao.CreateEntity(db, FreightTemplate)
if err1 != nil {
_, err2 := dao.UpdateEntity(db, FreightTemplate, "TemplateID")
if err2 != nil {
//多次同步数据库,兜底处理
if err := dao.CreateEntity(db, FreightTemplate); err != nil {
_, err1 := dao.UpdateEntity(db, FreightTemplate, "TemplateID", "TradeLimitID")
if err1 != nil {
errList.AddErr(fmt.Errorf("同步进数据库错误信息:%v", err1))
} else {
errList.AddErr(fmt.Errorf("同步进数据库错误信息:%v", err))
}
} else {
dao.WrapAddIDCULDEntity(FreightTemplate, userName)
}
endErr := errList.GetErrListAsOne()
globals.SugarLogger.Debugf("endErr===============%s", endErr)
globals.SugarLogger.Debugf("SpecialTreat wrong information endErr: %s", endErr)
return endErr
}