1
This commit is contained in:
@@ -784,3 +784,55 @@ func (a *API) EcommerceGetOrderIdByPage(poiCode string, startTime, endTime time.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// QuerySkuIsNeedUpc 查看商品是否需要填写upc
|
||||
func (a *API) QuerySkuIsNeedUpc(tagId int) bool {
|
||||
data, err := a.AccessAPI2("retail/field/required/info", true, map[string]interface{}{"tag_id": tagId}, "success_map", "")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
upc := data.(map[string]interface{})["upc"]
|
||||
upcCode := utils.Interface2Int64WithDefault(upc, 1)
|
||||
return upcCode == 0
|
||||
}
|
||||
|
||||
// 去除多以属性
|
||||
func CommonAttrValueUpdate(commonAttrValue string) string {
|
||||
commonAttrValueObj := make([]*CommonAttrValueList, 0, 0)
|
||||
if err := json.Unmarshal([]byte(commonAttrValue), &commonAttrValueObj); err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
result := make([]map[string]interface{}, 0, 0)
|
||||
for _, v := range commonAttrValueObj {
|
||||
commonAttrValueMap := utils.Struct2Map(v, "", false)
|
||||
delete(commonAttrValueMap, "setAttrId")
|
||||
delete(commonAttrValueMap, "setAttrName")
|
||||
delete(commonAttrValueMap, "setValueList")
|
||||
delete(commonAttrValueMap, "valueListSize")
|
||||
delete(commonAttrValueMap, "valueListIterator")
|
||||
result = append(result, commonAttrValueMap)
|
||||
}
|
||||
|
||||
result2, _ := json.Marshal(result)
|
||||
return string(result2)
|
||||
}
|
||||
|
||||
type CommonAttrValueList struct {
|
||||
AttrId int `json:"attrId"`
|
||||
AttrName string `json:"attrName"`
|
||||
ValueList []struct {
|
||||
SetValue bool `json:"setValue"`
|
||||
SetValueId bool `json:"setValueId"`
|
||||
Value string `json:"value"`
|
||||
ValueId int `json:"valueId"`
|
||||
} `json:"valueList"`
|
||||
|
||||
SetAttrId bool `json:"setAttrId"`
|
||||
SetAttrName bool `json:"setAttrName"`
|
||||
SetValueList bool `json:"setValueList"`
|
||||
ValueListIterator []struct {
|
||||
Ref string `json:"$ref"`
|
||||
} `json:"valueListIterator"`
|
||||
ValueListSize int `json:"valueListSize"`
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package mtwmapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"math"
|
||||
@@ -252,3 +253,214 @@ func TestEcommerceGetOrderIdByPage(t *testing.T) {
|
||||
t.Log(orderIdList)
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
// TestUpdateSkuBoxFee 修改打包费
|
||||
func TestUpdateSkuBoxFee(t *testing.T) {
|
||||
toApi := New("5873", "41c479790a76f86326f89e8048964739", "", "token_qJalvtSnVB-hBeDvRLVN_w")
|
||||
toApi.RetailBatchInitData(utils.GetUUID(), "12371130", []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"app_food_code": "mtcode_1788146996860325928",
|
||||
"category_name": "神价商品",
|
||||
"unit": "罐",
|
||||
"sequence": -361,
|
||||
"tag_id": 200001294,
|
||||
"upc": 6920226221352,
|
||||
"description": "",
|
||||
"price": 20,
|
||||
"picture": `http://p0.meituan.net/retailsp/8e6cd87119cd6c36d2e1cdd1c5345ab266547.jpg,http://p0.meituan.net/retailsp/49856b31a8aa526d69931a160e7c18b841941.jpg,http://p1.meituan.net/retailsp/e590574f5a75e5fb1d576ded5d0418cf81638.jpg`,
|
||||
"picture_contents": "",
|
||||
"skus": []map[string]interface{}{
|
||||
{
|
||||
"isSellFlag": 1,
|
||||
"price": "20.0",
|
||||
"unit": "罐",
|
||||
"available_times": map[string]string{"friday": "", "monday": "", "saturday": "", "sunday": "", "thursday": "", "tuesday": "", "wednesday": ""},
|
||||
"sku_id": "mtcode_1788146996860325928",
|
||||
"spec": "330ml*6罐",
|
||||
"upc": "6920226221352",
|
||||
"weight": "1980",
|
||||
"limit_open_sync_stock_now": false,
|
||||
"location_code": "",
|
||||
"stock": 989,
|
||||
},
|
||||
},
|
||||
"name": "【六罐装】可口可乐 碳酸饮料汽水饮料 330ml*6罐/件",
|
||||
"min_order_count": 1,
|
||||
"common_attr_value": `[{"attrId":1200000135,"attrName":"包装方式","valueList":[{"setValue":true,"setValueId":true,"value":"罐装","valueId":1300000333}]},{"attrId":1200000132,"attrName":"国产/进口","valueList":[{"setValue":true,"setValueId":true,"value":"国产","valueId":1300000003}]},{"attrId":1200000133,"attrName":"口味","valueList":[{"setValue":true,"setValueId":true,"value":"其他","valueId":1300000249}]},{"attrId":1200000204,"attrName":"是否含糖","valueList":[{"setValue":true,"setValueId":true,"value":"含糖","valueId":1300000468}]},{"attrId":1200000333,"attrName":"单件容量","valueList":[{"setValue":true,"setValueId":true,"value":"330ml","valueId":0}]},{"attrId":1200000210,"attrName":"商品类别","valueList":[{"setValue":true,"setValueId":true,"value":"可乐","valueId":1300000483}]},{"attrId":1200000094,"attrName":"产地","valueList":[{"setValue":true,"setValueId":true,"value":"中国","valueId":100000050}]},{"attrId":1200000088,"attrName":"品牌","valueList":[{"setValue":true,"setValueId":true,"value":"可口可乐(Coca-Cola)","valueId":1000557}]}]`,
|
||||
"is_sold_out": 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCopyMtToMT(t *testing.T) {
|
||||
CopyMtToMT("1693690", "12371130", 20)
|
||||
}
|
||||
|
||||
// CopyMtToMT 美团商品复制到美团
|
||||
func CopyMtToMT(fromStoreId, toStoreId string, offSet int) (hint string, data []string, err error) {
|
||||
var fromApi *API //= mtwm.GetAPI(fromStore.VendorOrgCode, fromStore.ID, fromStore.VendorStoreID)
|
||||
var toApi *API // = mtwm.GetAPI(toStore.VendorOrgCode, toStore.ID, toStore.VendorStoreID)
|
||||
var errList = make([]*AppFoodResult, 0, 0)
|
||||
var errData = make([]string, 0, 0)
|
||||
fromApi = New("5873", "41c479790a76f86326f89e8048964739", "", "token_vNCxaqyai16or9en_C5PSw")
|
||||
toApi = New("5873", "41c479790a76f86326f89e8048964739", "", "token_qJalvtSnVB-hBeDvRLVN_w")
|
||||
|
||||
i := offSet
|
||||
for {
|
||||
// 同步商品
|
||||
fromFoodList, err1 := fromApi.RetailListAll(fromStoreId, offSet)
|
||||
if len(fromFoodList) == 0 || fromFoodList == nil {
|
||||
return "", nil, err1
|
||||
}
|
||||
|
||||
errDataList, err := BatchInitSkuMT2MT(fromFoodList, toApi, toStoreId, i)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("BatchInitData : %v", err)
|
||||
}
|
||||
if len(errDataList) > 0 {
|
||||
//globals.SugarLogger.Debugf("errListData %d:= %s", i, utils.Format4Output(errDataList, false))
|
||||
errList = append(errList, errDataList...)
|
||||
}
|
||||
globals.SugarLogger.Debugf("==========页数[%d],数据长度[%d]", i, len(fromFoodList))
|
||||
if len(fromFoodList) < 100 {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
for _, v := range errList {
|
||||
errData = append(errData, fmt.Sprintf("food_id:%s,错误:%s", v.AppFoodCode, v.ErrorMsg))
|
||||
}
|
||||
globals.SugarLogger.Debugf("errList := %s", utils.Format4Output(errList, false))
|
||||
return hint, errData, err
|
||||
}
|
||||
|
||||
// BatchInitSkuMT2MT 批量创建商品
|
||||
func BatchInitSkuMT2MT(fromSku []*AppFood, toApi *API, vendorStoreID string, offset int) ([]*AppFoodResult, error) {
|
||||
errList := make([]*AppFoodResult, 0, 0)
|
||||
foodDataList := make([]map[string]interface{}, len(fromSku))
|
||||
|
||||
apijd := jdapi.New("1e87595b-e850-4ba4-9ee0-53bcfe383a4f", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4")
|
||||
apijd.SetCookieWithStr(`user_email=jd_jxcs1223; lsp-store1.jddj.com=OPJQMA7B3FTKCAUGO7FHCH5NMBGAWGGXYRNLEHYYZNGNPNIBCAM4IOEPG3NT3RIA44G5C3535Q5LGG4F4SR4AZVLGYKYTKFJJKEAOXENVBL5VXNILRP3GLNVVWA26XZ3VGSYOHA72RICMVZS3G53DTEH3KKPE2KWRJ56RVQ2FMRXLQLWO4QBQL7EIOBUFAULGOCVWY7RBKZGAICS43NT6J6SUQ6QKCZ5CPQJXLXRTXJ6TTQZ76WIPY3FIXEQWDFYBPQQMRRIIWHZJ24QAGVWTRELTJ4ANKYUYK6KOCYNU7MPQZRGZ7A3RCFZCSP5UJH6H2OTKVR4EGOCXYTZO2DXT6UDKHMIWF7PCFTVIYAVZV6TUYE43JONRCTQBY2PDBQYCB4ONJOEWAF6KFL3GJ3XH26R6E; __jda=1736810.11184102.1626140984.1626140984.1626140984.1; __jdb=1736810.1.11184102%7C1.1626140984; __jdv=1736810%7Cdirect%7C-%7Cnone%7C-; __jdc=1736810; UM_distinctid=17a9d8e412b8f-0db54dad15adbc-5b1e341a-1fa400-17a9d8e412c298; josl-privilege1.jddj.com=OPJQMA7B3FTKCAUGO7FHCH5NMBGAWGGXYRNLEHYYZNGNPNIBCAM4IOEPG3NT3RIA44G5C3535Q5LGG4F4SR4AZVLGYKYTKFJJKEAOXENVBL5VXNILRP3GLNVVWA26XZ3VGSYOHA72RICMVZS3G53DTEH3L5R67UBB3LZWSV7QY5A7WMTVESBQL7EIOBUFAULGOCVWY7RBKZGB4IDIBOFHLL26YJTJU5SFCC7CKHRTXJ6TTQZ76WIPY3FIXEQWDFYES24CC32SX326B3WVAC6EVB4YIAQWEDFKRBXVVYOYZRBTKYYJZ5HQBVLCTBLZJYLBWT5R6DGE3H4C4L7R23TYZA5JMSPJU7HE6MGAWXAMIJ7H54ZWWGP56KATLF26DHPBFC7H6AGN62RYAH3GOOTQMZPFOOK3A5M4RSJGLYDIG2YB3HH35HA; o2o-pms1.jddj.com=OPJQMA7B3FTKCAUGO7FHCH5NMBGAWGGXYRNLEHYYZNGNPNIBCAM4IOEPG3NT3RIA44G5C3535Q5LGG4F4SR4AZVLGYKYTKFJJKEAOXENVBL5VXNILRP3GLNVVWA26XZ3VGSYOHA72RICMVZS3G53DTEH3LPBK4CTTQUICQG4IXP7VTZQY3RRQL7EIOBUFAULGOCVWY7RBKZGA4IDAH46XCGKM54EGU3D4E25KTQMIOV7EVR4JGDPUMIPCVZVKBP5E4RJGGER5KFUQWJBFZJVCAXQUQ; o2o-stock1.jddj.com=OPJQMA7B3FTKCAUGO7FHCH5NMBGAWGGXYRNLEHYYZNGNPNIBCAM4IOEPG3NT3RIA44G5C3535Q5LGG4F4SR4AZVLGYKYTKFJJKEAOXENVBL5VXNILRP3GLNVVWA26XZ3VGSYOHA72RICMVZS3G53DTEH3LDRI5V7NVUHTVXQQYNAA4HGUZJBQL7EIOBUFAULGOCVWY7RBKZGBYT7E4RO4CXG23IJO2MNVRCTQIIMIOV7EVR4JGDPUMIPCVZVKBP5E4RJGGER5KFUQWJBFZJVCAXQUQ`)
|
||||
|
||||
for k, storeSku := range fromSku {
|
||||
foodData := make(map[string]interface{})
|
||||
if storeSku.AppFoodCode != "" {
|
||||
foodData[KeyAppFoodCode] = storeSku.AppFoodCode
|
||||
} else {
|
||||
foodData[KeyAppFoodCode] = time.Now().UnixNano() + int64(k*3)
|
||||
}
|
||||
|
||||
skus := make([]interface{}, 0)
|
||||
upc := ""
|
||||
for _, v := range storeSku.SkuList {
|
||||
if v.Stock == "" {
|
||||
v.Stock = "99999"
|
||||
}
|
||||
if v.SkuId == "" {
|
||||
v.SkuId = storeSku.AppFoodCode
|
||||
}
|
||||
if v.SkuId == "" {
|
||||
v.SkuId = utils.Int2Str(storeSku.Ctime + int(k*3))
|
||||
}
|
||||
// salesCycle, _ := json.Marshal(v.AvailableTimes)
|
||||
mapSkuList := utils.Struct2MapByJson(v)
|
||||
if v.BoxNum == "" {
|
||||
delete(mapSkuList, "box_num")
|
||||
}
|
||||
if v.BoxPrice == "" {
|
||||
delete(mapSkuList, "box_price")
|
||||
}
|
||||
if v.LadderBoxNum == "" {
|
||||
delete(mapSkuList, "ladder_box_num")
|
||||
}
|
||||
if v.LadderBoxPrice == "" {
|
||||
delete(mapSkuList, "ladder_box_price")
|
||||
}
|
||||
delete(mapSkuList, "min_order_count")
|
||||
if v.Upc != "" {
|
||||
upc = v.Upc
|
||||
} else if api.QuerySkuIsNeedUpc(storeSku.TagID) {
|
||||
upcList, _ := apijd.GetJdUpcCodeByName(storeSku.Name, "", 1, 20)
|
||||
if len(upcList) != 0 {
|
||||
upc = upcList[0].UpcCode
|
||||
}
|
||||
}
|
||||
//mapSkuList["available_times"] = string(salesCycle)
|
||||
mapSkuList["available_times"] = v.AvailableTimes
|
||||
//if v.MinOrderCount != "" {
|
||||
// mapSkuList["min_order_count"] = utils.Str2Int(v.MinOrderCount)
|
||||
//}
|
||||
if upc != "" {
|
||||
mapSkuList["upc"] = upc
|
||||
}
|
||||
skus = append(skus, mapSkuList)
|
||||
}
|
||||
foodData["skus"] = skus
|
||||
foodData["name"] = utils.LimitUTF8StringLen(storeSku.Name, MaxSkuNameCharCount)
|
||||
foodData["description"] = storeSku.Description
|
||||
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"] = CommonAttrValueUpdate(storeSku.CommonAttrValue)
|
||||
}
|
||||
if storeSku.SecondaryCategoryCode != "" {
|
||||
foodData["category_code"] = storeSku.SecondaryCategoryCode
|
||||
} else {
|
||||
foodData["category_name"] = storeSku.SecondaryCategoryName
|
||||
}
|
||||
|
||||
if storeSku.SecondaryCategoryName == "" && storeSku.SecondaryCategoryCode == "" {
|
||||
if storeSku.SecondaryCategoryCode != "" {
|
||||
foodData["category_code"] = storeSku.CategoryCode
|
||||
} else {
|
||||
foodData["category_name"] = storeSku.CategoryName
|
||||
}
|
||||
}
|
||||
|
||||
foodData["is_sold_out"] = storeSku.IsSoldOut
|
||||
foodData["picture"] = storeSku.Picture
|
||||
foodData["picture_contents"] = storeSku.PictureContents
|
||||
foodData["sequence"] = storeSku.Sequence
|
||||
foodData["tag_id"] = storeSku.TagID
|
||||
foodData["upc"] = storeSku.UpcCode
|
||||
if foodData["upc"].(string) == "" {
|
||||
foodData["upc"] = upc
|
||||
}
|
||||
if foodData["upc"].(string) == "" {
|
||||
foodData["upc"] = "no_upc"
|
||||
}
|
||||
|
||||
foodDataList[k] = foodData
|
||||
}
|
||||
|
||||
count := len(foodDataList) / 10
|
||||
if len(foodDataList)%10 != 0 {
|
||||
count += 1
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
if i == count-1 {
|
||||
failedFoodList, _ := toApi.RetailBatchInitData("liulei1973", vendorStoreID, foodDataList[i*10:])
|
||||
if len(failedFoodList) != 0 {
|
||||
//globals.SugarLogger.Debugf("failedFoodList := %s", utils.Format4Output(failedFoodList, false))
|
||||
errList = append(errList, failedFoodList...)
|
||||
}
|
||||
} else {
|
||||
data := foodDataList[i*10 : (i+1)*10]
|
||||
failedFoodList, _ := toApi.RetailBatchInitData("liulei1973", vendorStoreID, data)
|
||||
if len(failedFoodList) != 0 {
|
||||
//globals.SugarLogger.Debugf("failedFoodList := %s", utils.Format4Output(failedFoodList, false))
|
||||
errList = append(errList, failedFoodList...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errList, nil
|
||||
}
|
||||
|
||||
func TestStr(t *testing.T) {
|
||||
api.QuerySkuIsNeedUpc(200005466)
|
||||
}
|
||||
|
||||
@@ -321,23 +321,6 @@ func TestErrList(t *testing.T) {
|
||||
fmt.Println(data)
|
||||
}
|
||||
|
||||
// TestUpdateSkuBoxFee 修改打包费
|
||||
func TestUpdateSkuBoxFee(t *testing.T) {
|
||||
api.RetailBatchInitData(utils.GetUUID(), "17901037", []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"app_spu_code": "34712",
|
||||
"skus": []map[string]interface{}{
|
||||
{
|
||||
"sku_id": "34712",
|
||||
"ladder_box_num": "0",
|
||||
"ladder_box_price": "0",
|
||||
},
|
||||
},
|
||||
"picture": "https://image.jxc4.com/image/4fd5cd77a6fce23ee26f8d40392d83b1.gif",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestRetailBatchInitData(t *testing.T) {
|
||||
failedFoods, err := api.RetailBatchInitData(utils.GetUUID(), "20498582", []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user