Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop

This commit is contained in:
richboo111
2023-03-01 16:05:21 +08:00
29 changed files with 370 additions and 110 deletions

View File

@@ -27,7 +27,6 @@ const (
// OnOrderMsg 抖音
func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackResponse) {
globals.SugarLogger.Debugf("guoyuan %s,%s", msgId, utils.Format4Output(msg, false))
if CurPurchaseHandler != nil {
orderId, shopId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg)
globals.SugarLogger.Debugf("order_id %s,%d", orderId, shopId)

View File

@@ -87,25 +87,24 @@ func (p *PurchaseHandler) getOrder(vendorOrgCode, vendorOrderID, vendorStoreID s
}
orderMap = result
order = &model.GoodsOrder{
VendorOrderID: result.OrderId,
VendorID: model.VendorIDDD,
VendorStoreID: "",
StoreID: 0,
CoordinateType: model.CoordinateTypeMars,
BuyerComment: result.BuyerWords,
ExpectedDeliveredTime: getTimeFromTimestamp(result.EarliestReceiptTime + 30*60), // 预计最晚送达时间
PickDeadline: utils.DefaultTimeValue,
VendorStatus: utils.Int64ToStr(result.OrderStatus), //1待支付/103部分支付/105已支付/2备货中/101部分发货/3已发货/4取消/完成/21发货前退款完成/22发货后退款/39收货后退款
OrderSeq: 0,
StatusTime: getTimeFromTimestamp(result.CreateTime),
OrderCreatedAt: getTimeFromTimestamp(result.CreateTime),
OriginalData: string(utils.MustMarshal(result)),
ActualPayPrice: result.PayAmount,
BaseFreightMoney: result.PostAmount,
InvoiceTitle: "",
InvoiceTaxerID: "",
InvoiceEmail: "",
VendorOrgCode: vendorOrgCode,
VendorOrderID: result.OrderId,
VendorID: model.VendorIDDD,
VendorStoreID: "",
StoreID: 0,
CoordinateType: model.CoordinateTypeMars,
BuyerComment: result.BuyerWords,
PickDeadline: utils.DefaultTimeValue,
VendorStatus: utils.Int64ToStr(result.OrderStatus), //1待支付/103部分支付/105已支付/2备货中/101部分发货/3已发货/4取消/完成/21发货前退款完成/22发货后退款/39收货后退款
OrderSeq: 0,
StatusTime: getTimeFromTimestamp(result.CreateTime),
OrderCreatedAt: getTimeFromTimestamp(result.CreateTime),
OriginalData: string(utils.MustMarshal(result)),
ActualPayPrice: result.PayAmount,
BaseFreightMoney: result.PostAmount,
InvoiceTitle: "",
InvoiceTaxerID: "",
InvoiceEmail: "",
VendorOrgCode: vendorOrgCode,
}
if result.FinishTime != 0 {
@@ -195,18 +194,27 @@ func (p *PurchaseHandler) getOrder(vendorOrgCode, vendorOrderID, vendorStoreID s
globals.SugarLogger.Debugf("平台门店未绑定到京西系统 %s", err.Error())
return nil, nil, err
}
// 订单不在门店营业时间来的订单,
openTime := localStore.OpenTime1 // 门店开始营业时间
closeTime := localStore.CloseTime1 // 门店结束营业时间
if localStore.CloseTime2 != 0 {
closeTime = localStore.CloseTime2
}
h, m, _ := order.ExpectedDeliveredTime.Clock()
if order.ExpectedDeliveredTime.Day() == time.Now().Day() && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) >= openTime && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) < closeTime && localStore.Status == model.StoreStatusOpened {
// 订单不在门店营业时间来的订单,
//openTime := localStore.OpenTime1 // 门店开始营业时间
//closeTime := localStore.CloseTime1 // 门店结束营业时间
//if localStore.CloseTime2 != 0 {
// closeTime = localStore.CloseTime2
//}
//
//h, m, _ := order.ExpectedDeliveredTime.Clock()
//if order.ExpectedDeliveredTime.Day() == time.Now().Day() && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) >= openTime && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) < closeTime && localStore.Status == model.StoreStatusOpened {
// order.BusinessType = model.BusinessTypeImmediate
//} else {
// order.BusinessType = model.BusinessTypeDingshida
//}
if result.EarlyArrival { // 立即达
order.BusinessType = model.BusinessTypeImmediate
} else {
order.ExpectedDeliveredTime = getTimeFromTimestamp(result.TargetArrivalTime + 30*60) // 预计最晚送达时间
} else { // 定时达
order.BusinessType = model.BusinessTypeDingshida
order.ExpectedDeliveredTime = getTimeFromTimestamp(result.EarliestReceiptTime + 30*60) // 预计最晚送达时间
}
// 用户保密信息脱敏
@@ -1030,3 +1038,8 @@ func GetOrderTotalShopMoney(appOrgCode string, orderIds string, nextStartIndex s
func GetOrderDetail(appOrgCode, vendorOrderID string) (*order_orderDetail_response.ShopOrderDetail, error) {
return getAPI(appOrgCode, 0, "").GetTiktokOrderDetail(vendorOrderID)
}
// GetOrderSettleAccounts 获取订单结算信息
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
return 0, nil
}

View File

@@ -152,21 +152,25 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
if len(localThing) == 0 {
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(time.Now().Unix()), storeDetail.VendorOrgCode, "本地不存在,线上也不存在", model.ThingTypeSku, model.ThingTypeSyncing); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
continue
}
param, failedList2 := makeMainProductSku(db, api, storeSku, storeDetail, storeID, vendorStoreID, syncType)
if len(failedList2) != 0 {
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
failedList = append(failedList, failedList2...)
continue
}
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
if err != nil {
dao.UpdateThingMap(db, model.ThingTypeSyncFail, utils.Int64ToStr(time.Now().Unix()), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode)
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
if err := dao.UpdateThingMap(db, model.ThingTypeSyncSuccess, utils.Int64ToStr(tiktokResult.ProductId), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode); err != nil {
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
@@ -190,12 +194,14 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
}
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
if err != nil {
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
dao.UpdateThingMap(db, model.ThingTypeSyncFail, utils.Int64ToStr(time.Now().Unix()), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode)
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
if err := dao.UpdateThingMap(db, model.ThingTypeSyncSuccess, utils.Int64ToStr(tiktokResult.ProductId), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode); err != nil {
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
@@ -214,6 +220,8 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
if time.Now().Unix()-localThing[0].CreatedAt.Unix() > 300 {
dao.DeleteThingToTiktokMapList(model.VendorIDDD, localThing[0].VendorThingID, storeSku.SkuID)
}
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("商品同步中或同步错误"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
} else if localThing[0].SyncStatus == model.ThingTypeSyncSuccess {
// 主商品存在,直接同步子商品
@@ -249,15 +257,16 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
updateParam.Pic = param.Pic
updateParam.Description = param.Description
updateParam.WeightUnit = tiktokShop.WeightUint_G
updateParam.StandardBrandId, err = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, updateParam.CategoryLeafId)
updateParam.ProductId = mainOrderDetail.ProductId
updateParam.MainProductId = mainProductId
updateParam.SpecPrices = param.SpecPrices
updateParam.StandardBrandId = param.StandardBrandId
if err2 := api.EditStoreCommodity(updateParam); err2 != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err2, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
}
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("修改主品,主品审核中/失败,子商品未创建"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
@@ -368,8 +377,8 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
}
// 获取商品的属性
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" || storeSku.UpcTiktokBrandId == "" {
param.ProductFormatNew, param.StandardBrandId, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
@@ -378,7 +387,12 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
param.ProductFormatNew = storeSku.TiktokAttribute
}
// 获取品牌
param.StandardBrandId = 789194134 // 默认品牌京西菜市
if param.StandardBrandId == 0 {
param.StandardBrandId, _ = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId)
}
if param.StandardBrandId == 0 {
param.StandardBrandId = 596120136 // 无品牌
}
// 修改商品
param.ProductId = mainIdInt
@@ -454,22 +468,22 @@ func makeMainProductSku(db *dao.DaoDB, api *tiktokShop.API, storeSku *dao.StoreS
// spec_prices
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
// 获取商品的属性
if storeSku.TiktokAttribute != "" && storeSku.TiktokAttribute != "{}" {
param.ProductFormatNew = storeSku.TiktokAttribute
} else if storeSku.VendorSkuAttrId != "" && storeSku.VendorSkuAttrId != "{}" {
if storeSku.TiktokAttribute != "" && storeSku.TiktokAttribute != "{}" && storeSku.UpcTiktokBrandId != "" {
param.ProductFormatNew = storeSku.TiktokAttribute
} else {
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
param.ProductFormatNew, param.StandardBrandId, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId)
//param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
return
}
}
param.StandardBrandId, err = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
return
if param.StandardBrandId == 0 {
param.StandardBrandId, _ = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId)
}
if param.StandardBrandId == 0 {
param.StandardBrandId = 596120136
}
param.FreightId, param.SaleLimitId, err = getFreightIdAndSaleLimitId(api, db, storeDetail, vendorStoreID)
@@ -481,12 +495,23 @@ func makeMainProductSku(db *dao.DaoDB, api *tiktokShop.API, storeSku *dao.StoreS
}
func getTiktokBrandId(api *tiktokShop.API, db *dao.DaoDB, upc, upcBrandName, upcTiktokBrandId string, categoryLeafId int64) (int64, error) {
globals.SugarLogger.Debugf("upc:%s,upcBrandName:%s,upcTiktokBrandId:%s,categoryLeafId:%d", upc, upcBrandName, upcTiktokBrandId, categoryLeafId)
if upc == "" { // 默认品牌京西菜市 596120136
return 596120136, nil
} else if upc != "" && upcBrandName != "" && upcTiktokBrandId != "" {
return utils.Str2Int64(upcTiktokBrandId), nil
} else if upc != "" && upcBrandName != "" && upcTiktokBrandId == "" {
standardBrandId, err := api.GetSkuBrand(categoryLeafId, upcBrandName)
brandName := upcBrandName
if strings.Contains(brandName, "/") {
brandName = strings.Split(brandName, "/")[0]
}
if strings.Contains(brandName, "(") {
brandName = strings.Split(brandName, "(")[0]
}
if strings.Contains(brandName, "") {
brandName = strings.Split(brandName, "")[0]
}
standardBrandId, err := api.GetSkuBrand(categoryLeafId, brandName)
if err != nil {
return 0, err
}
@@ -497,6 +522,15 @@ func getTiktokBrandId(api *tiktokShop.API, db *dao.DaoDB, upc, upcBrandName, upc
if err != nil {
return 0, err
}
if strings.Contains(brandName, "/") || strings.Contains(brandName, "(") || strings.Contains(brandName, "") {
brandName = strings.Split(brandName, "/")[0]
}
if strings.Contains(brandName, "(") {
brandName = strings.Split(brandName, "(")[0]
}
if strings.Contains(brandName, "") {
brandName = strings.Split(brandName, "")[0]
}
standardBrandId, err := api.GetSkuBrand(categoryLeafId, brandName)
if err != nil {
return 0, err
@@ -907,19 +941,21 @@ func GetTiktokImgList(api *tiktokShop.API, storeId, appOrgCode string, detailImg
return strings.Join(tiktokImg, "|"), detailTiktok, nil
}
func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId int64) (string, error) {
func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId int64, upcCode, upcBrandName, upcTiktokBrandId string) (string, int64, error) {
db := dao.GetDB()
categoryList, err := api.GetCatePropertyV2(categoryLeafId)
if err != nil {
return "", err
return "", 0, err
}
categoryMap := make(map[string][]map[string]interface{})
tiktokBrandId, _ := getTiktokBrandId(api, db, upcCode, upcBrandName, upcTiktokBrandId, categoryLeafId)
for _, v := range categoryList.Data.Data {
if v.Required != model.YES {
continue
}
options := make([]map[string]interface{}, 0)
if v.PropertyName == "品牌" {
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 789194134, "diy_type": v.DiyType})
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": tiktokBrandId, "diy_type": v.DiyType})
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
} else if v.PropertyName == "产地" {
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 13850, "diy_type": v.DiyType})
@@ -934,7 +970,7 @@ func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId i
}
productFormatNew := utils.Format4Output(categoryMap, false)
dao.UpdateSkuNameTiktokAttr(dao.GetDB(), skuNameId, productFormatNew)
return utils.Format4Output(categoryMap, false), nil
return utils.Format4Output(categoryMap, false), tiktokBrandId, nil
}
// GetSpecPrices 解析属性和规格参数