添加平台门店免运配置,当前只有京东实现了
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/mobile"
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/msg"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
@@ -185,6 +186,24 @@ func checkConfig(opFlag int, configType, key, value string) (err error) {
|
||||
err = fmt.Errorf("配置:%s不合法", value)
|
||||
}
|
||||
}
|
||||
case model.ConfigTypeFreightPack:
|
||||
if value != "" {
|
||||
freightPack := dao.FreightDeductionPack2Obj(value)
|
||||
if freightPack == nil {
|
||||
err = fmt.Errorf("配置:%s不合法", value)
|
||||
} else {
|
||||
var lastStage *model.FreightDeductionItem
|
||||
for _, v := range freightPack.FreightDeductionList {
|
||||
if lastStage != nil && lastStage.DeductFreight > v.DeductFreight {
|
||||
err = fmt.Errorf("免运设置不合理:门槛:%s,免运金额:%s,门槛:%s,免运金额:%s",
|
||||
jxutils.IntPrice2StandardString(int64(lastStage.BeginPrice)), jxutils.IntPrice2StandardString(int64(lastStage.DeductFreight)),
|
||||
jxutils.IntPrice2StandardString(int64(v.BeginPrice)), jxutils.IntPrice2StandardString(int64(v.DeductFreight)))
|
||||
return err
|
||||
}
|
||||
lastStage = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case model.ConfigTypeBank:
|
||||
if value != "" {
|
||||
if model.BankName[key] == "" {
|
||||
@@ -226,11 +245,24 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
||||
case model.ConfigTypePricePack:
|
||||
storeMapList, err := dao.GetStoresMapList(db, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, key)
|
||||
if err == nil {
|
||||
if len(storeMapList) > 0 {
|
||||
var storeInfo []string
|
||||
for _, v := range storeMapList {
|
||||
var storeInfo []string
|
||||
for _, v := range storeMapList {
|
||||
storeInfo = append(storeInfo, fmt.Sprintf("门店:%d, 平台:%s", v.StoreID, model.VendorChineseNames[v.VendorID]))
|
||||
}
|
||||
if len(storeInfo) > 0 {
|
||||
err = fmt.Errorf("还有门店在使用价格包:%s,门店信息:%s", key, strings.Join(storeInfo, ","))
|
||||
}
|
||||
}
|
||||
case model.ConfigTypeFreightPack:
|
||||
storeMapList, err := dao.GetStoresMapList(db, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
|
||||
if err == nil {
|
||||
var storeInfo []string
|
||||
for _, v := range storeMapList {
|
||||
if v.FreightDeductionPack == key {
|
||||
storeInfo = append(storeInfo, fmt.Sprintf("门店:%d, 平台:%s", v.StoreID, model.VendorChineseNames[v.VendorID]))
|
||||
}
|
||||
}
|
||||
if len(storeInfo) > 0 {
|
||||
err = fmt.Errorf("还有门店在使用价格包:%s,门店信息:%s", key, strings.Join(storeInfo, ","))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -829,6 +829,7 @@ func GetStoreVendorMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, vend
|
||||
return storeMaps, dao.GetEntitiesByKV(db, &storeMaps, cond, false)
|
||||
}
|
||||
|
||||
// todo 需要对字段做有效性检查
|
||||
func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeMap *model.StoreMap) (outStoreMap *model.StoreMap, err error) {
|
||||
if storeID == 0 {
|
||||
return nil, fmt.Errorf("storeID不能为0")
|
||||
@@ -923,14 +924,26 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
if valid["status"] != nil {
|
||||
syncStatus |= model.SyncFlagStoreStatus
|
||||
}
|
||||
if valid["pricePercentagePack"] != nil {
|
||||
if pricePercentagePack := utils.Interface2String(valid["pricePercentagePack"]); pricePercentagePack != "" {
|
||||
_, err2 := dao.QueryConfigs(db, pricePercentagePack, model.ConfigTypePricePack, "")
|
||||
if err = err2; err != nil {
|
||||
return 0, err
|
||||
for _, v := range [][]string{
|
||||
[]string{
|
||||
"pricePercentagePack",
|
||||
model.ConfigTypePricePack,
|
||||
},
|
||||
[]string{
|
||||
"freightDeductionPack",
|
||||
model.ConfigTypeFreightPack,
|
||||
},
|
||||
} {
|
||||
if valid[v[0]] != nil {
|
||||
if value := utils.Interface2String(valid[v[0]]); value != "" {
|
||||
_, err2 := dao.QueryConfigs(db, value, v[1], "")
|
||||
if err = err2; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if vendorStoreID := utils.Interface2String(valid["vendorStoreID"]); vendorStoreID != "" {
|
||||
vendorStoreInfo, err2 := storeHandler.ReadStore(ctx, vendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
|
||||
@@ -23,6 +23,9 @@ type StoreDetail struct {
|
||||
PricePercentagePackStr string `orm:"size(4096)" json:"-"` //
|
||||
PricePercentagePackObj model.PricePercentagePack `orm:"-" json:"-"`
|
||||
|
||||
FreightDeductionPackStr string `orm:"size(4096)" json:"-"` //
|
||||
FreightDeductionPackObj *model.FreightDeductionPack `orm:"-" json:"-"`
|
||||
|
||||
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
||||
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
||||
DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争
|
||||
@@ -61,7 +64,9 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee, t2.sync_status,
|
||||
t2.price_percentage, t3.value price_percentage_pack_str, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync,
|
||||
t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync,
|
||||
t3.value price_percentage_pack_str,
|
||||
t4.value freight_deduction_pack_str,
|
||||
district.name district_name,
|
||||
city.name city_name
|
||||
FROM store t1
|
||||
@@ -69,6 +74,7 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
||||
LEFT JOIN place city ON city.code = t1.city_code
|
||||
LEFT JOIN place district ON district.code = t1.district_code
|
||||
LEFT JOIN new_config t3 ON t3.key = t2.price_percentage_pack AND t3.type = ? AND t3.deleted_at = ?
|
||||
LEFT JOIN new_config t4 ON t4.key = t2.freight_deduction_pack AND t4.type = ? AND t4.deleted_at = ?
|
||||
WHERE t1.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
@@ -76,6 +82,8 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
||||
utils.DefaultTimeValue,
|
||||
model.ConfigTypePricePack,
|
||||
utils.DefaultTimeValue,
|
||||
model.ConfigTypeFreightPack,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if vendorID != model.VendorIDJX {
|
||||
@@ -92,6 +100,7 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
||||
storeDetail = &StoreDetail{}
|
||||
if err = GetRow(db, storeDetail, sql, sqlParams...); err == nil {
|
||||
storeDetail.PricePercentagePackObj = PricePercentagePack2Obj(storeDetail.PricePercentagePackStr)
|
||||
storeDetail.FreightDeductionPackObj = FreightDeductionPack2Obj(storeDetail.FreightDeductionPackStr)
|
||||
return storeDetail, nil
|
||||
}
|
||||
return nil, err
|
||||
@@ -517,3 +526,12 @@ func GetCityBankBranches(db *DaoDB, cityCode int, bankCode string) (list []*City
|
||||
err = GetRows(db, &list, sql, sqlParams...)
|
||||
return list, err
|
||||
}
|
||||
|
||||
func FreightDeductionPack2Obj(packStr string) (obj *model.FreightDeductionPack) {
|
||||
if packStr != "" {
|
||||
if err := utils.UnmarshalUseNumber([]byte(packStr), &obj); err == nil {
|
||||
sort.Sort(obj)
|
||||
}
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
ConfigTypeSys = "Sys"
|
||||
ConfigTypePricePack = "PricePack"
|
||||
ConfigTypeBank = "Bank"
|
||||
ConfigTypeRole = "Role"
|
||||
ConfigTypeSys = "Sys"
|
||||
ConfigTypePricePack = "PricePack"
|
||||
ConfigTypeFreightPack = "FreightPack"
|
||||
ConfigTypeBank = "Bank"
|
||||
ConfigTypeRole = "Role"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -13,10 +14,11 @@ const (
|
||||
|
||||
var (
|
||||
ConfigTypeName = map[string]string{
|
||||
ConfigTypeSys: "系统",
|
||||
ConfigTypePricePack: "价格包",
|
||||
ConfigTypeBank: "银行",
|
||||
ConfigTypeRole: "角色",
|
||||
ConfigTypeSys: "系统",
|
||||
ConfigTypePricePack: "价格包",
|
||||
ConfigTypeFreightPack: "免运包",
|
||||
ConfigTypeBank: "银行",
|
||||
ConfigTypeRole: "角色",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -366,6 +366,8 @@ type StoreMap struct {
|
||||
PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格
|
||||
PricePercentagePack string `orm:"size(32)" json:"pricePercentagePack"` //
|
||||
|
||||
FreightDeductionPack string `orm:"size(32)" json:"freightDeductionPack"` //
|
||||
|
||||
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
||||
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
||||
DeliveryFee int `json:"deliveryFee"`
|
||||
@@ -454,7 +456,7 @@ func (v *VendorStoreSnapshot) CompareOperationTime(s2 *VendorStoreSnapshot) int
|
||||
}
|
||||
|
||||
type PricePercentageItem struct {
|
||||
BeginPrice int `json:"beginPrice"` // 启始价格区间(包括)
|
||||
BeginPrice int `json:"beginPrice"` // 起始价格区间(包括)
|
||||
PricePercentage int `json:"pricePercentage"` // 调价比例
|
||||
}
|
||||
|
||||
@@ -476,3 +478,31 @@ func (l PricePercentagePack) Swap(i, j int) {
|
||||
l[i] = l[j]
|
||||
l[j] = tmp
|
||||
}
|
||||
|
||||
type FreightDeductionItem struct {
|
||||
BeginPrice int `json:"beginPrice"` // 起始价格区间(包括)
|
||||
DeductFreight int `json:"deductFreight"` // 减免运费
|
||||
}
|
||||
|
||||
type FreightDeductionPack struct {
|
||||
StartPrice int `json:"startPrice"` // 起送价
|
||||
FreightDeductionList []*FreightDeductionItem `json:"freightDeductionList"`
|
||||
}
|
||||
|
||||
func (l *FreightDeductionPack) Len() int {
|
||||
return len(l.FreightDeductionList)
|
||||
}
|
||||
|
||||
// Less reports whether the element with
|
||||
// index i should sort before the element with index j.
|
||||
func (l *FreightDeductionPack) Less(i, j int) bool {
|
||||
return l.FreightDeductionList[i].BeginPrice < l.FreightDeductionList[j].BeginPrice
|
||||
}
|
||||
|
||||
// Swap swaps the elements with indexes i and j.
|
||||
func (l *FreightDeductionPack) Swap(i, j int) {
|
||||
l2 := l.FreightDeductionList
|
||||
tmp := l2[i]
|
||||
l2[i] = l2[j]
|
||||
l2[j] = tmp
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ const (
|
||||
|
||||
type tJdStoreInfo struct {
|
||||
model.Store
|
||||
|
||||
FreightDeductionPack string `orm:"size(32)" json:"freightDeductionPack"` //
|
||||
|
||||
JdCityCode int
|
||||
JdDistrictCode int
|
||||
JdStoreStatus int
|
||||
@@ -105,8 +108,9 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorStoreID string
|
||||
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
|
||||
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
|
||||
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
|
||||
FROM store t1
|
||||
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND (t2.deleted_at = ?)
|
||||
LEFT JOIN place city ON t1.city_code = city.code
|
||||
@@ -160,6 +164,33 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
return err
|
||||
}
|
||||
}
|
||||
if store.FreightDeductionPack != "" {
|
||||
storeDetail, err2 := dao.GetStoreDetail(db, store.ID, model.VendorIDJD)
|
||||
if err2 == nil {
|
||||
if storeDetail.FreightDeductionPackObj != nil {
|
||||
freightParams := &jdapi.UpdateStoreFreightParam{
|
||||
StationNo: store.VendorStoreID,
|
||||
UserPin: userName,
|
||||
OpenDistanceFreight: true,
|
||||
IsFullFree: len(storeDetail.FreightDeductionPackObj.FreightDeductionList) > 0,
|
||||
StartCharge: int64(storeDetail.FreightDeductionPackObj.StartPrice),
|
||||
}
|
||||
if freightParams.IsFullFree {
|
||||
for _, v := range storeDetail.FreightDeductionPackObj.FreightDeductionList {
|
||||
freightParams.FreeFreightInfoList = append(freightParams.FreeFreightInfoList, &jdapi.FreeFreightInfo{
|
||||
FullFreeMoney: int64(v.BeginPrice),
|
||||
FreeType: jdapi.FreightFreeTypePartBase,
|
||||
FreeMoney: int64(v.DeductFreight),
|
||||
})
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(freightParams, false))
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateStoreFreightConfigNew(freightParams)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user