diff --git a/business/jxstore/cms/system_store_sku.go b/business/jxstore/cms/system_store_sku.go index 879ce86ae..ce2caac41 100644 --- a/business/jxstore/cms/system_store_sku.go +++ b/business/jxstore/cms/system_store_sku.go @@ -1,12 +1,14 @@ package cms import ( + "encoding/json" "fmt" "git.rosy.net.cn/baseapi/platformapi/ebaiapi" "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" "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/business/partner/purchase/mtwm" "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" beego "github.com/astaxie/beego/server/web" @@ -223,7 +225,6 @@ func CopyMtToMT(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail, isA globals.SugarLogger.Debugf("err := RetailCatUpdate : %v", categoryErr) } if v.Children != nil && len(v.Children) != 0 { - globals.SugarLogger.Debugf("---------v.Children := %s", utils.Format4Output(v.Children, false)) for _, c := range v.Children { if err3 := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{ CategoryNameOrigin: v.Name, @@ -345,11 +346,7 @@ func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi foodData["price"] = storeSku.Price foodData["min_order_count"] = storeSku.MinOrderCount foodData["unit"] = storeSku.Unit - //todo 增加商品必填属性 - //foodData["common_attr_value"] = storeSku.CommonAttrValue - if storeSku.CommonAttrValue != "" && storeSku.CommonAttrValue != "[]" { - foodData["common_attr_value"] = mtwmapi.CommonAttrValueUpdate(storeSku.CommonAttrValue) - } + if storeSku.SecondaryCategoryCode != "" { foodData["category_code"] = storeSku.SecondaryCategoryCode } else { @@ -364,6 +361,18 @@ func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi } } + //todo 增加商品必填属性 + //foodData["common_attr_value"] = storeSku.CommonAttrValue + if categoryCode := utils.Interface2Int64WithDefault(foodData["category_code"], 0); categoryCode != 0 { + commonAttrValue, err := createCommonAttrValue(toApi, categoryCode, utils.Interface2String(foodData["name"])) + if err == nil { + foodData["common_attr_value"] = commonAttrValue + globals.SugarLogger.Debugf("------------common_attr_value := %s", commonAttrValue) + } else if storeSku.CommonAttrValue != "" && storeSku.CommonAttrValue != "[]" { + foodData["common_attr_value"] = mtwmapi.CommonAttrValueUpdate(storeSku.CommonAttrValue) + } + } + foodData["is_sold_out"] = storeSku.IsSoldOut foodData["picture"] = storeSku.Picture foodData["picture_contents"] = storeSku.PictureContents @@ -403,6 +412,55 @@ func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi return errList, nil } +func createCommonAttrValue(apiObj *mtwmapi.API, tempCatID int64, name string) (string, error) { + var ( + attrValue mtwm.CommonAttrValue + attrValues []mtwm.CommonAttrValue + ) + + attrList, err := apiObj.CategoryAttrList(tempCatID) + if err == nil && len(attrList) > 0 { + for _, v := range attrList { + if v.Need == mtwmapi.NeedYes { + attrValue = mtwm.CommonAttrValue{ + AttrID: utils.Str2Int(v.AttrID), + AttrName: v.AttrName, + } + if v.AttrID == mtwmapi.SpecialAttrBrand || v.AttrID == mtwmapi.SpecialAttrProducer { //单独获取特殊属性 + data, err1 := apiObj.CategoryAttrValueList(utils.Str2Int64(v.AttrID), name) + if len(data) > 0 { + attrValue.ValueList = []mtwm.ValueList{{ //默认取推荐第一个 + ValueID: utils.Str2Int(data[0].ValueID), + Value: data[0].Value, + }} + } + if err1 != nil || len(data) == 0 { + attrValue.ValueList = []mtwm.ValueList{{ //兜底处理 + Value: "其他", + }} + } + } else { + if len(v.ValueList) > 0 { + attrValue.ValueList = []mtwm.ValueList{{ + ValueID: utils.Str2Int(v.ValueList[0].ValueID), + Value: v.ValueList[0].Value, + }} + } else { //兜底处理 + attrValue.ValueList = []mtwm.ValueList{{ + Value: "其他", + }} + } + } + attrValues = append(attrValues, attrValue) + } + } + temp, err := json.Marshal(attrValues) + return string(temp), err + } + + return "", fmt.Errorf("暂未获取到") +} + //#endregion ////#region 同步活动 diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index ef17acae5..3f321fb63 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1441,7 +1441,8 @@ func GetJxOrderCount(db *DaoDB, storeID int, orderID string, date time.Time) (co // GetVendorOrderNumber 查询当前平台当然订单数(抖音没有订单seq) func GetVendorOrderNumber(db *DaoDB, vendorId int64, vendorStoreId string) (count int, err error) { - date := time.Now() + nowTime := time.Now() + date := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local) sql := ` SELECT COUNT(*) ct FROM goods_order t1