- 使用mapstructure进行map到struct的映射,简化API编写
This commit is contained in:
@@ -28,32 +28,32 @@ type ActivityRule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ActivityInfo struct {
|
type ActivityInfo struct {
|
||||||
ActivityID int64 `json:"-"`
|
ActivityID int64 `json:"activityID,omitempty"`
|
||||||
ActivityName string `json:"activity_name"`
|
ActivityName string `json:"activity_name"`
|
||||||
ActivityType int `json:"activity_type"`
|
ActivityType int `json:"activity_type"`
|
||||||
StartTime int64 `json:"start_time"` // 活动开始时间,时间戳,需大于当前时间。
|
StartTime int64 `json:"start_time"` // 活动开始时间,时间戳,需大于当前时间。
|
||||||
EndTime int64 `json:"end_time"`
|
EndTime int64 `json:"end_time"`
|
||||||
OpenTime string `json:"open_time"` // "22:47"
|
OpenTime string `json:"open_time,omitempty"` // "22:47"
|
||||||
CloseTime string `json:"close_time"`
|
CloseTime string `json:"close_time,omitempty"`
|
||||||
WeekDay string `json:"weekday"` // 活动开始时间段内,每周具体星期几支持,默认活动生效时间段内全周支持。0,1,2,3,4,5,6代表周日到周六。
|
WeekDay string `json:"weekday,omitempty"` // 活动开始时间段内,每周具体星期几支持,默认活动生效时间段内全周支持。0,1,2,3,4,5,6代表周日到周六。
|
||||||
ActivityPlatform int `json:"activity_platform"`
|
ActivityPlatform int `json:"activity_platform,omitempty"`
|
||||||
IsConflictActivity int `json:"is_conflict_activity"`
|
IsConflictActivity int `json:"is_conflict_activity,omitempty"`
|
||||||
DayLimit int `json:"day_limit"` // 每日限购X单,1-1000整数。
|
DayLimit int `json:"day_limit,omitempty"` // 每日限购X单,1-1000整数。
|
||||||
OrderLimit int `json:"order_limit"` // 每单限购商品数量。直降用到,满减没用到。1-1000整数。
|
OrderLimit int `json:"order_limit,omitempty"` // 每单限购商品数量。直降用到,满减没用到。1-1000整数。
|
||||||
ActivityDesc string `json:"activity_desc"`
|
ActivityDesc string `json:"activity_desc,omitempty"`
|
||||||
ShowCategory string `json:"show_category"`
|
ShowCategory string `json:"show_category,omitempty"`
|
||||||
PromotionSkuDesc string `json:"promotion_sku_desc"` // 店铺页活动商品的分类名称,不超过8个字。
|
PromotionSkuDesc string `json:"promotion_sku_desc,omitempty"` // 店铺页活动商品的分类名称,不超过8个字。
|
||||||
Rule []*ActivityRule `json:"rule"`
|
Rule []*ActivityRule `json:"rule,omitempty"`
|
||||||
|
|
||||||
BaiduShopID int64 `json:"-"`
|
BaiduShopID int64 `json:"baiduShopID,omitempty"`
|
||||||
ShowStatus int `json:"-"`
|
ShowStatus int `json:"showStatus,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActivitySkuInfo struct {
|
type ActivitySkuInfo struct {
|
||||||
SkuID string `json:"sku_id"`
|
SkuID string `json:"sku_id"`
|
||||||
Stock int `json:"stock"`
|
Stock int `json:"stock"`
|
||||||
|
|
||||||
PromotionPrice float32 `json:"special_price"` // 直降用
|
PromotionPrice float32 `json:"special_price"` // 直降用,复用
|
||||||
StoreUserLimit int `json:"store_user_limit"` // 直降用
|
StoreUserLimit int `json:"store_user_limit"` // 直降用
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,18 +78,8 @@ type ActivitySkuListInfo struct {
|
|||||||
SkuList []*ActivitySkuInfoEx `json:"sku_list"`
|
SkuList []*ActivitySkuInfoEx `json:"sku_list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
ignoreActivityInfo = ActivityInfo{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (a *API) ActivityCreate(shopID string, baiduShopID, supplierID int64, activity *ActivityInfo) (activityID int64, err error) {
|
func (a *API) ActivityCreate(shopID string, baiduShopID, supplierID int64, activity *ActivityInfo) (activityID int64, err error) {
|
||||||
params := utils.Struct2MapWithIgnore(activity, map[string]interface{}{
|
params := utils.Struct2FlatMap(activity)
|
||||||
"open_time": ignoreActivityInfo.OpenTime,
|
|
||||||
"close_time": ignoreActivityInfo.CloseTime,
|
|
||||||
"is_conflict_activity": ignoreActivityInfo.IsConflictActivity,
|
|
||||||
"order_limit": ignoreActivityInfo.OrderLimit,
|
|
||||||
"rule": ignoreActivityInfo.Rule,
|
|
||||||
})
|
|
||||||
result, err := a.AccessAPI("activity.create", utils.MergeMaps(params, a.genShopIDParams(shopID, baiduShopID, supplierID)))
|
result, err := a.AccessAPI("activity.create", utils.MergeMaps(params, a.genShopIDParams(shopID, baiduShopID, supplierID)))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return utils.Str2Int64(utils.Interface2String(result.Data.(map[string]interface{})["activity_id"])), nil
|
return utils.Str2Int64(utils.Interface2String(result.Data.(map[string]interface{})["activity_id"])), nil
|
||||||
@@ -98,18 +88,7 @@ func (a *API) ActivityCreate(shopID string, baiduShopID, supplierID int64, activ
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ActivityUpdate(activityID int64, shopID string, baiduShopID, supplierID int64, activity *ActivityInfo) (newActivityID int64, err error) {
|
func (a *API) ActivityUpdate(activityID int64, shopID string, baiduShopID, supplierID int64, activity *ActivityInfo) (newActivityID int64, err error) {
|
||||||
params := utils.Struct2MapWithIgnore(activity, map[string]interface{}{
|
params := utils.Struct2FlatMap(activity)
|
||||||
"open_time": ignoreActivityInfo.OpenTime,
|
|
||||||
"close_time": ignoreActivityInfo.CloseTime,
|
|
||||||
"weekday": ignoreActivityInfo.WeekDay,
|
|
||||||
"day_limit": ignoreActivityInfo.DayLimit,
|
|
||||||
"order_limit": ignoreActivityInfo.OrderLimit,
|
|
||||||
"activity_desc": ignoreActivityInfo.ActivityDesc,
|
|
||||||
"show_category": ignoreActivityInfo.ShowCategory,
|
|
||||||
"promotion_sku_desc": ignoreActivityInfo.PromotionSkuDesc,
|
|
||||||
"is_conflict_activity": ignoreActivityInfo.IsConflictActivity,
|
|
||||||
"rule": ignoreActivityInfo.Rule,
|
|
||||||
})
|
|
||||||
params[KeyActivityID] = activityID
|
params[KeyActivityID] = activityID
|
||||||
result, err := a.AccessAPI("activity.update", utils.MergeMaps(params, a.genShopIDParams(shopID, baiduShopID, supplierID)))
|
result, err := a.AccessAPI("activity.update", utils.MergeMaps(params, a.genShopIDParams(shopID, baiduShopID, supplierID)))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -130,39 +109,10 @@ func (a *API) ActivityGet(activityID int64, shopID string, baiduShopID, supplier
|
|||||||
params[KeyActivityID] = activityID
|
params[KeyActivityID] = activityID
|
||||||
result, err := a.AccessAPI("activity.get", params)
|
result, err := a.AccessAPI("activity.get", params)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dataMap := result.Data.(map[string]interface{})
|
activityInfo = &ActivityInfo{}
|
||||||
activityInfo = &ActivityInfo{
|
err = utils.Map2StructByJson(result.Data, activityInfo, true)
|
||||||
ActivityID: utils.Str2Int64(utils.Interface2String(dataMap["activity_id"])),
|
|
||||||
ActivityName: utils.Interface2String(dataMap["activity_name"]),
|
|
||||||
ActivityType: int(utils.Str2Int64(utils.Interface2String(dataMap["activity_type"]))),
|
|
||||||
StartTime: utils.Str2Int64(utils.Interface2String(dataMap["start_time"])),
|
|
||||||
EndTime: utils.Str2Int64(utils.Interface2String(dataMap["end_time"])),
|
|
||||||
OpenTime: utils.Interface2String(dataMap["open_time"]),
|
|
||||||
CloseTime: utils.Interface2String(dataMap["close_time"]),
|
|
||||||
WeekDay: utils.Interface2String(dataMap["weekday"]),
|
|
||||||
ActivityPlatform: int(utils.Str2Int64(utils.Interface2String(dataMap["activity_platform"]))),
|
|
||||||
IsConflictActivity: int(utils.Str2Int64(utils.Interface2String(dataMap["is_conflict_activity"]))),
|
|
||||||
DayLimit: int(utils.Str2Int64(utils.Interface2String(dataMap["day_limit"]))),
|
|
||||||
OrderLimit: int(utils.Str2Int64(utils.Interface2String(dataMap["order_limit"]))),
|
|
||||||
ActivityDesc: utils.Interface2String(dataMap["activity_desc"]),
|
|
||||||
ShowCategory: utils.Interface2String(dataMap["show_category"]),
|
|
||||||
PromotionSkuDesc: utils.Interface2String(dataMap["promotion_sku_desc"]),
|
|
||||||
|
|
||||||
BaiduShopID: utils.Str2Int64(utils.Interface2String(dataMap["baidu_shop_id"])),
|
|
||||||
ShowStatus: int(utils.Str2Int64(utils.Interface2String(dataMap["show_status"]))),
|
|
||||||
}
|
|
||||||
if rule, ok := dataMap["rule"].([]interface{}); ok {
|
|
||||||
for _, v := range rule {
|
|
||||||
vMap := v.(map[string]interface{})
|
|
||||||
activityInfo.Rule = append(activityInfo.Rule, &ActivityRule{
|
|
||||||
Accords: int(utils.MustInterface2Int64(vMap["accords"])),
|
|
||||||
Sale: int(utils.MustInterface2Int64(vMap["sale"])),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return activityInfo, nil
|
|
||||||
}
|
}
|
||||||
return nil, err
|
return activityInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ActivitySkuAddBatch(activityID int64, shopID string, baiduShopID int64, activityType int, skuList []*ActivitySkuInfo, isSkuIDCustom bool) (successIDs []string, err error) {
|
func (a *API) ActivitySkuAddBatch(activityID int64, shopID string, baiduShopID int64, activityType int, skuList []*ActivitySkuInfo, isSkuIDCustom bool) (successIDs []string, err error) {
|
||||||
@@ -229,6 +179,15 @@ func (a *API) ActivitySkuList(activityID int64, shopID string, baiduShopID, supp
|
|||||||
params["page"] = page
|
params["page"] = page
|
||||||
result, err = a.AccessAPI("activity.sku.list", params)
|
result, err = a.AccessAPI("activity.sku.list", params)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
// tmpActivityInfo := &ActivitySkuListInfo{}
|
||||||
|
// if err = utils.Map2StructByJson(result.Data, tmpActivityInfo, true); err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// if activityInfo == nil {
|
||||||
|
// activityInfo = tmpActivityInfo
|
||||||
|
// } else {
|
||||||
|
// activityInfo.SkuList = append(activityInfo.SkuList, tmpActivityInfo.SkuList...)
|
||||||
|
// }
|
||||||
resultMap := result.Data.(map[string]interface{})
|
resultMap := result.Data.(map[string]interface{})
|
||||||
if activityInfo == nil {
|
if activityInfo == nil {
|
||||||
activityInfo = &ActivitySkuListInfo{
|
activityInfo = &ActivitySkuListInfo{
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ type OrderDiscountGift struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OrderDiscountRuleRequest struct {
|
type OrderDiscountRuleRequest struct {
|
||||||
LowerLimitAmount int `json:"lowerLimitAmount"`
|
LowerLimitAmount int `json:"lowerLimitAmount,omitempty"`
|
||||||
DiscountAmount int `json:"discountAmount"`
|
DiscountAmount int `json:"discountAmount,omitempty"`
|
||||||
UpperLimitCount int `json:"upperLimitCount"`
|
UpperLimitCount int `json:"upperLimitCount,omitempty"`
|
||||||
LowerLimitCount int `json:"lowerLimitCount"`
|
LowerLimitCount int `json:"lowerLimitCount,omitempty"`
|
||||||
DiscountRate float32 `json:"discountRate"`
|
DiscountRate float32 `json:"discountRate,omitempty"`
|
||||||
AddPrice int `json:"addPrice"` // 分
|
AddPrice int `json:"addPrice,omitempty"` // 分
|
||||||
GiftList []*OrderDiscountGift `json:"giftList"`
|
GiftList []*OrderDiscountGift `json:"giftList,omitempty"`
|
||||||
LadderLimit int `json:"ladderLimit"`
|
LadderLimit int `json:"ladderLimit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderDiscountActivity struct {
|
type OrderDiscountActivity struct {
|
||||||
@@ -42,14 +42,14 @@ type OrderDiscountActivity struct {
|
|||||||
BeginTime string `json:"beginTime"` // 必须
|
BeginTime string `json:"beginTime"` // 必须
|
||||||
EndTime string `json:"endTime"` // 必须
|
EndTime string `json:"endTime"` // 必须
|
||||||
ParticipationMode int `json:"participationMode"` // 必须
|
ParticipationMode int `json:"participationMode"` // 必须
|
||||||
OutStationNos []string `json:"outStationNos"`
|
OutStationNos []string `json:"outStationNos,omitempty"`
|
||||||
StationNos []string `json:"stationNos"`
|
StationNos []string `json:"stationNos,omitempty"`
|
||||||
OutSkuIds []string `json:"outSkuIds"`
|
OutSkuIds []string `json:"outSkuIds,omitempty"`
|
||||||
SkuIds []string `json:"skuIds"`
|
SkuIds []string `json:"skuIds,omitempty"`
|
||||||
LimitOrderTotalNumber int `json:"limitOrderTotalNumber"` // 必须
|
LimitOrderTotalNumber int `json:"limitOrderTotalNumber"` // 必须
|
||||||
LimitUserTotalNumber int `json:"limitUserTotalNumber"`
|
LimitUserTotalNumber int `json:"limitUserTotalNumber,omitempty"`
|
||||||
Display string `json:"display"` // 必须
|
Display string `json:"display"` // 必须
|
||||||
RuleRequestList []*OrderDiscountRuleRequest `json:"ruleRequestList"`
|
RuleRequestList []*OrderDiscountRuleRequest `json:"ruleRequestList,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActivityOpResultInfo struct {
|
type ActivityOpResultInfo struct {
|
||||||
@@ -82,31 +82,8 @@ type ActivityOpQueryInfoResponse struct {
|
|||||||
LadderList []int `json:"ladderList"`
|
LadderList []int `json:"ladderList"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
ignoreOrderDiscountActivity = OrderDiscountActivity{}
|
|
||||||
ignoreOrderDiscountRuleRequest = OrderDiscountRuleRequest{}
|
|
||||||
|
|
||||||
ignoreOrderDiscountSubmitActivityMap = map[string]interface{}{
|
|
||||||
"outStationNos": ignoreOrderDiscountActivity.OutStationNos,
|
|
||||||
"stationNos": ignoreOrderDiscountActivity.StationNos,
|
|
||||||
"outSkuIds": ignoreOrderDiscountActivity.OutSkuIds,
|
|
||||||
"skuIds": ignoreOrderDiscountActivity.SkuIds,
|
|
||||||
"limitUserTotalNumber": ignoreOrderDiscountActivity.LimitUserTotalNumber,
|
|
||||||
"ruleRequestList": ignoreOrderDiscountActivity.RuleRequestList,
|
|
||||||
|
|
||||||
"lowerLimitAmount": ignoreOrderDiscountRuleRequest.LowerLimitAmount,
|
|
||||||
"discountAmount": ignoreOrderDiscountRuleRequest.DiscountAmount,
|
|
||||||
"upperLimitCount": ignoreOrderDiscountRuleRequest.UpperLimitCount,
|
|
||||||
"lowerLimitCount": ignoreOrderDiscountRuleRequest.LowerLimitCount,
|
|
||||||
"discountRate": ignoreOrderDiscountRuleRequest.DiscountRate,
|
|
||||||
"addPrice": ignoreOrderDiscountRuleRequest.AddPrice,
|
|
||||||
"giftList": ignoreOrderDiscountRuleRequest.GiftList,
|
|
||||||
"ladderLimit": ignoreOrderDiscountRuleRequest.LadderLimit,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (a *API) OrderDiscountSubmitActivity(actInfo *OrderDiscountActivity) (activityID int64, err error) {
|
func (a *API) OrderDiscountSubmitActivity(actInfo *OrderDiscountActivity) (activityID int64, err error) {
|
||||||
result, err := a.AccessAPINoPage("orderdiscount/submitActivity", utils.Struct2MapWithIgnore(actInfo, ignoreOrderDiscountSubmitActivityMap), nil, nil, nil)
|
result, err := a.AccessAPINoPage("orderdiscount/submitActivity", utils.Struct2FlatMap(actInfo), nil, nil, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return utils.MustInterface2Int64((result.(map[string]interface{}))["activityId"]), nil
|
return utils.MustInterface2Int64((result.(map[string]interface{}))["activityId"]), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,10 +86,10 @@ type ShippingFeeActDetail struct {
|
|||||||
type ShippingFeeActData struct {
|
type ShippingFeeActData struct {
|
||||||
StartTime int64 `json:"start_time"` // 活动开始时间,单s位秒
|
StartTime int64 `json:"start_time"` // 活动开始时间,单s位秒
|
||||||
EndTime int64 `json:"end_time"` // 活动结束时间,单位秒
|
EndTime int64 `json:"end_time"` // 活动结束时间,单位秒
|
||||||
WeeksTime string `json:"weeks_time"`
|
WeeksTime string `json:"weeks_time,omitempty"`
|
||||||
Period string `json:"period"`
|
Period string `json:"period,omitempty"`
|
||||||
ActDetail []*ShippingFeeActDetail `json:"act_detail"`
|
ActDetail []*ShippingFeeActDetail `json:"act_detail"`
|
||||||
MaxPrice float64 `json:"max_price"`
|
MaxPrice float64 `json:"max_price,omitempty"`
|
||||||
|
|
||||||
AppPoiCode string `json:"-"`
|
AppPoiCode string `json:"-"`
|
||||||
ActID string `json:"-"`
|
ActID string `json:"-"`
|
||||||
@@ -108,8 +108,8 @@ type RetailActData struct {
|
|||||||
SettingType int `json:"setting_type"`
|
SettingType int `json:"setting_type"`
|
||||||
ActPrice float64 `json:"act_price"` // 折扣价格(单位元):必须为大于0的数字,且不能超过2位小数。
|
ActPrice float64 `json:"act_price"` // 折扣价格(单位元):必须为大于0的数字,且不能超过2位小数。
|
||||||
DiscountCoefficient float64 `json:"discount_coefficient"` // 折扣系数:必须大于0小于9.8,最多支持两位小数。如输入3,即为3折
|
DiscountCoefficient float64 `json:"discount_coefficient"` // 折扣系数:必须大于0小于9.8,最多支持两位小数。如输入3,即为3折
|
||||||
Sequence int `json:"sequence"`
|
Sequence int `json:"sequence,omitempty"`
|
||||||
ItemID int64 `json:"item_id"` // 活动ID,为什么这里又是int64
|
ItemID int64 `json:"item_id,omitempty"` // 活动ID,为什么这里又是int64
|
||||||
|
|
||||||
// 以下参数只有查询时用到
|
// 以下参数只有查询时用到
|
||||||
OriginalPrice float64 `json:"-"` // 商品原价,单位元
|
OriginalPrice float64 `json:"-"` // 商品原价,单位元
|
||||||
@@ -119,17 +119,11 @@ type RetailActData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RetailActDataLimit struct {
|
type RetailActDataLimit struct {
|
||||||
ItemID int64 `json:"item_id"` // 活动ID,为什么这里又是int64
|
ItemID int64 `json:"item_id"` // 活动ID,为什么这里又是int64
|
||||||
DayLimit int `json:"day_limit"` // 当日活动库存,只能为正整数或-1,-1表示无限库存
|
DayLimit int `json:"day_limit,omitempty"` // 当日活动库存,只能为正整数或-1,-1表示无限库存
|
||||||
OrderLimit int `json:"order_limit"` // 每单可购买的折扣商品数量
|
OrderLimit int `json:"order_limit,omitempty"` // 每单可购买的折扣商品数量
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
ignoreShippingFeeActData = ShippingFeeActData{}
|
|
||||||
ignoreRetailActData = &RetailActData{}
|
|
||||||
ignoreRetailActDataLimit = &RetailActDataLimit{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (a *API) FullDiscountBatchSave(poiCode string, actInfo *FullDiscountActInfo, actList []*FullDiscountActDetail, actSkuList []*FullDiscountSku) (actID int64, err error) {
|
func (a *API) FullDiscountBatchSave(poiCode string, actInfo *FullDiscountActInfo, actList []*FullDiscountActDetail, actSkuList []*FullDiscountSku) (actID int64, err error) {
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
KeyAppPoiCode: poiCode,
|
KeyAppPoiCode: poiCode,
|
||||||
@@ -152,43 +146,11 @@ func (a *API) FullDiscountList(poiCode string, actType int) (actInfoList []*Full
|
|||||||
"act_type": actType,
|
"act_type": actType,
|
||||||
})
|
})
|
||||||
if err == nil && result != nil {
|
if err == nil && result != nil {
|
||||||
for _, v := range result.([]interface{}) {
|
err = utils.Map2StructByJson(result, &actInfoList, false)
|
||||||
actMap := v.(map[string]interface{})
|
|
||||||
actWholeInfo := &FullDiscountActData{
|
|
||||||
ActInfo: interface2ActInfo(actMap["act_info"]),
|
|
||||||
ActRemark: utils.Interface2String(actMap["act_remark"]),
|
|
||||||
AppPoiCode: utils.Interface2String(actMap["app_poi_code"]),
|
|
||||||
}
|
|
||||||
actInfoList = append(actInfoList, actWholeInfo)
|
|
||||||
for _, v := range actMap["act_details"].([]interface{}) {
|
|
||||||
vMap := v.(map[string]interface{})
|
|
||||||
actWholeInfo.ActDetails = append(actWholeInfo.ActDetails, &FullDiscountActDetail{
|
|
||||||
OriginalPrice: float64(utils.MustInterface2Float64(vMap["origin_price"])),
|
|
||||||
ActPrice: float64(utils.MustInterface2Float64(vMap["act_price"])),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// decoder, _ := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
|
||||||
// TagName: "json",
|
|
||||||
// Result: &actInfoList,
|
|
||||||
// })
|
|
||||||
// if err = decoder.Decode(result); err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return actInfoList, err
|
return actInfoList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func interface2ActInfo(actInfo interface{}) *FullDiscountActInfo {
|
|
||||||
actInfoMap := actInfo.(map[string]interface{})
|
|
||||||
return &FullDiscountActInfo{
|
|
||||||
ActIDs: utils.Interface2String(actInfoMap["act_ids"]),
|
|
||||||
StartTime: utils.MustInterface2Int64(actInfoMap["start_time"]),
|
|
||||||
EndTime: utils.MustInterface2Int64(actInfoMap["end_time"]),
|
|
||||||
Status: int(utils.MustInterface2Int64(actInfoMap["status"])),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *API) FullDiscountDelete(poiCode string, actIDList []string, actType int) (err error) {
|
func (a *API) FullDiscountDelete(poiCode string, actIDList []string, actType int) (err error) {
|
||||||
_, err = a.AccessAPI("act/full/discount/delete", false, map[string]interface{}{
|
_, err = a.AccessAPI("act/full/discount/delete", false, map[string]interface{}{
|
||||||
KeyAppPoiCode: poiCode,
|
KeyAppPoiCode: poiCode,
|
||||||
@@ -219,15 +181,15 @@ func (a *API) FullDiscountFoodsList(poiCode, actID string) (actFoodsInfo *FullDi
|
|||||||
"offset": offset,
|
"offset": offset,
|
||||||
})
|
})
|
||||||
if err == nil && result != nil {
|
if err == nil && result != nil {
|
||||||
resultMap := result.(map[string]interface{})
|
tmpActFoodsInfo := &FullDiscountFoodsInfo{}
|
||||||
if actFoodsInfo == nil {
|
if err = utils.Map2StructByJson(result, tmpActFoodsInfo, false); err != nil {
|
||||||
actFoodsInfo = &FullDiscountFoodsInfo{
|
return nil, err
|
||||||
ActInfo: interface2ActInfo(resultMap["act_info"]),
|
}
|
||||||
ActRemark: utils.Interface2String(resultMap["act_remark"]),
|
if actFoodsInfo == nil {
|
||||||
AppPoiCode: utils.Interface2String(resultMap["app_poi_code"]),
|
actFoodsInfo = tmpActFoodsInfo
|
||||||
}
|
} else {
|
||||||
|
actFoodsInfo.AppFoods = append(actFoodsInfo.AppFoods, tmpActFoodsInfo.AppFoods...)
|
||||||
}
|
}
|
||||||
actFoodsInfo.AppFoods = append(actFoodsInfo.AppFoods, interface2SkuInfoList(resultMap["app_foods"])...)
|
|
||||||
offset++
|
offset++
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
@@ -237,18 +199,6 @@ func (a *API) FullDiscountFoodsList(poiCode, actID string) (actFoodsInfo *FullDi
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func interface2SkuInfoList(value interface{}) (actSkuList []*FullDiscountSku) {
|
|
||||||
for _, v := range value.([]interface{}) {
|
|
||||||
vMap := v.(map[string]interface{})
|
|
||||||
actSkuList = append(actSkuList, &FullDiscountSku{
|
|
||||||
AppFoodCode: utils.Interface2String(vMap["app_food_code"]),
|
|
||||||
DayLimit: int(utils.Interface2Int64WithDefault(vMap["day_limit"], 0)),
|
|
||||||
Name: utils.Interface2String(vMap["name"]),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return actSkuList
|
|
||||||
}
|
|
||||||
|
|
||||||
// 批量删除活动商品至指定商品满减活动
|
// 批量删除活动商品至指定商品满减活动
|
||||||
// appFoodCodeList 删除商品数量上限为100,如果删除门店多个活动商品,用英文逗号隔开
|
// appFoodCodeList 删除商品数量上限为100,如果删除门店多个活动商品,用英文逗号隔开
|
||||||
func (a *API) FullDiscountFoodsDelete(poiCode, actID string, appFoodCodeList []string) (err error) {
|
func (a *API) FullDiscountFoodsDelete(poiCode, actID string, appFoodCodeList []string) (err error) {
|
||||||
@@ -275,11 +225,7 @@ func (a *API) FullDiscountFoodsDayLimit(poiCode, actID string, appFoodList []*Fu
|
|||||||
func (a *API) FulllDiscountShippingFeeBatchSave(poiCode string, actData []*ShippingFeeActData) (err error) {
|
func (a *API) FulllDiscountShippingFeeBatchSave(poiCode string, actData []*ShippingFeeActData) (err error) {
|
||||||
_, err = a.AccessAPI("act/full/discount/shippingfee/batchsave", false, map[string]interface{}{
|
_, err = a.AccessAPI("act/full/discount/shippingfee/batchsave", false, map[string]interface{}{
|
||||||
KeyAppPoiCode: poiCode,
|
KeyAppPoiCode: poiCode,
|
||||||
"act_data": string(utils.MustMarshal(utils.StructList2MapListWithIgnore(actData, map[string]interface{}{
|
"act_data": string(utils.MustMarshal(actData)),
|
||||||
"weeks_time": ignoreShippingFeeActData.WeeksTime,
|
|
||||||
"period": ignoreShippingFeeActData.Period,
|
|
||||||
"max_price": ignoreShippingFeeActData.MaxPrice,
|
|
||||||
}))),
|
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -290,30 +236,7 @@ func (a *API) FulllDiscountShippingFeeList(poiCode string) (actList []*ShippingF
|
|||||||
KeyAppPoiCode: poiCode,
|
KeyAppPoiCode: poiCode,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, v := range result.([]interface{}) {
|
err = utils.Map2StructByJson(result, &actList, false)
|
||||||
vMap := v.(map[string]interface{})
|
|
||||||
act := &ShippingFeeActData{
|
|
||||||
AppPoiCode: utils.Interface2String(vMap["app_poi_code"]),
|
|
||||||
ActID: utils.Interface2String(vMap["act_id"]),
|
|
||||||
StartTime: utils.MustInterface2Int64(vMap["start_time"]),
|
|
||||||
EndTime: utils.MustInterface2Int64(vMap["end_time"]),
|
|
||||||
WeeksTime: utils.Interface2String(vMap["weeks_time"]),
|
|
||||||
Period: utils.Interface2String(vMap["period"]),
|
|
||||||
|
|
||||||
MaxPrice: utils.Interface2Float64WithDefault(vMap["max_price"], 0),
|
|
||||||
ActStatus: utils.Interface2String(vMap["actStatus"]),
|
|
||||||
}
|
|
||||||
actList = append(actList, act)
|
|
||||||
for _, v := range vMap["act_detail"].([]interface{}) {
|
|
||||||
vMap := v.(map[string]interface{})
|
|
||||||
act.ActDetail = append(act.ActDetail, &ShippingFeeActDetail{
|
|
||||||
LimitPrice: utils.Interface2Float64WithDefault(vMap["limit_price"], 0),
|
|
||||||
DiscountPrice: utils.Interface2Float64WithDefault(vMap["discount_price"], 0),
|
|
||||||
PoiCharge: utils.Interface2Float64WithDefault(vMap["poi_charge"], 0),
|
|
||||||
MtCharge: utils.Interface2Float64WithDefault(vMap["mt_charge"], 0),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return actList, err
|
return actList, err
|
||||||
}
|
}
|
||||||
@@ -322,10 +245,7 @@ func (a *API) FulllDiscountShippingFeeList(poiCode string) (actList []*ShippingF
|
|||||||
func (a *API) RetailDiscountBatchSave(poiCode string, actData []*RetailActData) (actID int64, err error) {
|
func (a *API) RetailDiscountBatchSave(poiCode string, actData []*RetailActData) (actID int64, err error) {
|
||||||
result, err := a.AccessAPI2("act/retail/discount/batchsave", false, map[string]interface{}{
|
result, err := a.AccessAPI2("act/retail/discount/batchsave", false, map[string]interface{}{
|
||||||
KeyAppPoiCode: poiCode,
|
KeyAppPoiCode: poiCode,
|
||||||
"act_data": string(utils.MustMarshal(utils.StructList2MapListWithIgnore(actData, map[string]interface{}{
|
"act_data": string(utils.MustMarshal(actData)),
|
||||||
"sequence": ignoreRetailActData.Sequence,
|
|
||||||
"item_id": ignoreRetailActData.ItemID,
|
|
||||||
}))),
|
|
||||||
}, resultKeyMsg)
|
}, resultKeyMsg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return utils.MustInterface2Int64(result.([]interface{})[0].(map[string]interface{})["act_id"]), nil
|
return utils.MustInterface2Int64(result.([]interface{})[0].(map[string]interface{})["act_id"]), nil
|
||||||
@@ -344,31 +264,12 @@ func (a *API) RetailDiscountList(poiCode string) (actList []*RetailActData, err
|
|||||||
"offset": offset,
|
"offset": offset,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
resultList := result.([]interface{})
|
var tmpActList []*RetailActData
|
||||||
for _, v := range resultList {
|
if err = utils.Map2StructByJson(result, &tmpActList, false); err != nil {
|
||||||
vMap := v.(map[string]interface{})
|
return nil, err
|
||||||
act := &RetailActData{
|
|
||||||
AppFoodCode: utils.Interface2String(vMap["app_food_code"]),
|
|
||||||
UserType: int(utils.MustInterface2Int64(vMap["user_type"])),
|
|
||||||
StartTime: utils.MustInterface2Int64(vMap["start_time"]),
|
|
||||||
EndTime: utils.MustInterface2Int64(vMap["end_time"]),
|
|
||||||
OrderLimit: int(utils.MustInterface2Int64(vMap["order_limit"])),
|
|
||||||
DayLimit: int(utils.MustInterface2Int64(vMap["day_limit"])),
|
|
||||||
WeeksTime: utils.Interface2String(vMap["weeks_time"]),
|
|
||||||
Period: utils.Interface2String(vMap["period"]),
|
|
||||||
SettingType: int(utils.MustInterface2Int64(vMap["setting_type"])),
|
|
||||||
ActPrice: utils.Interface2Float64WithDefault(vMap["act_price"], 0),
|
|
||||||
DiscountCoefficient: utils.Interface2Float64WithDefault(vMap["discount_coefficient"], 0),
|
|
||||||
ItemID: utils.MustInterface2Int64(vMap["item_id"]),
|
|
||||||
OriginalPrice: utils.Interface2Float64WithDefault(vMap["origin_price"], 0),
|
|
||||||
Stock: int(utils.MustInterface2Int64(vMap["stock"])),
|
|
||||||
Status: int(utils.MustInterface2Int64(vMap["status"])),
|
|
||||||
Name: utils.Interface2String(vMap["name"]),
|
|
||||||
Sequence: int(utils.MustInterface2Int64(vMap["sequence"])),
|
|
||||||
}
|
|
||||||
actList = append(actList, act)
|
|
||||||
}
|
}
|
||||||
if len(resultList) < limit {
|
actList = append(actList, tmpActList...)
|
||||||
|
if len(tmpActList) < limit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
offset++
|
offset++
|
||||||
@@ -392,9 +293,7 @@ func (a *API) RetailDiscountDelete(poiCode string, actIDList []string) (err erro
|
|||||||
func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailActDataLimit) (err error) {
|
func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailActDataLimit) (err error) {
|
||||||
_, err = a.AccessAPI("act/retail/discount/batchstock", false, map[string]interface{}{
|
_, err = a.AccessAPI("act/retail/discount/batchstock", false, map[string]interface{}{
|
||||||
KeyAppPoiCode: poiCode,
|
KeyAppPoiCode: poiCode,
|
||||||
"act_data": string(utils.MustMarshalJSONIgnoreValues(actDataList, map[string]interface{}{
|
"act_data": string(utils.MustMarshal(actDataList)),
|
||||||
"order_limit": ignoreRetailActDataLimit.OrderLimit,
|
|
||||||
})),
|
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -403,9 +302,7 @@ func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailActDataLimi
|
|||||||
func (a *API) RetailDiscountBatchLimit(poiCode, actDataList []*RetailActDataLimit) (err error) {
|
func (a *API) RetailDiscountBatchLimit(poiCode, actDataList []*RetailActDataLimit) (err error) {
|
||||||
_, err = a.AccessAPI("act/retail/discount/batchlimit", false, map[string]interface{}{
|
_, err = a.AccessAPI("act/retail/discount/batchlimit", false, map[string]interface{}{
|
||||||
KeyAppPoiCode: poiCode,
|
KeyAppPoiCode: poiCode,
|
||||||
"act_data": string(utils.MustMarshalJSONIgnoreValues(actDataList, map[string]interface{}{
|
"act_data": string(utils.MustMarshal(actDataList)),
|
||||||
"day_limit": ignoreRetailActDataLimit.DayLimit,
|
|
||||||
})),
|
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
"github.com/fatih/structs"
|
"github.com/fatih/structs"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -471,58 +472,11 @@ func Struct2FlatMap(obj interface{}) map[string]interface{} {
|
|||||||
return FlatMap(m)
|
return FlatMap(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeIgnoreFields(data interface{}, ignoreValues map[string]interface{}) {
|
func Map2StructByJson(inObj interface{}, outObjAddr interface{}, weaklyTypedInput bool) (err error) {
|
||||||
dataType := reflect.TypeOf(data).Kind()
|
decoder, _ := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||||
if dataType == reflect.Map {
|
TagName: "json",
|
||||||
inMap := data.(map[string]interface{})
|
Result: outObjAddr,
|
||||||
for k, v := range inMap {
|
WeaklyTypedInput: weaklyTypedInput,
|
||||||
// fmt.Printf("k:%s v:%v, ignoreValues[k]:%v\n", k, v, ignoreValues[k])
|
})
|
||||||
if fmt.Sprint(ignoreValues[k]) == fmt.Sprint(v) {
|
return decoder.Decode(inObj)
|
||||||
delete(inMap, k)
|
|
||||||
} else {
|
|
||||||
fieldType := reflect.TypeOf(v).Kind()
|
|
||||||
if fieldType == reflect.Map || fieldType == reflect.Slice {
|
|
||||||
removeIgnoreFields(v, ignoreValues)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if dataType == reflect.Slice {
|
|
||||||
dataList := Interface2Slice(data)
|
|
||||||
for _, v := range dataList {
|
|
||||||
removeIgnoreFields(v, ignoreValues)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// mapData := data.(map[string]interface{})
|
|
||||||
// for k, v := range ignoreValues {
|
|
||||||
// if fmt.Sprint(mapData[k]) == fmt.Sprint(v) {
|
|
||||||
// delete(mapData, k)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
func Struct2MapWithIgnore(obj interface{}, ignoreValues map[string]interface{}) map[string]interface{} {
|
|
||||||
mapData := Struct2FlatMap(obj)
|
|
||||||
removeIgnoreFields(mapData, ignoreValues)
|
|
||||||
return mapData
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:如下两个函数的行为与标准的json.Marshal的行为是有区别的
|
|
||||||
// 这两个函数,只要成员是对象或map(不是指针),都会被展开
|
|
||||||
// 而json.Marshal不是这样的,只会展开内嵌的(包括指针)
|
|
||||||
// 所以原则是不用map的对象,行为就比较一致
|
|
||||||
func MarshalJSONIgnoreValues(obj interface{}, ignoreValues map[string]interface{}) ([]byte, error) {
|
|
||||||
return json.Marshal(Struct2MapWithIgnore(obj, ignoreValues))
|
|
||||||
}
|
|
||||||
|
|
||||||
func MustMarshalJSONIgnoreValues(obj interface{}, ignoreValues map[string]interface{}) []byte {
|
|
||||||
return MustMarshal(Struct2MapWithIgnore(obj, ignoreValues))
|
|
||||||
}
|
|
||||||
|
|
||||||
func StructList2MapListWithIgnore(obj interface{}, ignoreValues map[string]interface{}) (mapList []map[string]interface{}) {
|
|
||||||
objList := Interface2Slice(obj)
|
|
||||||
mapList = make([]map[string]interface{}, len(objList))
|
|
||||||
for k, v := range objList {
|
|
||||||
mapList[k] = Struct2MapWithIgnore(v, ignoreValues)
|
|
||||||
}
|
|
||||||
return mapList
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user